KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
As I understood all types of boost.variant are parsed into real types (meaning as if boost variant<int, string> a; a="bla-bla" would after compilation turn into string a; a="bla-bla" ) And so I wonder: how to get what type was put into boost variant? What have I tried: #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; }
Tags (comma-separated)
Save Edits
Cancel