Created
August 11, 2018 04:49
-
-
Save kfish/90002e1eb88546e17a98b70cfd109c28 to your computer and use it in GitHub Desktop.
Rapidcheck(C++) Arbitrary instance for `std::variant`
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
// An Arbitrary instance generator for std::variant, for | |
// Rapidcheck: https://github.com/emil-e/rapidcheck | |
#include <variant> | |
namespace rc { | |
template<> | |
struct Arbitrary<std::monostate> { | |
static Gen<std::monostate> arbitrary() { | |
return gen::element(std::monostate()); | |
} | |
}; | |
template <typename T, typename... Ts> | |
struct Arbitrary<std::variant<T, Ts...>> { | |
static Gen<std::variant<T, Ts...>> arbitrary() { | |
return gen::oneOf( | |
gen::cast<std::variant<T, Ts...>>(gen::arbitrary<T>()), | |
gen::cast<std::variant<T, Ts...>>(gen::arbitrary<Ts>())...); | |
} | |
}; | |
} // namespace rc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment