Eric Fiselier | 58ad17d | 2016-07-23 22:19:19 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Eric Fiselier | 58ad17d | 2016-07-23 22:19:19 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Louis Dionne | 31cbe0f | 2020-06-01 10:38:23 -0400 | [diff] [blame] | 9 | // UNSUPPORTED: c++03, c++11, c++14 |
Eric Fiselier | 58ad17d | 2016-07-23 22:19:19 +0000 | [diff] [blame] | 10 | |
| 11 | // <utility> |
| 12 | |
Eric Fiselier | 66ddd34 | 2016-11-17 19:23:35 +0000 | [diff] [blame] | 13 | // struct in_place_t { |
| 14 | // explicit in_place_t() = default; |
| 15 | // }; |
| 16 | // inline constexpr in_place_t in_place{}; |
| 17 | |
Eric Fiselier | 58ad17d | 2016-07-23 22:19:19 +0000 | [diff] [blame] | 18 | // template <class T> |
Eric Fiselier | 66ddd34 | 2016-11-17 19:23:35 +0000 | [diff] [blame] | 19 | // struct in_place_type_t { |
| 20 | // explicit in_place_type_t() = default; |
| 21 | // }; |
| 22 | // template <class T> |
| 23 | // inline constexpr in_place_type_t<T> in_place_type{}; |
| 24 | |
| 25 | // template <size_t I> |
| 26 | // struct in_place_index_t { |
| 27 | // explicit in_place_index_t() = default; |
| 28 | // }; |
| 29 | // template <size_t I> |
| 30 | // inline constexpr in_place_index_t<I> in_place_index{}; |
Eric Fiselier | 58ad17d | 2016-07-23 22:19:19 +0000 | [diff] [blame] | 31 | |
| 32 | #include <utility> |
| 33 | #include <cassert> |
| 34 | #include <memory> |
| 35 | |
| 36 | #include "test_macros.h" |
Eric Fiselier | 58ad17d | 2016-07-23 22:19:19 +0000 | [diff] [blame] | 37 | |
Eric Fiselier | 66ddd34 | 2016-11-17 19:23:35 +0000 | [diff] [blame] | 38 | template <class Tp, class Up> |
| 39 | constexpr bool check_tag(Up) { |
| 40 | return std::is_same<Tp, std::decay_t<Tp>>::value |
| 41 | && std::is_same<Tp, Up>::value; |
Eric Fiselier | 58ad17d | 2016-07-23 22:19:19 +0000 | [diff] [blame] | 42 | } |
| 43 | |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 44 | int main(int, char**) { |
Eric Fiselier | 58ad17d | 2016-07-23 22:19:19 +0000 | [diff] [blame] | 45 | // test in_place_t |
| 46 | { |
| 47 | using T = std::in_place_t; |
Eric Fiselier | 66ddd34 | 2016-11-17 19:23:35 +0000 | [diff] [blame] | 48 | static_assert(check_tag<T>(std::in_place)); |
Eric Fiselier | 58ad17d | 2016-07-23 22:19:19 +0000 | [diff] [blame] | 49 | } |
| 50 | // test in_place_type_t |
| 51 | { |
| 52 | using T1 = std::in_place_type_t<void>; |
| 53 | using T2 = std::in_place_type_t<int>; |
| 54 | using T3 = std::in_place_type_t<const int>; |
Eric Fiselier | 66ddd34 | 2016-11-17 19:23:35 +0000 | [diff] [blame] | 55 | static_assert(!std::is_same<T1, T2>::value && !std::is_same<T1, T3>::value); |
| 56 | static_assert(!std::is_same<T2, T3>::value); |
| 57 | static_assert(check_tag<T1>(std::in_place_type<void>)); |
| 58 | static_assert(check_tag<T2>(std::in_place_type<int>)); |
| 59 | static_assert(check_tag<T3>(std::in_place_type<const int>)); |
Eric Fiselier | 58ad17d | 2016-07-23 22:19:19 +0000 | [diff] [blame] | 60 | } |
| 61 | // test in_place_index_t |
| 62 | { |
| 63 | using T1 = std::in_place_index_t<0>; |
| 64 | using T2 = std::in_place_index_t<1>; |
| 65 | using T3 = std::in_place_index_t<static_cast<size_t>(-1)>; |
Eric Fiselier | 66ddd34 | 2016-11-17 19:23:35 +0000 | [diff] [blame] | 66 | static_assert(!std::is_same<T1, T2>::value && !std::is_same<T1, T3>::value); |
| 67 | static_assert(!std::is_same<T2, T3>::value); |
| 68 | static_assert(check_tag<T1>(std::in_place_index<0>)); |
| 69 | static_assert(check_tag<T2>(std::in_place_index<1>)); |
| 70 | static_assert(check_tag<T3>(std::in_place_index<static_cast<size_t>(-1)>)); |
Eric Fiselier | 58ad17d | 2016-07-23 22:19:19 +0000 | [diff] [blame] | 71 | } |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 72 | |
| 73 | return 0; |
Eric Fiselier | 66ddd34 | 2016-11-17 19:23:35 +0000 | [diff] [blame] | 74 | } |