|
Boost Users : |
Subject: Re: [Boost-users] variadic template function using fusion vector
From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2010-01-14 13:55:20
Roman Perepelitsa wrote:
> 2010/1/13 noman javed <noman_bwp_at_[hidden] <mailto:noman_bwp_at_[hidden]>>
>
>
> You can do that, but execute must be a function object instead of function.
>
> #include <boost/fusion/functional/adapter/unfused.hpp>
>
> struct execute_impl
> {
> template <class Seq>
> struct result
> {
> typedef void type;
> };
>
Yeah, used to be that way. And works (by "coincidence" :-).
Fusion has been changed at some point to use the
boost::result_of protocol for result type computation.
Thus, to really get to the argument vector you'll have to
write:
template< typename Signature >
struct result;
template< class Self, class ArgSeq >
struct result< Self(ArgSeq&) > // <- NOTE: deducing
// [... defines type memember 'type']
Anyway, in this very case the result type does not depend
on the arguments and so it's sufficient to just write:
typedef void result_type;
> template <class Seq>
> void operator()(Seq const & s) const
> {
> // s contains all arguments passed to execute.
> }
> };
>
> boost::fusion::unfused<execute_impl> execute;
>
> int main()
> {
> const char* s = "hello";
> int n = 42;
> execute(s, n);
> }
>
> Here "execute" suffers from perfect forwarding problem, which you can
> solve by using perfect forwarding adaptor. There is one in p-stade
> <http://p-stade.sourceforge.net/egg/doc/html/egg/function_adaptors.html#egg.function_adaptors.perfect>
> and also I remember seeing one being proposed for boost, but I can't
> find it.
>
Once Fusion's Functional adapters used to attack the Forwarding Problem
themselves. Today, there's Boost.Functional.Forward (and .Factory in
case u want to e.g. fusion::invoke constructors).
Regards,
Tobias
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net