From 13a74602bd4c46149da9949d448387a40b8ebd1c Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Sun, 25 Jun 2023 20:01:32 +1000 Subject: Upgrade to C++17 --- source/core/CMakeLists.txt | 2 ++ source/core/StarAlgorithm.hpp | 9 --------- source/core/StarConfig.hpp | 19 ++----------------- source/core/StarPch.hpp | 25 +++++++++++++++++++++++++ source/core/StarRandom.hpp | 6 ++++-- source/core/StarStaticRandom.hpp | 22 +++++++++++++++++++--- 6 files changed, 52 insertions(+), 31 deletions(-) create mode 100644 source/core/StarPch.hpp (limited to 'source/core') 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 -#include -#include - #include "StarException.hpp" namespace Star { @@ -267,11 +263,6 @@ void stableSortByComputedValue(Container& container, Getter&& valueGetter) { return sortByComputedValue(container, forward(valueGetter), true); } -template -void shuffle(Container& c) { - std::random_shuffle(c.begin(), c.end()); -} - template 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#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 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([this, max]() { return randUInt(max - 1); })); } template @@ -208,7 +209,8 @@ typename Container::value_type Random::randValueFrom( template 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([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 +class URBG { +public: + typedef function Function; + + URBG(Function func) : m_func(func) {}; + + typedef T result_type; + static constexpr T min() { return std::numeric_limits::min(); }; + static constexpr T max() { return std::numeric_limits::max(); }; + T operator()() { return m_func(); }; +private: + Function m_func; +}; + template 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([&]() { + return staticRandomU32Range(0, max - 1, ++mix, d, rest...); + })); } } -- cgit v1.2.3