Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2008-04-08 21:55:21

On Apr 8, 2008, at 9:40 PM, Steven Watanabe wrote:
> Howard Hinnant wrote:
>>> template <class T, class U>
>>> decltype(true ? T() : U()) Min(T&& a, U&& b) {
>>> return b < a ? b : a;
>>> }
> Should this really work if T of U is a reference type and thus cannot
> be default constructed?

You're right. Not by current language rules. The reported error
message could have been better.

By coincidence I'm dealing with a similar problem here:
  , and dealing with it via a promote trait, quite similar to what
I've seen in boost. I.e. the Min signature might look like:

    template <class T, class U> typename promote<T, U>::type Min(T&&
a, U&& b);

With the *default* (and preferably standardized) promote trait looking

template <class T, class U>
struct promote
     static T t;
     static U u;
     typedef decltype(true ? static_cast<T&&>(t) :
static_cast<U&&>(u)) type;

// promote is specializable for client-defined types


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