, X<int> x<char> .
, , .
, , .
, , X<> templated , print() ( , ). , , : , - . , , , .
std::function<void ()> , , , "" ( : X<int>, x<char> , , print()).
- , X<int>, x<char> (boost:: variant < > ). , print() .
, :
typedef boost::variant<X<int>, X<char>> genericX;
class print_visitor : public boost::static_visitor<void>
{
public:
template <typename SomeType>
void operator()(const SomeType& x) const
{
}
};
int main()
{
boost::optional<genericX> my_x;
if (type=="int") {
my_x = X<int>(a,b);
} else if(type=="char") {
my_x = X<char>(a,b);
}
if (my_x) {
boost::apply_visitor(print_visitor(), *my_x)
}
}
, : "", , , . " ", .