Boost Variant: как получить в настоящее время проводимый тип?
Как я поняла все типыboost.variant разбираются на реальные типы (то есть, как будто повышениеvariant<int, string> a; a="bla-bla"
после компиляции превратится вstring a; a="bla-bla"
) И вот мне интересно: как получить, какой тип был вставлен в буст-вариант?
Что я пробовал:
#include <boost/variant.hpp>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include <iostream>
int main()
{
typedef boost::function<double (double x)> func0;
typedef boost::function<double (double x, double y)> func1;
typedef boost::variant<int, func0, func1> variant_func;
func1 fn = std::plus<double>();
variant_func v(fn);
std::cout << boost::get<func1>(v)(1.0, 1.0) << std::endl; // this works
//std::cout << boost::get<v::type>(v)(1.0, 1.0) << std::endl; // this does not compile with many errors
// std::cout << (v)(1.0, 1.0) << std::endl; // this fails with Error 1 error C2064: term does not evaluate to a function taking 2 arguments
std::cin.get();
return 0;
}