Skip to content
Snippets Groups Projects
Commit f0b60296 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

test variant movability

parent 7dd01715
No related branches found
No related tags found
No related merge requests found
......@@ -242,8 +242,13 @@ public:
helper_t::move(old.type_id, &old.data, &this->data);
}
 
//assignment operator
variant<Ts...>& operator= (variant<Ts...> old) noexcept {
// copy assignment operator
variant<Ts...>& operator =( const variant<Ts...> & other ) {
return this->operator =( variant <Ts...> ( other ) );
}
// move assignment operator
variant<Ts...>& operator= (variant<Ts...> && old) noexcept {
std::swap(this->type_id, old.type_id);
std::swap(this->data, old.data);
 
......
......@@ -168,3 +168,8 @@ void VariantTest::testSizeT() {
CPPUNIT_ASSERT ( b.is < int > ( ) );
CPPUNIT_ASSERT ( c.is < void > ( ) );
}
void VariantTest::testMoveSemantics() {
CPPUNIT_ASSERT ( ( std::is_nothrow_move_constructible < std::variant < void, int, size_t > >::value ) );
CPPUNIT_ASSERT ( ( std::is_move_constructible < std::variant < void, int, size_t > >::value && std::is_move_assignable < std::variant < void, int, size_t > >::value ) );
}
......@@ -14,6 +14,7 @@ class VariantTest : public CppUnit::TestFixture
CPPUNIT_TEST( testVariantDefault );
CPPUNIT_TEST( testVariantSameTypes );
CPPUNIT_TEST( testSizeT );
CPPUNIT_TEST( testMoveSemantics );
CPPUNIT_TEST_SUITE_END();
 
public:
......@@ -76,6 +77,7 @@ public:
void testVariantDefault();
void testVariantSameTypes();
void testSizeT();
void testMoveSemantics();
};
 
namespace std {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment