OGLplus  (0.59.0) a C++ wrapper for rendering APIs

random_bites.hpp
Go to the documentation of this file.
1 #ifndef EAGINE_RANDOM_BITES_HPP
9 #define EAGINE_RANDOM_BITES_HPP
10 
11 #include "biteset.hpp"
12 #include "instead_of.hpp"
13 #include "int_constant.hpp"
14 #include <random>
15 
16 namespace eagine {
17 //------------------------------------------------------------------------------
18 template <
19  std::size_t B,
20  typename T,
21  std::size_t... I,
22  typename Distribution,
23  typename Engine>
24 auto make_random_biteset(
25  std::index_sequence<I...>,
26  Distribution& dist,
27  Engine& engine) {
28  using R = biteset<sizeof...(I), B, T>;
29  return R{instead_of_t<size_constant<I>, Distribution&>(dist)(engine)...};
30 }
31 //------------------------------------------------------------------------------
32 template <std::size_t B, typename T, std::size_t... I, typename Engine>
33 auto make_random_biteset(
34  std::index_sequence<I...> idx_seq,
35  T min,
36  T max,
37  Engine& engine) {
38  std::uniform_int_distribution<T> dist(min, max);
39  return make_random_biteset<B, T>(idx_seq, dist, engine);
40 }
41 //------------------------------------------------------------------------------
42 template <std::size_t N, std::size_t B, typename T, typename Engine>
43 auto random_biteset(T min, T max, Engine& engine) -> biteset<N, B, T> {
44  return make_random_biteset<B, T>(
45  std::make_index_sequence<N>(), min, max, engine);
46 }
47 //------------------------------------------------------------------------------
48 template <std::size_t N, std::size_t B, typename T>
49 auto random_biteset(T min, T max) -> biteset<N, B, T> {
50  std::random_device engine;
51  return make_random_biteset<B, T>(
52  std::make_index_sequence<N>(), min, max, engine);
53 }
54 //------------------------------------------------------------------------------
55 } // namespace eagine
56 
57 #endif // EAGINE_RANDOM_BITES_HPP
Common code is placed in this namespace.
Definition: eagine.hpp:21

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).