Merge commit '62e8601919faca57a0fa4be1a910458390450cc9' as 'third_party/variant'
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
|
||||
// @EXPECTED: First type in variant must be default constructible to allow default construction of variant
|
||||
|
||||
#include <variant.hpp>
|
||||
|
||||
// Checks that the first type in a variant must be default constructible to
|
||||
// make the variant default constructible.
|
||||
|
||||
struct no_def_constructor
|
||||
{
|
||||
|
||||
int value;
|
||||
|
||||
no_def_constructor() = delete;
|
||||
|
||||
no_def_constructor(int v) : value(v) {}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
mapbox::util::variant<no_def_constructor> x;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
// @EXPECTED: Template parameter type list of variant can not be empty
|
||||
|
||||
#include <variant.hpp>
|
||||
|
||||
// Empty type list should not work.
|
||||
|
||||
int main()
|
||||
{
|
||||
mapbox::util::variant<> x;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
// @EXPECTED:
|
||||
|
||||
#include <variant.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
mapbox::util::variant<int> x;
|
||||
mapbox::util::variant<double> y;
|
||||
x == y;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
// @EXPECTED: enable_if
|
||||
|
||||
#include <variant.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
mapbox::util::variant<int, double> x;
|
||||
x.get<std::string>();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
// @EXPECTED: invalid type in T in `is<T>()` for this variant
|
||||
|
||||
#include <variant.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
mapbox::util::variant<int, double> x;
|
||||
x.is<std::string>();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
|
||||
// @EXPECTED: const int
|
||||
|
||||
#include <variant.hpp>
|
||||
|
||||
struct mutating_visitor
|
||||
{
|
||||
mutating_visitor(int val)
|
||||
: val_(val) {}
|
||||
|
||||
void operator()(int& val) const
|
||||
{
|
||||
val = val_;
|
||||
}
|
||||
|
||||
int val_;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
const mapbox::util::variant<int> var(123);
|
||||
const mutating_visitor visitor(456);
|
||||
mapbox::util::apply_visitor(visitor, var);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
// @EXPECTED: Variant can not hold reference types
|
||||
|
||||
#include <variant.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
mapbox::util::variant<double, int&, long> x{mapbox::util::no_init()};
|
||||
}
|
||||
Reference in New Issue
Block a user