//demo a simple recursive variant. // #include "boost/variant.hpp" #include "boost/blank.hpp" #include #include #include template struct list_bounded ; template using list_var= boost::variant < boost::blank , boost::recursive_wrapper< list_bounded< T> > > ; template struct list_bounded { T head; list_var tail; list_bounded ( T a_head , list_varconst& a_tail ) : head(a_head) , tail(a_tail) { std::cout<<"CTOR_COPY:"<&& a_tail ) : head(a_head) , tail(std::forward >(a_tail)) { std::cout<<"MOVE_COPY:"< { template std::string operator()(const list_bounded& lst) const { std::ostringstream ost; ost << "( "; ost << lst.head <<", "; ost << boost::apply_visitor( list_printer(), lst.tail); ost << ") "; return ost.str(); } template std::string operator()(const T& operand) const { std::ostringstream ost; ost << operand << ' '; return ost.str(); } }; template< typename T> std::ostream& operator<< ( std::ostream& sout , list_varconst& a_list ) { list_printer prtr; std::string result=boost::apply_visitor( prtr, a_list); sout< list_int_t; list_int_t list_empty; std::cout << __LINE__<<":list_empty constructed which="<( 1, list_empty)); std::cout << __LINE__<<":list_empty copied which="<( 2, std::move(list_1))); std::cout << __LINE__<<":list_1 moved which="<