1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/template_util.h"
6
7 #include <stdint.h>
8
9 #include <string>
10 #include <type_traits>
11
12 #include "base/containers/flat_tree.h"
13 #include "base/test/move_only_int.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace base {
17 namespace {
18
19 enum SimpleEnum { SIMPLE_ENUM };
20 enum EnumWithExplicitType : uint64_t { ENUM_WITH_EXPLICIT_TYPE };
21 enum class ScopedEnum { SCOPED_ENUM };
22 struct SimpleStruct {};
23
24 // is_scoped_enum
TEST(TemplateUtil,IsScopedEnum)25 TEST(TemplateUtil, IsScopedEnum) {
26 static_assert(!is_scoped_enum<int>::value, "");
27 static_assert(!is_scoped_enum<SimpleEnum>::value, "");
28 static_assert(!is_scoped_enum<EnumWithExplicitType>::value, "");
29 static_assert(is_scoped_enum<ScopedEnum>::value, "");
30 }
31
TEST(TemplateUtil,RemoveCvRefT)32 TEST(TemplateUtil, RemoveCvRefT) {
33 static_assert(std::is_same_v<int, remove_cvref_t<const int>>, "");
34 static_assert(std::is_same_v<int, remove_cvref_t<const volatile int>>, "");
35 static_assert(std::is_same_v<int, remove_cvref_t<int&>>, "");
36 static_assert(std::is_same_v<int, remove_cvref_t<const int&>>, "");
37 static_assert(std::is_same_v<int, remove_cvref_t<const volatile int&>>, "");
38 static_assert(std::is_same_v<int, remove_cvref_t<int&&>>, "");
39 static_assert(
40 std::is_same_v<SimpleStruct, remove_cvref_t<const SimpleStruct&>>, "");
41 static_assert(std::is_same_v<int*, remove_cvref_t<int*>>, "");
42
43 // Test references and pointers to arrays.
44 static_assert(std::is_same_v<int[3], remove_cvref_t<int[3]>>, "");
45 static_assert(std::is_same_v<int[3], remove_cvref_t<int(&)[3]>>, "");
46 static_assert(std::is_same_v<int(*)[3], remove_cvref_t<int(*)[3]>>, "");
47
48 // Test references and pointers to functions.
49 static_assert(std::is_same_v<void(int), remove_cvref_t<void(int)>>, "");
50 static_assert(std::is_same_v<void(int), remove_cvref_t<void (&)(int)>>, "");
51 static_assert(std::is_same_v<void (*)(int), remove_cvref_t<void (*)(int)>>,
52 "");
53 }
54
55 } // namespace
56
57 } // namespace base
58