Implement C++17 tuple bits. Including apply and make_from_tuple.

This patch upgrades <tuple> to be C++17 compliant by implementing:

* tuple_size_v: This was forgotten when implementing the other _v traits.
* std::apply: This was added via LFTS v1 in p0220r1.
* std::make_from_tuple: This was added in p0209r2.


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@275745 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2016-07-18 00:35:56 +00:00
parent 41aafc25c6
commit 5839fedf28
9 changed files with 1205 additions and 2 deletions

View File

@@ -0,0 +1,27 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03
// <tuple>
// template <class... Types>
// class tuple_size<tuple<Types...>>
// : public integral_constant<size_t, sizeof...(Types)> { };
// Expect failures with a reference type, pointer type, and a non-tuple type.
#include <tuple>
int main()
{
(void)std::tuple_size<std::tuple<> &>::value; // expected-error {{implicit instantiation of undefined template}}
(void)std::tuple_size<int>::value; // expected-error {{implicit instantiation of undefined template}}
(void)std::tuple_size<std::tuple<>*>::value; // expected-error {{implicit instantiation of undefined template}}
}

View File

@@ -0,0 +1,26 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11, c++14
// <tuple>
// template <class T> constexpr size_t tuple_size_v = tuple_size<T>::value;
// Expect failures with a reference type, pointer type, and a non-tuple type.
#include <tuple>
int main()
{
(void)std::tuple_size_v<std::tuple<> &>; // expected-note {{requested here}}
(void)std::tuple_size_v<int>; // expected-note {{requested here}}
(void)std::tuple_size_v<std::tuple<>*>; // expected-note {{requested here}}
// expected-error@tuple:* 3 {{implicit instantiation of undefined template}}
}

View File

@@ -0,0 +1,43 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11, c++14
// <tuple>
// template <class T> constexpr size_t tuple_size_v = tuple_size<T>::value;
#include <tuple>
#include <utility>
#include <array>
template <class Tuple, int Expect>
void test()
{
static_assert(std::tuple_size_v<Tuple> == Expect, "");
static_assert(std::tuple_size_v<Tuple> == std::tuple_size<Tuple>::value, "");
static_assert(std::tuple_size_v<Tuple const> == std::tuple_size<Tuple>::value, "");
static_assert(std::tuple_size_v<Tuple volatile> == std::tuple_size<Tuple>::value, "");
static_assert(std::tuple_size_v<Tuple const volatile> == std::tuple_size<Tuple>::value, "");
}
int main()
{
test<std::tuple<>, 0>();
test<std::tuple<int>, 1>();
test<std::array<int, 1>, 1>();
test<std::tuple<int, int>, 2>();
test<std::pair<int, int>, 2>();
test<std::array<int, 2>, 2>();
test<std::tuple<int, int, int>, 3>();
test<std::array<int, 3>, 3>();
}