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 | |
| 9 | // UNSUPPORTED: c++98, c++03, c++11, c++14 |
| 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" |
| 37 | #include "type_id.h" |
| 38 | |
Eric Fiselier | 66ddd34 | 2016-11-17 19:23:35 +0000 | [diff] [blame] | 39 | template <class Tp, class Up> |
| 40 | constexpr bool check_tag(Up) { |
| 41 | return std::is_same<Tp, std::decay_t<Tp>>::value |
| 42 | && std::is_same<Tp, Up>::value; |
Eric Fiselier | 58ad17d | 2016-07-23 22:19:19 +0000 | [diff] [blame] | 43 | } |
| 44 | |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 45 | int main(int, char**) { |
Eric Fiselier | 58ad17d | 2016-07-23 22:19:19 +0000 | [diff] [blame] | 46 | // test in_place_t |
| 47 | { |
| 48 | using T = std::in_place_t; |
Eric Fiselier | 66ddd34 | 2016-11-17 19:23:35 +0000 | [diff] [blame] | 49 | static_assert(check_tag<T>(std::in_place)); |
Eric Fiselier | 58ad17d | 2016-07-23 22:19:19 +0000 | [diff] [blame] | 50 | } |
| 51 | // test in_place_type_t |
| 52 | { |
| 53 | using T1 = std::in_place_type_t<void>; |
| 54 | using T2 = std::in_place_type_t<int>; |
| 55 | using T3 = std::in_place_type_t<const int>; |
Eric Fiselier | 66ddd34 | 2016-11-17 19:23:35 +0000 | [diff] [blame] | 56 | static_assert(!std::is_same<T1, T2>::value && !std::is_same<T1, T3>::value); |
| 57 | static_assert(!std::is_same<T2, T3>::value); |
| 58 | static_assert(check_tag<T1>(std::in_place_type<void>)); |
| 59 | static_assert(check_tag<T2>(std::in_place_type<int>)); |
| 60 | static_assert(check_tag<T3>(std::in_place_type<const int>)); |
Eric Fiselier | 58ad17d | 2016-07-23 22:19:19 +0000 | [diff] [blame] | 61 | } |
| 62 | // test in_place_index_t |
| 63 | { |
| 64 | using T1 = std::in_place_index_t<0>; |
| 65 | using T2 = std::in_place_index_t<1>; |
| 66 | using T3 = std::in_place_index_t<static_cast<size_t>(-1)>; |
Eric Fiselier | 66ddd34 | 2016-11-17 19:23:35 +0000 | [diff] [blame] | 67 | static_assert(!std::is_same<T1, T2>::value && !std::is_same<T1, T3>::value); |
| 68 | static_assert(!std::is_same<T2, T3>::value); |
| 69 | static_assert(check_tag<T1>(std::in_place_index<0>)); |
| 70 | static_assert(check_tag<T2>(std::in_place_index<1>)); |
| 71 | 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] | 72 | } |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 73 | |
| 74 | return 0; |
Eric Fiselier | 66ddd34 | 2016-11-17 19:23:35 +0000 | [diff] [blame] | 75 | } |