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)
visitor.

The zipped package can be loaded from
http://groups.yahoo.com/group/boost/files/Power_visitor/power_visitor.zip

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(); }

   private:
      std::ostringstream ost_;

   }; //Any_print_policy

   int main() {

      using namespace boost::Power_visitor;

      typedef Power_visitor<Any_print_policy, Member_function_policy>
t_visitor;
      t_visitor av;

      typedef vany<t_visitor> t_any;

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

      av.start(a).start(b);

      a = b;
      av.start(a);

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

-Itay.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk