id summary reporter owner description type status milestone component version severity resolution keywords cc 4967 apply_visitor_delayed_t 's operator() is not const correct zhuo.qiang@… ebf "The operator() overload in Boost.Variant's boost::apply_visitor_delayed_t is not const qualified which I think could be safely add. The benefit of adding const is as following: There are some generic function need to store and call the apply_visitor_delayed_t instance, transform_iterator & transform_range, for example. The following code will not compile without the const quality: ---------------------------------------------------- using namespace boost; using namespace std; typedef variant V; struct times_2_t : public static_visitor { template int operator()(T const& t) const { return 2 * t; }; int operator()(string const& s) const { return 2 * s.size(); }; }; BOOST_AUTO_TEST_CASE(Test) { vector all; all.push_back(1); all.push_back(2); times_2_t times_2; int const result = boost::accumulate( all | boost::adaptors::transformed(apply_visitor(times_2)), 0); BOOST_CHECK_EQUAL(6, result); } --------------------------------------- One way to fix this is using a boost::funciton to hold the apply_visitor_delayed_t instance and pass the wrapper to transformed: --------------------------------------------------------- times_2_t times_2; function f = apply_visitor(times_2); int const result = boost::accumulate( all | boost::adaptors::transformed(apply_visitor(f)), 0); ------------------------------------------------------- However, this will make simple things complex and have runtime cost. So a more direct fix would be add the harmless const qualify to the operator() for apply_visitor_delayed_t The attached is a simply patch: " Patches closed To Be Determined variant Boost 1.45.0 Problem fixed prabhu.swain@…