Upgrade to mapbox/variant 1.1.4
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
||||
|
||||
#include "variant.hpp"
|
||||
#include <mapbox/variant.hpp>
|
||||
|
||||
#define NAME_EXT " i-d"
|
||||
using variant_type = mapbox::util::variant<int, double>;
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
|
||||
#include "variant.hpp"
|
||||
#include <mapbox/variant.hpp>
|
||||
|
||||
#define NAME_EXT " b-i-d"
|
||||
using variant_type = mapbox::util::variant<bool, int, double>;
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
|
||||
#include "variant.hpp"
|
||||
#include <mapbox/variant.hpp>
|
||||
|
||||
#define NAME_EXT " i-d-b"
|
||||
using variant_type = mapbox::util::variant<int, double, bool>;
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
|
||||
#include "variant.hpp"
|
||||
#include <mapbox/variant.hpp>
|
||||
|
||||
#define NAME_EXT " b-i-d-c"
|
||||
using variant_type = mapbox::util::variant<bool, int, double, char>;
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
|
||||
#include "variant.hpp"
|
||||
#include <mapbox/variant.hpp>
|
||||
|
||||
#define NAME_EXT " b-i-c-d-i"
|
||||
using variant_type = mapbox::util::variant<bool, int, char, double, int>;
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
|
||||
#include "variant.hpp"
|
||||
#include <mapbox/variant.hpp>
|
||||
|
||||
#define NAME_EXT " b-i-i-d-c-u"
|
||||
using variant_type = mapbox::util::variant<bool, int, int, double, char, short int>;
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "variant_io.hpp"
|
||||
#include <mapbox/variant_io.hpp>
|
||||
|
||||
struct add_visitor
|
||||
{
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <mapbox/variant.hpp>
|
||||
#include <mapbox/variant_io.hpp>
|
||||
|
||||
// https://github.com/mapbox/variant/issues/122
|
||||
|
||||
struct X
|
||||
{
|
||||
template <typename ValueType>
|
||||
X(const ValueType&) {}
|
||||
};
|
||||
|
||||
|
||||
TEST_CASE("Correctly choose appropriate constructor", "[variant]")
|
||||
{
|
||||
mapbox::util::variant<X, int> a{123};
|
||||
decltype(a) b(a);
|
||||
REQUIRE(a.which() == b.which());
|
||||
}
|
||||
+10
-4
@@ -1,8 +1,7 @@
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "variant.hpp"
|
||||
#include "variant_io.hpp"
|
||||
#include <mapbox/variant.hpp>
|
||||
#include <mapbox/variant_io.hpp>
|
||||
|
||||
// https://github.com/mapbox/variant/issues/21
|
||||
|
||||
@@ -11,6 +10,12 @@ static int count;
|
||||
struct t1
|
||||
{
|
||||
int value;
|
||||
|
||||
t1(t1 const& rhs)
|
||||
: value(rhs.value)
|
||||
{
|
||||
++count;
|
||||
}
|
||||
t1(int v) : value(v)
|
||||
{
|
||||
++count;
|
||||
@@ -37,7 +42,8 @@ TEST_CASE("set() works cleanly even if the constructor throws ", "[variant]")
|
||||
|
||||
count = 0;
|
||||
{
|
||||
variant_type v{42};
|
||||
t1 obj{42};
|
||||
variant_type v = obj;
|
||||
REQUIRE(v.is<t1>());
|
||||
REQUIRE(v.get<t1>().value == 42);
|
||||
REQUIRE_THROWS({
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "variant.hpp"
|
||||
#include "variant_io.hpp"
|
||||
#include <mapbox/variant.hpp>
|
||||
#include <mapbox/variant_io.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "optional.hpp"
|
||||
#include <mapbox/optional.hpp>
|
||||
|
||||
struct dummy
|
||||
{
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "recursive_wrapper.hpp"
|
||||
#include <mapbox/recursive_wrapper.hpp>
|
||||
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
+2
-2
@@ -5,8 +5,8 @@
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "variant.hpp"
|
||||
#include "variant_io.hpp"
|
||||
#include <mapbox/variant.hpp>
|
||||
#include <mapbox/variant_io.hpp>
|
||||
|
||||
struct some_struct
|
||||
{
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "variant.hpp"
|
||||
#include "variant_io.hpp"
|
||||
#include <mapbox/variant.hpp>
|
||||
#include <mapbox/variant_io.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
+28
-5
@@ -1,7 +1,7 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "variant.hpp"
|
||||
#include "variant_io.hpp"
|
||||
#include <mapbox/variant.hpp>
|
||||
#include <mapbox/variant_io.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
@@ -325,7 +325,7 @@ TEST_CASE("implicit conversion", "[variant][implicit conversion]")
|
||||
TEST_CASE("implicit conversion to first type in variant type list", "[variant][implicit conversion]")
|
||||
{
|
||||
using variant_type = mapbox::util::variant<long, char>;
|
||||
variant_type var = 5.0; // converted to long
|
||||
variant_type var = 5l; // converted to long
|
||||
REQUIRE(var.get<long>() == 5);
|
||||
REQUIRE_THROWS_AS({
|
||||
var.get<char>();
|
||||
@@ -543,9 +543,9 @@ TEST_CASE("storing reference wrappers to consts works")
|
||||
int a = 1;
|
||||
variant_type v{std::cref(a)};
|
||||
REQUIRE(v.get<int const>() == 1);
|
||||
REQUIRE(v.get<int>() == 1); // this works (see #82)
|
||||
REQUIRE(v.get<int>() == 1);
|
||||
REQUIRE(mapbox::util::get<int const>(v) == 1);
|
||||
// REQUIRE(mapbox::util::get<int>(v) == 1); // this doesn't work (see #82)
|
||||
REQUIRE(mapbox::util::get<int>(v) == 1);
|
||||
REQUIRE_THROWS_AS({
|
||||
v.get<double const>();
|
||||
},
|
||||
@@ -568,3 +568,26 @@ TEST_CASE("storing reference wrappers to consts works")
|
||||
},
|
||||
mapbox::util::bad_variant_access&);
|
||||
}
|
||||
|
||||
TEST_CASE("recursive wrapper")
|
||||
{
|
||||
using variant_type = mapbox::util::variant<mapbox::util::recursive_wrapper<int>>;
|
||||
variant_type v(1);
|
||||
REQUIRE(v.is<int>());
|
||||
REQUIRE(v.get<int>() == 1);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("variant : direct_type helper should match T, references (T&) and const references (T const&) to the original type T)")
|
||||
{
|
||||
using value = mapbox::util::variant<bool, std::uint64_t>;
|
||||
|
||||
std::uint64_t u(1234);
|
||||
REQUIRE(value(u).is<std::uint64_t>()); // matches T
|
||||
|
||||
std::uint64_t& ur(u);
|
||||
REQUIRE(value(ur).is<std::uint64_t>()); // matches T&
|
||||
|
||||
std::uint64_t const& ucr(u);
|
||||
REQUIRE(value(ucr).is<std::uint64_t>()); // matches T const&
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user