From 083d04dd4a62ebbf037079b06e49b323c5e1192a Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 7 Aug 2018 11:43:34 -0700 Subject: Export of internal Abseil changes. -- c1f3a243ff3713917eaf0255c86ddd1b40461ba9 by Abseil Team : Remove stray space. PiperOrigin-RevId: 207753171 -- 4abe43b174f7fafa390d2f6eb96f31977a38fc69 by Shaindel Schwartz : Typo fix. PiperOrigin-RevId: 207572868 -- e7757b409256b025cadba20a84a93cb9dc4319e1 by Abseil Team : Adds backported is_(copy|move)_assignable PiperOrigin-RevId: 207572180 GitOrigin-RevId: c1f3a243ff3713917eaf0255c86ddd1b40461ba9 Change-Id: I1202715e5092b54d5967017728044715d6eb2ec0 --- absl/meta/type_traits_test.cc | 76 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'absl/meta/type_traits_test.cc') diff --git a/absl/meta/type_traits_test.cc b/absl/meta/type_traits_test.cc index 81b4bd323977..f51f5dedee43 100644 --- a/absl/meta/type_traits_test.cc +++ b/absl/meta/type_traits_test.cc @@ -877,4 +877,80 @@ TEST(TypeTraitsTest, TestResultOf) { EXPECT_EQ(TypeEnum::D, GetTypeExt(Wrap())); } +template +bool TestCopyAssign() { + return absl::is_copy_assignable::value == + std::is_copy_assignable::value; +} + +TEST(TypeTraitsTest, IsCopyAssignable) { + EXPECT_TRUE(TestCopyAssign()); + EXPECT_TRUE(TestCopyAssign()); + EXPECT_TRUE(TestCopyAssign()); + + struct S {}; + EXPECT_TRUE(TestCopyAssign()); + EXPECT_TRUE(TestCopyAssign()); + EXPECT_TRUE(TestCopyAssign()); + + class C { + public: + explicit C(C* c) : c_(c) {} + ~C() { delete c_; } + + private: + C* c_; + }; + EXPECT_TRUE(TestCopyAssign()); + EXPECT_TRUE(TestCopyAssign()); + EXPECT_TRUE(TestCopyAssign()); + + // Reason for ifndef: add_lvalue_reference in libc++ breaks for these cases +#ifndef _LIBCPP_VERSION + EXPECT_TRUE(TestCopyAssign()); + EXPECT_TRUE(TestCopyAssign()); + EXPECT_TRUE(TestCopyAssign()); + EXPECT_TRUE(TestCopyAssign()); +#endif // _LIBCPP_VERSION +} + +template +bool TestMoveAssign() { + return absl::is_move_assignable::value == + std::is_move_assignable::value; +} + +TEST(TypeTraitsTest, IsMoveAssignable) { + EXPECT_TRUE(TestMoveAssign()); + EXPECT_TRUE(TestMoveAssign()); + EXPECT_TRUE(TestMoveAssign()); + + struct S {}; + EXPECT_TRUE(TestMoveAssign()); + EXPECT_TRUE(TestMoveAssign()); + EXPECT_TRUE(TestMoveAssign()); + + class C { + public: + explicit C(C* c) : c_(c) {} + ~C() { delete c_; } + void operator=(const C&) = delete; + void operator=(C&&) = delete; + + private: + C* c_; + }; + EXPECT_TRUE(TestMoveAssign()); + EXPECT_TRUE(TestMoveAssign()); + EXPECT_TRUE(TestMoveAssign()); + + // Reason for ifndef: add_lvalue_reference in libc++ breaks for these cases +#ifndef _LIBCPP_VERSION + EXPECT_TRUE(TestMoveAssign()); + EXPECT_TRUE(TestMoveAssign()); + EXPECT_TRUE(TestMoveAssign()); + EXPECT_TRUE(TestMoveAssign()); +#endif // _LIBCPP_VERSION +} + } // namespace -- cgit 1.4.1