Add initializer list support

This commit is contained in:
Peter Dimov committed 2017-05-31 04:19:40 +03:00
1 parent 8301228e22
commit 755bc60c2b
5 files changed
+67 -7

No files matched your search

+8
View File
@@ -128,6 +128,14 @@ int main()
v.emplace<3>();
BOOST_TEST_EQ( v.index(), 3 );
BOOST_TEST_EQ( get<3>(v), std::string() );
v.emplace<3>( { 'a', 'b' } );
BOOST_TEST_EQ( v.index(), 3 );
BOOST_TEST_EQ( get<3>(v), (std::string{ 'a', 'b'}) );
v.emplace<3>( { 'c', 'd' }, std::allocator<char>() );
BOOST_TEST_EQ( v.index(), 3 );
BOOST_TEST_EQ( get<3>(v), (std::string{ 'c', 'd'}) );
}
{
+8
View File
@@ -116,6 +116,14 @@ int main()
v.emplace<std::string>();
BOOST_TEST_EQ( v.index(), 3 );
BOOST_TEST_EQ( get<3>(v), std::string() );
v.emplace<std::string>( { 'a', 'b' } );
BOOST_TEST_EQ( v.index(), 3 );
BOOST_TEST_EQ( get<3>(v), (std::string{ 'a', 'b' }) );
v.emplace<std::string>( { 'c', 'd' }, std::allocator<char>() );
BOOST_TEST_EQ( v.index(), 3 );
BOOST_TEST_EQ( get<3>(v), (std::string{ 'c', 'd' }) );
}
{
+16 -2
View File
@@ -17,8 +17,8 @@ using namespace boost::variant2;
struct X
{
X() = default;
X( in_place_index_t<0> ) = delete;
X() = default;
X( in_place_index_t<0> ) = delete;
};
int main()
@@ -120,5 +120,19 @@ int main()
BOOST_TEST_EQ( get<5>(v), std::string( 4, 'a' ) );
}
{
variant<int, int, float, float, std::string, std::string> v( in_place_index<4>, { 'a', 'b', 'c' } );
BOOST_TEST_EQ( v.index(), 4 );
BOOST_TEST_EQ( get<4>(v), (std::string{ 'a', 'b', 'c' }) );
}
{
variant<int, int, float, float, std::string, std::string> v( in_place_index<5>, { 'a', 'b', 'c' }, std::allocator<char>() );
BOOST_TEST_EQ( v.index(), 5 );
BOOST_TEST_EQ( get<5>(v), (std::string{ 'a', 'b', 'c' }) );
}
return boost::report_errors();
}
+18
View File
@@ -112,5 +112,23 @@ int main()
BOOST_TEST( holds_alternative<std::string>(v) );
}
{
variant<int, int, float, float, std::string> v( in_place_type<std::string>, { 'a', 'b', 'c' } );
BOOST_TEST_EQ( v.index(), 4 );
BOOST_TEST_EQ( get<4>(v), (std::string{ 'a', 'b', 'c' }) );
BOOST_TEST( holds_alternative<std::string>(v) );
}
{
variant<int, int, float, float, std::string> v( in_place_type<std::string>, { 'a', 'b', 'c' }, std::allocator<char>() );
BOOST_TEST_EQ( v.index(), 4 );
BOOST_TEST_EQ( get<4>(v), (std::string{ 'a', 'b', 'c' }) );
BOOST_TEST( holds_alternative<std::string>(v) );
}
return boost::report_errors();
}