test/unit/test_variant.cpp
// Test generic accessors for pair, tuple.
Test generic accessors for pair, tuple.
Test generic accessors for pair tuple .
TEST(variant, get_pair_tuple) {
    {
        using pair_ni_nd = std::pair<nocopy<int>, nocopy<double>>;
        nocopy<int>::reset_counts();
        nocopy<double>::reset_counts();
        auto f = first(pair_ni_nd{2, 3.4});
        EXPECT_EQ(2, f.value);
        EXPECT_EQ(1, nocopy<int>::move_ctor_count);
        auto s = second(pair_ni_nd{2, 3.4});
        EXPECT_EQ(3.4, s.value);
        EXPECT_EQ(1, nocopy<double>::move_ctor_count);
        nocopy<int>::reset_counts();
        nocopy<double>::reset_counts();
        auto g0 = ::arb::util::get<0>(pair_ni_nd{2, 3.4});
        EXPECT_EQ(2, g0.value);
        EXPECT_EQ(1, nocopy<int>::move_ctor_count);
        auto g1 = ::arb::util::get<1>(pair_ni_nd{2, 3.4});
        EXPECT_EQ(3.4, g1.value);
        EXPECT_EQ(1, nocopy<double>::move_ctor_count);
    }
    {
        struct X {};
        using tuple_ni_nd_nx = std::tuple<nocopy<int>, nocopy<double>, nocopy<X>>;
        nocopy<int>::reset_counts();
        nocopy<double>::reset_counts();
        nocopy<X>::reset_counts();
        auto f = first(tuple_ni_nd_nx{2, 3.4, X{}});
        EXPECT_EQ(2, f.value);
        EXPECT_EQ(1, nocopy<int>::move_ctor_count);
        auto s = second(tuple_ni_nd_nx{2, 3.4, X{}});
        EXPECT_EQ(3.4, s.value);
        EXPECT_EQ(1, nocopy<double>::move_ctor_count);
        nocopy<int>::reset_counts();
        nocopy<double>::reset_counts();
        auto g0 = ::arb::util::get<0>(tuple_ni_nd_nx{2, 3.4, X{}});
        EXPECT_EQ(2, g0.value);
        EXPECT_EQ(1, nocopy<int>::move_ctor_count);
        auto g1 = ::arb::util::get<1>(tuple_ni_nd_nx{2, 3.4, X{}});
        EXPECT_EQ(3.4, g1.value);
        EXPECT_EQ(1, nocopy<double>::move_ctor_count);
        auto g2 = ::arb::util::get<2>(tuple_ni_nd_nx{2, 3.4, X{}});
        (void)g2;
        EXPECT_EQ(1, nocopy<X>::move_ctor_count);
    }
}
TEST ( variant , get_pair_tuple ) { { using pair_ni_nd = std :: pair < nocopy < int > , nocopy < double > > ; nocopy < int > :: reset_counts ( ) ; nocopy < double > :: reset_counts ( ) ; auto f = first ( pair_ni_nd { 2 , 3.4 } ) ; EXPECT_EQ ( 2 , f . value ) ; EXPECT_EQ ( 1 , nocopy < int > :: move_ctor_count ) ; auto s = second ( pair_ni_nd { 2 , 3.4 } ) ; EXPECT_EQ ( 3.4 , s . value ) ; EXPECT_EQ ( 1 , nocopy < double > :: move_ctor_count ) ; nocopy < int > :: reset_counts ( ) ; nocopy < double > :: reset_counts ( ) ; auto g0 = :: arb :: util :: get < 0 > ( pair_ni_nd { 2 , 3.4 } ) ; EXPECT_EQ ( 2 , g0 . value ) ; EXPECT_EQ ( 1 , nocopy < int > :: move_ctor_count ) ; auto g1 = :: arb :: util :: get < 1 > ( pair_ni_nd { 2 , 3.4 } ) ; EXPECT_EQ ( 3.4 , g1 . value ) ; EXPECT_EQ ( 1 , nocopy < double > :: move_ctor_count ) ; } { struct X { } ; using tuple_ni_nd_nx = std :: tuple < nocopy < int > , nocopy < double > , nocopy < X > > ; nocopy < int > :: reset_counts ( ) ; nocopy < double > :: reset_counts ( ) ; nocopy < X > :: reset_counts ( ) ; auto f = first ( tuple_ni_nd_nx { 2 , 3.4 , X { } } ) ; EXPECT_EQ ( 2 , f . value ) ; EXPECT_EQ ( 1 , nocopy < int > :: move_ctor_count ) ; auto s = second ( tuple_ni_nd_nx { 2 , 3.4 , X { } } ) ; EXPECT_EQ ( 3.4 , s . value ) ; EXPECT_EQ ( 1 , nocopy < double > :: move_ctor_count ) ; nocopy < int > :: reset_counts ( ) ; nocopy < double > :: reset_counts ( ) ; auto g0 = :: arb :: util :: get < 0 > ( tuple_ni_nd_nx { 2 , 3.4 , X { } } ) ; EXPECT_EQ ( 2 , g0 . value ) ; EXPECT_EQ ( 1 , nocopy < int > :: move_ctor_count ) ; auto g1 = :: arb :: util :: get < 1 > ( tuple_ni_nd_nx { 2 , 3.4 , X { } } ) ; EXPECT_EQ ( 3.4 , g1 . value ) ; EXPECT_EQ ( 1 , nocopy < double > :: move_ctor_count ) ; auto g2 = :: arb :: util :: get < 2 > ( tuple_ni_nd_nx { 2 , 3.4 , X { } } ) ; ( void ) g2 ; EXPECT_EQ ( 1 , nocopy < X > :: move_ctor_count ) ; } }
Test generic accessors for pair, tuple.
Test generic accessors for pair tuple .