type_traits_test.cc
Go to the documentation of this file.
00001 // Copyright 2017 The Abseil Authors.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //      https://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 // Unless required by applicable law or agreed to in writing, software
00010 // distributed under the License is distributed on an "AS IS" BASIS,
00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 // See the License for the specific language governing permissions and
00013 // limitations under the License.
00014 
00015 #include "absl/meta/type_traits.h"
00016 
00017 #include <cstdint>
00018 #include <string>
00019 #include <type_traits>
00020 #include <utility>
00021 #include <vector>
00022 
00023 #include "gtest/gtest.h"
00024 
00025 namespace {
00026 
00027 using ::testing::StaticAssertTypeEq;
00028 
00029 template <class T, class U>
00030 struct simple_pair {
00031   T first;
00032   U second;
00033 };
00034 
00035 struct Dummy {};
00036 
00037 struct ReturnType {};
00038 struct ConvertibleToReturnType {
00039   operator ReturnType() const;  // NOLINT
00040 };
00041 
00042 // Unique types used as parameter types for testing the detection idiom.
00043 struct StructA {};
00044 struct StructB {};
00045 struct StructC {};
00046 
00047 struct TypeWithBarFunction {
00048   template <class T,
00049             absl::enable_if_t<std::is_same<T&&, StructA&>::value, int> = 0>
00050   ReturnType bar(T&&, const StructB&, StructC&&) &&;  // NOLINT
00051 };
00052 
00053 struct TypeWithBarFunctionAndConvertibleReturnType {
00054   template <class T,
00055             absl::enable_if_t<std::is_same<T&&, StructA&>::value, int> = 0>
00056   ConvertibleToReturnType bar(T&&, const StructB&, StructC&&) &&;  // NOLINT
00057 };
00058 
00059 template <class Class, class... Ts>
00060 using BarIsCallableImpl =
00061     decltype(std::declval<Class>().bar(std::declval<Ts>()...));
00062 
00063 template <class Class, class... T>
00064 using BarIsCallable =
00065     absl::type_traits_internal::is_detected<BarIsCallableImpl, Class, T...>;
00066 
00067 template <class Class, class... T>
00068 using BarIsCallableConv = absl::type_traits_internal::is_detected_convertible<
00069     ReturnType, BarIsCallableImpl, Class, T...>;
00070 
00071 // NOTE: Test of detail type_traits_internal::is_detected.
00072 TEST(IsDetectedTest, BasicUsage) {
00073   EXPECT_TRUE((BarIsCallable<TypeWithBarFunction, StructA&, const StructB&,
00074                              StructC>::value));
00075   EXPECT_TRUE(
00076       (BarIsCallable<TypeWithBarFunction, StructA&, StructB&, StructC>::value));
00077   EXPECT_TRUE(
00078       (BarIsCallable<TypeWithBarFunction, StructA&, StructB, StructC>::value));
00079 
00080   EXPECT_FALSE((BarIsCallable<int, StructA&, const StructB&, StructC>::value));
00081   EXPECT_FALSE((BarIsCallable<TypeWithBarFunction&, StructA&, const StructB&,
00082                               StructC>::value));
00083   EXPECT_FALSE((BarIsCallable<TypeWithBarFunction, StructA, const StructB&,
00084                               StructC>::value));
00085 }
00086 
00087 // NOTE: Test of detail type_traits_internal::is_detected_convertible.
00088 TEST(IsDetectedConvertibleTest, BasicUsage) {
00089   EXPECT_TRUE((BarIsCallableConv<TypeWithBarFunction, StructA&, const StructB&,
00090                                  StructC>::value));
00091   EXPECT_TRUE((BarIsCallableConv<TypeWithBarFunction, StructA&, StructB&,
00092                                  StructC>::value));
00093   EXPECT_TRUE((BarIsCallableConv<TypeWithBarFunction, StructA&, StructB,
00094                                  StructC>::value));
00095   EXPECT_TRUE((BarIsCallableConv<TypeWithBarFunctionAndConvertibleReturnType,
00096                                  StructA&, const StructB&, StructC>::value));
00097   EXPECT_TRUE((BarIsCallableConv<TypeWithBarFunctionAndConvertibleReturnType,
00098                                  StructA&, StructB&, StructC>::value));
00099   EXPECT_TRUE((BarIsCallableConv<TypeWithBarFunctionAndConvertibleReturnType,
00100                                  StructA&, StructB, StructC>::value));
00101 
00102   EXPECT_FALSE(
00103       (BarIsCallableConv<int, StructA&, const StructB&, StructC>::value));
00104   EXPECT_FALSE((BarIsCallableConv<TypeWithBarFunction&, StructA&,
00105                                   const StructB&, StructC>::value));
00106   EXPECT_FALSE((BarIsCallableConv<TypeWithBarFunction, StructA, const StructB&,
00107                                   StructC>::value));
00108   EXPECT_FALSE((BarIsCallableConv<TypeWithBarFunctionAndConvertibleReturnType&,
00109                                   StructA&, const StructB&, StructC>::value));
00110   EXPECT_FALSE((BarIsCallableConv<TypeWithBarFunctionAndConvertibleReturnType,
00111                                   StructA, const StructB&, StructC>::value));
00112 }
00113 
00114 TEST(VoidTTest, BasicUsage) {
00115   StaticAssertTypeEq<void, absl::void_t<Dummy>>();
00116   StaticAssertTypeEq<void, absl::void_t<Dummy, Dummy, Dummy>>();
00117 }
00118 
00119 TEST(ConjunctionTest, BasicBooleanLogic) {
00120   EXPECT_TRUE(absl::conjunction<>::value);
00121   EXPECT_TRUE(absl::conjunction<std::true_type>::value);
00122   EXPECT_TRUE((absl::conjunction<std::true_type, std::true_type>::value));
00123   EXPECT_FALSE((absl::conjunction<std::true_type, std::false_type>::value));
00124   EXPECT_FALSE((absl::conjunction<std::false_type, std::true_type>::value));
00125   EXPECT_FALSE((absl::conjunction<std::false_type, std::false_type>::value));
00126 }
00127 
00128 struct MyTrueType {
00129   static constexpr bool value = true;
00130 };
00131 
00132 struct MyFalseType {
00133   static constexpr bool value = false;
00134 };
00135 
00136 TEST(ConjunctionTest, ShortCircuiting) {
00137   EXPECT_FALSE(
00138       (absl::conjunction<std::true_type, std::false_type, Dummy>::value));
00139   EXPECT_TRUE((std::is_base_of<MyFalseType,
00140                                absl::conjunction<std::true_type, MyFalseType,
00141                                                  std::false_type>>::value));
00142   EXPECT_TRUE(
00143       (std::is_base_of<MyTrueType,
00144                        absl::conjunction<std::true_type, MyTrueType>>::value));
00145 }
00146 
00147 TEST(DisjunctionTest, BasicBooleanLogic) {
00148   EXPECT_FALSE(absl::disjunction<>::value);
00149   EXPECT_FALSE(absl::disjunction<std::false_type>::value);
00150   EXPECT_TRUE((absl::disjunction<std::true_type, std::true_type>::value));
00151   EXPECT_TRUE((absl::disjunction<std::true_type, std::false_type>::value));
00152   EXPECT_TRUE((absl::disjunction<std::false_type, std::true_type>::value));
00153   EXPECT_FALSE((absl::disjunction<std::false_type, std::false_type>::value));
00154 }
00155 
00156 TEST(DisjunctionTest, ShortCircuiting) {
00157   EXPECT_TRUE(
00158       (absl::disjunction<std::false_type, std::true_type, Dummy>::value));
00159   EXPECT_TRUE((
00160       std::is_base_of<MyTrueType, absl::disjunction<std::false_type, MyTrueType,
00161                                                     std::true_type>>::value));
00162   EXPECT_TRUE((
00163       std::is_base_of<MyFalseType,
00164                       absl::disjunction<std::false_type, MyFalseType>>::value));
00165 }
00166 
00167 TEST(NegationTest, BasicBooleanLogic) {
00168   EXPECT_FALSE(absl::negation<std::true_type>::value);
00169   EXPECT_FALSE(absl::negation<MyTrueType>::value);
00170   EXPECT_TRUE(absl::negation<std::false_type>::value);
00171   EXPECT_TRUE(absl::negation<MyFalseType>::value);
00172 }
00173 
00174 // all member functions are trivial
00175 class Trivial {
00176   int n_;
00177 };
00178 
00179 struct TrivialDestructor {
00180   ~TrivialDestructor() = default;
00181 };
00182 
00183 struct NontrivialDestructor {
00184   ~NontrivialDestructor() {}
00185 };
00186 
00187 struct DeletedDestructor {
00188   ~DeletedDestructor() = delete;
00189 };
00190 
00191 class TrivialDefaultCtor {
00192  public:
00193   TrivialDefaultCtor() = default;
00194   explicit TrivialDefaultCtor(int n) : n_(n) {}
00195 
00196  private:
00197   int n_;
00198 };
00199 
00200 class NontrivialDefaultCtor {
00201  public:
00202   NontrivialDefaultCtor() : n_(1) {}
00203 
00204  private:
00205   int n_;
00206 };
00207 
00208 class DeletedDefaultCtor {
00209  public:
00210   DeletedDefaultCtor() = delete;
00211   explicit DeletedDefaultCtor(int n) : n_(n) {}
00212 
00213  private:
00214   int n_;
00215 };
00216 
00217 class TrivialMoveCtor {
00218  public:
00219   explicit TrivialMoveCtor(int n) : n_(n) {}
00220   TrivialMoveCtor(TrivialMoveCtor&&) = default;
00221   TrivialMoveCtor& operator=(const TrivialMoveCtor& t) {
00222     n_ = t.n_;
00223     return *this;
00224   }
00225 
00226  private:
00227   int n_;
00228 };
00229 
00230 class NontrivialMoveCtor {
00231  public:
00232   explicit NontrivialMoveCtor(int n) : n_(n) {}
00233   NontrivialMoveCtor(NontrivialMoveCtor&& t) noexcept : n_(t.n_) {}
00234   NontrivialMoveCtor& operator=(const NontrivialMoveCtor&) = default;
00235 
00236  private:
00237   int n_;
00238 };
00239 
00240 class TrivialCopyCtor {
00241  public:
00242   explicit TrivialCopyCtor(int n) : n_(n) {}
00243   TrivialCopyCtor(const TrivialCopyCtor&) = default;
00244   TrivialCopyCtor& operator=(const TrivialCopyCtor& t) {
00245     n_ = t.n_;
00246     return *this;
00247   }
00248 
00249  private:
00250   int n_;
00251 };
00252 
00253 class NontrivialCopyCtor {
00254  public:
00255   explicit NontrivialCopyCtor(int n) : n_(n) {}
00256   NontrivialCopyCtor(const NontrivialCopyCtor& t) : n_(t.n_) {}
00257   NontrivialCopyCtor& operator=(const NontrivialCopyCtor&) = default;
00258 
00259  private:
00260   int n_;
00261 };
00262 
00263 class DeletedCopyCtor {
00264  public:
00265   explicit DeletedCopyCtor(int n) : n_(n) {}
00266   DeletedCopyCtor(const DeletedCopyCtor&) = delete;
00267   DeletedCopyCtor& operator=(const DeletedCopyCtor&) = default;
00268 
00269  private:
00270   int n_;
00271 };
00272 
00273 class TrivialMoveAssign {
00274  public:
00275   explicit TrivialMoveAssign(int n) : n_(n) {}
00276   TrivialMoveAssign(const TrivialMoveAssign& t) : n_(t.n_) {}
00277   TrivialMoveAssign& operator=(TrivialMoveAssign&&) = default;
00278   ~TrivialMoveAssign() {}  // can have nontrivial destructor
00279  private:
00280   int n_;
00281 };
00282 
00283 class NontrivialMoveAssign {
00284  public:
00285   explicit NontrivialMoveAssign(int n) : n_(n) {}
00286   NontrivialMoveAssign(const NontrivialMoveAssign&) = default;
00287   NontrivialMoveAssign& operator=(NontrivialMoveAssign&& t) noexcept {
00288     n_ = t.n_;
00289     return *this;
00290   }
00291 
00292  private:
00293   int n_;
00294 };
00295 
00296 class TrivialCopyAssign {
00297  public:
00298   explicit TrivialCopyAssign(int n) : n_(n) {}
00299   TrivialCopyAssign(const TrivialCopyAssign& t) : n_(t.n_) {}
00300   TrivialCopyAssign& operator=(const TrivialCopyAssign& t) = default;
00301   ~TrivialCopyAssign() {}  // can have nontrivial destructor
00302  private:
00303   int n_;
00304 };
00305 
00306 class NontrivialCopyAssign {
00307  public:
00308   explicit NontrivialCopyAssign(int n) : n_(n) {}
00309   NontrivialCopyAssign(const NontrivialCopyAssign&) = default;
00310   NontrivialCopyAssign& operator=(const NontrivialCopyAssign& t) {
00311     n_ = t.n_;
00312     return *this;
00313   }
00314 
00315  private:
00316   int n_;
00317 };
00318 
00319 class DeletedCopyAssign {
00320  public:
00321   explicit DeletedCopyAssign(int n) : n_(n) {}
00322   DeletedCopyAssign(const DeletedCopyAssign&) = default;
00323   DeletedCopyAssign& operator=(const DeletedCopyAssign&) = delete;
00324 
00325  private:
00326   int n_;
00327 };
00328 
00329 struct MovableNonCopyable {
00330   MovableNonCopyable() = default;
00331   MovableNonCopyable(const MovableNonCopyable&) = delete;
00332   MovableNonCopyable(MovableNonCopyable&&) = default;
00333   MovableNonCopyable& operator=(const MovableNonCopyable&) = delete;
00334   MovableNonCopyable& operator=(MovableNonCopyable&&) = default;
00335 };
00336 
00337 struct NonCopyableOrMovable {
00338   NonCopyableOrMovable() = default;
00339   NonCopyableOrMovable(const NonCopyableOrMovable&) = delete;
00340   NonCopyableOrMovable(NonCopyableOrMovable&&) = delete;
00341   NonCopyableOrMovable& operator=(const NonCopyableOrMovable&) = delete;
00342   NonCopyableOrMovable& operator=(NonCopyableOrMovable&&) = delete;
00343 };
00344 
00345 class Base {
00346  public:
00347   virtual ~Base() {}
00348 };
00349 
00350 // In GCC/Clang, std::is_trivially_constructible requires that the destructor is
00351 // trivial. However, MSVC doesn't require that. This results in different
00352 // behavior when checking is_trivially_constructible on any type with
00353 // nontrivial destructor. Since absl::is_trivially_default_constructible and
00354 // absl::is_trivially_copy_constructible both follows Clang/GCC's interpretation
00355 // and check is_trivially_destructible, it results in inconsistency with
00356 // std::is_trivially_xxx_constructible on MSVC. This macro is used to work
00357 // around this issue in test. In practice, a trivially constructible type
00358 // should also be trivially destructible.
00359 // GCC bug 51452: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51452
00360 // LWG issue 2116: http://cplusplus.github.io/LWG/lwg-active.html#2116
00361 #ifndef _MSC_VER
00362 #define ABSL_TRIVIALLY_CONSTRUCTIBLE_VERIFY_TRIVIALLY_DESTRUCTIBLE 1
00363 #endif
00364 
00365 // Old versions of libc++, around Clang 3.5 to 3.6, consider deleted destructors
00366 // as also being trivial. With the resolution of CWG 1928 and CWG 1734, this
00367 // is no longer considered true and has thus been amended.
00368 // Compiler Explorer: https://godbolt.org/g/zT59ZL
00369 // CWG issue 1734: http://open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#1734
00370 // CWG issue 1928: http://open-std.org/JTC1/SC22/WG21/docs/cwg_closed.html#1928
00371 #if !defined(_LIBCPP_VERSION) || _LIBCPP_VERSION >= 3700
00372 #define ABSL_TRIVIALLY_DESTRUCTIBLE_CONSIDER_DELETED_DESTRUCTOR_NOT_TRIVIAL 1
00373 #endif
00374 
00375 // As of the moment, GCC versions >5.1 have a problem compiling for
00376 // std::is_trivially_default_constructible<NontrivialDestructor[10]>, where
00377 // NontrivialDestructor is a struct with a custom nontrivial destructor. Note
00378 // that this problem only occurs for arrays of a known size, so something like
00379 // std::is_trivially_default_constructible<NontrivialDestructor[]> does not
00380 // have any problems.
00381 // Compiler Explorer: https://godbolt.org/g/dXRbdK
00382 // GCC bug 83689: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83689
00383 #if defined(__clang__) || defined(_MSC_VER) || \
00384     (defined(__GNUC__) && __GNUC__ < 5)
00385 #define ABSL_GCC_BUG_TRIVIALLY_CONSTRUCTIBLE_ON_ARRAY_OF_NONTRIVIAL 1
00386 #endif
00387 
00388 TEST(TypeTraitsTest, TestTrivialDestructor) {
00389   // Verify that arithmetic types and pointers have trivial destructors.
00390   EXPECT_TRUE(absl::is_trivially_destructible<bool>::value);
00391   EXPECT_TRUE(absl::is_trivially_destructible<char>::value);
00392   EXPECT_TRUE(absl::is_trivially_destructible<unsigned char>::value);
00393   EXPECT_TRUE(absl::is_trivially_destructible<signed char>::value);
00394   EXPECT_TRUE(absl::is_trivially_destructible<wchar_t>::value);
00395   EXPECT_TRUE(absl::is_trivially_destructible<int>::value);
00396   EXPECT_TRUE(absl::is_trivially_destructible<unsigned int>::value);
00397   EXPECT_TRUE(absl::is_trivially_destructible<int16_t>::value);
00398   EXPECT_TRUE(absl::is_trivially_destructible<uint16_t>::value);
00399   EXPECT_TRUE(absl::is_trivially_destructible<int64_t>::value);
00400   EXPECT_TRUE(absl::is_trivially_destructible<uint64_t>::value);
00401   EXPECT_TRUE(absl::is_trivially_destructible<float>::value);
00402   EXPECT_TRUE(absl::is_trivially_destructible<double>::value);
00403   EXPECT_TRUE(absl::is_trivially_destructible<long double>::value);
00404   EXPECT_TRUE(absl::is_trivially_destructible<std::string*>::value);
00405   EXPECT_TRUE(absl::is_trivially_destructible<Trivial*>::value);
00406   EXPECT_TRUE(absl::is_trivially_destructible<const std::string*>::value);
00407   EXPECT_TRUE(absl::is_trivially_destructible<const Trivial*>::value);
00408   EXPECT_TRUE(absl::is_trivially_destructible<std::string**>::value);
00409   EXPECT_TRUE(absl::is_trivially_destructible<Trivial**>::value);
00410 
00411   // classes with destructors
00412   EXPECT_TRUE(absl::is_trivially_destructible<Trivial>::value);
00413   EXPECT_TRUE(absl::is_trivially_destructible<TrivialDestructor>::value);
00414 
00415   // Verify that types with a nontrivial or deleted destructor
00416   // are marked as such.
00417   EXPECT_FALSE(absl::is_trivially_destructible<NontrivialDestructor>::value);
00418 #ifdef ABSL_TRIVIALLY_DESTRUCTIBLE_CONSIDER_DELETED_DESTRUCTOR_NOT_TRIVIAL
00419   EXPECT_FALSE(absl::is_trivially_destructible<DeletedDestructor>::value);
00420 #endif
00421 
00422   // simple_pair of such types is trivial
00423   EXPECT_TRUE((absl::is_trivially_destructible<simple_pair<int, int>>::value));
00424   EXPECT_TRUE((absl::is_trivially_destructible<
00425                simple_pair<Trivial, TrivialDestructor>>::value));
00426 
00427   // Verify that types without trivial destructors are correctly marked as such.
00428   EXPECT_FALSE(absl::is_trivially_destructible<std::string>::value);
00429   EXPECT_FALSE(absl::is_trivially_destructible<std::vector<int>>::value);
00430 
00431   // Verify that simple_pairs of types without trivial destructors
00432   // are not marked as trivial.
00433   EXPECT_FALSE((absl::is_trivially_destructible<
00434                 simple_pair<int, std::string>>::value));
00435   EXPECT_FALSE((absl::is_trivially_destructible<
00436                 simple_pair<std::string, int>>::value));
00437 
00438   // array of such types is trivial
00439   using int10 = int[10];
00440   EXPECT_TRUE(absl::is_trivially_destructible<int10>::value);
00441   using Trivial10 = Trivial[10];
00442   EXPECT_TRUE(absl::is_trivially_destructible<Trivial10>::value);
00443   using TrivialDestructor10 = TrivialDestructor[10];
00444   EXPECT_TRUE(absl::is_trivially_destructible<TrivialDestructor10>::value);
00445 
00446   // Conversely, the opposite also holds.
00447   using NontrivialDestructor10 = NontrivialDestructor[10];
00448   EXPECT_FALSE(absl::is_trivially_destructible<NontrivialDestructor10>::value);
00449 }
00450 
00451 TEST(TypeTraitsTest, TestTrivialDefaultCtor) {
00452   // arithmetic types and pointers have trivial default constructors.
00453   EXPECT_TRUE(absl::is_trivially_default_constructible<bool>::value);
00454   EXPECT_TRUE(absl::is_trivially_default_constructible<char>::value);
00455   EXPECT_TRUE(absl::is_trivially_default_constructible<unsigned char>::value);
00456   EXPECT_TRUE(absl::is_trivially_default_constructible<signed char>::value);
00457   EXPECT_TRUE(absl::is_trivially_default_constructible<wchar_t>::value);
00458   EXPECT_TRUE(absl::is_trivially_default_constructible<int>::value);
00459   EXPECT_TRUE(absl::is_trivially_default_constructible<unsigned int>::value);
00460   EXPECT_TRUE(absl::is_trivially_default_constructible<int16_t>::value);
00461   EXPECT_TRUE(absl::is_trivially_default_constructible<uint16_t>::value);
00462   EXPECT_TRUE(absl::is_trivially_default_constructible<int64_t>::value);
00463   EXPECT_TRUE(absl::is_trivially_default_constructible<uint64_t>::value);
00464   EXPECT_TRUE(absl::is_trivially_default_constructible<float>::value);
00465   EXPECT_TRUE(absl::is_trivially_default_constructible<double>::value);
00466   EXPECT_TRUE(absl::is_trivially_default_constructible<long double>::value);
00467   EXPECT_TRUE(absl::is_trivially_default_constructible<std::string*>::value);
00468   EXPECT_TRUE(absl::is_trivially_default_constructible<Trivial*>::value);
00469   EXPECT_TRUE(
00470       absl::is_trivially_default_constructible<const std::string*>::value);
00471   EXPECT_TRUE(absl::is_trivially_default_constructible<const Trivial*>::value);
00472   EXPECT_TRUE(absl::is_trivially_default_constructible<std::string**>::value);
00473   EXPECT_TRUE(absl::is_trivially_default_constructible<Trivial**>::value);
00474 
00475   // types with compiler generated default ctors
00476   EXPECT_TRUE(absl::is_trivially_default_constructible<Trivial>::value);
00477   EXPECT_TRUE(
00478       absl::is_trivially_default_constructible<TrivialDefaultCtor>::value);
00479 
00480   // Verify that types without them are not.
00481   EXPECT_FALSE(
00482       absl::is_trivially_default_constructible<NontrivialDefaultCtor>::value);
00483   EXPECT_FALSE(
00484       absl::is_trivially_default_constructible<DeletedDefaultCtor>::value);
00485 
00486 #ifdef ABSL_TRIVIALLY_CONSTRUCTIBLE_VERIFY_TRIVIALLY_DESTRUCTIBLE
00487   // types with nontrivial destructor are nontrivial
00488   EXPECT_FALSE(
00489       absl::is_trivially_default_constructible<NontrivialDestructor>::value);
00490 #endif
00491 
00492   // types with vtables
00493   EXPECT_FALSE(absl::is_trivially_default_constructible<Base>::value);
00494 
00495   // Verify that simple_pair has trivial constructors where applicable.
00496   EXPECT_TRUE((absl::is_trivially_default_constructible<
00497                simple_pair<int, char*>>::value));
00498   EXPECT_TRUE((absl::is_trivially_default_constructible<
00499                simple_pair<int, Trivial>>::value));
00500   EXPECT_TRUE((absl::is_trivially_default_constructible<
00501                simple_pair<int, TrivialDefaultCtor>>::value));
00502 
00503   // Verify that types without trivial constructors are
00504   // correctly marked as such.
00505   EXPECT_FALSE(absl::is_trivially_default_constructible<std::string>::value);
00506   EXPECT_FALSE(
00507       absl::is_trivially_default_constructible<std::vector<int>>::value);
00508 
00509   // Verify that simple_pairs of types without trivial constructors
00510   // are not marked as trivial.
00511   EXPECT_FALSE((absl::is_trivially_default_constructible<
00512                 simple_pair<int, std::string>>::value));
00513   EXPECT_FALSE((absl::is_trivially_default_constructible<
00514                 simple_pair<std::string, int>>::value));
00515 
00516   // Verify that arrays of such types are trivially default constructible
00517   using int10 = int[10];
00518   EXPECT_TRUE(absl::is_trivially_default_constructible<int10>::value);
00519   using Trivial10 = Trivial[10];
00520   EXPECT_TRUE(absl::is_trivially_default_constructible<Trivial10>::value);
00521   using TrivialDefaultCtor10 = TrivialDefaultCtor[10];
00522   EXPECT_TRUE(
00523       absl::is_trivially_default_constructible<TrivialDefaultCtor10>::value);
00524 
00525   // Conversely, the opposite also holds.
00526 #ifdef ABSL_GCC_BUG_TRIVIALLY_CONSTRUCTIBLE_ON_ARRAY_OF_NONTRIVIAL
00527   using NontrivialDefaultCtor10 = NontrivialDefaultCtor[10];
00528   EXPECT_FALSE(
00529       absl::is_trivially_default_constructible<NontrivialDefaultCtor10>::value);
00530 #endif
00531 }
00532 
00533 TEST(TypeTraitsTest, TestTrivialMoveCtor) {
00534   // Verify that arithmetic types and pointers have trivial move
00535   // constructors.
00536   EXPECT_TRUE(absl::is_trivially_move_constructible<bool>::value);
00537   EXPECT_TRUE(absl::is_trivially_move_constructible<char>::value);
00538   EXPECT_TRUE(absl::is_trivially_move_constructible<unsigned char>::value);
00539   EXPECT_TRUE(absl::is_trivially_move_constructible<signed char>::value);
00540   EXPECT_TRUE(absl::is_trivially_move_constructible<wchar_t>::value);
00541   EXPECT_TRUE(absl::is_trivially_move_constructible<int>::value);
00542   EXPECT_TRUE(absl::is_trivially_move_constructible<unsigned int>::value);
00543   EXPECT_TRUE(absl::is_trivially_move_constructible<int16_t>::value);
00544   EXPECT_TRUE(absl::is_trivially_move_constructible<uint16_t>::value);
00545   EXPECT_TRUE(absl::is_trivially_move_constructible<int64_t>::value);
00546   EXPECT_TRUE(absl::is_trivially_move_constructible<uint64_t>::value);
00547   EXPECT_TRUE(absl::is_trivially_move_constructible<float>::value);
00548   EXPECT_TRUE(absl::is_trivially_move_constructible<double>::value);
00549   EXPECT_TRUE(absl::is_trivially_move_constructible<long double>::value);
00550   EXPECT_TRUE(absl::is_trivially_move_constructible<std::string*>::value);
00551   EXPECT_TRUE(absl::is_trivially_move_constructible<Trivial*>::value);
00552   EXPECT_TRUE(absl::is_trivially_move_constructible<const std::string*>::value);
00553   EXPECT_TRUE(absl::is_trivially_move_constructible<const Trivial*>::value);
00554   EXPECT_TRUE(absl::is_trivially_move_constructible<std::string**>::value);
00555   EXPECT_TRUE(absl::is_trivially_move_constructible<Trivial**>::value);
00556 
00557   // Reference types
00558   EXPECT_TRUE(absl::is_trivially_move_constructible<int&>::value);
00559   EXPECT_TRUE(absl::is_trivially_move_constructible<int&&>::value);
00560 
00561   // types with compiler generated move ctors
00562   EXPECT_TRUE(absl::is_trivially_move_constructible<Trivial>::value);
00563   EXPECT_TRUE(absl::is_trivially_move_constructible<TrivialMoveCtor>::value);
00564 
00565   // Verify that types without them (i.e. nontrivial or deleted) are not.
00566   EXPECT_FALSE(
00567       absl::is_trivially_move_constructible<NontrivialCopyCtor>::value);
00568   EXPECT_FALSE(absl::is_trivially_move_constructible<DeletedCopyCtor>::value);
00569   EXPECT_FALSE(
00570       absl::is_trivially_move_constructible<NonCopyableOrMovable>::value);
00571 
00572 #ifdef ABSL_TRIVIALLY_CONSTRUCTIBLE_VERIFY_TRIVIALLY_DESTRUCTIBLE
00573   // type with nontrivial destructor are nontrivial move construbtible
00574   EXPECT_FALSE(
00575       absl::is_trivially_move_constructible<NontrivialDestructor>::value);
00576 #endif
00577 
00578   // types with vtables
00579   EXPECT_FALSE(absl::is_trivially_move_constructible<Base>::value);
00580 
00581   // Verify that simple_pair of such types is trivially move constructible
00582   EXPECT_TRUE(
00583       (absl::is_trivially_move_constructible<simple_pair<int, char*>>::value));
00584   EXPECT_TRUE((
00585       absl::is_trivially_move_constructible<simple_pair<int, Trivial>>::value));
00586   EXPECT_TRUE((absl::is_trivially_move_constructible<
00587                simple_pair<int, TrivialMoveCtor>>::value));
00588 
00589   // Verify that types without trivial move constructors are
00590   // correctly marked as such.
00591   EXPECT_FALSE(absl::is_trivially_move_constructible<std::string>::value);
00592   EXPECT_FALSE(absl::is_trivially_move_constructible<std::vector<int>>::value);
00593 
00594   // Verify that simple_pairs of types without trivial move constructors
00595   // are not marked as trivial.
00596   EXPECT_FALSE((absl::is_trivially_move_constructible<
00597                 simple_pair<int, std::string>>::value));
00598   EXPECT_FALSE((absl::is_trivially_move_constructible<
00599                 simple_pair<std::string, int>>::value));
00600 
00601   // Verify that arrays are not
00602   using int10 = int[10];
00603   EXPECT_FALSE(absl::is_trivially_move_constructible<int10>::value);
00604 }
00605 
00606 TEST(TypeTraitsTest, TestTrivialCopyCtor) {
00607   // Verify that arithmetic types and pointers have trivial copy
00608   // constructors.
00609   EXPECT_TRUE(absl::is_trivially_copy_constructible<bool>::value);
00610   EXPECT_TRUE(absl::is_trivially_copy_constructible<char>::value);
00611   EXPECT_TRUE(absl::is_trivially_copy_constructible<unsigned char>::value);
00612   EXPECT_TRUE(absl::is_trivially_copy_constructible<signed char>::value);
00613   EXPECT_TRUE(absl::is_trivially_copy_constructible<wchar_t>::value);
00614   EXPECT_TRUE(absl::is_trivially_copy_constructible<int>::value);
00615   EXPECT_TRUE(absl::is_trivially_copy_constructible<unsigned int>::value);
00616   EXPECT_TRUE(absl::is_trivially_copy_constructible<int16_t>::value);
00617   EXPECT_TRUE(absl::is_trivially_copy_constructible<uint16_t>::value);
00618   EXPECT_TRUE(absl::is_trivially_copy_constructible<int64_t>::value);
00619   EXPECT_TRUE(absl::is_trivially_copy_constructible<uint64_t>::value);
00620   EXPECT_TRUE(absl::is_trivially_copy_constructible<float>::value);
00621   EXPECT_TRUE(absl::is_trivially_copy_constructible<double>::value);
00622   EXPECT_TRUE(absl::is_trivially_copy_constructible<long double>::value);
00623   EXPECT_TRUE(absl::is_trivially_copy_constructible<std::string*>::value);
00624   EXPECT_TRUE(absl::is_trivially_copy_constructible<Trivial*>::value);
00625   EXPECT_TRUE(absl::is_trivially_copy_constructible<const std::string*>::value);
00626   EXPECT_TRUE(absl::is_trivially_copy_constructible<const Trivial*>::value);
00627   EXPECT_TRUE(absl::is_trivially_copy_constructible<std::string**>::value);
00628   EXPECT_TRUE(absl::is_trivially_copy_constructible<Trivial**>::value);
00629 
00630   // Reference types
00631   EXPECT_TRUE(absl::is_trivially_copy_constructible<int&>::value);
00632   EXPECT_FALSE(absl::is_trivially_copy_constructible<int&&>::value);
00633 
00634   // types with compiler generated copy ctors
00635   EXPECT_TRUE(absl::is_trivially_copy_constructible<Trivial>::value);
00636   EXPECT_TRUE(absl::is_trivially_copy_constructible<TrivialCopyCtor>::value);
00637 
00638   // Verify that types without them (i.e. nontrivial or deleted) are not.
00639   EXPECT_FALSE(
00640       absl::is_trivially_copy_constructible<NontrivialCopyCtor>::value);
00641   EXPECT_FALSE(absl::is_trivially_copy_constructible<DeletedCopyCtor>::value);
00642   EXPECT_FALSE(
00643       absl::is_trivially_copy_constructible<MovableNonCopyable>::value);
00644   EXPECT_FALSE(
00645       absl::is_trivially_copy_constructible<NonCopyableOrMovable>::value);
00646 
00647 #ifdef ABSL_TRIVIALLY_CONSTRUCTIBLE_VERIFY_TRIVIALLY_DESTRUCTIBLE
00648   // type with nontrivial destructor are nontrivial copy construbtible
00649   EXPECT_FALSE(
00650       absl::is_trivially_copy_constructible<NontrivialDestructor>::value);
00651 #endif
00652 
00653   // types with vtables
00654   EXPECT_FALSE(absl::is_trivially_copy_constructible<Base>::value);
00655 
00656   // Verify that simple_pair of such types is trivially copy constructible
00657   EXPECT_TRUE(
00658       (absl::is_trivially_copy_constructible<simple_pair<int, char*>>::value));
00659   EXPECT_TRUE((
00660       absl::is_trivially_copy_constructible<simple_pair<int, Trivial>>::value));
00661   EXPECT_TRUE((absl::is_trivially_copy_constructible<
00662                simple_pair<int, TrivialCopyCtor>>::value));
00663 
00664   // Verify that types without trivial copy constructors are
00665   // correctly marked as such.
00666   EXPECT_FALSE(absl::is_trivially_copy_constructible<std::string>::value);
00667   EXPECT_FALSE(absl::is_trivially_copy_constructible<std::vector<int>>::value);
00668 
00669   // Verify that simple_pairs of types without trivial copy constructors
00670   // are not marked as trivial.
00671   EXPECT_FALSE((absl::is_trivially_copy_constructible<
00672                 simple_pair<int, std::string>>::value));
00673   EXPECT_FALSE((absl::is_trivially_copy_constructible<
00674                 simple_pair<std::string, int>>::value));
00675 
00676   // Verify that arrays are not
00677   using int10 = int[10];
00678   EXPECT_FALSE(absl::is_trivially_copy_constructible<int10>::value);
00679 }
00680 
00681 TEST(TypeTraitsTest, TestTrivialMoveAssign) {
00682   // Verify that arithmetic types and pointers have trivial move
00683   // assignment operators.
00684   EXPECT_TRUE(absl::is_trivially_move_assignable<bool>::value);
00685   EXPECT_TRUE(absl::is_trivially_move_assignable<char>::value);
00686   EXPECT_TRUE(absl::is_trivially_move_assignable<unsigned char>::value);
00687   EXPECT_TRUE(absl::is_trivially_move_assignable<signed char>::value);
00688   EXPECT_TRUE(absl::is_trivially_move_assignable<wchar_t>::value);
00689   EXPECT_TRUE(absl::is_trivially_move_assignable<int>::value);
00690   EXPECT_TRUE(absl::is_trivially_move_assignable<unsigned int>::value);
00691   EXPECT_TRUE(absl::is_trivially_move_assignable<int16_t>::value);
00692   EXPECT_TRUE(absl::is_trivially_move_assignable<uint16_t>::value);
00693   EXPECT_TRUE(absl::is_trivially_move_assignable<int64_t>::value);
00694   EXPECT_TRUE(absl::is_trivially_move_assignable<uint64_t>::value);
00695   EXPECT_TRUE(absl::is_trivially_move_assignable<float>::value);
00696   EXPECT_TRUE(absl::is_trivially_move_assignable<double>::value);
00697   EXPECT_TRUE(absl::is_trivially_move_assignable<long double>::value);
00698   EXPECT_TRUE(absl::is_trivially_move_assignable<std::string*>::value);
00699   EXPECT_TRUE(absl::is_trivially_move_assignable<Trivial*>::value);
00700   EXPECT_TRUE(absl::is_trivially_move_assignable<const std::string*>::value);
00701   EXPECT_TRUE(absl::is_trivially_move_assignable<const Trivial*>::value);
00702   EXPECT_TRUE(absl::is_trivially_move_assignable<std::string**>::value);
00703   EXPECT_TRUE(absl::is_trivially_move_assignable<Trivial**>::value);
00704 
00705   // const qualified types are not assignable
00706   EXPECT_FALSE(absl::is_trivially_move_assignable<const int>::value);
00707 
00708   // types with compiler generated move assignment
00709   EXPECT_TRUE(absl::is_trivially_move_assignable<Trivial>::value);
00710   EXPECT_TRUE(absl::is_trivially_move_assignable<TrivialMoveAssign>::value);
00711 
00712   // Verify that types without them (i.e. nontrivial or deleted) are not.
00713   EXPECT_FALSE(absl::is_trivially_move_assignable<NontrivialCopyAssign>::value);
00714   EXPECT_FALSE(absl::is_trivially_move_assignable<DeletedCopyAssign>::value);
00715   EXPECT_FALSE(absl::is_trivially_move_assignable<NonCopyableOrMovable>::value);
00716 
00717   // types with vtables
00718   EXPECT_FALSE(absl::is_trivially_move_assignable<Base>::value);
00719 
00720   // Verify that simple_pair is trivially assignable
00721   EXPECT_TRUE(
00722       (absl::is_trivially_move_assignable<simple_pair<int, char*>>::value));
00723   EXPECT_TRUE(
00724       (absl::is_trivially_move_assignable<simple_pair<int, Trivial>>::value));
00725   EXPECT_TRUE((absl::is_trivially_move_assignable<
00726                simple_pair<int, TrivialMoveAssign>>::value));
00727 
00728   // Verify that types not trivially move assignable are
00729   // correctly marked as such.
00730   EXPECT_FALSE(absl::is_trivially_move_assignable<std::string>::value);
00731   EXPECT_FALSE(absl::is_trivially_move_assignable<std::vector<int>>::value);
00732 
00733   // Verify that simple_pairs of types not trivially move assignable
00734   // are not marked as trivial.
00735   EXPECT_FALSE((absl::is_trivially_move_assignable<
00736                 simple_pair<int, std::string>>::value));
00737   EXPECT_FALSE((absl::is_trivially_move_assignable<
00738                 simple_pair<std::string, int>>::value));
00739 
00740   // Verify that arrays are not trivially move assignable
00741   using int10 = int[10];
00742   EXPECT_FALSE(absl::is_trivially_move_assignable<int10>::value);
00743 
00744   // Verify that references are handled correctly
00745   EXPECT_TRUE(absl::is_trivially_move_assignable<Trivial&&>::value);
00746   EXPECT_TRUE(absl::is_trivially_move_assignable<Trivial&>::value);
00747 }
00748 
00749 TEST(TypeTraitsTest, TestTrivialCopyAssign) {
00750   // Verify that arithmetic types and pointers have trivial copy
00751   // assignment operators.
00752   EXPECT_TRUE(absl::is_trivially_copy_assignable<bool>::value);
00753   EXPECT_TRUE(absl::is_trivially_copy_assignable<char>::value);
00754   EXPECT_TRUE(absl::is_trivially_copy_assignable<unsigned char>::value);
00755   EXPECT_TRUE(absl::is_trivially_copy_assignable<signed char>::value);
00756   EXPECT_TRUE(absl::is_trivially_copy_assignable<wchar_t>::value);
00757   EXPECT_TRUE(absl::is_trivially_copy_assignable<int>::value);
00758   EXPECT_TRUE(absl::is_trivially_copy_assignable<unsigned int>::value);
00759   EXPECT_TRUE(absl::is_trivially_copy_assignable<int16_t>::value);
00760   EXPECT_TRUE(absl::is_trivially_copy_assignable<uint16_t>::value);
00761   EXPECT_TRUE(absl::is_trivially_copy_assignable<int64_t>::value);
00762   EXPECT_TRUE(absl::is_trivially_copy_assignable<uint64_t>::value);
00763   EXPECT_TRUE(absl::is_trivially_copy_assignable<float>::value);
00764   EXPECT_TRUE(absl::is_trivially_copy_assignable<double>::value);
00765   EXPECT_TRUE(absl::is_trivially_copy_assignable<long double>::value);
00766   EXPECT_TRUE(absl::is_trivially_copy_assignable<std::string*>::value);
00767   EXPECT_TRUE(absl::is_trivially_copy_assignable<Trivial*>::value);
00768   EXPECT_TRUE(absl::is_trivially_copy_assignable<const std::string*>::value);
00769   EXPECT_TRUE(absl::is_trivially_copy_assignable<const Trivial*>::value);
00770   EXPECT_TRUE(absl::is_trivially_copy_assignable<std::string**>::value);
00771   EXPECT_TRUE(absl::is_trivially_copy_assignable<Trivial**>::value);
00772 
00773   // const qualified types are not assignable
00774   EXPECT_FALSE(absl::is_trivially_copy_assignable<const int>::value);
00775 
00776   // types with compiler generated copy assignment
00777   EXPECT_TRUE(absl::is_trivially_copy_assignable<Trivial>::value);
00778   EXPECT_TRUE(absl::is_trivially_copy_assignable<TrivialCopyAssign>::value);
00779 
00780   // Verify that types without them (i.e. nontrivial or deleted) are not.
00781   EXPECT_FALSE(absl::is_trivially_copy_assignable<NontrivialCopyAssign>::value);
00782   EXPECT_FALSE(absl::is_trivially_copy_assignable<DeletedCopyAssign>::value);
00783   EXPECT_FALSE(absl::is_trivially_copy_assignable<MovableNonCopyable>::value);
00784   EXPECT_FALSE(absl::is_trivially_copy_assignable<NonCopyableOrMovable>::value);
00785 
00786   // types with vtables
00787   EXPECT_FALSE(absl::is_trivially_copy_assignable<Base>::value);
00788 
00789   // Verify that simple_pair is trivially assignable
00790   EXPECT_TRUE(
00791       (absl::is_trivially_copy_assignable<simple_pair<int, char*>>::value));
00792   EXPECT_TRUE(
00793       (absl::is_trivially_copy_assignable<simple_pair<int, Trivial>>::value));
00794   EXPECT_TRUE((absl::is_trivially_copy_assignable<
00795                simple_pair<int, TrivialCopyAssign>>::value));
00796 
00797   // Verify that types not trivially copy assignable are
00798   // correctly marked as such.
00799   EXPECT_FALSE(absl::is_trivially_copy_assignable<std::string>::value);
00800   EXPECT_FALSE(absl::is_trivially_copy_assignable<std::vector<int>>::value);
00801 
00802   // Verify that simple_pairs of types not trivially copy assignable
00803   // are not marked as trivial.
00804   EXPECT_FALSE((absl::is_trivially_copy_assignable<
00805                 simple_pair<int, std::string>>::value));
00806   EXPECT_FALSE((absl::is_trivially_copy_assignable<
00807                 simple_pair<std::string, int>>::value));
00808 
00809   // Verify that arrays are not trivially copy assignable
00810   using int10 = int[10];
00811   EXPECT_FALSE(absl::is_trivially_copy_assignable<int10>::value);
00812 
00813   // Verify that references are handled correctly
00814   EXPECT_TRUE(absl::is_trivially_copy_assignable<Trivial&&>::value);
00815   EXPECT_TRUE(absl::is_trivially_copy_assignable<Trivial&>::value);
00816 }
00817 
00818 TEST(TypeTraitsTest, TestTriviallyCopyable) {
00819   // Verify that arithmetic types and pointers are trivially copyable.
00820   EXPECT_TRUE(absl::type_traits_internal::is_trivially_copyable<bool>::value);
00821   EXPECT_TRUE(absl::type_traits_internal::is_trivially_copyable<char>::value);
00822   EXPECT_TRUE(
00823       absl::type_traits_internal::is_trivially_copyable<unsigned char>::value);
00824   EXPECT_TRUE(
00825       absl::type_traits_internal::is_trivially_copyable<signed char>::value);
00826   EXPECT_TRUE(
00827       absl::type_traits_internal::is_trivially_copyable<wchar_t>::value);
00828   EXPECT_TRUE(absl::type_traits_internal::is_trivially_copyable<int>::value);
00829   EXPECT_TRUE(
00830       absl::type_traits_internal::is_trivially_copyable<unsigned int>::value);
00831   EXPECT_TRUE(
00832       absl::type_traits_internal::is_trivially_copyable<int16_t>::value);
00833   EXPECT_TRUE(
00834       absl::type_traits_internal::is_trivially_copyable<uint16_t>::value);
00835   EXPECT_TRUE(
00836       absl::type_traits_internal::is_trivially_copyable<int64_t>::value);
00837   EXPECT_TRUE(
00838       absl::type_traits_internal::is_trivially_copyable<uint64_t>::value);
00839   EXPECT_TRUE(absl::type_traits_internal::is_trivially_copyable<float>::value);
00840   EXPECT_TRUE(absl::type_traits_internal::is_trivially_copyable<double>::value);
00841   EXPECT_TRUE(
00842       absl::type_traits_internal::is_trivially_copyable<long double>::value);
00843   EXPECT_TRUE(
00844       absl::type_traits_internal::is_trivially_copyable<std::string*>::value);
00845   EXPECT_TRUE(
00846       absl::type_traits_internal::is_trivially_copyable<Trivial*>::value);
00847   EXPECT_TRUE(absl::type_traits_internal::is_trivially_copyable<
00848               const std::string*>::value);
00849   EXPECT_TRUE(
00850       absl::type_traits_internal::is_trivially_copyable<const Trivial*>::value);
00851   EXPECT_TRUE(
00852       absl::type_traits_internal::is_trivially_copyable<std::string**>::value);
00853   EXPECT_TRUE(
00854       absl::type_traits_internal::is_trivially_copyable<Trivial**>::value);
00855 
00856   // const qualified types are not assignable but are constructible
00857   EXPECT_TRUE(
00858       absl::type_traits_internal::is_trivially_copyable<const int>::value);
00859 
00860   // Trivial copy constructor/assignment and destructor.
00861   EXPECT_TRUE(
00862       absl::type_traits_internal::is_trivially_copyable<Trivial>::value);
00863   // Trivial copy assignment, but non-trivial copy constructor/destructor.
00864   EXPECT_FALSE(absl::type_traits_internal::is_trivially_copyable<
00865                TrivialCopyAssign>::value);
00866   // Trivial copy constructor, but non-trivial assignment.
00867   EXPECT_FALSE(absl::type_traits_internal::is_trivially_copyable<
00868                TrivialCopyCtor>::value);
00869 
00870   // Types with a non-trivial copy constructor/assignment
00871   EXPECT_FALSE(absl::type_traits_internal::is_trivially_copyable<
00872                NontrivialCopyCtor>::value);
00873   EXPECT_FALSE(absl::type_traits_internal::is_trivially_copyable<
00874                NontrivialCopyAssign>::value);
00875 
00876   // Types without copy constructor/assignment, but with move
00877   // MSVC disagrees with other compilers about this:
00878   // EXPECT_TRUE(absl::type_traits_internal::is_trivially_copyable<
00879   //             MovableNonCopyable>::value);
00880 
00881   // Types without copy/move constructor/assignment
00882   EXPECT_FALSE(absl::type_traits_internal::is_trivially_copyable<
00883                NonCopyableOrMovable>::value);
00884 
00885   // No copy assign, but has trivial copy constructor.
00886   EXPECT_TRUE(absl::type_traits_internal::is_trivially_copyable<
00887               DeletedCopyAssign>::value);
00888 
00889   // types with vtables
00890   EXPECT_FALSE(absl::type_traits_internal::is_trivially_copyable<Base>::value);
00891 
00892   // Verify that simple_pair is trivially copyable if members are
00893   EXPECT_TRUE((absl::type_traits_internal::is_trivially_copyable<
00894                simple_pair<int, char*>>::value));
00895   EXPECT_TRUE((absl::type_traits_internal::is_trivially_copyable<
00896                simple_pair<int, Trivial>>::value));
00897 
00898   // Verify that types not trivially copyable are
00899   // correctly marked as such.
00900   EXPECT_FALSE(
00901       absl::type_traits_internal::is_trivially_copyable<std::string>::value);
00902   EXPECT_FALSE(absl::type_traits_internal::is_trivially_copyable<
00903                std::vector<int>>::value);
00904 
00905   // Verify that simple_pairs of types not trivially copyable
00906   // are not marked as trivial.
00907   EXPECT_FALSE((absl::type_traits_internal::is_trivially_copyable<
00908                 simple_pair<int, std::string>>::value));
00909   EXPECT_FALSE((absl::type_traits_internal::is_trivially_copyable<
00910                 simple_pair<std::string, int>>::value));
00911   EXPECT_FALSE((absl::type_traits_internal::is_trivially_copyable<
00912                 simple_pair<int, TrivialCopyAssign>>::value));
00913 
00914   // Verify that arrays of trivially copyable types are trivially copyable
00915   using int10 = int[10];
00916   EXPECT_TRUE(absl::type_traits_internal::is_trivially_copyable<int10>::value);
00917   using int10x10 = int[10][10];
00918   EXPECT_TRUE(
00919       absl::type_traits_internal::is_trivially_copyable<int10x10>::value);
00920 
00921   // Verify that references are handled correctly
00922   EXPECT_FALSE(
00923       absl::type_traits_internal::is_trivially_copyable<Trivial&&>::value);
00924   EXPECT_FALSE(
00925       absl::type_traits_internal::is_trivially_copyable<Trivial&>::value);
00926 }
00927 
00928 #define ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(trait_name, ...)          \
00929   EXPECT_TRUE((std::is_same<typename std::trait_name<__VA_ARGS__>::type, \
00930                             absl::trait_name##_t<__VA_ARGS__>>::value))
00931 
00932 TEST(TypeTraitsTest, TestRemoveCVAliases) {
00933   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_cv, int);
00934   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_cv, const int);
00935   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_cv, volatile int);
00936   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_cv, const volatile int);
00937 
00938   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_const, int);
00939   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_const, const int);
00940   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_const, volatile int);
00941   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_const, const volatile int);
00942 
00943   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_volatile, int);
00944   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_volatile, const int);
00945   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_volatile, volatile int);
00946   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_volatile, const volatile int);
00947 }
00948 
00949 TEST(TypeTraitsTest, TestAddCVAliases) {
00950   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_cv, int);
00951   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_cv, const int);
00952   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_cv, volatile int);
00953   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_cv, const volatile int);
00954 
00955   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_const, int);
00956   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_const, const int);
00957   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_const, volatile int);
00958   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_const, const volatile int);
00959 
00960   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_volatile, int);
00961   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_volatile, const int);
00962   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_volatile, volatile int);
00963   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_volatile, const volatile int);
00964 }
00965 
00966 TEST(TypeTraitsTest, TestReferenceAliases) {
00967   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_reference, int);
00968   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_reference, volatile int);
00969   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_reference, int&);
00970   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_reference, volatile int&);
00971   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_reference, int&&);
00972   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_reference, volatile int&&);
00973 
00974   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_lvalue_reference, int);
00975   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_lvalue_reference, volatile int);
00976   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_lvalue_reference, int&);
00977   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_lvalue_reference, volatile int&);
00978   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_lvalue_reference, int&&);
00979   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_lvalue_reference, volatile int&&);
00980 
00981   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_rvalue_reference, int);
00982   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_rvalue_reference, volatile int);
00983   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_rvalue_reference, int&);
00984   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_rvalue_reference, volatile int&);
00985   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_rvalue_reference, int&&);
00986   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_rvalue_reference, volatile int&&);
00987 }
00988 
00989 TEST(TypeTraitsTest, TestPointerAliases) {
00990   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_pointer, int*);
00991   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_pointer, volatile int*);
00992 
00993   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_pointer, int);
00994   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(add_pointer, volatile int);
00995 }
00996 
00997 TEST(TypeTraitsTest, TestSignednessAliases) {
00998   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(make_signed, int);
00999   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(make_signed, volatile int);
01000   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(make_signed, unsigned);
01001   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(make_signed, volatile unsigned);
01002 
01003   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(make_unsigned, int);
01004   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(make_unsigned, volatile int);
01005   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(make_unsigned, unsigned);
01006   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(make_unsigned, volatile unsigned);
01007 }
01008 
01009 TEST(TypeTraitsTest, TestExtentAliases) {
01010   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_extent, int[]);
01011   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_extent, int[1]);
01012   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_extent, int[1][1]);
01013   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_extent, int[][1]);
01014 
01015   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_all_extents, int[]);
01016   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_all_extents, int[1]);
01017   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_all_extents, int[1][1]);
01018   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(remove_all_extents, int[][1]);
01019 }
01020 
01021 TEST(TypeTraitsTest, TestAlignedStorageAlias) {
01022   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 1);
01023   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 2);
01024   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 3);
01025   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 4);
01026   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 5);
01027   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 6);
01028   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 7);
01029   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 8);
01030   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 9);
01031   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 10);
01032   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 11);
01033   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 12);
01034   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 13);
01035   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 14);
01036   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 15);
01037   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 16);
01038   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 17);
01039   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 18);
01040   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 19);
01041   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 20);
01042   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 21);
01043   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 22);
01044   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 23);
01045   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 24);
01046   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 25);
01047   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 26);
01048   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 27);
01049   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 28);
01050   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 29);
01051   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 30);
01052   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 31);
01053   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 32);
01054   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 33);
01055 
01056   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 1, 128);
01057   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 2, 128);
01058   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 3, 128);
01059   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 4, 128);
01060   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 5, 128);
01061   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 6, 128);
01062   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 7, 128);
01063   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 8, 128);
01064   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 9, 128);
01065   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 10, 128);
01066   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 11, 128);
01067   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 12, 128);
01068   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 13, 128);
01069   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 14, 128);
01070   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 15, 128);
01071   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 16, 128);
01072   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 17, 128);
01073   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 18, 128);
01074   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 19, 128);
01075   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 20, 128);
01076   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 21, 128);
01077   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 22, 128);
01078   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 23, 128);
01079   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 24, 128);
01080   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 25, 128);
01081   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 26, 128);
01082   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 27, 128);
01083   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 28, 128);
01084   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 29, 128);
01085   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 30, 128);
01086   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 31, 128);
01087   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 32, 128);
01088   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(aligned_storage, 33, 128);
01089 }
01090 
01091 TEST(TypeTraitsTest, TestDecay) {
01092   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, int);
01093   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, const int);
01094   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, volatile int);
01095   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, const volatile int);
01096 
01097   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, int&);
01098   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, const int&);
01099   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, volatile int&);
01100   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, const volatile int&);
01101 
01102   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, int&);
01103   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, const int&);
01104   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, volatile int&);
01105   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, const volatile int&);
01106 
01107   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, int[1]);
01108   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, int[1][1]);
01109   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, int[][1]);
01110 
01111   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, int());
01112   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, int(float));  // NOLINT
01113   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(decay, int(char, ...));  // NOLINT
01114 }
01115 
01116 struct TypeA {};
01117 struct TypeB {};
01118 struct TypeC {};
01119 struct TypeD {};
01120 
01121 template <typename T>
01122 struct Wrap {};
01123 
01124 enum class TypeEnum { A, B, C, D };
01125 
01126 struct GetTypeT {
01127   template <typename T,
01128             absl::enable_if_t<std::is_same<T, TypeA>::value, int> = 0>
01129   TypeEnum operator()(Wrap<T>) const {
01130     return TypeEnum::A;
01131   }
01132 
01133   template <typename T,
01134             absl::enable_if_t<std::is_same<T, TypeB>::value, int> = 0>
01135   TypeEnum operator()(Wrap<T>) const {
01136     return TypeEnum::B;
01137   }
01138 
01139   template <typename T,
01140             absl::enable_if_t<std::is_same<T, TypeC>::value, int> = 0>
01141   TypeEnum operator()(Wrap<T>) const {
01142     return TypeEnum::C;
01143   }
01144 
01145   // NOTE: TypeD is intentionally not handled
01146 } constexpr GetType = {};
01147 
01148 TEST(TypeTraitsTest, TestEnableIf) {
01149   EXPECT_EQ(TypeEnum::A, GetType(Wrap<TypeA>()));
01150   EXPECT_EQ(TypeEnum::B, GetType(Wrap<TypeB>()));
01151   EXPECT_EQ(TypeEnum::C, GetType(Wrap<TypeC>()));
01152 }
01153 
01154 TEST(TypeTraitsTest, TestConditional) {
01155   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(conditional, true, int, char);
01156   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(conditional, false, int, char);
01157 }
01158 
01159 // TODO(calabrese) Check with specialized std::common_type
01160 TEST(TypeTraitsTest, TestCommonType) {
01161   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(common_type, int);
01162   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(common_type, int, char);
01163   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(common_type, int, char, int);
01164 
01165   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(common_type, int&);
01166   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(common_type, int, char&);
01167   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(common_type, int, char, int&);
01168 }
01169 
01170 TEST(TypeTraitsTest, TestUnderlyingType) {
01171   enum class enum_char : char {};
01172   enum class enum_long_long : long long {};  // NOLINT(runtime/int)
01173 
01174   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(underlying_type, enum_char);
01175   ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(underlying_type, enum_long_long);
01176 }
01177 
01178 struct GetTypeExtT {
01179   template <typename T>
01180   absl::result_of_t<const GetTypeT&(T)> operator()(T&& arg) const {
01181     return GetType(std::forward<T>(arg));
01182   }
01183 
01184   TypeEnum operator()(Wrap<TypeD>) const { return TypeEnum::D; }
01185 } constexpr GetTypeExt = {};
01186 
01187 TEST(TypeTraitsTest, TestResultOf) {
01188   EXPECT_EQ(TypeEnum::A, GetTypeExt(Wrap<TypeA>()));
01189   EXPECT_EQ(TypeEnum::B, GetTypeExt(Wrap<TypeB>()));
01190   EXPECT_EQ(TypeEnum::C, GetTypeExt(Wrap<TypeC>()));
01191   EXPECT_EQ(TypeEnum::D, GetTypeExt(Wrap<TypeD>()));
01192 }
01193 
01194 template <typename T>
01195 bool TestCopyAssign() {
01196   return absl::is_copy_assignable<T>::value ==
01197          std::is_copy_assignable<T>::value;
01198 }
01199 
01200 TEST(TypeTraitsTest, IsCopyAssignable) {
01201   EXPECT_TRUE(TestCopyAssign<int>());
01202   EXPECT_TRUE(TestCopyAssign<int&>());
01203   EXPECT_TRUE(TestCopyAssign<int&&>());
01204 
01205   struct S {};
01206   EXPECT_TRUE(TestCopyAssign<S>());
01207   EXPECT_TRUE(TestCopyAssign<S&>());
01208   EXPECT_TRUE(TestCopyAssign<S&&>());
01209 
01210   class C {
01211    public:
01212     explicit C(C* c) : c_(c) {}
01213     ~C() { delete c_; }
01214 
01215    private:
01216     C* c_;
01217   };
01218   EXPECT_TRUE(TestCopyAssign<C>());
01219   EXPECT_TRUE(TestCopyAssign<C&>());
01220   EXPECT_TRUE(TestCopyAssign<C&&>());
01221 
01222   // Reason for ifndef: add_lvalue_reference<T> in libc++ breaks for these cases
01223 #ifndef _LIBCPP_VERSION
01224   EXPECT_TRUE(TestCopyAssign<int()>());
01225   EXPECT_TRUE(TestCopyAssign<int(int) const>());
01226   EXPECT_TRUE(TestCopyAssign<int(...) volatile&>());
01227   EXPECT_TRUE(TestCopyAssign<int(int, ...) const volatile&&>());
01228 #endif  // _LIBCPP_VERSION
01229 }
01230 
01231 template <typename T>
01232 bool TestMoveAssign() {
01233   return absl::is_move_assignable<T>::value ==
01234          std::is_move_assignable<T>::value;
01235 }
01236 
01237 TEST(TypeTraitsTest, IsMoveAssignable) {
01238   EXPECT_TRUE(TestMoveAssign<int>());
01239   EXPECT_TRUE(TestMoveAssign<int&>());
01240   EXPECT_TRUE(TestMoveAssign<int&&>());
01241 
01242   struct S {};
01243   EXPECT_TRUE(TestMoveAssign<S>());
01244   EXPECT_TRUE(TestMoveAssign<S&>());
01245   EXPECT_TRUE(TestMoveAssign<S&&>());
01246 
01247   class C {
01248    public:
01249     explicit C(C* c) : c_(c) {}
01250     ~C() { delete c_; }
01251     void operator=(const C&) = delete;
01252     void operator=(C&&) = delete;
01253 
01254    private:
01255     C* c_;
01256   };
01257   EXPECT_TRUE(TestMoveAssign<C>());
01258   EXPECT_TRUE(TestMoveAssign<C&>());
01259   EXPECT_TRUE(TestMoveAssign<C&&>());
01260 
01261   // Reason for ifndef: add_lvalue_reference<T> in libc++ breaks for these cases
01262 #ifndef _LIBCPP_VERSION
01263   EXPECT_TRUE(TestMoveAssign<int()>());
01264   EXPECT_TRUE(TestMoveAssign<int(int) const>());
01265   EXPECT_TRUE(TestMoveAssign<int(...) volatile&>());
01266   EXPECT_TRUE(TestMoveAssign<int(int, ...) const volatile&&>());
01267 #endif  // _LIBCPP_VERSION
01268 }
01269 
01270 namespace adl_namespace {
01271 
01272 struct DeletedSwap {
01273 };
01274 
01275 void swap(DeletedSwap&, DeletedSwap&) = delete;
01276 
01277 struct SpecialNoexceptSwap {
01278   SpecialNoexceptSwap(SpecialNoexceptSwap&&) {}
01279   SpecialNoexceptSwap& operator=(SpecialNoexceptSwap&&) { return *this; }
01280   ~SpecialNoexceptSwap() = default;
01281 };
01282 
01283 void swap(SpecialNoexceptSwap&, SpecialNoexceptSwap&) noexcept {}
01284 
01285 }  // namespace adl_namespace
01286 
01287 TEST(TypeTraitsTest, IsSwappable) {
01288   using absl::type_traits_internal::IsSwappable;
01289   using absl::type_traits_internal::StdSwapIsUnconstrained;
01290 
01291   EXPECT_TRUE(IsSwappable<int>::value);
01292 
01293   struct S {};
01294   EXPECT_TRUE(IsSwappable<S>::value);
01295 
01296   struct NoConstruct {
01297     NoConstruct(NoConstruct&&) = delete;
01298     NoConstruct& operator=(NoConstruct&&) { return *this; }
01299     ~NoConstruct() = default;
01300   };
01301 
01302   EXPECT_EQ(IsSwappable<NoConstruct>::value, StdSwapIsUnconstrained::value);
01303   struct NoAssign {
01304     NoAssign(NoAssign&&) {}
01305     NoAssign& operator=(NoAssign&&) = delete;
01306     ~NoAssign() = default;
01307   };
01308 
01309   EXPECT_EQ(IsSwappable<NoAssign>::value, StdSwapIsUnconstrained::value);
01310 
01311   EXPECT_FALSE(IsSwappable<adl_namespace::DeletedSwap>::value);
01312 
01313   EXPECT_TRUE(IsSwappable<adl_namespace::SpecialNoexceptSwap>::value);
01314 }
01315 
01316 TEST(TypeTraitsTest, IsNothrowSwappable) {
01317   using absl::type_traits_internal::IsNothrowSwappable;
01318   using absl::type_traits_internal::StdSwapIsUnconstrained;
01319 
01320   EXPECT_TRUE(IsNothrowSwappable<int>::value);
01321 
01322   struct NonNoexceptMoves {
01323     NonNoexceptMoves(NonNoexceptMoves&&) {}
01324     NonNoexceptMoves& operator=(NonNoexceptMoves&&) { return *this; }
01325     ~NonNoexceptMoves() = default;
01326   };
01327 
01328   EXPECT_FALSE(IsNothrowSwappable<NonNoexceptMoves>::value);
01329 
01330   struct NoConstruct {
01331     NoConstruct(NoConstruct&&) = delete;
01332     NoConstruct& operator=(NoConstruct&&) { return *this; }
01333     ~NoConstruct() = default;
01334   };
01335 
01336   EXPECT_FALSE(IsNothrowSwappable<NoConstruct>::value);
01337 
01338   struct NoAssign {
01339     NoAssign(NoAssign&&) {}
01340     NoAssign& operator=(NoAssign&&) = delete;
01341     ~NoAssign() = default;
01342   };
01343 
01344   EXPECT_FALSE(IsNothrowSwappable<NoAssign>::value);
01345 
01346   EXPECT_FALSE(IsNothrowSwappable<adl_namespace::DeletedSwap>::value);
01347 
01348   EXPECT_TRUE(IsNothrowSwappable<adl_namespace::SpecialNoexceptSwap>::value);
01349 }
01350 
01351 }  // namespace


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:42:16