The Standard says that std::tuple
has the following member functions
constexpr tuple();
explicit tuple(const Types&...);
C
I guess the definition given in the standard is supposed to be pseudocode. That is the case with many of the definitions in the standard; it contains several requirements that are given verbally, but are satisfiable only with tricks like enable_if
. This seems to be an example where the C++-like pseudocode notation can actually lead to illegal C++ when trying to instantiate such an empty tuple (or it might just be an omission).
Both stdlibc++ and libc++ have an explicit specialization for the zero-element tuple. For example, in stdlibc++:
// Explicit specialization, zero-element tuple.
template<>
class tuple<>
{
public:
void swap(tuple&) noexcept { /* no-op */ }
};
with an implicitly-defined unambiguous default constructor.
Libc++ does not explicitly declare the parameterless default constructor. Presumably the templated constructor is then chosen as default constructor for non-empty tuples.
Interestingly, the two libraries disagree on what members the empty tuple has. For example, the following compiles with libc++, but not with libstdc++:
#include
#include
int main() {
std::tuple<> t(std::allocator_arg, std::allocator());
}