HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
seed_intf.hpp
1// Copyright Take Vos 2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
8#pragma once
9
10#include "../utility/utility.hpp"
11#include "../SIMD/module.hpp"
12#include "../macros.hpp"
13#include <random>
14#include <concepts>
15#include <type_traits>
16#include <bit>
17
18hi_export_module(hikogui.random.seed : intf);
19
20hi_export namespace hi::inline v1 {
21
28void generate_seed(void *ptr, size_t size);
29
37template<typename T>
38struct seed {
39 [[nodiscard]] T operator()() const
40 {
41 hi_not_implemented();
42 }
43
44 [[nodiscard]] T operator()() const requires(std::has_unique_object_representations_v<T> and not std::is_pointer_v<T>)
45 {
46 auto buffer = std::array<uint8_t, sizeof(T)>{};
47 generate_seed(buffer.data(), buffer.size());
48 return std::bit_cast<T>(buffer);
49 }
50};
51
52} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:16
void generate_seed(void *ptr, size_t size)
Load a random seed.
Definition seed_win32_impl.hpp:16
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Randomly generate an object.
Definition seed_intf.hpp:38