1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
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"
9 #include "base/containers/flat_tree.h"
10 #include "base/test/move_only_int.h"
11 #include "testing/gtest/include/gtest/gtest.h"
16 enum SimpleEnum { SIMPLE_ENUM };
17 enum EnumWithExplicitType : uint64_t { ENUM_WITH_EXPLICIT_TYPE };
18 enum class ScopedEnum { SCOPED_ENUM };
19 enum class ScopedEnumWithOperator { SCOPED_ENUM_WITH_OPERATOR };
20 std::ostream& operator<<(std::ostream& os, ScopedEnumWithOperator v) {
23 struct SimpleStruct {};
24 struct StructWithOperator {};
25 std::ostream& operator<<(std::ostream& os, const StructWithOperator& v) {
29 // is_non_const_reference<Type>
30 static_assert(!is_non_const_reference<int>::value, "IsNonConstReference");
31 static_assert(!is_non_const_reference<const int&>::value,
32 "IsNonConstReference");
33 static_assert(is_non_const_reference<int&>::value, "IsNonConstReference");
35 // A few standard types that definitely support printing.
36 static_assert(internal::SupportsOstreamOperator<int>::value,
37 "ints should be printable");
38 static_assert(internal::SupportsOstreamOperator<const char*>::value,
39 "C strings should be printable");
40 static_assert(internal::SupportsOstreamOperator<std::string>::value,
41 "std::string should be printable");
43 // Various kinds of enums operator<< support.
44 static_assert(internal::SupportsOstreamOperator<SimpleEnum>::value,
45 "simple enum should be printable by value");
46 static_assert(internal::SupportsOstreamOperator<const SimpleEnum&>::value,
47 "simple enum should be printable by const ref");
48 static_assert(internal::SupportsOstreamOperator<EnumWithExplicitType>::value,
49 "enum with explicit type should be printable by value");
51 internal::SupportsOstreamOperator<const EnumWithExplicitType&>::value,
52 "enum with explicit type should be printable by const ref");
53 static_assert(!internal::SupportsOstreamOperator<ScopedEnum>::value,
54 "scoped enum should not be printable by value");
55 static_assert(!internal::SupportsOstreamOperator<const ScopedEnum&>::value,
56 "simple enum should not be printable by const ref");
57 static_assert(internal::SupportsOstreamOperator<ScopedEnumWithOperator>::value,
58 "scoped enum with operator<< should be printable by value");
60 internal::SupportsOstreamOperator<const ScopedEnumWithOperator&>::value,
61 "scoped enum with operator<< should be printable by const ref");
63 // operator<< support on structs.
64 static_assert(!internal::SupportsOstreamOperator<SimpleStruct>::value,
65 "simple struct should not be printable by value");
66 static_assert(!internal::SupportsOstreamOperator<const SimpleStruct&>::value,
67 "simple struct should not be printable by const ref");
68 static_assert(internal::SupportsOstreamOperator<StructWithOperator>::value,
69 "struct with operator<< should be printable by value");
71 internal::SupportsOstreamOperator<const StructWithOperator&>::value,
72 "struct with operator<< should be printable by const ref");
74 // base::is_trivially_copyable
77 TrivialCopy(int d) : data_(d) {}
83 class TrivialCopyButWithDestructor : public TrivialCopy {
85 TrivialCopyButWithDestructor(int d) : TrivialCopy(d) {}
86 ~TrivialCopyButWithDestructor() { data_ = 0; }
89 static_assert(base::is_trivially_copyable<TrivialCopy>::value,
90 "TrivialCopy should be detected as trivially copyable");
91 static_assert(!base::is_trivially_copyable<TrivialCopyButWithDestructor>::value,
92 "TrivialCopyButWithDestructor should not be detected as "
93 "trivially copyable");
97 NoCopy(const NoCopy&) = delete;
101 !base::is_trivially_copy_constructible<std::vector<NoCopy>>::value,
102 "is_trivially_copy_constructible<std::vector<T>> must be compiled.");