Skip to content

Commit 9c04404

Browse files
committed
arbitrary instance for std::complex
1 parent 86b4e1a commit 9c04404

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

include/rapidcheck/gen/Numeric.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#pragma once
22

3+
#include <complex>
4+
35
#include "rapidcheck/detail/BitStream.h"
46
#include "rapidcheck/shrinkable/Create.h"
57
#include "rapidcheck/shrink/Shrink.h"
68
#include "rapidcheck/gen/Transform.h"
9+
#include "rapidcheck/gen/Tuple.h"
710
#include "rapidcheck/gen/detail/ScaleInteger.h"
811

912
namespace rc {
@@ -80,6 +83,18 @@ struct DefaultArbitrary<long double> {
8083
static Gen<long double> arbitrary() { return real<long double>; }
8184
};
8285

86+
template <typename T>
87+
struct DefaultArbitrary<std::complex<T>> {
88+
static Gen<std::complex<T>> arbitrary() {
89+
return gen::map(
90+
gen::pair(
91+
DefaultArbitrary<T>::arbitrary(),
92+
DefaultArbitrary<T>::arbitrary()),
93+
[](std::pair<T, T> pair) { return std::complex<T> (pair.first, pair.second); }
94+
);
95+
}
96+
};
97+
8398
template <>
8499
struct DefaultArbitrary<bool> {
85100
static Gen<bool> arbitrary() { return boolean; }

0 commit comments

Comments
 (0)