forked from boostorg/variant2
Add tests for holds_alternative
This commit is contained in:
@ -13,3 +13,5 @@ REQ = ; #[ requires cxx11_variadic_templates cxx11_template_aliases cxx11_declty
|
||||
|
||||
run variant_size.cpp : : : $(REQ) ;
|
||||
run variant_alternative.cpp : : : $(REQ) ;
|
||||
run holds_alternative.cpp : : : $(REQ) ;
|
||||
run holds_alternative_cx.cpp : : : $(REQ) ;
|
||||
|
78
test/holds_alternative.cpp
Normal file
78
test/holds_alternative.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
|
||||
// Copyright 2017 Peter Dimov.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
//
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <string>
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
variant<int> v;
|
||||
BOOST_TEST( holds_alternative<int>( v ) );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, float> v;
|
||||
BOOST_TEST( holds_alternative<int>( v ) );
|
||||
BOOST_TEST( !holds_alternative<float>( v ) );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, float> v( 3.14f );
|
||||
BOOST_TEST( !holds_alternative<int>( v ) );
|
||||
BOOST_TEST( holds_alternative<float>( v ) );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, float, float> v;
|
||||
BOOST_TEST( holds_alternative<int>( v ) );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, int, float> v( 3.14f );
|
||||
BOOST_TEST( holds_alternative<float>( v ) );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, float, std::string> v;
|
||||
BOOST_TEST( holds_alternative<int>( v ) );
|
||||
BOOST_TEST( !holds_alternative<float>( v ) );
|
||||
BOOST_TEST( !holds_alternative<std::string>( v ) );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, float, std::string> v( 3.14f );
|
||||
BOOST_TEST( !holds_alternative<int>( v ) );
|
||||
BOOST_TEST( holds_alternative<float>( v ) );
|
||||
BOOST_TEST( !holds_alternative<std::string>( v ) );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, float, std::string> v( "text" );
|
||||
BOOST_TEST( !holds_alternative<int>( v ) );
|
||||
BOOST_TEST( !holds_alternative<float>( v ) );
|
||||
BOOST_TEST( holds_alternative<std::string>( v ) );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, int, float, std::string> v( 3.14f );
|
||||
BOOST_TEST( holds_alternative<float>( v ) );
|
||||
BOOST_TEST( !holds_alternative<std::string>( v ) );
|
||||
}
|
||||
|
||||
{
|
||||
variant<int, int, float, std::string> v( "text" );
|
||||
BOOST_TEST( !holds_alternative<float>( v ) );
|
||||
BOOST_TEST( holds_alternative<std::string>( v ) );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
43
test/holds_alternative_cx.cpp
Normal file
43
test/holds_alternative_cx.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
// Copyright 2017 Peter Dimov.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
//
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/variant2/variant.hpp>
|
||||
|
||||
using namespace boost::variant2;
|
||||
|
||||
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
constexpr variant<int> v;
|
||||
STATIC_ASSERT( holds_alternative<int>( v ) );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<int, float> v;
|
||||
STATIC_ASSERT( holds_alternative<int>( v ) );
|
||||
STATIC_ASSERT( !holds_alternative<float>( v ) );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<int, float> v( 3.14f );
|
||||
STATIC_ASSERT( !holds_alternative<int>( v ) );
|
||||
STATIC_ASSERT( holds_alternative<float>( v ) );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<int, float, float> v;
|
||||
STATIC_ASSERT( holds_alternative<int>( v ) );
|
||||
}
|
||||
|
||||
{
|
||||
constexpr variant<int, int, float> v( 3.14f );
|
||||
STATIC_ASSERT( holds_alternative<float>( v ) );
|
||||
}
|
||||
}
|
@ -20,7 +20,6 @@ template<class I, class T> using var_alt_t = variant_alternative_t<I::value, T>;
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<variant_alternative_t<0, variant<void>>, void>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<variant_alternative_t<0, variant<void> const>, void const>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<variant_alternative_t<0, variant<void> volatile>, void volatile>));
|
||||
|
@ -20,7 +20,6 @@ template<class T> using var_size_t = mp_size_t<variant_size<T>::value>;
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
BOOST_TEST_EQ( (variant_size<variant<>>::value), 0 );
|
||||
BOOST_TEST_EQ( (variant_size<variant<> const>::value), 0 );
|
||||
BOOST_TEST_EQ( (variant_size<variant<> volatile>::value), 0 );
|
||||
|
Reference in New Issue
Block a user