generated from mcpplibs/templates
-
Notifications
You must be signed in to change notification settings - Fork 0
Enhance algorithms and limits modules with improved functionality and tests #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e33c615
refactor: Update implementation plan with clear responsibilities and …
FrozenLemonTee 0fd1654
feat: Implement hash module for enhanced type hashing and value retri…
FrozenLemonTee 6e44abf
feat: Add limits module for enhanced type limits and value retrieval
FrozenLemonTee 3e03ce8
feat: Add algorithms module for enhanced algorithmic operations and i…
FrozenLemonTee 7e21e4e
feat: Add tests for algorithms module including hash and limits funct…
FrozenLemonTee 314b19a
feat: Replace std::numeric_limits with algorithms module for improved…
FrozenLemonTee 43bcc15
feat: Enhance hash module with additional type constraints for improv…
FrozenLemonTee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| module; | ||
|
|
||
| export module mcpplibs.primitives.algorithms; | ||
|
|
||
| export import mcpplibs.primitives.algorithms.hash; | ||
| export import mcpplibs.primitives.algorithms.limits; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| module; | ||
|
|
||
| #include <concepts> | ||
| #include <cstddef> | ||
| #include <functional> | ||
| #include <type_traits> | ||
|
|
||
| export module mcpplibs.primitives.algorithms.hash; | ||
|
|
||
| import mcpplibs.primitives.underlying; | ||
|
|
||
| namespace mcpplibs::primitives::algorithms::details { | ||
|
|
||
| template <typename T> | ||
| concept std_hashable = requires(std::remove_cv_t<T> const &value) { | ||
| { | ||
| std::hash<std::remove_cv_t<T>>{}(value) | ||
| } -> std::convertible_to<std::size_t>; | ||
| }; | ||
|
|
||
| } // namespace mcpplibs::primitives::algorithms::details | ||
|
|
||
| export namespace mcpplibs::primitives::algorithms { | ||
|
|
||
| template <typename T> struct hash { | ||
| using value_type = std::remove_cv_t<T>; | ||
| using result_type = std::size_t; | ||
|
|
||
| static constexpr bool enabled = false; | ||
|
|
||
| auto operator()(value_type const &) const noexcept -> result_type { | ||
| return result_type{}; | ||
| } | ||
| }; | ||
|
|
||
| template <typename T> | ||
| using hash_result_t = hash<std::remove_cvref_t<T>>::result_type; | ||
|
|
||
| template <typename T> | ||
| concept hashable = hash<std::remove_cvref_t<T>>::enabled; | ||
|
|
||
| template <typename T> | ||
| requires details::std_hashable<T> | ||
| struct hash<T> { | ||
| using value_type = std::remove_cv_t<T>; | ||
| using result_type = std::size_t; | ||
|
|
||
| static constexpr bool enabled = true; | ||
|
|
||
| auto operator()(value_type const &value) const noexcept( | ||
| noexcept(std::hash<value_type>{}(value))) -> result_type { | ||
| return std::hash<value_type>{}(value); | ||
| } | ||
| }; | ||
|
|
||
| template <underlying_type T> | ||
| requires (!details::std_hashable<T> && | ||
| !std::same_as<std::remove_cv_t<T>, | ||
| typename underlying::traits<std::remove_cv_t<T>>::rep_type> && | ||
| hash<typename underlying::traits<std::remove_cv_t<T>>::rep_type>::enabled) | ||
| struct hash<T> { | ||
| using value_type = std::remove_cv_t<T>; | ||
| using rep_type = underlying::traits<value_type>::rep_type; | ||
| using result_type = hash_result_t<rep_type>; | ||
|
|
||
| static constexpr bool enabled = true; | ||
|
|
||
| auto operator()(value_type const &value) const noexcept( | ||
| noexcept(hash<rep_type>{}(underlying::traits<value_type>::to_rep(value)))) | ||
| -> result_type { | ||
| return hash<rep_type>{}(underlying::traits<value_type>::to_rep(value)); | ||
| } | ||
| }; | ||
|
|
||
| template <hashable T> | ||
| auto hash_value(T const &value) noexcept( | ||
| noexcept(hash<std::remove_cvref_t<T>>{}(value))) -> hash_result_t<T> { | ||
| return hash<std::remove_cvref_t<T>>{}(value); | ||
| } | ||
|
|
||
| } // namespace mcpplibs::primitives::algorithms | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| module; | ||
|
|
||
| #include <concepts> | ||
| #include <limits> | ||
| #include <type_traits> | ||
|
|
||
| export module mcpplibs.primitives.algorithms.limits; | ||
|
|
||
| import mcpplibs.primitives.underlying; | ||
|
|
||
| namespace mcpplibs::primitives::algorithms::details { | ||
|
|
||
| template <typename T> | ||
| concept has_numeric_limits = | ||
| std::numeric_limits<std::remove_cv_t<T>>::is_specialized; | ||
|
|
||
| template <typename T> | ||
| consteval auto category_from_type() -> underlying::category { | ||
| using value_type = std::remove_cv_t<T>; | ||
| if constexpr (std_bool<value_type>) { | ||
| return underlying::category::boolean; | ||
| } else if constexpr (std_char<value_type>) { | ||
| return underlying::category::character; | ||
| } else if constexpr (std::numeric_limits<value_type>::is_integer) { | ||
| return underlying::category::integer; | ||
| } else { | ||
| return underlying::category::floating; | ||
| } | ||
| } | ||
|
|
||
| } // namespace mcpplibs::primitives::algorithms::details | ||
|
|
||
| export namespace mcpplibs::primitives::algorithms { | ||
|
|
||
| template <typename T> struct limits { | ||
| using value_type = std::remove_cv_t<T>; | ||
| using rep_type = value_type; | ||
|
|
||
| static constexpr bool enabled = false; | ||
| static constexpr bool is_specialized = false; | ||
| static constexpr bool is_bounded = false; | ||
| static constexpr bool is_exact = false; | ||
| static constexpr bool is_signed = false; | ||
| static constexpr bool is_integer = false; | ||
| static constexpr bool is_iec559 = false; | ||
| static constexpr bool has_infinity = false; | ||
| static constexpr bool has_quiet_nan = false; | ||
| static constexpr int digits = 0; | ||
| static constexpr int digits10 = 0; | ||
| static constexpr int radix = 0; | ||
| static constexpr auto kind = static_cast<underlying::category>(-1); | ||
|
|
||
| static constexpr auto min() noexcept -> value_type { return {}; } | ||
| static constexpr auto lowest() noexcept -> value_type { return {}; } | ||
| static constexpr auto max() noexcept -> value_type { return {}; } | ||
| static constexpr auto epsilon() noexcept -> value_type { return {}; } | ||
| static constexpr auto infinity() noexcept -> value_type { return {}; } | ||
| static constexpr auto quiet_nan() noexcept -> value_type { return {}; } | ||
| }; | ||
|
|
||
| template <typename T> | ||
| requires details::has_numeric_limits<T> | ||
| struct limits<T> { | ||
| using value_type = std::remove_cv_t<T>; | ||
| using rep_type = value_type; | ||
|
|
||
| static constexpr bool enabled = true; | ||
| static constexpr bool is_specialized = true; | ||
| static constexpr bool is_bounded = std::numeric_limits<value_type>::is_bounded; | ||
| static constexpr bool is_exact = std::numeric_limits<value_type>::is_exact; | ||
| static constexpr bool is_signed = std::numeric_limits<value_type>::is_signed; | ||
| static constexpr bool is_integer = std::numeric_limits<value_type>::is_integer; | ||
| static constexpr bool is_iec559 = std::numeric_limits<value_type>::is_iec559; | ||
| static constexpr bool has_infinity = | ||
| std::numeric_limits<value_type>::has_infinity; | ||
| static constexpr bool has_quiet_nan = | ||
| std::numeric_limits<value_type>::has_quiet_NaN; | ||
| static constexpr int digits = std::numeric_limits<value_type>::digits; | ||
| static constexpr int digits10 = std::numeric_limits<value_type>::digits10; | ||
| static constexpr int radix = std::numeric_limits<value_type>::radix; | ||
| static constexpr auto kind = details::category_from_type<value_type>(); | ||
|
|
||
| static constexpr auto min() noexcept -> value_type { | ||
| return std::numeric_limits<value_type>::min(); | ||
| } | ||
|
|
||
| static constexpr auto lowest() noexcept -> value_type { | ||
| return std::numeric_limits<value_type>::lowest(); | ||
| } | ||
|
|
||
| static constexpr auto max() noexcept -> value_type { | ||
| return std::numeric_limits<value_type>::max(); | ||
| } | ||
|
|
||
| static constexpr auto epsilon() noexcept -> value_type { | ||
| return std::numeric_limits<value_type>::epsilon(); | ||
| } | ||
|
|
||
| static constexpr auto infinity() noexcept -> value_type { | ||
| return std::numeric_limits<value_type>::infinity(); | ||
| } | ||
|
|
||
| static constexpr auto quiet_nan() noexcept -> value_type { | ||
| return std::numeric_limits<value_type>::quiet_NaN(); | ||
| } | ||
| }; | ||
|
|
||
| template <underlying_type T> | ||
| requires (!details::has_numeric_limits<T> && | ||
| !std::same_as<std::remove_cv_t<T>, | ||
| typename underlying::traits<std::remove_cv_t<T>>::rep_type> && | ||
| limits<typename underlying::traits<std::remove_cv_t<T>>::rep_type>::enabled) | ||
| struct limits<T> { | ||
| using value_type = std::remove_cv_t<T>; | ||
| using rep_type = underlying::traits<value_type>::rep_type; | ||
| using rep_limits = limits<rep_type>; | ||
|
|
||
| static constexpr bool enabled = true; | ||
| static constexpr bool is_specialized = rep_limits::is_specialized; | ||
| static constexpr bool is_bounded = rep_limits::is_bounded; | ||
| static constexpr bool is_exact = rep_limits::is_exact; | ||
| static constexpr bool is_signed = rep_limits::is_signed; | ||
| static constexpr bool is_integer = rep_limits::is_integer; | ||
| static constexpr bool is_iec559 = rep_limits::is_iec559; | ||
| static constexpr bool has_infinity = rep_limits::has_infinity; | ||
| static constexpr bool has_quiet_nan = rep_limits::has_quiet_nan; | ||
| static constexpr int digits = rep_limits::digits; | ||
| static constexpr int digits10 = rep_limits::digits10; | ||
| static constexpr int radix = rep_limits::radix; | ||
| static constexpr auto kind = underlying::traits<value_type>::kind; | ||
|
|
||
| static constexpr auto min() noexcept -> value_type { | ||
| return underlying::traits<value_type>::from_rep(rep_limits::min()); | ||
| } | ||
|
|
||
| static constexpr auto lowest() noexcept -> value_type { | ||
| return underlying::traits<value_type>::from_rep(rep_limits::lowest()); | ||
| } | ||
|
|
||
| static constexpr auto max() noexcept -> value_type { | ||
| return underlying::traits<value_type>::from_rep(rep_limits::max()); | ||
| } | ||
|
|
||
| static constexpr auto epsilon() noexcept -> value_type { | ||
| return underlying::traits<value_type>::from_rep(rep_limits::epsilon()); | ||
| } | ||
|
|
||
| static constexpr auto infinity() noexcept -> value_type { | ||
| return underlying::traits<value_type>::from_rep(rep_limits::infinity()); | ||
| } | ||
|
|
||
| static constexpr auto quiet_nan() noexcept -> value_type { | ||
| return underlying::traits<value_type>::from_rep(rep_limits::quiet_nan()); | ||
| } | ||
| }; | ||
|
|
||
| template <typename T> | ||
| concept limited_type = limits<std::remove_cvref_t<T>>::enabled; | ||
|
|
||
| template <typename T> | ||
| using limit_value_t = limits<std::remove_cvref_t<T>>::value_type; | ||
FrozenLemonTee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| template <limited_type T> | ||
| constexpr auto min_value() noexcept( | ||
| noexcept(limits<std::remove_cvref_t<T>>::min())) -> limit_value_t<T> { | ||
| return limits<std::remove_cvref_t<T>>::min(); | ||
| } | ||
|
|
||
| template <limited_type T> | ||
| constexpr auto lowest_value() noexcept( | ||
| noexcept(limits<std::remove_cvref_t<T>>::lowest())) -> limit_value_t<T> { | ||
| return limits<std::remove_cvref_t<T>>::lowest(); | ||
| } | ||
|
|
||
| template <limited_type T> | ||
| constexpr auto max_value() noexcept( | ||
| noexcept(limits<std::remove_cvref_t<T>>::max())) -> limit_value_t<T> { | ||
| return limits<std::remove_cvref_t<T>>::max(); | ||
| } | ||
|
|
||
| template <limited_type T> | ||
| constexpr auto epsilon_value() noexcept( | ||
| noexcept(limits<std::remove_cvref_t<T>>::epsilon())) -> limit_value_t<T> { | ||
| return limits<std::remove_cvref_t<T>>::epsilon(); | ||
| } | ||
|
|
||
| template <limited_type T> | ||
| constexpr auto infinity_value() noexcept( | ||
| noexcept(limits<std::remove_cvref_t<T>>::infinity())) -> limit_value_t<T> { | ||
| return limits<std::remove_cvref_t<T>>::infinity(); | ||
| } | ||
|
|
||
| template <limited_type T> | ||
| constexpr auto quiet_nan_value() noexcept( | ||
| noexcept(limits<std::remove_cvref_t<T>>::quiet_nan())) -> limit_value_t<T> { | ||
| return limits<std::remove_cvref_t<T>>::quiet_nan(); | ||
| } | ||
|
|
||
| } // namespace mcpplibs::primitives::algorithms | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.