Boost logo

Boost Users :

Subject: Re: [Boost-users] Bind/Function: use reference arguments in template variadic functions
From: Yannick POTIN (yannp63_at_[hidden])
Date: 2013-04-13 08:14:29


>

> Actually, I try to use template variadic functions which can contains references, pointers and/or values which must be converted to boost::function0<void>.

>

> I tried to use forward() but I lose references with it. I tried ref() to but it make values interpreted as references (so ints are broken). So I'm looking for a magic way to use ref() only when needed by the arguments.

>

What do you mean by "when needed by the arguments?"
How do you specify what should have ref added and
what shouldn't?

Well, I tried to make a template pseudo-code to determine which function it needs to use.
Like this code that does not work:

///// Big code to make it working
template<typename W,typename T>
struct SignalArgumentValueConverter { };

template<typename T>
struct SignalArgumentValueConverter<const boost::reference_wrapper<T>,T> {
        static const boost::reference_wrapper<T> convert(T&& t) {
                return boost::ref<T>(t);
        }
};

template<typename T>
struct SignalArgumentValueConverter<T&&,T> {
        static T&& convert(T&& t) {
                return std::forward<T&&>(t);
        }
};

template<typename T>
struct SignalArgumentTypeConverter {
        typedef typename std::conditional<std::is_reference<T>::value,const boost::reference_wrapper<T>,T&&>::type type;

        static type convert(T&& t) {
                return SignalArgumentValueConverter<type,T>::convert(std::forward<T&&>(t));
        }
};

////// Little code to use it
// Note: current is an iterator on a std::vector< boost::function<void(Args…)> >
(*current)(
        SignalArgumentTypeConverter<Args>::convert(boost::forward<Args>(args))...
);

This code does not compile and I think that I may break its code while I made some tests.

Any idea to create something lile that (or even better) ?

Regards,

Yannick POTIN



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