Boost logo

Boost Users :

Subject: Re: [Boost-users] Testing whether result_of<F(U)> is a valid expression
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2013-02-08 12:40:25


On Fri, Feb 8, 2013 at 2:12 AM, oswin krause <
oswin.krause_at_[hidden]> 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
> ){
> //slow default implementation
> Container<T> res(c.size());
> std::transform(c.begin(),c.**end(),res.begin(),f):
> return res;
> }
>
> //blocked implmentation of transform
> template<class T, class F>
> Container< typename boost::result_of<F(T)>::type > transform(
> Container<T>, F functor,
> std::enable_if<valid_**expression<F(Block<T>) > >::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<F(Block<T>) > could be implemented
> and right now the only mechanism which get's close to what i want would be
> checking result_of<F(Block<T>)> 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



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