Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / grpc-cloned / deps / grpc / third_party / abseil-cpp / absl / random / internal / distribution_caller.h
1 //
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
22 namespace absl {
23 namespace 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.
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:
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_