Add test/get_by_type(_cx).cpp, get_by_index_cx.cpp

This commit is contained in:
Peter Dimov committed 2017-05-30 02:08:31 +03:00
1 parent 781977a237
commit 07be071794
5 files changed
+342 -5

No files matched your search

+90
View File
@@ -0,0 +1,90 @@
// 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( get<0>(v) == 0 );
STATIC_ASSERT( get_if<0>(&v) == &get<0>(v) );
}
{
constexpr variant<int> v( 1 );
STATIC_ASSERT( get<0>(v) == 1 );
STATIC_ASSERT( get_if<0>(&v) == &get<0>(v) );
}
{
constexpr variant<int, float> v;
STATIC_ASSERT( get<0>(v) == 0 );
STATIC_ASSERT( get_if<0>(&v) == &get<0>(v) );
STATIC_ASSERT( get_if<1>(&v) == nullptr );
}
{
constexpr variant<int, float> v( 1 );
STATIC_ASSERT( get<0>(v) == 1 );
STATIC_ASSERT( get_if<0>(&v) == &get<0>(v) );
STATIC_ASSERT( get_if<1>(&v) == nullptr );
}
{
constexpr variant<int, float> v( 3.14f );
STATIC_ASSERT( get_if<0>(&v) == nullptr );
STATIC_ASSERT( get<1>(v) == 3.14f );
STATIC_ASSERT( get_if<1>(&v) == &get<1>(v) );
}
{
constexpr variant<int, float, float> v;
STATIC_ASSERT( get<0>(v) == 0 );
STATIC_ASSERT( get_if<0>(&v) == &get<0>(v) );
STATIC_ASSERT( get_if<1>(&v) == nullptr );
STATIC_ASSERT( get_if<2>(&v) == nullptr );
}
{
constexpr variant<int, float, float> v( 1 );
STATIC_ASSERT( get<0>(v) == 1 );
STATIC_ASSERT( get_if<0>(&v) == &get<0>(v) );
STATIC_ASSERT( get_if<1>(&v) == nullptr );
STATIC_ASSERT( get_if<2>(&v) == nullptr );
}
{
constexpr variant<int, int, float> v( 3.14f );
STATIC_ASSERT( get_if<0>(&v) == nullptr );
STATIC_ASSERT( get_if<1>(&v) == nullptr );
STATIC_ASSERT( get<2>(v) == 3.14f );
STATIC_ASSERT( get_if<2>(&v) == &get<2>(v) );
}
}