Testing whether result_of<F(U)> is a valid expression

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

2013/2/8 oswin krause
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
Container< typename boost::result_of ::type > transform( Container<T> c, F f, std::disable_if >::type* dummy = 0 ){ //slow default implementation Container<T> res(c.size()); std::transform(c.begin(),c.**end(),res.begin(),f): return res; } //blocked implmentation of transform template
Container< typename boost::result_of ::type > transform( Container<T>, F functor, std::enable_if >::type* dummy = 0 ){ //functor supports fast implementation Container<T> res(c.size()); std::transform(c.blocks().**begin(),c.blocks().end(),res.**blocks().begin(),functor): return res; }
the question is, how valid_expression
could be implemented and right now the only mechanism which get's close to what i want would be checking result_of is valid.
Hmm... I have implemented `has_call

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
Container< typename boost::result_of ::type > transform( Container<T> c, F f, std::disable_if >::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).

Hi, thanks for both answers! Jeffreys suggestion is just perfect and so extremely nice, that i just have to link it :) http://www.boost.org/doc/libs/1_52_0/doc/html/proto/appendices.html#boost_pr... awesome stuff! Also thanks Mathias. Your trick using F::result< F(Block<T>) >::type instead of boost::result_of is a nice way to solve the problem pre C++11, however it would not generalize to C++11 compilers where I would not be able to require the existence of the struct. As I want to support both, this is unfortunately ruled out. But many thanks! Greetings, Oswin First of all, I can't use C++11, so i am bit a in a disadvantage. On 08.02.2013 18:26, Mathias Gaunard wrote:
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 mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On Fri, Feb 8, 2013 at 2:12 AM, oswin krause < oswin.krause@ruhr-uni-bochum.de> 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
Container< typename boost::result_of ::type > transform( Container<T> c, F f, std::disable_if >::type* dummy = 0 ){ //slow default implementation Container<T> res(c.size()); std::transform(c.begin(),c.**end(),res.begin(),f): return res; } //blocked implmentation of transform template
Container< typename boost::result_of ::type > transform( Container<T>, F functor, std::enable_if >::type* dummy = 0 ){ //functor supports fast implementation Container<T> res(c.size()); std::transform(c.blocks().**begin(),c.blocks().end(),res.**blocks().begin(),functor): return res; }
the question is, how valid_expression
could be implemented and right now the only mechanism which get's close to what i want would be checking result_of is valid.
Google search "boost can_be_called" or similar. Among other hits will probably be something Eric Niebler wrote for Boost.Proto (within whose documentation I think there's an explanation of how it works). TONGARI's implementation also pops up, I think. - Jeff
participants (4)
-
Jeffrey Lee Hellrung, Jr.
-
Mathias Gaunard
-
oswin krause
-
TONGARI