diff --git a/bind_visitor.cpp b/bind_visitor.cpp index 3e79579..1ce7b53 100644 --- a/bind_visitor.cpp +++ b/bind_visitor.cpp @@ -31,32 +31,18 @@ #pragma warning(pop) #endif -// default implementation of visit_each - -namespace boost -{ - template void visit_each(V & v, T const & t, long) - { - v(t, 0); - } -} - -// visitor - -int hash = 0; +// struct visitor { - template void operator()(boost::reference_wrapper const & r, int) const + template void operator()( boost::reference_wrapper const & r ) const { std::cout << "Reference to " << typeid(T).name() << " @ " << &r.get() << " (with value " << r.get() << ")\n"; - hash += r.get(); } - template void operator()(T const &, long) const + template void operator()( T const & t ) const { - std::cout << "Value of type " << typeid(T).name() << '\n'; - ++hash; + std::cout << "Value of type " << typeid(T).name() << " (with value " << t << ")\n"; } }; @@ -70,26 +56,10 @@ int f(int & i, int & j, int) int x = 2; int y = 7; -int detect_errors(bool x) -{ - if(x) - { - std::cerr << "no errors detected.\n"; - return 0; - } - else - { - std::cerr << "test failed.\n"; - return 1; - } -} - int main() { using namespace boost; visitor v; visit_each(v, bind(bind(f, ref(x), _1, 42), ref(y)), 0); - - return detect_errors(hash == 12); }