diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-25 20:01:32 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-25 20:01:32 +1000 |
commit | 13a74602bd4c46149da9949d448387a40b8ebd1c (patch) | |
tree | 74c5d7c4f3732155e65e8df454017c5b7d2ca35d /source/core | |
parent | df661be1a3623d0a655758095fb08cb953448336 (diff) |
Upgrade to C++17
Diffstat (limited to 'source/core')
-rw-r--r-- | source/core/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/core/StarAlgorithm.hpp | 9 | ||||
-rw-r--r-- | source/core/StarConfig.hpp | 19 | ||||
-rw-r--r-- | source/core/StarPch.hpp | 25 | ||||
-rw-r--r-- | source/core/StarRandom.hpp | 6 | ||||
-rw-r--r-- | source/core/StarStaticRandom.hpp | 22 |
6 files changed, 52 insertions, 31 deletions
diff --git a/source/core/CMakeLists.txt b/source/core/CMakeLists.txt index 6668109..34d890f 100644 --- a/source/core/CMakeLists.txt +++ b/source/core/CMakeLists.txt @@ -84,6 +84,7 @@ SET (star_core_HEADERS StarOrderedMap.hpp StarOrderedSet.hpp StarParametricFunction.hpp + StarPch.hpp StarPeriodic.hpp StarPeriodicFunction.hpp StarPerlin.hpp @@ -203,3 +204,4 @@ ELSEIF (STAR_SYSTEM_FAMILY_WINDOWS) ENDIF () ADD_LIBRARY (star_core OBJECT ${star_core_SOURCES} ${star_core_HEADERS}) +TARGET_PRECOMPILE_HEADERS (star_core PUBLIC StarPch.hpp)
\ No newline at end of file diff --git a/source/core/StarAlgorithm.hpp b/source/core/StarAlgorithm.hpp index 331f653..e26917a 100644 --- a/source/core/StarAlgorithm.hpp +++ b/source/core/StarAlgorithm.hpp @@ -1,10 +1,6 @@ #ifndef STAR_ALGORITHM_HPP #define STAR_ALGORITHM_HPP -#include <type_traits> -#include <vector> -#include <iterator> - #include "StarException.hpp" namespace Star { @@ -268,11 +264,6 @@ void stableSortByComputedValue(Container& container, Getter&& valueGetter) { } template <typename Container> -void shuffle(Container& c) { - std::random_shuffle(c.begin(), c.end()); -} - -template <typename Container> void reverse(Container& c) { std::reverse(c.begin(), c.end()); } diff --git a/source/core/StarConfig.hpp b/source/core/StarConfig.hpp index 22c2607..e7a5ff0 100644 --- a/source/core/StarConfig.hpp +++ b/source/core/StarConfig.hpp @@ -1,23 +1,8 @@ +#include "StarPch.hpp" + #ifndef STAR_CONFIG_HPP #define STAR_CONFIG_HPP -#include <cstdint> -#include <cstdlib> -#include <cstddef> -#include <cstring> -#include <cmath> -#include <tuple> -#include <memory> -#include <functional> -#include <algorithm> -#include <iostream> -#include <initializer_list> -#include <exception> -#include <stdexcept> -#include <atomic> -#include <string> -#include <iterator> - namespace Star { // Some really common std namespace includes diff --git a/source/core/StarPch.hpp b/source/core/StarPch.hpp new file mode 100644 index 0000000..809156c --- /dev/null +++ b/source/core/StarPch.hpp @@ -0,0 +1,25 @@ +#ifndef STAR_PCH_HPP +#define STAR_PCH_HPP + +#include <cstdint> +#include <cstdlib> +#include <cstddef> +#include <cstring> +#include <cmath> +#include <tuple> +#include <memory> +#include <functional> +#include <algorithm> +#include <iostream> +#include <initializer_list> +#include <exception> +#include <stdexcept> +#include <atomic> +#include <string> +#include <string_view> +#include <iterator> +#include <type_traits> +#include <vector> + + +#endif
\ No newline at end of file diff --git a/source/core/StarRandom.hpp b/source/core/StarRandom.hpp index b3c8ba2..c39f6ef 100644 --- a/source/core/StarRandom.hpp +++ b/source/core/StarRandom.hpp @@ -187,7 +187,8 @@ typename Container::value_type RandomSource::randValueFrom( template <typename Container> void RandomSource::shuffle(Container& container) { - std::random_shuffle(container.begin(), container.end(), [this](size_t max) { return randUInt(max - 1); }); + size_t max = container.size(); + std::shuffle(container.begin(), container.end(), URBG<size_t>([this, max]() { return randUInt(max - 1); })); } template <typename Container> @@ -208,7 +209,8 @@ typename Container::value_type Random::randValueFrom( template <typename Container> void Random::shuffle(Container& container) { - std::random_shuffle(container.begin(), container.end(), [](size_t max) { return Random::randUInt(max - 1); }); + size_t max = container.size(); + std::shuffle(container.begin(), container.end(), URBG<size_t>([max]() { return Random::randUInt(max - 1); })); } } diff --git a/source/core/StarStaticRandom.hpp b/source/core/StarStaticRandom.hpp index 97cfdef..b55b411 100644 --- a/source/core/StarStaticRandom.hpp +++ b/source/core/StarStaticRandom.hpp @@ -118,12 +118,28 @@ typename Container::value_type staticRandomValueFrom(Container const& container, } } +template <typename T> +class URBG { +public: + typedef function <T()> Function; + + URBG(Function func) : m_func(func) {}; + + typedef T result_type; + static constexpr T min() { return std::numeric_limits<T>::min(); }; + static constexpr T max() { return std::numeric_limits<T>::max(); }; + T operator()() { return m_func(); }; +private: + Function m_func; +}; + template <typename Container, typename T, typename... TL> void staticRandomShuffle(Container& container, T const& d, TL const&... rest) { int mix = 0; - std::random_shuffle(container.begin(), - container.end(), - [&](size_t max) { return staticRandomU32Range(0, max - 1, ++mix, d, rest...); }); + size_t max = container.size(); + std::shuffle(container.begin(), container.end(), URBG<size_t>([&]() { + return staticRandomU32Range(0, max - 1, ++mix, d, rest...); + })); } } |