|
Boost Users : |
Subject: [Boost-users] [Fusion] functor fused and unfused at the same time
From: alfC (alfredo.correa_at_[hidden])
Date: 2010-11-09 07:52:14
Hi,
I have an internally generated templated functor that naturally takes
fusion sequences. since this function can also be called by the user I
want to make it also "unfused"
For example, the struct is
struct F{
typedef result_of::make_map<
p , q ,
double, double
>::type mapped_arguments;
template<class Args> struct result{ typedef double type; };
double operator()(mapped_arguments const& args) const{
return at_key<p>(args) + at_key<q>(args);
}
};
and can be called as
F f;
f(make_map<p,q>(one, two));
(I need this because of internal conventions of the library)
but I want it to be also called as
f(one, two); // somehow
(I need this because the user can call it)
I tried this
struct F : unfused<F const&>{
typedef result_of::make_map<
p , q ,
double, double
>::type mapped_arguments;
template<class Args> struct result{ typedef double type; };
double operator()(mapped_arguments const& args) const{
return at_key<p>(args) + at_key<q>(args);
}
};
but I get:
usr/include/boost/utility/result_of.hpp:80: error: invalid use of
incomplete type const struct F
I then tried this
struct F_impl{
typedef result_of::make_map<
p , q ,
double, double
>::type mapped_arguments;
template<class Args> struct result{ typedef double type; };
double operator()(mapped_arguments const& args) const{
return at_key<p>(args) + at_key<q>(args);
}
};
struct F : F_impl, unfused<F_impl const&>{
F() : unfused<F_impl const&>((F_impl const&)*this){}
F(F_impl const& f) : F_impl(f), unfused<F_impl const&>((F_impl
const&)*this){}
template<class Args> struct result{ typedef typename
F_impl::result<Args>::type type; };
using F_impl::operator();
};
which seems to work but looks and feels awkward. It works in the sense
that
F f;
can be called
clog << f(make_map<p,q>(1.,2.)) << endl;
clog << fu(uno, dos) << endl;
Is there any simpler way to get this.
Thank you,
Alfredo
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