Boost logo

Boost Users :

From: Stjepan Rajko (stipe_at_[hidden])
Date: 2008-08-11 13:40:35


On Mon, Aug 11, 2008 at 9:33 AM, joel falcou <joel.falcou_at_[hidden]> wrote:
>
> I was trying to use it as a simple traits to see if a given type fullfilled
> the result_of protocol
> whatever the arguments used. It works ok for the result_type variant but now
> I see it's still incomplete. The problem is that I can't see, for an
> arbitrary result structure, how I can see if it actually has at least one
> overload that has a proper nested type typedef.
>

I can't either :-)

> Typical use is :
>
> For F a given type, support_result_of_protocol<F>::type evaluates as a
> compile time boolean indicating if either F has a nested result structure or
> result_type typedef. It doesn't make any assumptions on wether or nor result
> is correcly implemented.
>
> As for testing if a particuliar set of arguments produces a valid result_of,
> one can easily do :
>
> template< class F
> , template<class> class T = boost::result_of<F>::type
> > struct valid_impl
> {
> typedef void type;
> };
>
> template<class F, class EnableIf = void>
> struct produce_valid_result_of : boost::false_type {};
>
> template<class F>
> struct produce_valid_result_of<F,typename valid_impl<F>::type> :
> boost::true_type {};
>
> or did I miss something in your question ?

I think you got my question, but that won't work. If you fix it to:

template< class F
        , typename T = typename boost::result_of<F>::type
> struct valid_impl
{
  typedef void type;
};

template<class F, class EnableIf = void>
struct produce_valid_result_of : boost::false_type {};

template<class F>
struct produce_valid_result_of<F,typename valid_impl<F>::type> :
boost::true_type {};

...and then try:

struct x
{};

std::cout << produce_valid_result_of<x(x)>::type::value << std::endl;

... you will get an error. I get:
/Development/boost/boost/utility/result_of.hpp: In instantiation of
'boost::detail::result_of_nested_result<x, x ()(x)>':
/Development/boost/boost/utility/result_of.hpp:38: instantiated from
'boost::detail::result_of_impl<x, x ()(x), false>'
/Development/boost/boost/utility/result_of.hpp:31: instantiated from
'boost::result_of<x ()(x)>'
../../libs/patterns/example/video_gesture_recognition.cpp:224:
instantiated from here
/Development/boost/boost/utility/result_of.hpp:73: error: no class
template named 'result' in 'struct x'

With the way boost::result_of is implemented, I couldn't find a way to
make an approach like the above work. The best I could do was the
result_of_defined code.

Kind regards,

Stjepan


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