-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from mapbox/variant_alternative
add `variant_alternative` and `variant_size` implementations
- Loading branch information
Showing
3 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "catch.hpp" | ||
|
||
#include <mapbox/variant.hpp> | ||
#include <mapbox/variant_io.hpp> | ||
|
||
#include <string> | ||
|
||
TEST_CASE("variant_alternative", "[types]") | ||
{ | ||
using variant_type = mapbox::util::variant<int, double, std::string>; | ||
using type_0 = mapbox::util::variant_alternative<0, variant_type>::type; | ||
using type_1 = mapbox::util::variant_alternative<1, variant_type>::type; | ||
using type_2 = mapbox::util::variant_alternative<2, variant_type>::type; | ||
//using type_3 = mapbox::util::variant_alternative<3, variant_type>::type; // compile error | ||
constexpr bool check_0 = std::is_same<int, type_0>::value; | ||
constexpr bool check_1 = std::is_same<double, type_1>::value; | ||
constexpr bool check_2 = std::is_same<std::string, type_2>::value; | ||
CHECK(check_0); | ||
CHECK(check_1); | ||
CHECK(check_2); | ||
} | ||
|
||
TEST_CASE("variant_size", "[types]") | ||
{ | ||
constexpr auto value_0 = mapbox::util::variant_size<mapbox::util::variant<>>::value; | ||
constexpr auto value_1 = mapbox::util::variant_size<mapbox::util::variant<int>>::value; | ||
constexpr auto value_2 = mapbox::util::variant_size<mapbox::util::variant<int, std::string>>::value; | ||
CHECK(value_0 == 0); | ||
CHECK(value_1 == 1); | ||
CHECK(value_2 == 2); | ||
} |