type_traits_test.cc
Go to the documentation of this file.
1 // Copyright 2017 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "absl/meta/type_traits.h"
16 
17 #include <cstdint>
18 #include <string>
19 #include <type_traits>
20 #include <utility>
21 #include <vector>
22 
23 #include "gtest/gtest.h"
24 
25 namespace {
26 
27 using ::testing::StaticAssertTypeEq;
28 
29 template <class T, class U>
30 struct simple_pair {
31  T first;
32  U second;
33 };
34 
35 struct Dummy {};
36 
37 struct ReturnType {};
38 struct ConvertibleToReturnType {
39  operator ReturnType() const; // NOLINT
40 };
41 
42 // Unique types used as parameter types for testing the detection idiom.
43 struct StructA {};
44 struct StructB {};
45 struct StructC {};
46 
47 struct TypeWithBarFunction {
48  template <class T,
50  ReturnType bar(T&&, const StructB&, StructC&&) &&; // NOLINT
51 };
52 
53 struct TypeWithBarFunctionAndConvertibleReturnType {
54  template <class T,
56  ConvertibleToReturnType bar(T&&, const StructB&, StructC&&) &&; // NOLINT
57 };
58 
59 template <class Class, class... Ts>
60 using BarIsCallableImpl =
61  decltype(std::declval<Class>().bar(std::declval<Ts>()...));
62 
63 template <class Class, class... T>
64 using BarIsCallable =
65  absl::type_traits_internal::is_detected<BarIsCallableImpl, Class, T...>;
66 
67 template <class Class, class... T>
69  ReturnType, BarIsCallableImpl, Class, T...>;
70 
71 // NOTE: Test of detail type_traits_internal::is_detected.
72 TEST(IsDetectedTest, BasicUsage) {
73  EXPECT_TRUE((BarIsCallable<TypeWithBarFunction, StructA&, const StructB&,
74  StructC>::value));
75  EXPECT_TRUE(
77  EXPECT_TRUE(
79 
81  EXPECT_FALSE((BarIsCallable<TypeWithBarFunction&, StructA&, const StructB&,
82  StructC>::value));
83  EXPECT_FALSE((BarIsCallable<TypeWithBarFunction, StructA, const StructB&,
84  StructC>::value));
85 }
86 
87 // NOTE: Test of detail type_traits_internal::is_detected_convertible.
88 TEST(IsDetectedConvertibleTest, BasicUsage) {
89  EXPECT_TRUE((BarIsCallableConv<TypeWithBarFunction, StructA&, const StructB&,
90  StructC>::value));
91  EXPECT_TRUE((BarIsCallableConv<TypeWithBarFunction, StructA&, StructB&,
92  StructC>::value));
93  EXPECT_TRUE((BarIsCallableConv<TypeWithBarFunction, StructA&, StructB,
94  StructC>::value));
95  EXPECT_TRUE((BarIsCallableConv<TypeWithBarFunctionAndConvertibleReturnType,
96  StructA&, const StructB&, StructC>::value));
97  EXPECT_TRUE((BarIsCallableConv<TypeWithBarFunctionAndConvertibleReturnType,
98  StructA&, StructB&, StructC>::value));
99  EXPECT_TRUE((BarIsCallableConv<TypeWithBarFunctionAndConvertibleReturnType,
100  StructA&, StructB, StructC>::value));
101 
102  EXPECT_FALSE(
104  EXPECT_FALSE((BarIsCallableConv<TypeWithBarFunction&, StructA&,
105  const StructB&, StructC>::value));
106  EXPECT_FALSE((BarIsCallableConv<TypeWithBarFunction, StructA, const StructB&,
107  StructC>::value));
108  EXPECT_FALSE((BarIsCallableConv<TypeWithBarFunctionAndConvertibleReturnType&,
109  StructA&, const StructB&, StructC>::value));
110  EXPECT_FALSE((BarIsCallableConv<TypeWithBarFunctionAndConvertibleReturnType,
111  StructA, const StructB&, StructC>::value));
112 }
113 
114 TEST(VoidTTest, BasicUsage) {
115  StaticAssertTypeEq<void, absl::void_t<Dummy>>();
116  StaticAssertTypeEq<void, absl::void_t<Dummy, Dummy, Dummy>>();
117 }
118 
119 TEST(ConjunctionTest, BasicBooleanLogic) {
120  EXPECT_TRUE(absl::conjunction<>::value);
126 }
127 
128 struct MyTrueType {
129  static constexpr bool value = true;
130 };
131 
132 struct MyFalseType {
133  static constexpr bool value = false;
134 };
135 
136 TEST(ConjunctionTest, ShortCircuiting) {
137  EXPECT_FALSE(
139  EXPECT_TRUE((std::is_base_of<MyFalseType,
140  absl::conjunction<std::true_type, MyFalseType,
141  std::false_type>>::value));
142  EXPECT_TRUE(
143  (std::is_base_of<MyTrueType,
145 }
146 
147 TEST(DisjunctionTest, BasicBooleanLogic) {
148  EXPECT_FALSE(absl::disjunction<>::value);
154 }
155 
156 TEST(DisjunctionTest, ShortCircuiting) {
157  EXPECT_TRUE(
159  EXPECT_TRUE((
160  std::is_base_of<MyTrueType, absl::disjunction<std::false_type, MyTrueType,
161  std::true_type>>::value));
162  EXPECT_TRUE((
163  std::is_base_of<MyFalseType,
165 }
166 
167 TEST(NegationTest, BasicBooleanLogic) {
169  EXPECT_FALSE(absl::negation<MyTrueType>::value);
172 }
173 
174 // all member functions are trivial
175 class Trivial {
176  int n_;
177 };
178 
179 struct TrivialDestructor {
180  ~TrivialDestructor() = default;
181 };
182 
183 struct NontrivialDestructor {
184  ~NontrivialDestructor() {}
185 };
186 
187 struct DeletedDestructor {
188  ~DeletedDestructor() = delete;
189 };
190 
191 class TrivialDefaultCtor {
192  public:
193  TrivialDefaultCtor() = default;
194  explicit TrivialDefaultCtor(int n) : n_(n) {}
195 
196  private:
197  int n_;
198 };
199 
200 class NontrivialDefaultCtor {
201  public:
202  NontrivialDefaultCtor() : n_(1) {}
203 
204  private:
205  int n_;
206 };
207 
208 class DeletedDefaultCtor {
209  public:
210  DeletedDefaultCtor() = delete;
211  explicit DeletedDefaultCtor(int n) : n_(n) {}
212 
213  private:
214  int n_;
215 };
216 
217 class TrivialMoveCtor {
218  public:
219  explicit TrivialMoveCtor(int n) : n_(n) {}
220  TrivialMoveCtor(TrivialMoveCtor&&) = default;
221  TrivialMoveCtor& operator=(const TrivialMoveCtor& t) {
222  n_ = t.n_;
223  return *this;
224  }
225 
226  private:
227  int n_;
228 };
229 
230 class NontrivialMoveCtor {
231  public:
232  explicit NontrivialMoveCtor(int n) : n_(n) {}
233  NontrivialMoveCtor(NontrivialMoveCtor&& t) noexcept : n_(t.n_) {}
234  NontrivialMoveCtor& operator=(const NontrivialMoveCtor&) = default;
235 
236  private:
237  int n_;
238 };
239 
240 class TrivialCopyCtor {
241  public:
242  explicit TrivialCopyCtor(int n) : n_(n) {}
243  TrivialCopyCtor(const TrivialCopyCtor&) = default;
244  TrivialCopyCtor& operator=(const TrivialCopyCtor& t) {
245  n_ = t.n_;
246  return *this;
247  }
248 
249  private:
250  int n_;
251 };
252 
253 class NontrivialCopyCtor {
254  public:
255  explicit NontrivialCopyCtor(int n) : n_(n) {}
256  NontrivialCopyCtor(const NontrivialCopyCtor& t) : n_(t.n_) {}
257  NontrivialCopyCtor& operator=(const NontrivialCopyCtor&) = default;
258 
259  private:
260  int n_;
261 };
262 
263 class DeletedCopyCtor {
264  public:
265  explicit DeletedCopyCtor(int n) : n_(n) {}
266  DeletedCopyCtor(const DeletedCopyCtor&) = delete;
267  DeletedCopyCtor& operator=(const DeletedCopyCtor&) = default;
268 
269  private:
270  int n_;
271 };
272 
273 class TrivialMoveAssign {
274  public:
275  explicit TrivialMoveAssign(int n) : n_(n) {}
276  TrivialMoveAssign(const TrivialMoveAssign& t) : n_(t.n_) {}
277  TrivialMoveAssign& operator=(TrivialMoveAssign&&) = default;
278  ~TrivialMoveAssign() {} // can have nontrivial destructor
279  private:
280  int n_;
281 };
282 
283 class NontrivialMoveAssign {
284  public:
285  explicit NontrivialMoveAssign(int n) : n_(n) {}
286  NontrivialMoveAssign(const NontrivialMoveAssign&) = default;
287  NontrivialMoveAssign& operator=(NontrivialMoveAssign&& t) noexcept {
288  n_ = t.n_;
289  return *this;
290  }
291 
292  private:
293  int n_;
294 };
295 
296 class TrivialCopyAssign {
297  public:
298  explicit TrivialCopyAssign(int n) : n_(n) {}
299  TrivialCopyAssign(const TrivialCopyAssign& t) : n_(t.n_) {}
300  TrivialCopyAssign& operator=(const TrivialCopyAssign& t) = default;
301  ~TrivialCopyAssign() {} // can have nontrivial destructor
302  private:
303  int n_;
304 };
305 
306 class NontrivialCopyAssign {
307  public:
308  explicit NontrivialCopyAssign(int n) : n_(n) {}
309  NontrivialCopyAssign(const NontrivialCopyAssign&) = default;
310  NontrivialCopyAssign& operator=(const NontrivialCopyAssign& t) {
311  n_ = t.n_;
312  return *this;
313  }
314 
315  private:
316  int n_;
317 };
318 
319 class DeletedCopyAssign {
320  public:
321  explicit DeletedCopyAssign(int n) : n_(n) {}
322  DeletedCopyAssign(const DeletedCopyAssign&) = default;
323  DeletedCopyAssign& operator=(const DeletedCopyAssign&) = delete;
324 
325  private:
326  int n_;
327 };
328 
329 struct MovableNonCopyable {
330  MovableNonCopyable() = default;
331  MovableNonCopyable(const MovableNonCopyable&) = delete;
332  MovableNonCopyable(MovableNonCopyable&&) = default;
333  MovableNonCopyable& operator=(const MovableNonCopyable&) = delete;
334  MovableNonCopyable& operator=(MovableNonCopyable&&) = default;
335 };
336 
337 struct NonCopyableOrMovable {
338  NonCopyableOrMovable() = default;
339  NonCopyableOrMovable(const NonCopyableOrMovable&) = delete;
340  NonCopyableOrMovable(NonCopyableOrMovable&&) = delete;
341  NonCopyableOrMovable& operator=(const NonCopyableOrMovable&) = delete;
342  NonCopyableOrMovable& operator=(NonCopyableOrMovable&&) = delete;
343 };
344 
345 class Base {
346  public:
347  virtual ~Base() {}
348 };
349 
350 // In GCC/Clang, std::is_trivially_constructible requires that the destructor is
351 // trivial. However, MSVC doesn't require that. This results in different
352 // behavior when checking is_trivially_constructible on any type with
353 // nontrivial destructor. Since absl::is_trivially_default_constructible and
354 // absl::is_trivially_copy_constructible both follows Clang/GCC's interpretation
355 // and check is_trivially_destructible, it results in inconsistency with
356 // std::is_trivially_xxx_constructible on MSVC. This macro is used to work
357 // around this issue in test. In practice, a trivially constructible type
358 // should also be trivially destructible.
359 // GCC bug 51452: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51452
360 // LWG issue 2116: http://cplusplus.github.io/LWG/lwg-active.html#2116
361 #ifndef _MSC_VER
362 #define ABSL_TRIVIALLY_CONSTRUCTIBLE_VERIFY_TRIVIALLY_DESTRUCTIBLE 1
363 #endif
364 
365 // Old versions of libc++, around Clang 3.5 to 3.6, consider deleted destructors
366 // as also being trivial. With the resolution of CWG 1928 and CWG 1734, this
367 // is no longer considered true and has thus been amended.
368 // Compiler Explorer: https://godbolt.org/g/zT59ZL
369 // CWG issue 1734: http://open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#1734
370 // CWG issue 1928: http://open-std.org/JTC1/SC22/WG21/docs/cwg_closed.html#1928
371 #if !defined(_LIBCPP_VERSION) || _LIBCPP_VERSION >= 3700
372 #define ABSL_TRIVIALLY_DESTRUCTIBLE_CONSIDER_DELETED_DESTRUCTOR_NOT_TRIVIAL 1
373 #endif
374 
375 // As of the moment, GCC versions >5.1 have a problem compiling for
376 // std::is_trivially_default_constructible<NontrivialDestructor[10]>, where
377 // NontrivialDestructor is a struct with a custom nontrivial destructor. Note
378 // that this problem only occurs for arrays of a known size, so something like
379 // std::is_trivially_default_constructible<NontrivialDestructor[]> does not
380 // have any problems.
381 // Compiler Explorer: https://godbolt.org/g/dXRbdK
382 // GCC bug 83689: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83689
383 #if defined(__clang__) || defined(_MSC_VER) || \
384  (defined(__GNUC__) && __GNUC__ < 5)
385 #define ABSL_GCC_BUG_TRIVIALLY_CONSTRUCTIBLE_ON_ARRAY_OF_NONTRIVIAL 1
386 #endif
387 
388 TEST(TypeTraitsTest, TestTrivialDestructor) {
389  // Verify that arithmetic types and pointers have trivial destructors.
410 
411  // classes with destructors
414 
415  // Verify that types with a nontrivial or deleted destructor
416  // are marked as such.
418 #ifdef ABSL_TRIVIALLY_DESTRUCTIBLE_CONSIDER_DELETED_DESTRUCTOR_NOT_TRIVIAL
420 #endif
421 
422  // simple_pair of such types is trivial
423  EXPECT_TRUE((absl::is_trivially_destructible<simple_pair<int, int>>::value));
424  EXPECT_TRUE((absl::is_trivially_destructible<
425  simple_pair<Trivial, TrivialDestructor>>::value));
426 
427  // Verify that types without trivial destructors are correctly marked as such.
429  EXPECT_FALSE(absl::is_trivially_destructible<std::vector<int>>::value);
430 
431  // Verify that simple_pairs of types without trivial destructors
432  // are not marked as trivial.
433  EXPECT_FALSE((absl::is_trivially_destructible<
434  simple_pair<int, std::string>>::value));
435  EXPECT_FALSE((absl::is_trivially_destructible<
436  simple_pair<std::string, int>>::value));
437 
438  // array of such types is trivial
439  using int10 = int[10];
441  using Trivial10 = Trivial[10];
443  using TrivialDestructor10 = TrivialDestructor[10];
445 
446  // Conversely, the opposite also holds.
447  using NontrivialDestructor10 = NontrivialDestructor[10];
449 }
450 
451 TEST(TypeTraitsTest, TestTrivialDefaultCtor) {
452  // arithmetic types and pointers have trivial default constructors.
469  EXPECT_TRUE(
474 
475  // types with compiler generated default ctors
477  EXPECT_TRUE(
479 
480  // Verify that types without them are not.
481  EXPECT_FALSE(
483  EXPECT_FALSE(
485 
486 #ifdef ABSL_TRIVIALLY_CONSTRUCTIBLE_VERIFY_TRIVIALLY_DESTRUCTIBLE
487  // types with nontrivial destructor are nontrivial
488  EXPECT_FALSE(
490 #endif
491 
492  // types with vtables
494 
495  // Verify that simple_pair has trivial constructors where applicable.
497  simple_pair<int, char*>>::value));
499  simple_pair<int, Trivial>>::value));
501  simple_pair<int, TrivialDefaultCtor>>::value));
502 
503  // Verify that types without trivial constructors are
504  // correctly marked as such.
506  EXPECT_FALSE(
508 
509  // Verify that simple_pairs of types without trivial constructors
510  // are not marked as trivial.
512  simple_pair<int, std::string>>::value));
514  simple_pair<std::string, int>>::value));
515 
516  // Verify that arrays of such types are trivially default constructible
517  using int10 = int[10];
519  using Trivial10 = Trivial[10];
521  using TrivialDefaultCtor10 = TrivialDefaultCtor[10];
522  EXPECT_TRUE(
524 
525  // Conversely, the opposite also holds.
526 #ifdef ABSL_GCC_BUG_TRIVIALLY_CONSTRUCTIBLE_ON_ARRAY_OF_NONTRIVIAL
527  using NontrivialDefaultCtor10 = NontrivialDefaultCtor[10];
528  EXPECT_FALSE(
530 #endif
531 }
532 
533 TEST(TypeTraitsTest, TestTrivialMoveCtor) {
534  // Verify that arithmetic types and pointers have trivial move
535  // constructors.
556 
557  // Reference types
560 
561  // types with compiler generated move ctors
564 
565  // Verify that types without them (i.e. nontrivial or deleted) are not.
566  EXPECT_FALSE(
569  EXPECT_FALSE(
571 
572 #ifdef ABSL_TRIVIALLY_CONSTRUCTIBLE_VERIFY_TRIVIALLY_DESTRUCTIBLE
573  // type with nontrivial destructor are nontrivial move construbtible
574  EXPECT_FALSE(
576 #endif
577 
578  // types with vtables
580 
581  // Verify that simple_pair of such types is trivially move constructible
582  EXPECT_TRUE(
583  (absl::is_trivially_move_constructible<simple_pair<int, char*>>::value));
584  EXPECT_TRUE((
585  absl::is_trivially_move_constructible<simple_pair<int, Trivial>>::value));
587  simple_pair<int, TrivialMoveCtor>>::value));
588 
589  // Verify that types without trivial move constructors are
590  // correctly marked as such.
592  EXPECT_FALSE(absl::is_trivially_move_constructible<std::vector<int>>::value);
593 
594  // Verify that simple_pairs of types without trivial move constructors
595  // are not marked as trivial.
597  simple_pair<int, std::string>>::value));
599  simple_pair<std::string, int>>::value));
600 
601  // Verify that arrays are not
602  using int10 = int[10];
604 }
605 
606 TEST(TypeTraitsTest, TestTrivialCopyCtor) {
607  // Verify that arithmetic types and pointers have trivial copy
608  // constructors.
629 
630  // Reference types
633 
634  // types with compiler generated copy ctors
637 
638  // Verify that types without them (i.e. nontrivial or deleted) are not.
639  EXPECT_FALSE(
642  EXPECT_FALSE(
644  EXPECT_FALSE(
646 
647 #ifdef ABSL_TRIVIALLY_CONSTRUCTIBLE_VERIFY_TRIVIALLY_DESTRUCTIBLE
648  // type with nontrivial destructor are nontrivial copy construbtible
649  EXPECT_FALSE(
651 #endif
652 
653  // types with vtables
655 
656  // Verify that simple_pair of such types is trivially copy constructible
657  EXPECT_TRUE(
658  (absl::is_trivially_copy_constructible<simple_pair<int, char*>>::value));
659  EXPECT_TRUE((
660  absl::is_trivially_copy_constructible<simple_pair<int, Trivial>>::value));
662  simple_pair<int, TrivialCopyCtor>>::value));
663 
664  // Verify that types without trivial copy constructors are
665  // correctly marked as such.
667  EXPECT_FALSE(absl::is_trivially_copy_constructible<std::vector<int>>::value);
668 
669  // Verify that simple_pairs of types without trivial copy constructors
670  // are not marked as trivial.
672  simple_pair<int, std::string>>::value));
674  simple_pair<std::string, int>>::value));
675 
676  // Verify that arrays are not
677  using int10 = int[10];
679 }
680 
681 TEST(TypeTraitsTest, TestTrivialMoveAssign) {
682  // Verify that arithmetic types and pointers have trivial move
683  // assignment operators.
704 
705  // const qualified types are not assignable
707 
708  // types with compiler generated move assignment
711 
712  // Verify that types without them (i.e. nontrivial or deleted) are not.
716 
717  // types with vtables
719 
720  // Verify that simple_pair is trivially assignable
721  EXPECT_TRUE(
722  (absl::is_trivially_move_assignable<simple_pair<int, char*>>::value));
723  EXPECT_TRUE(
724  (absl::is_trivially_move_assignable<simple_pair<int, Trivial>>::value));
726  simple_pair<int, TrivialMoveAssign>>::value));
727 
728  // Verify that types not trivially move assignable are
729  // correctly marked as such.
731  EXPECT_FALSE(absl::is_trivially_move_assignable<std::vector<int>>::value);
732 
733  // Verify that simple_pairs of types not trivially move assignable
734  // are not marked as trivial.
736  simple_pair<int, std::string>>::value));
738  simple_pair<std::string, int>>::value));
739 
740  // Verify that arrays are not trivially move assignable
741  using int10 = int[10];
743 
744  // Verify that references are handled correctly
747 }
748 
749 TEST(TypeTraitsTest, TestTrivialCopyAssign) {
750  // Verify that arithmetic types and pointers have trivial copy
751  // assignment operators.
772 
773  // const qualified types are not assignable
775 
776  // types with compiler generated copy assignment
779 
780  // Verify that types without them (i.e. nontrivial or deleted) are not.
785 
786  // types with vtables
788 
789  // Verify that simple_pair is trivially assignable
790  EXPECT_TRUE(
791  (absl::is_trivially_copy_assignable<simple_pair<int, char*>>::value));
792  EXPECT_TRUE(
793  (absl::is_trivially_copy_assignable<simple_pair<int, Trivial>>::value));
795  simple_pair<int, TrivialCopyAssign>>::value));
796 
797  // Verify that types not trivially copy assignable are
798  // correctly marked as such.
800  EXPECT_FALSE(absl::is_trivially_copy_assignable<std::vector<int>>::value);
801 
802  // Verify that simple_pairs of types not trivially copy assignable
803  // are not marked as trivial.
805  simple_pair<int, std::string>>::value));
807  simple_pair<std::string, int>>::value));
808 
809  // Verify that arrays are not trivially copy assignable
810  using int10 = int[10];
812 
813  // Verify that references are handled correctly
816 }
817 
818 TEST(TypeTraitsTest, TestTriviallyCopyable) {
819  // Verify that arithmetic types and pointers are trivially copyable.
822  EXPECT_TRUE(
824  EXPECT_TRUE(
826  EXPECT_TRUE(
829  EXPECT_TRUE(
831  EXPECT_TRUE(
833  EXPECT_TRUE(
835  EXPECT_TRUE(
837  EXPECT_TRUE(
841  EXPECT_TRUE(
843  EXPECT_TRUE(
845  EXPECT_TRUE(
848  const std::string*>::value);
849  EXPECT_TRUE(
851  EXPECT_TRUE(
853  EXPECT_TRUE(
855 
856  // const qualified types are not assignable but are constructible
857  EXPECT_TRUE(
859 
860  // Trivial copy constructor/assignment and destructor.
861  EXPECT_TRUE(
863  // Trivial copy assignment, but non-trivial copy constructor/destructor.
865  TrivialCopyAssign>::value);
866  // Trivial copy constructor, but non-trivial assignment.
868  TrivialCopyCtor>::value);
869 
870  // Types with a non-trivial copy constructor/assignment
872  NontrivialCopyCtor>::value);
874  NontrivialCopyAssign>::value);
875 
876  // Types without copy constructor/assignment, but with move
877  // MSVC disagrees with other compilers about this:
878  // EXPECT_TRUE(absl::type_traits_internal::is_trivially_copyable<
879  // MovableNonCopyable>::value);
880 
881  // Types without copy/move constructor/assignment
883  NonCopyableOrMovable>::value);
884 
885  // No copy assign, but has trivial copy constructor.
887  DeletedCopyAssign>::value);
888 
889  // types with vtables
891 
892  // Verify that simple_pair is trivially copyable if members are
894  simple_pair<int, char*>>::value));
896  simple_pair<int, Trivial>>::value));
897 
898  // Verify that types not trivially copyable are
899  // correctly marked as such.
900  EXPECT_FALSE(
903  std::vector<int>>::value);
904 
905  // Verify that simple_pairs of types not trivially copyable
906  // are not marked as trivial.
908  simple_pair<int, std::string>>::value));
910  simple_pair<std::string, int>>::value));
912  simple_pair<int, TrivialCopyAssign>>::value));
913 
914  // Verify that arrays of trivially copyable types are trivially copyable
915  using int10 = int[10];
917  using int10x10 = int[10][10];
918  EXPECT_TRUE(
920 
921  // Verify that references are handled correctly
922  EXPECT_FALSE(
924  EXPECT_FALSE(
926 }
927 
928 #define ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(trait_name, ...) \
929  EXPECT_TRUE((std::is_same<typename std::trait_name<__VA_ARGS__>::type, \
930  absl::trait_name##_t<__VA_ARGS__>>::value))
931 
932 TEST(TypeTraitsTest, TestRemoveCVAliases) {
934  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_cv, const int);
935  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_cv, volatile int);
936  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_cv, const volatile int);
937 
938  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_const, int);
939  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_const, const int);
940  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_const, volatile int);
941  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_const, const volatile int);
942 
943  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_volatile, int);
944  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_volatile, const int);
945  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_volatile, volatile int);
946  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_volatile, const volatile int);
947 }
948 
949 TEST(TypeTraitsTest, TestAddCVAliases) {
951  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_cv, const int);
952  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_cv, volatile int);
953  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_cv, const volatile int);
954 
956  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_const, const int);
957  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_const, volatile int);
958  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_const, const volatile int);
959 
960  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_volatile, int);
961  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_volatile, const int);
962  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_volatile, volatile int);
963  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_volatile, const volatile int);
964 }
965 
966 TEST(TypeTraitsTest, TestReferenceAliases) {
967  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_reference, int);
968  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_reference, volatile int);
969  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_reference, int&);
970  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_reference, volatile int&);
971  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_reference, int&&);
972  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_reference, volatile int&&);
973 
974  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_lvalue_reference, int);
975  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_lvalue_reference, volatile int);
976  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_lvalue_reference, int&);
977  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_lvalue_reference, volatile int&);
978  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_lvalue_reference, int&&);
979  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_lvalue_reference, volatile int&&);
980 
981  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_rvalue_reference, int);
982  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_rvalue_reference, volatile int);
983  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_rvalue_reference, int&);
984  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_rvalue_reference, volatile int&);
985  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_rvalue_reference, int&&);
986  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_rvalue_reference, volatile int&&);
987 }
988 
989 TEST(TypeTraitsTest, TestPointerAliases) {
990  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_pointer, int*);
991  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_pointer, volatile int*);
992 
993  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_pointer, int);
994  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_pointer, volatile int);
995 }
996 
997 TEST(TypeTraitsTest, TestSignednessAliases) {
998  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(make_signed, int);
999  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(make_signed, volatile int);
1000  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(make_signed, unsigned);
1001  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(make_signed, volatile unsigned);
1002 
1003  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(make_unsigned, int);
1004  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(make_unsigned, volatile int);
1005  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(make_unsigned, unsigned);
1006  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(make_unsigned, volatile unsigned);
1007 }
1008 
1009 TEST(TypeTraitsTest, TestExtentAliases) {
1010  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_extent, int[]);
1011  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_extent, int[1]);
1012  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_extent, int[1][1]);
1013  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_extent, int[][1]);
1014 
1015  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_all_extents, int[]);
1016  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_all_extents, int[1]);
1017  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_all_extents, int[1][1]);
1018  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_all_extents, int[][1]);
1019 }
1020 
1021 TEST(TypeTraitsTest, TestAlignedStorageAlias) {
1022  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 1);
1023  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 2);
1024  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 3);
1025  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 4);
1026  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 5);
1027  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 6);
1028  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 7);
1029  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 8);
1030  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 9);
1031  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 10);
1032  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 11);
1033  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 12);
1034  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 13);
1035  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 14);
1036  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 15);
1037  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 16);
1038  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 17);
1039  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 18);
1040  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 19);
1041  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 20);
1042  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 21);
1043  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 22);
1044  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 23);
1045  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 24);
1046  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 25);
1047  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 26);
1048  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 27);
1049  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 28);
1050  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 29);
1051  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 30);
1052  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 31);
1053  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 32);
1054  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 33);
1055 
1056  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 1, 128);
1057  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 2, 128);
1058  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 3, 128);
1059  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 4, 128);
1060  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 5, 128);
1061  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 6, 128);
1062  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 7, 128);
1063  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 8, 128);
1064  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 9, 128);
1065  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 10, 128);
1066  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 11, 128);
1067  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 12, 128);
1068  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 13, 128);
1069  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 14, 128);
1070  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 15, 128);
1071  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 16, 128);
1072  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 17, 128);
1073  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 18, 128);
1074  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 19, 128);
1075  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 20, 128);
1076  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 21, 128);
1077  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 22, 128);
1078  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 23, 128);
1079  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 24, 128);
1080  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 25, 128);
1081  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 26, 128);
1082  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 27, 128);
1083  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 28, 128);
1084  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 29, 128);
1085  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 30, 128);
1086  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 31, 128);
1087  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 32, 128);
1088  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 33, 128);
1089 }
1090 
1091 TEST(TypeTraitsTest, TestDecay) {
1093  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, const int);
1094  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, volatile int);
1095  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, const volatile int);
1096 
1098  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, const int&);
1099  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, volatile int&);
1100  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, const volatile int&);
1101 
1103  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, const int&);
1104  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, volatile int&);
1105  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, const volatile int&);
1106 
1108  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, int[1][1]);
1109  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, int[][1]);
1110 
1112  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, int(float)); // NOLINT
1113  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, int(char, ...)); // NOLINT
1114 }
1115 
1116 struct TypeA {};
1117 struct TypeB {};
1118 struct TypeC {};
1119 struct TypeD {};
1120 
1121 template <typename T>
1122 struct Wrap {};
1123 
1124 enum class TypeEnum { A, B, C, D };
1125 
1126 struct GetTypeT {
1127  template <typename T,
1129  TypeEnum operator()(Wrap<T>) const {
1130  return TypeEnum::A;
1131  }
1132 
1133  template <typename T,
1135  TypeEnum operator()(Wrap<T>) const {
1136  return TypeEnum::B;
1137  }
1138 
1139  template <typename T,
1141  TypeEnum operator()(Wrap<T>) const {
1142  return TypeEnum::C;
1143  }
1144 
1145  // NOTE: TypeD is intentionally not handled
1146 } constexpr GetType = {};
1147 
1148 TEST(TypeTraitsTest, TestEnableIf) {
1149  EXPECT_EQ(TypeEnum::A, GetType(Wrap<TypeA>()));
1150  EXPECT_EQ(TypeEnum::B, GetType(Wrap<TypeB>()));
1151  EXPECT_EQ(TypeEnum::C, GetType(Wrap<TypeC>()));
1152 }
1153 
1154 TEST(TypeTraitsTest, TestConditional) {
1155  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(conditional, true, int, char);
1156  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(conditional, false, int, char);
1157 }
1158 
1159 // TODO(calabrese) Check with specialized std::common_type
1160 TEST(TypeTraitsTest, TestCommonType) {
1161  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(common_type, int);
1162  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(common_type, int, char);
1163  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(common_type, int, char, int);
1164 
1165  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(common_type, int&);
1166  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(common_type, int, char&);
1167  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(common_type, int, char, int&);
1168 }
1169 
1170 TEST(TypeTraitsTest, TestUnderlyingType) {
1171  enum class enum_char : char {};
1172  enum class enum_long_long : long long {}; // NOLINT(runtime/int)
1173 
1174  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(underlying_type, enum_char);
1175  ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(underlying_type, enum_long_long);
1176 }
1177 
1178 struct GetTypeExtT {
1179  template <typename T>
1180  absl::result_of_t<const GetTypeT&(T)> operator()(T&& arg) const {
1181  return GetType(std::forward<T>(arg));
1182  }
1183 
1184  TypeEnum operator()(Wrap<TypeD>) const { return TypeEnum::D; }
1185 } constexpr GetTypeExt = {};
1186 
1187 TEST(TypeTraitsTest, TestResultOf) {
1188  EXPECT_EQ(TypeEnum::A, GetTypeExt(Wrap<TypeA>()));
1189  EXPECT_EQ(TypeEnum::B, GetTypeExt(Wrap<TypeB>()));
1190  EXPECT_EQ(TypeEnum::C, GetTypeExt(Wrap<TypeC>()));
1191  EXPECT_EQ(TypeEnum::D, GetTypeExt(Wrap<TypeD>()));
1192 }
1193 
1194 template <typename T>
1195 bool TestCopyAssign() {
1198 }
1199 
1200 TEST(TypeTraitsTest, IsCopyAssignable) {
1201  EXPECT_TRUE(TestCopyAssign<int>());
1202  EXPECT_TRUE(TestCopyAssign<int&>());
1203  EXPECT_TRUE(TestCopyAssign<int&&>());
1204 
1205  struct S {};
1206  EXPECT_TRUE(TestCopyAssign<S>());
1207  EXPECT_TRUE(TestCopyAssign<S&>());
1208  EXPECT_TRUE(TestCopyAssign<S&&>());
1209 
1210  class C {
1211  public:
1212  explicit C(C* c) : c_(c) {}
1213  ~C() { delete c_; }
1214 
1215  private:
1216  C* c_;
1217  };
1218  EXPECT_TRUE(TestCopyAssign<C>());
1219  EXPECT_TRUE(TestCopyAssign<C&>());
1220  EXPECT_TRUE(TestCopyAssign<C&&>());
1221 
1222  // Reason for ifndef: add_lvalue_reference<T> in libc++ breaks for these cases
1223 #ifndef _LIBCPP_VERSION
1224  EXPECT_TRUE(TestCopyAssign<int()>());
1225  EXPECT_TRUE(TestCopyAssign<int(int) const>());
1226  EXPECT_TRUE(TestCopyAssign<int(...) volatile&>());
1227  EXPECT_TRUE(TestCopyAssign<int(int, ...) const volatile&&>());
1228 #endif // _LIBCPP_VERSION
1229 }
1230 
1231 template <typename T>
1232 bool TestMoveAssign() {
1235 }
1236 
1237 TEST(TypeTraitsTest, IsMoveAssignable) {
1238  EXPECT_TRUE(TestMoveAssign<int>());
1239  EXPECT_TRUE(TestMoveAssign<int&>());
1240  EXPECT_TRUE(TestMoveAssign<int&&>());
1241 
1242  struct S {};
1243  EXPECT_TRUE(TestMoveAssign<S>());
1244  EXPECT_TRUE(TestMoveAssign<S&>());
1245  EXPECT_TRUE(TestMoveAssign<S&&>());
1246 
1247  class C {
1248  public:
1249  explicit C(C* c) : c_(c) {}
1250  ~C() { delete c_; }
1251  void operator=(const C&) = delete;
1252  void operator=(C&&) = delete;
1253 
1254  private:
1255  C* c_;
1256  };
1257  EXPECT_TRUE(TestMoveAssign<C>());
1258  EXPECT_TRUE(TestMoveAssign<C&>());
1259  EXPECT_TRUE(TestMoveAssign<C&&>());
1260 
1261  // Reason for ifndef: add_lvalue_reference<T> in libc++ breaks for these cases
1262 #ifndef _LIBCPP_VERSION
1263  EXPECT_TRUE(TestMoveAssign<int()>());
1264  EXPECT_TRUE(TestMoveAssign<int(int) const>());
1265  EXPECT_TRUE(TestMoveAssign<int(...) volatile&>());
1266  EXPECT_TRUE(TestMoveAssign<int(int, ...) const volatile&&>());
1267 #endif // _LIBCPP_VERSION
1268 }
1269 
1270 namespace adl_namespace {
1271 
1272 struct DeletedSwap {
1273 };
1274 
1275 void swap(DeletedSwap&, DeletedSwap&) = delete;
1276 
1277 struct SpecialNoexceptSwap {
1278  SpecialNoexceptSwap(SpecialNoexceptSwap&&) {}
1279  SpecialNoexceptSwap& operator=(SpecialNoexceptSwap&&) { return *this; }
1280  ~SpecialNoexceptSwap() = default;
1281 };
1282 
1283 void swap(SpecialNoexceptSwap&, SpecialNoexceptSwap&) noexcept {}
1284 
1285 } // namespace adl_namespace
1286 
1287 TEST(TypeTraitsTest, IsSwappable) {
1288  using absl::type_traits_internal::IsSwappable;
1290 
1291  EXPECT_TRUE(IsSwappable<int>::value);
1292 
1293  struct S {};
1294  EXPECT_TRUE(IsSwappable<S>::value);
1295 
1296  struct NoConstruct {
1297  NoConstruct(NoConstruct&&) = delete;
1298  NoConstruct& operator=(NoConstruct&&) { return *this; }
1299  ~NoConstruct() = default;
1300  };
1301 
1303  struct NoAssign {
1304  NoAssign(NoAssign&&) {}
1305  NoAssign& operator=(NoAssign&&) = delete;
1306  ~NoAssign() = default;
1307  };
1308 
1310 
1312 
1314 }
1315 
1316 TEST(TypeTraitsTest, IsNothrowSwappable) {
1317  using absl::type_traits_internal::IsNothrowSwappable;
1319 
1320  EXPECT_TRUE(IsNothrowSwappable<int>::value);
1321 
1322  struct NonNoexceptMoves {
1323  NonNoexceptMoves(NonNoexceptMoves&&) {}
1324  NonNoexceptMoves& operator=(NonNoexceptMoves&&) { return *this; }
1325  ~NonNoexceptMoves() = default;
1326  };
1327 
1329 
1330  struct NoConstruct {
1331  NoConstruct(NoConstruct&&) = delete;
1332  NoConstruct& operator=(NoConstruct&&) { return *this; }
1333  ~NoConstruct() = default;
1334  };
1335 
1337 
1338  struct NoAssign {
1339  NoAssign(NoAssign&&) {}
1340  NoAssign& operator=(NoAssign&&) = delete;
1341  ~NoAssign() = default;
1342  };
1343 
1345 
1347 
1349 }
1350 
1351 } // namespace
typename std::result_of< T >::type result_of_t
Definition: type_traits.h:559
typename std::enable_if< B, T >::type enable_if_t
Definition: type_traits.h:547
size_t value
IsSwappable< void()> StdSwapIsUnconstrained
Definition: type_traits.h:682
void swap(absl::InlinedVector< T, N, A > &a, absl::InlinedVector< T, N, A > &b) noexcept(noexcept(a.swap(b)))
void * arg
Definition: mutex.cc:292
TEST(Symbolize, Unimplemented)
#define C(x)
Definition: city_test.cc:47
#define ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(trait_name,...)


abseil_cpp
Author(s):
autogenerated on Tue Jun 18 2019 19:44:37