Boost logo

Boost :

Subject: Re: [boost] Does boost help in creating generic function wrappers?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-07-14 22:55:44


AMDG

Andy Venikov wrote:
> In c++0x, creating a generic function wrapper is a bliss:
>
> template <typename Func>
> class gen_wrapper
> {
> Func && func_;
> public:
> gen_wrapper(Func && in) : func_(in) {}
>
> template <typename ... Prms>
> /*deduce result here */
> operator() (Prms && ... prms)
> {
> //Do something special here.
> //NOTE: we can operate with arguments here too
>
> return func_(std::forward<Prms>(prms)...);
> }
>
> };
>
> That's it.
>
> But if I don't have C++0x, can boost help here?
>
> functional/forward_adapter won't work since it hides function
> parameters, it only lets you operate with the function.

What do you mean by "hides function parameters"?

> It looks like it may be possible to do that by using boost/preprocessor
> I'll have to generate a whole lot of overloads with O(2^N) (because of
> the overload on (T &) or (T const &) for every argument).
> But it looks pretty dounting. It's basically what forward_adapter had
> to do.
>
> Isn't there a ready-made library that would allow me to generate all
> of the overloads?

Just define your wrapper to take references, and wrap it in forward_adapter.
This should have exactly the same effect as defining all the overloads
yourself.

In Christ,
Steven Watanabe


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk