Boost logo

Boost Users :

Subject: Re: [Boost-users] Testing whether result_of<F(U)> is a valid expression
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2013-02-08 12:26:35


On 08/02/13 11:12, oswin krause wrote:
> Hi,
>
> Is it possible to evaluate, whether a certain argument type given to a
> functor will lead to a valid expression with the result_of template?
>
> i am trying to achieve the following, maybe there is a better way to do it:
>
> template<class T, class F>
> Container< typename boost::result_of<F(T)>::type > transform(
> Container<T> c, F f,
> std::disable_if<valid_expression<F(Block<T>) > >::type* dummy = 0

What do you call a valid expression? F(Block<T>) is certainly not an
expression.

You could test if F::result< F(Block<T>) >::type exists, or whether
declval<F>()(declval< Block<T> >()) is a valid expression.

Both can be done using SFINAE, the latter will require a recent enough
compiler that supports generalized SFINAE (GCC does it since 4.6 I believe).


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