Commit 20641ec5 authored by Armin Sobhani's avatar Armin Sobhani
Browse files

add copy and move assignment operators to sequence_host class template

parent 0b183d70
......@@ -114,6 +114,29 @@ public:
: ContainerT<CharT, AllocatorT<CharT>>(init, alloc)
{}
sequence_host& operator= (const sequence_host& other)
{
// std::cout << "copy assignment operator called" << std::endl;
self_type::clear();
self_type::insert(self_type::begin(), other.cbegin(), other.cend());
copy_name(other, has_name_component<self_type>());
copy_dscr(other, has_description_component<self_type>());
return *this;
}
sequence_host& operator= (sequence_host&& other)
{
// std::cout << "move assignment operator called" << std::endl;
self_type::swap(other);
move_name(
std::forward<sequence_host>(other)
, has_name_component<self_type>() );
move_dscr(
std::forward<sequence_host>(other)
, has_description_component<self_type>() );
return *this;
}
std::basic_string<CharT> short_name() const
{
return get_name(has_name_component<self_type>());
......
......@@ -82,9 +82,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(move_constructor_noname, T, seqnd_type)
BOOST_AUTO_TEST_CASE_TEMPLATE(copy_assignment_operator, T, seq_type)
{
T s;
T s, c;
s.description("copied");
T c = s;
c = s;
BOOST_CHECK( s.empty() );
BOOST_CHECK_EQUAL( s.description(), "copied" );
......@@ -94,8 +94,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(copy_assignment_operator, T, seq_type)
BOOST_AUTO_TEST_CASE_TEMPLATE(copy_assignment_operator_nodscr, T, seqnd_type)
{
T s;
T c = s;
T s, c;
c = s;
BOOST_CHECK( s.empty() );
BOOST_CHECK( c.empty() );
......@@ -103,9 +103,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(copy_assignment_operator_nodscr, T, seqnd_type)
BOOST_AUTO_TEST_CASE_TEMPLATE(move_assignment_operator, T, seq_type)
{
T s;
T s, m;
s.description("moved");
T m = std::move(s);
m = std::move(s);
BOOST_CHECK( s.empty() );
BOOST_CHECK( s.description().empty() );
......@@ -115,10 +115,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(move_assignment_operator, T, seq_type)
BOOST_AUTO_TEST_CASE_TEMPLATE(move_assignment_operator_noname, T, seqnd_type)
{
T s;
T m = std::move(s);
T s, m;
m = std::move(s);
BOOST_CHECK( s.empty() );
BOOST_CHECK( m.empty() );
}
......@@ -82,9 +82,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(move_constructor_noname, T, seqnn_type)
BOOST_AUTO_TEST_CASE_TEMPLATE(copy_assignment_operator, T, seq_type)
{
T s;
T s, c;
s.name("copied");
T c = s;
c = s;
BOOST_CHECK( s.empty() );
BOOST_CHECK_EQUAL( s.name(), "copied" );
......@@ -94,8 +94,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(copy_assignment_operator, T, seq_type)
BOOST_AUTO_TEST_CASE_TEMPLATE(copy_assignment_operator_noname, T, seqnn_type)
{
T s;
T c = s;
T s, c;
c = s;
BOOST_CHECK( s.empty() );
BOOST_CHECK( c.empty() );
......@@ -103,9 +103,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(copy_assignment_operator_noname, T, seqnn_type)
BOOST_AUTO_TEST_CASE_TEMPLATE(move_assignment_operator, T, seq_type)
{
T s;
T s, m;
s.name("moved");
T m = std::move(s);
m = std::move(s);
BOOST_CHECK( s.empty() );
BOOST_CHECK( s.name().empty() );
......@@ -115,8 +115,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(move_assignment_operator, T, seq_type)
BOOST_AUTO_TEST_CASE_TEMPLATE(move_assignment_operator_noname, T, seqnn_type)
{
T s;
T m = std::move(s);
T s, m;
m = std::move(s);
BOOST_CHECK( s.empty() );
BOOST_CHECK( m.empty() );
......
......@@ -198,8 +198,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(move_constructor, T, seq_types)
BOOST_AUTO_TEST_CASE_TEMPLATE(copy_assignment_operator, T, seq_types)
{
T seq("ATCG");
T copy = seq;
T seq("ATCG"), copy("C");
copy = seq;
BOOST_CHECK_EQUAL(copy.size(), 4);
......@@ -212,8 +212,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(copy_assignment_operator, T, seq_types)
BOOST_AUTO_TEST_CASE_TEMPLATE(move_assignment_operator, T, seq_types)
{
T seq("ATCG");
T moved = std::move(seq);
T seq("ATCG"), moved;
moved = std::move(seq);
BOOST_CHECK( seq.empty() );
BOOST_CHECK_EQUAL(moved.size(), 4);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment