Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
array_distribution.hpp
Go to the documentation of this file.
1// Copyright 2026, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TESTING_ARRAY_DISTRIBUTION_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TESTING_ARRAY_DISTRIBUTION_HPP_
7
11#include "arene/base/stdlib_choice/cstddef.hpp"
12#include "arene/base/stdlib_choice/enable_if.hpp"
13#include "arene/base/stdlib_choice/is_default_constructible.hpp"
14#include "arene/base/stdlib_choice/is_move_assignable.hpp"
15#include "arene/base/stdlib_choice/is_move_constructible.hpp"
16#include "arene/base/stdlib_choice/reference_wrapper.hpp"
18
19namespace arene {
20namespace base {
21namespace testing {
22
23/// @brief A distribution adaptor producing an @c array by drawing each element from the wrapped distribution
24/// @tparam Distribution A distribution supplying the element values
25/// @tparam N The number of elements in the produced array
26///
27/// Elements are drawn in ascending index order, and a given PRNG state always yields the same array.
28template <class Distribution, std::size_t N>
30 public:
31 /// @brief The value type produced by this adaptor
33
34 static_assert(
36 "array_distribution builds its result in place, so the element type must be default constructible"
37 );
38
39 /// @brief Default construct adapted distribution
40 template <class T = Distribution, constraints<std::enable_if_t<std::is_default_constructible<T>::value>> = nullptr>
41 constexpr array_distribution() noexcept
42 : dist_{} {}
43
44 /// @brief Construct the adaptor wrapping the given distribution
45 /// @param dist The distribution to draw each element from
46 explicit constexpr array_distribution(Distribution dist) noexcept
47 : dist_{dist} {}
48
49 /// @brief Draw an array whose every element comes from an independent draw of the wrapped distribution
50 /// @tparam PRNG A bit generator (PRNG) type satisfying UniformRandomBitGenerator
51 /// @param prng A bit generator (PRNG) instance
52 /// @return An array of @c N values drawn from the wrapped distribution
53 template <class PRNG>
70
71 private:
72 /// @brief The distribution each element is drawn from
73 Distribution dist_;
74};
75
76} // namespace testing
77} // namespace base
78} // namespace arene
79
80#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TESTING_ARRAY_DISTRIBUTION_HPP_
A fixed-size array of T objects.
Definition array.hpp:77
A sum type which can hold either a value or an error. Similar to std::expected.
Definition result.hpp:104
arene::base::array< typename Distribution::result_type, N > result_type
The value type produced by this adaptor.
Definition array_distribution.hpp:32
auto operator()(PRNG &prng) const noexcept(arene::base::is_nothrow_invocable_v< Distribution const &, PRNG & > &&std::is_nothrow_move_assignable< typename Distribution::result_type >::value &&std::is_nothrow_default_constructible< typename Distribution::result_type >::value &&std::is_nothrow_move_constructible< result_type >::value) -> result_type
Draw an array whose every element comes from an independent draw of the wrapped distribution.
Definition array_distribution.hpp:54
constexpr array_distribution() noexcept
Default construct adapted distribution.
Definition array_distribution.hpp:41
constexpr array_distribution(Distribution dist) noexcept
Construct the adaptor wrapping the given distribution.
Definition array_distribution.hpp:46
static constexpr value_type value
Definition integral_constant.hpp:34
wraps a reference in a copyable and assignable object
Definition reference_wrapper.hpp:178
Definition customization.hpp:31
Definition accumulate.hpp:37
constexpr bool is_nothrow_invocable_v
Determine if a functor type is no-throw invocable with the specified argument types.
Definition accumulate.hpp:36