Boost logo

Boost Users :

From: Hansi (hansipet_at_[hidden])
Date: 2008-05-22 09:24:23


Hello,

I want to make a functor which uses automatically an reference type if
the provided value isn't a pointer.

Now I have thougth to use the call_traits library.

template<typename Value>
struct Setter
{
        typedef void result_type;

        void operator()(const std::wstring& newVal, Value* pVal)
        {
                *pVal = boost::lexical_cast<typename Value>(newVal);
        }

        void operator()(const std::wstring& newVal, typename
boost::call_traits<Value>::reference refVal)
        {
                refVal = boost::lexical_cast<typename Value>(newVal);
        }
};

To call the function I have the following statement:

SetValue setter = boost::bind(Setter<short>(),_1,x);

Now the only thing that I don't like very much is that the user has to
provide the template argument for setter. Is there some possibility to
solve it that the template argument is automatically deduced?
Important is that I have to possible calls one when the value is
provided as value -> I need to have a reference parameter and the other
is when a pointer is provided.

It would be great if someone can give me a hint.

Best regards
Hansjörg


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