Boost logo

Boost :

From: Itay Maman (itay_maman_at_[hidden])
Date: 2002-04-22 10:37:05


Hi

I just uploaded a Power_visitor library, which implements a generic,
compile-time based, visitor. Although it is

intrusive, I think it may have some relevancy to the on-going discussion
regarding any's visitability.

http://groups.yahoo.com/group/boost/files/Power_visitor/power_visitor.zip

(The code has been tested on MSVC6 and GCC 3.04)

All sorts of feedback are welcome.
Thanks, Itay.

[itay_maman_at_[hidden]]

//A simple demo:

#include <iostream>
#include <boost/power_visitor.hpp>
using boost::Power_visitor::Accepting_visitor;

struct Rect : Accepting_visitor<Rect> {
   int area() { return 25; }
};

struct Circle : Accepting_visitor<Circle> {
   int area() { return 50; }
};

struct Total_policy {
  Total_policy() : total_(0) { }

  template<class V, class H>
  void visit_at(V&, H& host) {
     total_ += host.area();
  }

  int result() { return total_; }

private:
  int total_;
}; //Total_policy

int main() {

  using namespace boost::Power_visitor;
  Power_visitor<Total_policy> vis;

  Rect rect;
  Circle circle;

  vis.start(rect);
  vis.start(circle);
  std::cout << "Total area = " << vis.get_policy().result() << '\n';

  return 0;
}


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