2 // Copyright 2018 The Abseil Authors.
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
8 // https://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ABSL_RANDOM_INTERNAL_DISTRIBUTION_CALLER_H_
18 #define ABSL_RANDOM_INTERNAL_DISTRIBUTION_CALLER_H_
23 namespace random_internal {
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.
28 template <typename URBG>
29 struct 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:
36 // using result_type = distribution_t::result_type;
37 // static std::string FormatCall(
38 // const distribution_t& distr,
39 // absl::Span<const result_type>);
41 // static std::string FormatExpectation(
42 // absl::string_view match_args,
43 // absl::Span<const result_t> results);
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)...);
53 } // namespace random_internal
56 #endif // ABSL_RANDOM_INTERNAL_DISTRIBUTION_CALLER_H_