Boost logo

Boost :

From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2007-11-26 09:14:14


On 11/26/07, shunsuke <pstade.mb_at_[hidden]> wrote:
> Hi,
>
> What happens if result_of is not consistent with decltype?
>
>
> struct my_fun_t
> {
> template<class Sig>
> struct result;
>
> template<class This>
> struct result<This(int)>
> {
> typedef int type; // avoid dangling.
> };
>
> template<class This>
> struct result<This(int const &)>
> {
> typedef int const & type;
> };
>
> int const & operator()(int const &i) const
> {
> return i;
> }
> };
>
> my_fun_t const my_fun = {};
>
> int main()
> {
> boost::result_of<my_fun_t const(int)>::type x = my_fun(10); // ok in C++98.
> decltype(my_fun(10)) x_ = my_fun(10); // dangling in C++0x.
> }
>
>

I do not think that a polymorphic function object is allowed to lie that way.
The result metafunction must return the exact type which is returned
by operator(). In fact even in TR1 an implementation is allowed to
implement result_of using whatever compiler intrinsic (or trick) and
only fall back to result when everything else fail. Of course in
C++0x, result_of is required to be implemented with decltype (or
equivalent).

--
gpd

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk