1

The article states that for free std::get function overloadings (from 4-6 items) they

Extracts the element of the tuple t whose type is T. Fails to compile if the tuple has more than one element of that type.

Is the last statement a requirements or just a possibility?

I ask the question because std::get< int >(std::make_tuple(1, 2)) compiles fine by clang++ -std=gnu++1z -stdlib=libc++ (live example). Is this tuple's behaviour a libc++ bug or is one conformant to the Standard?

Tomilov Anatoliy
  • 15,657
  • 10
  • 64
  • 169

1 Answers1

2

From the standard ยง20.4.2.6/8, the requirements are:

Requires: The type T occurs exactly once in Types.... Otherwise, the program is ill-formed.

So your program is ill-formed.

The standard even provides an example which is very similar to your situation:

const tuple<int, const int, double, double> t(1, 2, 3.4, 5.6);
const int &i1 = get<int>(t); // OK. Not ambiguous. i1 == 1
const int &i2 = get<const int>(t); // OK. Not ambiguous. i2 == 2
const double &d = get<double>(t); // ERROR. ill-formed

which if you plug in Clang compiles.

Shoe
  • 74,840
  • 36
  • 166
  • 272