|
Boost : |
From: Eric Niebler (eric_at_[hidden])
Date: 2008-04-07 12:38:07
Peter Dimov wrote:
> Eric Niebler:
>
>> // lvalue
>> result_of<identity(int &)>::type l = identity()(i);
>> assert( &l == &i );
>
> Does this really compile for you?
Yes.
#include <cassert>
#include <boost/utility/result_of.hpp>
struct identity
{
template<typename Sig>
struct result;
template<typename This, typename Arg>
struct result<This(Arg)>
{
typedef Arg type;
};
template<typename Arg>
Arg &operator()(Arg &arg) const
{
return arg;
}
template<typename Arg>
Arg const &operator()(Arg const &arg) const
{
return arg;
}
};
int main()
{
using boost::result_of;
int i = 0;
int const j = 0;
// rvalue
result_of<identity(int)>::type k = identity()(1);
assert( 1 == k );
// lvalue
result_of<identity(int &)>::type l = identity()(i);
assert( &l == &i );
// const lvalue
result_of<identity(int const &)>::type m = identity()(j);
assert( &m == &j );
}
-- Eric Niebler Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk