Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/generators.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Out of the box, RapidCheck has support for generating arbitrary values of the fo
- `std::pair<T1, T2>`
- `std::chrono::duration<Rep, Period>`
- `std::chrono::time_point<Clock, Duration>`
- `std::variant<Ts...>`
- `rc::Maybe<T>`

The caveat is, of course, that for template types, RapidCheck must know how to generate the template arguments.
Expand Down
1 change: 1 addition & 0 deletions include/rapidcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "rapidcheck/gen/Text.h"
#include "rapidcheck/gen/Transform.h"
#include "rapidcheck/gen/Tuple.h"
#include "rapidcheck/gen/Variant.h"

#include "rapidcheck/Assertions.h"
#include "rapidcheck/Check.h"
Expand Down
11 changes: 11 additions & 0 deletions include/rapidcheck/gen/Variant.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <variant>

namespace rc {
namespace gen {

} // namespace gen
} // namespace rc

#include "Variant.hpp"
25 changes: 25 additions & 0 deletions include/rapidcheck/gen/Variant.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

namespace rc {
namespace gen {
namespace detail {

template<>
struct DefaultArbitrary<std::monostate> {
static Gen<std::monostate> arbitrary() {
return gen::element(std::monostate());
}
};

template <typename T, typename... Ts>
struct DefaultArbitrary<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 detail
} // namespace gen
} // namespace rc