boost::variant conversion to type
I have the following variant from the boost lib: typedef boost::variant<int, float, double, long, bool, std::string, boost::posix_time::ptime> variant; Now I want to get a value from a variable declared as ' value ' in a struct node , so I thought I could work generic and call the function as such: find_attribute<long>(attribute); , however the compiler says it cannot cast from variant to long or any other type I give it. What am I doing wrong? template <typename T> T find_attribute(const std::string& attribute) { std::vector<boost::shared_ptr<node> >::iterator nodes_iter = _request->begin();