blob: 007c7a5bf1349828b6a4116ac0691089e11333e3 [file] [log] [blame]
Eric Fiselier58ad17d2016-07-23 22:19:19 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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 Fiselier58ad17d2016-07-23 22:19:19 +00006//
7//===----------------------------------------------------------------------===//
8
Louis Dionne31cbe0f2020-06-01 10:38:23 -04009// UNSUPPORTED: c++03, c++11, c++14
Eric Fiselier58ad17d2016-07-23 22:19:19 +000010
11// <utility>
12
Eric Fiselier66ddd342016-11-17 19:23:35 +000013// struct in_place_t {
14// explicit in_place_t() = default;
15// };
16// inline constexpr in_place_t in_place{};
17
Eric Fiselier58ad17d2016-07-23 22:19:19 +000018// template <class T>
Eric Fiselier66ddd342016-11-17 19:23:35 +000019// 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 Fiselier58ad17d2016-07-23 22:19:19 +000031
32#include <utility>
33#include <cassert>
34#include <memory>
35
36#include "test_macros.h"
Eric Fiselier58ad17d2016-07-23 22:19:19 +000037
Eric Fiselier66ddd342016-11-17 19:23:35 +000038template <class Tp, class Up>
39constexpr bool check_tag(Up) {
40 return std::is_same<Tp, std::decay_t<Tp>>::value
41 && std::is_same<Tp, Up>::value;
Eric Fiselier58ad17d2016-07-23 22:19:19 +000042}
43
JF Bastien2df59c52019-02-04 20:31:13 +000044int main(int, char**) {
Eric Fiselier58ad17d2016-07-23 22:19:19 +000045 // test in_place_t
46 {
47 using T = std::in_place_t;
Eric Fiselier66ddd342016-11-17 19:23:35 +000048 static_assert(check_tag<T>(std::in_place));
Eric Fiselier58ad17d2016-07-23 22:19:19 +000049 }
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 Fiselier66ddd342016-11-17 19:23:35 +000055 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 Fiselier58ad17d2016-07-23 22:19:19 +000060 }
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 Fiselier66ddd342016-11-17 19:23:35 +000066 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 Fiselier58ad17d2016-07-23 22:19:19 +000071 }
JF Bastien2df59c52019-02-04 20:31:13 +000072
73 return 0;
Eric Fiselier66ddd342016-11-17 19:23:35 +000074}