Sorry the location below deleted '<' '>' characters which are essential for
templates. Take a look at this location:
http://lists.boost.org/boost-users/2007/11/31849.php
On Tue, May 6, 2008 at 2:26 PM, Ovanes Markarian
Hi!
I had a similar question already. Please take a look at my post and answer from Dave Abrahams
http://archive.netbsd.se/?ml=boost-users&a=2007-10&t=5555956
With Kind Regards, Ovanes
On Tue, May 6, 2008 at 1:23 PM, Germán Diago Gómez
wrote: Hello. I'm trying to compile this code, but it doesn't do the trick and I don't know why.
struct print { typedef void result_type;
template <class T> void operator()(const T & elem) const { std::cout << elem << std::endl; } };
template
struct tuple_for_each_helper { private: Tuple & t_; UnaryF f_; public: typedef typename UnaryF::result_type result_type; tuple_for_each_helper(Tuple & t, UnaryF f) : t_(t), f_(f) { }
result_type operator()(typename boost::enable_if
, void> ::type * = 0) { f_(get<i>(t_)); typename boost::mpl::if_c, tuple_for_each_helper
::type(t_, f_)(); } }; template
struct tuple_for_each_helper { typedef typename UnaryF::result_type result_type; tuple_for_each_helper(Tuple & t, UnaryF f) {} result_type operator()() {} };
template
typename result_of ::type tuple_for_each (Tuple & t, UnaryF f, typename boost::enable_if , void> >::type * = 0) { tuple_for_each_helper (t, f)(); } int main(int argc, char * argv[]) { tuple
t(3, 5.3, "hello", "goodbye"); tuple_for_each(t, print()); } And the error is:
tuple_each.cpp: In function 'int main(int, char**)': tuple_each.cpp:99: error: no matching function for call to 'tuple_for_each(std::tr1::tuple
, std::basic_string , std::tr1::_NullClass, std::tr1::_NullClass, std::tr1::_NullClass, std::tr1::_NullClass, std::tr1::_NullClass, std::tr1::_NullClass>&, print)' If I change boost::enable_if by boost::disable_if the code compiles. But if I check typeid(typename print::result_type).name() and typeid(result_of
::type).name() they are the same. I'm using g++ 4.2.3 and boost 1.34.1. Thanks in advance.