From 7578eb6f79afbb421298088ee53da620eb04037f Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 2 Jun 2022 20:50:28 +0200 Subject: refactor: rename .tpp files to end with _impl.hpp --- src/util/algorithm.hpp | 2 +- src/util/algorithm.tpp | 57 ---------------------------------- src/util/algorithm_impl.hpp | 57 ++++++++++++++++++++++++++++++++++ src/util/function.hpp | 2 +- src/util/function.tpp | 76 --------------------------------------------- src/util/function_impl.hpp | 76 +++++++++++++++++++++++++++++++++++++++++++++ src/util/hash.hpp | 2 +- src/util/hash.tpp | 22 ------------- src/util/hash_impl.hpp | 22 +++++++++++++ 9 files changed, 158 insertions(+), 158 deletions(-) delete mode 100644 src/util/algorithm.tpp create mode 100644 src/util/algorithm_impl.hpp delete mode 100644 src/util/function.tpp create mode 100644 src/util/function_impl.hpp delete mode 100644 src/util/hash.tpp create mode 100644 src/util/hash_impl.hpp (limited to 'src/util') diff --git a/src/util/algorithm.hpp b/src/util/algorithm.hpp index 71a1724..e3d8b6f 100644 --- a/src/util/algorithm.hpp +++ b/src/util/algorithm.hpp @@ -28,4 +28,4 @@ constexpr auto container_filter(const ContainerType &container, Predicate predicate) noexcept -> ContainerType; -#include "algorithm.tpp" +#include "algorithm_impl.hpp" diff --git a/src/util/algorithm.tpp b/src/util/algorithm.tpp deleted file mode 100644 index 00269ed..0000000 --- a/src/util/algorithm.tpp +++ /dev/null @@ -1,57 +0,0 @@ -#pragma once - -#include "algorithm.hpp" - -#include - -template -requires Container -constexpr auto container_find(const ContainerType &container, const Value &value) noexcept - -> typename ContainerType::const_iterator -{ - return std::find(container.begin(), container.end(), value); -} - -template -requires Container -constexpr auto container_has(const ContainerType &container, const Value &value) noexcept - -> bool -{ - return container_find(container, value) != container.end(); -} - -template -requires Container && HasPushBack && - std::predicate -constexpr auto -container_filter(const ContainerType &container, Predicate predicate) noexcept - -> ContainerType -{ - ContainerType filtered_container; - - std::copy_if( - std::begin(container), - std::end(container), - std::back_inserter(filtered_container), - predicate); - - return filtered_container; -} - -template -requires Container && - std::predicate -constexpr auto -container_filter(const ContainerType &container, Predicate predicate) noexcept - -> ContainerType -{ - ContainerType filtered_container; - - std::copy_if( - std::begin(container), - std::end(container), - std::inserter(filtered_container, filtered_container.begin()), - predicate); - - return filtered_container; -} diff --git a/src/util/algorithm_impl.hpp b/src/util/algorithm_impl.hpp new file mode 100644 index 0000000..00269ed --- /dev/null +++ b/src/util/algorithm_impl.hpp @@ -0,0 +1,57 @@ +#pragma once + +#include "algorithm.hpp" + +#include + +template +requires Container +constexpr auto container_find(const ContainerType &container, const Value &value) noexcept + -> typename ContainerType::const_iterator +{ + return std::find(container.begin(), container.end(), value); +} + +template +requires Container +constexpr auto container_has(const ContainerType &container, const Value &value) noexcept + -> bool +{ + return container_find(container, value) != container.end(); +} + +template +requires Container && HasPushBack && + std::predicate +constexpr auto +container_filter(const ContainerType &container, Predicate predicate) noexcept + -> ContainerType +{ + ContainerType filtered_container; + + std::copy_if( + std::begin(container), + std::end(container), + std::back_inserter(filtered_container), + predicate); + + return filtered_container; +} + +template +requires Container && + std::predicate +constexpr auto +container_filter(const ContainerType &container, Predicate predicate) noexcept + -> ContainerType +{ + ContainerType filtered_container; + + std::copy_if( + std::begin(container), + std::end(container), + std::inserter(filtered_container, filtered_container.begin()), + predicate); + + return filtered_container; +} diff --git a/src/util/function.hpp b/src/util/function.hpp index 13f5356..329ad40 100644 --- a/src/util/function.hpp +++ b/src/util/function.hpp @@ -8,4 +8,4 @@ struct Signature template constexpr auto normalize_lambda(Function &&func) noexcept; -#include "function.tpp" +#include "function_impl.hpp" diff --git a/src/util/function.tpp b/src/util/function.tpp deleted file mode 100644 index 9d3d38c..0000000 --- a/src/util/function.tpp +++ /dev/null @@ -1,76 +0,0 @@ -#pragma once - -#include "function.hpp" - -#include - -template -struct remove_cv_seq; - -template -struct remove_cv_seq -{ - using type = Return(Args...); -}; - -template -struct remove_cv_seq -{ - using type = Return(Args...); -}; - -template -struct remove_cv_seq -{ - using type = Return(Args...); -}; - -template -constexpr inline auto extract_signature(Function * /*unused*/) noexcept -{ - return Signature::type>(); -} - -template -constexpr inline auto extract_signature(Function Class::* /*unused*/) noexcept -{ - return Signature::type>(); -} - -template -constexpr inline auto extract_signature(Function const & /*unused*/) noexcept - -> decltype(&Function::operator(), extract_signature(&Function::operator())) -{ - return extract_signature(&Function::operator()); -} - -template -inline auto -get_normalized_lambda(Function &&func, Signature /*unused*/) noexcept -{ - // Static copy of func. This will make it accessible for the lambda without using a - // lamda capture - static auto static_func = Function(std::forward(func)); - - return +[](Args... args) noexcept( - noexcept(std::declval()(std::forward(args)...))) -> Return - { - return static_func(std::forward(args)...); - }; -} - -/** - * Normalizes the type signature of a lambda function. - * - * This will make a lambda with captures passable to other functions. - * - * @param func A lambda function - * @returns The lambda function normalized. - */ -template -constexpr auto normalize_lambda(Function &&func) noexcept -{ - return get_normalized_lambda( - std::forward(func), - extract_signature(std::forward(func))); -} diff --git a/src/util/function_impl.hpp b/src/util/function_impl.hpp new file mode 100644 index 0000000..9d3d38c --- /dev/null +++ b/src/util/function_impl.hpp @@ -0,0 +1,76 @@ +#pragma once + +#include "function.hpp" + +#include + +template +struct remove_cv_seq; + +template +struct remove_cv_seq +{ + using type = Return(Args...); +}; + +template +struct remove_cv_seq +{ + using type = Return(Args...); +}; + +template +struct remove_cv_seq +{ + using type = Return(Args...); +}; + +template +constexpr inline auto extract_signature(Function * /*unused*/) noexcept +{ + return Signature::type>(); +} + +template +constexpr inline auto extract_signature(Function Class::* /*unused*/) noexcept +{ + return Signature::type>(); +} + +template +constexpr inline auto extract_signature(Function const & /*unused*/) noexcept + -> decltype(&Function::operator(), extract_signature(&Function::operator())) +{ + return extract_signature(&Function::operator()); +} + +template +inline auto +get_normalized_lambda(Function &&func, Signature /*unused*/) noexcept +{ + // Static copy of func. This will make it accessible for the lambda without using a + // lamda capture + static auto static_func = Function(std::forward(func)); + + return +[](Args... args) noexcept( + noexcept(std::declval()(std::forward(args)...))) -> Return + { + return static_func(std::forward(args)...); + }; +} + +/** + * Normalizes the type signature of a lambda function. + * + * This will make a lambda with captures passable to other functions. + * + * @param func A lambda function + * @returns The lambda function normalized. + */ +template +constexpr auto normalize_lambda(Function &&func) noexcept +{ + return get_normalized_lambda( + std::forward(func), + extract_signature(std::forward(func))); +} diff --git a/src/util/hash.hpp b/src/util/hash.hpp index 72e9b82..718fa83 100644 --- a/src/util/hash.hpp +++ b/src/util/hash.hpp @@ -7,4 +7,4 @@ constexpr auto GOLDEN_RATIO = 0x9e3779b9; template void hash_combine(std::size_t &seed, const Value &value) noexcept; -#include "hash.tpp" +#include "hash_impl.hpp" diff --git a/src/util/hash.tpp b/src/util/hash.tpp deleted file mode 100644 index 146cfa0..0000000 --- a/src/util/hash.tpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "hash.hpp" - -#include -#include - -/** - * Combines the hash 'seed' with the hash of 'value'. - * - * @param seed A hash that will be mutated - * @param value A hashable value - */ -template -void hash_combine(std::size_t &seed, const Value &value) noexcept -{ - constexpr uint32_t shift_left = 6; - constexpr uint32_t shift_right = 2; - - seed ^= std::hash()(value) + GOLDEN_RATIO + (seed << shift_left) + - (seed >> shift_right); -} diff --git a/src/util/hash_impl.hpp b/src/util/hash_impl.hpp new file mode 100644 index 0000000..146cfa0 --- /dev/null +++ b/src/util/hash_impl.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "hash.hpp" + +#include +#include + +/** + * Combines the hash 'seed' with the hash of 'value'. + * + * @param seed A hash that will be mutated + * @param value A hashable value + */ +template +void hash_combine(std::size_t &seed, const Value &value) noexcept +{ + constexpr uint32_t shift_left = 6; + constexpr uint32_t shift_right = 2; + + seed ^= std::hash()(value) + GOLDEN_RATIO + (seed << shift_left) + + (seed >> shift_right); +} -- cgit v1.2.3-18-g5258