22 May 15:24
design question with using call_traits and functors
From: Hansi <hansipet <at> web.de>
Subject: design question with using call_traits and functors
Newsgroups: gmane.comp.lib.boost.user
Date: 2008-05-22 13:24:23 GMT
Subject: design question with using call_traits and functors
Newsgroups: gmane.comp.lib.boost.user
Date: 2008-05-22 13:24:23 GMT
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
(Continue reading)
RSS Feed