Boost logo

Boost :

From: Itay Maman (itay_maman_at_[hidden])
Date: 2002-04-24 09:41:30

A couple of days ago, I made a post regarding a generic visitor called
Power_visitor, which is basically a static (i.e: compile time based)

The zipped package can be loaded from

Here's a sample usage with an any-like class 'vany' which takes the visitor
type a template parameter:

  struct Any_print_policy {

      template<class V, class H>
      void visit_at(V& , H& host) {
         //host.held is the internal value of the visited vany object
         ost_ << host.held;

      std::string result() { return ost_.str(); }

      std::ostringstream ost_;

   }; //Any_print_policy

   int main() {

      using namespace boost::Power_visitor;

      typedef Power_visitor<Any_print_policy, Member_function_policy>
      t_visitor av;

      typedef vany<t_visitor> t_any;

      t_any a = 1.2;
      t_any b = std::string(" two");


      a = b;

      std::cout << "Result = " << av.get_policy().result() << '\n';
//Output: "Result = 1.2 two two"
      return 0;


Boost list run by bdawes at, gregod at, cpdaniel at, john at