| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 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 |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// UNSUPPORTED: c++03, c++11, c++14 |
| 10 |
|
| 11 |
// <utility> |
| 12 |
|
| 13 |
// struct in_place_t { |
| 14 |
// explicit in_place_t() = default; |
| 15 |
// }; |
| 16 |
// inline constexpr in_place_t in_place{}; |
| 17 |
|
| 18 |
// template <class T> |
| 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{}; |
| 31 |
|
| 32 |
#include <cassert> |
| 33 |
#include <memory> |
| 34 |
#include <type_traits> |
| 35 |
#include <utility> |
| 36 |
|
| 37 |
template <class Tp, class Up> |
| 38 |
constexpr bool check_tag(Up) { |
| 39 |
return std::is_same<Tp, std::decay_t<Tp>>::value |
| 40 |
&& std::is_same<Tp, Up>::value; |
| 41 |
} |
| 42 |
|
| 43 |
int main(int, char**) { |
| 44 |
// test in_place_t |
| 45 |
{ |
| 46 |
using T = std::in_place_t; |
| 47 |
static_assert(check_tag<T>(std::in_place)); |
| 48 |
} |
| 49 |
// test in_place_type_t |
| 50 |
{ |
| 51 |
using T1 = std::in_place_type_t<void>; |
| 52 |
using T2 = std::in_place_type_t<int>; |
| 53 |
using T3 = std::in_place_type_t<const int>; |
| 54 |
static_assert(!std::is_same<T1, T2>::value && !std::is_same<T1, T3>::value); |
| 55 |
static_assert(!std::is_same<T2, T3>::value); |
| 56 |
static_assert(check_tag<T1>(std::in_place_type<void>)); |
| 57 |
static_assert(check_tag<T2>(std::in_place_type<int>)); |
| 58 |
static_assert(check_tag<T3>(std::in_place_type<const int>)); |
| 59 |
} |
| 60 |
// test in_place_index_t |
| 61 |
{ |
| 62 |
using T1 = std::in_place_index_t<0>; |
| 63 |
using T2 = std::in_place_index_t<1>; |
| 64 |
using T3 = std::in_place_index_t<static_cast<std::size_t>(-1)>; |
| 65 |
static_assert(!std::is_same<T1, T2>::value && !std::is_same<T1, T3>::value); |
| 66 |
static_assert(!std::is_same<T2, T3>::value); |
| 67 |
static_assert(check_tag<T1>(std::in_place_index<0>)); |
| 68 |
static_assert(check_tag<T2>(std::in_place_index<1>)); |
| 69 |
static_assert(check_tag<T3>(std::in_place_index<static_cast<std::size_t>(-1)>)); |
| 70 |
} |
| 71 |
|
| 72 |
return 0; |
| 73 |
} |