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.
5 #include "base/template_util.h"
10 #include <type_traits>
12 #include "base/containers/flat_tree.h"
13 #include "base/test/move_only_int.h"
14 #include "testing/gtest/include/gtest/gtest.h"
19 enum SimpleEnum { SIMPLE_ENUM };
20 enum EnumWithExplicitType : uint64_t { ENUM_WITH_EXPLICIT_TYPE };
21 enum class ScopedEnum { SCOPED_ENUM };
22 struct SimpleStruct {};
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, "");
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&&>>, "");
40 std::is_same_v<SimpleStruct, remove_cvref_t<const SimpleStruct&>>, "");
41 static_assert(std::is_same_v<int*, remove_cvref_t<int*>>, "");
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]>>, "");
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)>>,