blob: 0318e1f8072ec10f8fa43355240663aac66e2819 [file] [log] [blame]
Austin Schuh36244a12019-09-21 17:52:38 -07001//
2// Copyright 2018 The Abseil Authors.
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// https://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17#ifndef ABSL_RANDOM_INTERNAL_DISTRIBUTION_CALLER_H_
18#define ABSL_RANDOM_INTERNAL_DISTRIBUTION_CALLER_H_
19
20#include <utility>
21
22namespace absl {
23namespace random_internal {
24
25// DistributionCaller provides an opportunity to overload the general
26// mechanism for calling a distribution, allowing for mock-RNG classes
27// to intercept such calls.
28template <typename URBG>
29struct DistributionCaller {
30 // Call the provided distribution type. The parameters are expected
31 // to be explicitly specified.
32 // DistrT is the distribution type.
33 // FormatT is the formatter type:
34 //
35 // struct FormatT {
36 // using result_type = distribution_t::result_type;
37 // static std::string FormatCall(
38 // const distribution_t& distr,
39 // absl::Span<const result_type>);
40 //
41 // static std::string FormatExpectation(
42 // absl::string_view match_args,
43 // absl::Span<const result_t> results);
44 // }
45 //
46 template <typename DistrT, typename FormatT, typename... Args>
47 static typename DistrT::result_type Call(URBG* urbg, Args&&... args) {
48 DistrT dist(std::forward<Args>(args)...);
49 return dist(*urbg);
50 }
51};
52
53} // namespace random_internal
54} // namespace absl
55
56#endif // ABSL_RANDOM_INTERNAL_DISTRIBUTION_CALLER_H_