The Standard says that std::tuple has the following member functions
constexpr tuple();
explicit tuple(const Types&...);
Can someone please explain what is supposed to happen for std::tuple<>?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I believe this is a minor error in the standard. Clearly, when the
Typesparameter pack is empty, the two constructor calls are equivalent and cannot be overloaded (see C++11 section 13). (Further note that the constructor usingTypesis not a member template either –if it was, then it would be a legal overload.).In other words, this code will not compile:
e.g., a g++ v4.8 snapshot outputs:
This can be fixed by using partial specialization:
which will compile correctly.
It appears the standard wanted a
constexprdefault constructor was so thatstd::tuple<> var;could be written instead of writingstd::tuple<> var();orstd::tuple<> var{};because of the use ofexplicitwith the other constructor. Unfortunately, its definition ofstd::tupledoes not work for tuples of size zero. The standard does permit such in section 20.4.2.7 (relational operators) though, “For any two zero-length tuples, […]”. Oops! 🙂