2016-03-24 16:32:27 -04:00
|
|
|
|
|
|
|
#include "catch.hpp"
|
|
|
|
|
2016-12-01 18:44:27 -05:00
|
|
|
#include <mapbox/variant.hpp>
|
|
|
|
#include <mapbox/variant_io.hpp>
|
2016-03-24 16:32:27 -04:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct mutating_visitor
|
|
|
|
{
|
|
|
|
mutating_visitor(T& val)
|
|
|
|
: val_(val) {}
|
|
|
|
|
|
|
|
void operator()(T& val) const
|
|
|
|
{
|
|
|
|
val = val_;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T1>
|
|
|
|
void operator()(T1&) const
|
|
|
|
{
|
|
|
|
} // no-op
|
|
|
|
|
|
|
|
T& val_;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_CASE("variant visitation", "[visitor][unary visitor]")
|
|
|
|
{
|
|
|
|
mapbox::util::variant<int, double, std::string> var(123);
|
|
|
|
REQUIRE(var.get<int>() == 123);
|
|
|
|
int val = 456;
|
|
|
|
const mutating_visitor<int> visitor(val);
|
|
|
|
mapbox::util::apply_visitor(visitor, var);
|
|
|
|
REQUIRE(var.get<int>() == 456);
|
|
|
|
}
|