From 14ba9531d118fab87b360db4aae765807fca3cec Mon Sep 17 00:00:00 2001 From: hop311 Date: Wed, 24 Jan 2024 23:28:09 +0000 Subject: Added StringMapCase and case insensitive expect_dictionary_keys --- src/openvic-simulation/types/OrderedContainers.hpp | 52 +++++++++++++++++++--- 1 file changed, 46 insertions(+), 6 deletions(-) (limited to 'src/openvic-simulation/types/OrderedContainers.hpp') diff --git a/src/openvic-simulation/types/OrderedContainers.hpp b/src/openvic-simulation/types/OrderedContainers.hpp index e9f8717..31bf17a 100644 --- a/src/openvic-simulation/types/OrderedContainers.hpp +++ b/src/openvic-simulation/types/OrderedContainers.hpp @@ -72,17 +72,17 @@ namespace OpenVic { using ordered_set = vector_ordered_set; template - concept IsOrderedMap = utility::is_specialization_of_v; + concept IsOrderedMap = utility::is_derived_from_specialization_of; template - concept IsOrderedSet = utility::is_specialization_of_v; + concept IsOrderedSet = utility::is_derived_from_specialization_of; template - concept IsVectorOrderedMap = utility::is_specialization_of_v; + concept IsVectorOrderedMap = utility::is_derived_from_specialization_of; template - concept IsVectorOrderedSet = utility::is_specialization_of_v; + concept IsVectorOrderedSet = utility::is_derived_from_specialization_of; template - concept IsDequeOrderedMap = utility::is_specialization_of_v; + concept IsDequeOrderedMap = utility::is_derived_from_specialization_of; template - concept IsDequeOrderedSet = utility::is_specialization_of_v; + concept IsDequeOrderedSet = utility::is_derived_from_specialization_of; template concept IsOrderedMapOf = @@ -162,4 +162,44 @@ namespace OpenVic { template, class IndexType = std::uint_least32_t> using case_insensitive_ordered_set = case_insensitive_vector_ordered_set; + + template + concept StringMapCase = requires(std::string_view identifier) { + { typename Case::hash {}(identifier) } -> std::same_as; + { typename Case::equal {}(identifier, identifier) } -> std::same_as; + }; + struct StringMapCaseSensitive { + using hash = container_hash; + using equal = std::equal_to<>; + }; + struct StringMapCaseInsensitive { + using hash = case_insensitive_string_hash; + using equal = case_insensitive_string_equal; + }; + + /* Intermediate struct that "remembers" Case, instead of just decomposing it into its hash and equal components, + * needed so that templates can deduce the Case with which a type was defined. */ + template typename Container, StringMapCase Case, typename... Args> + struct template_case_container_t : Container { + using container_t = Container; + using container_t::container_t; + + using case_t = Case; + }; + + /* Template for map with string keys, supporting search by string_view without creating an intermediate string. */ + template + using template_string_map_t = template_case_container_t; + + template + using string_map_t = template_string_map_t; + template + using case_insensitive_string_map_t = template_string_map_t; + + /* Template for set with string elements, supporting search by string_view without creating an intermediate string. */ + template + using template_string_set_t = template_case_container_t; + + using string_set_t = template_string_set_t; + using case_insensitive_string_set_t = template_string_set_t; } -- cgit v1.2.3-56-ga3b1