Hi, I need to be explicit about a function call, but unsure quite how to make it work, cut down example follows: struct M { static void foo() { ... } }; struct R { static void foo() { ... } }; struct Func { typedef void result_type; template <typename T, typename U> result_type operator()(U& u) const { T::foo(); // call on either M or R // do something with 'u' } }; int main(int argc, char** argv) { using namespace boost::mpl; typedef vector<M, R> vec; Func f; Object instance; for_each<vec>(boost::bind(&Func::operator()<XXX, Object>, boost::ref(f), instance) ); return 0; } Question is, what goes in at XXX above? I was thinking something along the lines of: boost::mpl::bind<boost::mpl::_1> ..but well, that doesn't work. All help appreciated. Cheers, -- Manfred
Manfred Doudar wrote:
Hi,
I need to be explicit about a function call, but unsure quite how to make it work, cut down example follows:
struct M { static void foo() { ... } };
struct R { static void foo() { ... } };
struct Func { typedef void result_type;
template <typename T, typename U> result_type operator()(U& u) const { T::foo(); // call on either M or R
// do something with 'u' } };
int main(int argc, char** argv) { using namespace boost::mpl;
typedef vector<M, R> vec;
Func f; Object instance; for_each<vec>(boost::bind(&Func::operator()<XXX, Object>, boost::ref(f), instance) );
return 0; }
Question is, what goes in at XXX above?
I was thinking something along the lines of:
boost::mpl::bind<boost::mpl::_1>
..but well, that doesn't work.
Try passing an argument of type M or R as a parameter: template<typename T, typename U> void operator()(const T&, U& u) const { T::foo(); } ... for_each<vec>(boost::bind(boost::ref(f), _1, instance)) In Christ, Steven Watanabe
On Mon, 22 Feb 2010 20:51:58 -0800 Steven Watanabe <watanabesj@gmail.com> wrote:
Manfred Doudar wrote:
Hi,
I need to be explicit about a function call, but unsure quite how to make it work, cut down example follows:
struct M { static void foo() { ... } };
struct R { static void foo() { ... } };
struct Func { typedef void result_type;
template <typename T, typename U> result_type operator()(U& u) const { T::foo(); // call on either M or R
// do something with 'u' } };
int main(int argc, char** argv) { using namespace boost::mpl;
typedef vector<M, R> vec;
Func f; Object instance; for_each<vec>(boost::bind(&Func::operator()<XXX, Object>, boost::ref(f), instance) );
return 0; }
Question is, what goes in at XXX above?
I was thinking something along the lines of:
boost::mpl::bind<boost::mpl::_1>
..but well, that doesn't work.
Try passing an argument of type M or R as a parameter:
template<typename T, typename U> void operator()(const T&, U& u) const { T::foo(); } ... for_each<vec>(boost::bind(boost::ref(f), _1, instance))
Yes, I know I can do that, but I don't want to, because I don't need a T instance, I just need the type. Any ideas how I can achieve that would be appreciated. Cheers, -- Manfred
On Mon, 22 Feb 2010 20:51:58 -0800 Steven Watanabe <watanabesj@gmail.com> wrote:
Manfred Doudar wrote:
Hi,
using namespace boost::mpl;
typedef vector<M, R> vec;
Func f; Object instance; for_each<vec>(boost::bind(&Func::operator()<XXX, Object>, boost::ref(f), instance) );
Question is, what goes in at XXX above?
I was thinking something along the lines of:
boost::mpl::bind<boost::mpl::_1>
..but well, that doesn't work.
Try passing an argument of type M or R as a parameter:
template<typename T, typename U> void operator()(const T&, U& u) const { T::foo(); } ... for_each<vec>(boost::bind(boost::ref(f), _1, instance))
To both Steven & Rutger who answered - a short note of thanks. I was indeed aware of resloving the problem with the above mentioned approach, but was hoping for an explicit invocation of some kind without having to make use of a superfluous tag T in the parameter list. ..No matter. With thanks again to Steven and Rutger. Cheers, -- Manfred
Manfred Doudar wrote:
Question is, what goes in at XXX above?
I was thinking something along the lines of:
boost::mpl::bind<boost::mpl::_1>
..but well, that doesn't work.
All help appreciated.
If you're in the position to use tag dispatching, one idea would be to update Func to struct Func { typedef void result_type; template <typename U, typename T> result_type operator()(U& u, T ) const {} }; and the call to boost::mpl::for_each<vec>( boost::bind( boost::ref(f), instance, _1 ) ); which compiles on my system. Cheers, Rutger
participants (3)
-
Manfred Doudar
-
Rutger ter Borg
-
Steven Watanabe