blob: 155b2c0eb215cb207d5161adac9f70ea5ea96da5 [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
9// UNSUPPORTED: c++98, c++03, c++11, c++14
10
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"
37#include "type_id.h"
38
Eric Fiselier66ddd342016-11-17 19:23:35 +000039template <class Tp, class Up>
40constexpr bool check_tag(Up) {
41 return std::is_same<Tp, std::decay_t<Tp>>::value
42 && std::is_same<Tp, Up>::value;
Eric Fiselier58ad17d2016-07-23 22:19:19 +000043}
44
JF Bastien2df59c52019-02-04 20:31:13 +000045int main(int, char**) {
Eric Fiselier58ad17d2016-07-23 22:19:19 +000046 // test in_place_t
47 {
48 using T = std::in_place_t;
Eric Fiselier66ddd342016-11-17 19:23:35 +000049 static_assert(check_tag<T>(std::in_place));
Eric Fiselier58ad17d2016-07-23 22:19:19 +000050 }
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 Fiselier66ddd342016-11-17 19:23:35 +000056 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 Fiselier58ad17d2016-07-23 22:19:19 +000061 }
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 Fiselier66ddd342016-11-17 19:23:35 +000067 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 Fiselier58ad17d2016-07-23 22:19:19 +000072 }
JF Bastien2df59c52019-02-04 20:31:13 +000073
74 return 0;
Eric Fiselier66ddd342016-11-17 19:23:35 +000075}