Boost logo

Boost :

Subject: Re: [boost] is_range metafunction
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2008-10-06 06:58:03

Daniel Walker wrote:

> That's great news! That would do the trick!

Indeed, it's pretty cool.
In C++0x, if you write

template<typename T>
auto foo(T&& t) -> decltype(

Then that definition is only visible if T has a nullary foo member function.
It's basically the same as type inference in functional programming.

As of today, in GCC 4.4, you can do something equivalent but have to be
significantly more verbose:

template<typename T, size_t Cond>
struct foo_type
     typedef decltype(((T*)0)->foo()) type;

template<typename T>
typename foo_type<T, sizeof(((T*)0)->foo() > 0)>::type foo(T&& t)

(You cannot put decltype directly in the return type because of name
mangling issues)

Boost list run by bdawes at, gregod at, cpdaniel at, john at