26
26
#include < vector>
27
27
28
28
#include " absl/base/macros.h"
29
- #include " absl/meta/type_traits.h"
30
29
#include " absl/random/bernoulli_distribution.h"
31
30
#include " absl/random/beta_distribution.h"
32
31
#include " absl/random/exponential_distribution.h"
@@ -65,10 +64,10 @@ class PrecompiledSeedSeq {
65
64
PrecompiledSeedSeq () = default ;
66
65
67
66
template <typename Iterator>
68
- PrecompiledSeedSeq (Iterator begin , Iterator end ) {}
67
+ PrecompiledSeedSeq (Iterator, Iterator) {}
69
68
70
69
template <typename T>
71
- PrecompiledSeedSeq (std::initializer_list<T> il ) {}
70
+ PrecompiledSeedSeq (std::initializer_list<T>) {}
72
71
73
72
template <typename OutIterator>
74
73
void generate (OutIterator begin, OutIterator end) {
@@ -89,30 +88,23 @@ class PrecompiledSeedSeq {
89
88
}
90
89
};
91
90
92
- // use_default_initialization<T> indicates whether the random engine
93
- // T must be default initialized, or whether we may initialize it using
94
- // a seed sequence. This is used because some engines do not accept seed
95
- // sequence-based initialization.
96
- template <typename E>
97
- using use_default_initialization = std::false_type;
91
+ // Triggers default constructor initialization.
92
+ class DefaultConstructorSeedSeq {};
98
93
99
94
// make_engine<T, SSeq> returns a random_engine which is initialized,
100
95
// either via the default constructor, when use_default_initialization<T>
101
96
// is true, or via the indicated seed sequence, SSeq.
102
- template <typename Engine, typename SSeq = PrecompiledSeedSeq>
103
- typename absl::enable_if_t <!use_default_initialization<Engine>::value, Engine>
104
- make_engine () {
105
- // Initialize the random engine using the seed sequence SSeq, which
106
- // is constructed from the precompiled seed data.
107
- SSeq seq (std::begin (kSeedData ), std::end (kSeedData ));
108
- return Engine (seq);
109
- }
110
-
111
- template <typename Engine, typename SSeq = PrecompiledSeedSeq>
112
- typename absl::enable_if_t <use_default_initialization<Engine>::value, Engine>
113
- make_engine () {
114
- // Initialize the random engine using the default constructor.
115
- return Engine ();
97
+ template <typename Engine, typename SSeq = DefaultConstructorSeedSeq>
98
+ Engine make_engine () {
99
+ constexpr bool use_default_initialization =
100
+ std::is_same_v<SSeq, DefaultConstructorSeedSeq>;
101
+ if constexpr (use_default_initialization) {
102
+ return Engine ();
103
+ } else {
104
+ // Otherwise, use the provided seed sequence.
105
+ SSeq seq (std::begin (kSeedData ), std::end (kSeedData ));
106
+ return Engine (seq);
107
+ }
116
108
}
117
109
118
110
template <typename Engine, typename SSeq>
@@ -248,6 +240,7 @@ void BM_Thread(benchmark::State& state) {
248
240
249
241
// Normal benchmark suite
250
242
#define BM_BASIC (Engine ) \
243
+ BENCHMARK_TEMPLATE (BM_Construct, Engine, DefaultConstructorSeedSeq); \
251
244
BENCHMARK_TEMPLATE (BM_Construct, Engine, PrecompiledSeedSeq); \
252
245
BENCHMARK_TEMPLATE (BM_Construct, Engine, std::seed_seq); \
253
246
BENCHMARK_TEMPLATE (BM_Direct, Engine); \
0 commit comments