From ad9a17b6db391ee029a17cbeda9a485493e535b7 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 12 Jun 2025 18:32:00 +0100 Subject: [PATCH 01/12] Removed redundant ETL_USING_WIDE_CHARACTERS Added using_libc_wchar_h to ETL traits --- include/etl/platform.h | 2 +- test/test_etl_traits.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/etl/platform.h b/include/etl/platform.h index b51bc33b..f8ecb237 100644 --- a/include/etl/platform.h +++ b/include/etl/platform.h @@ -579,7 +579,7 @@ namespace etl static ETL_CONSTANT bool using_generic_compiler = (ETL_USING_GENERIC_COMPILER == 1); static ETL_CONSTANT bool using_legacy_bitset = (ETL_USING_LEGACY_BITSET == 1); static ETL_CONSTANT bool using_exceptions = (ETL_USING_EXCEPTIONS == 1); - static ETL_CONSTANT bool using_wide_characters = (ETL_USING_WIDE_CHARACTERS == 1); + static ETL_CONSTANT bool using_libc_wchar_h = (ETL_USING_LIBC_WCHAR_H == 1); // Has... static ETL_CONSTANT bool has_initializer_list = (ETL_HAS_INITIALIZER_LIST == 1); diff --git a/test/test_etl_traits.cpp b/test/test_etl_traits.cpp index 6adf725d..fa1c700d 100644 --- a/test/test_etl_traits.cpp +++ b/test/test_etl_traits.cpp @@ -50,7 +50,7 @@ namespace CHECK_EQUAL((ETL_USING_CPP20 == 1), etl::traits::using_cpp20); CHECK_EQUAL((ETL_USING_CPP23 == 1), etl::traits::using_cpp23); CHECK_EQUAL((ETL_USING_EXCEPTIONS == 1), etl::traits::using_exceptions); - CHECK_EQUAL((ETL_USING_WIDE_CHARACTERS == 1), etl::traits::using_wide_characters); + CHECK_EQUAL((ETL_USING_LIBC_WCHAR_H == 1), etl::traits::using_libc_wchar_h); CHECK_EQUAL((ETL_USING_GCC_COMPILER == 1), etl::traits::using_gcc_compiler); CHECK_EQUAL((ETL_USING_MICROSOFT_COMPILER == 1), etl::traits::using_microsoft_compiler); CHECK_EQUAL((ETL_USING_ARM5_COMPILER == 1), etl::traits::using_arm5_compiler); From 9832157fc4c3b5a0bcfd0402903592ef576bba98 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 14 Jun 2025 19:50:41 +0100 Subject: [PATCH 02/12] Work in progress --- include/etl/algorithm.h | 84 +++++ include/etl/const_map.h | 434 ++++++++++++++++++++++ test/test_algorithm.cpp | 56 +++ test/test_const_map.cpp | 799 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1373 insertions(+) create mode 100644 include/etl/const_map.h create mode 100644 test/test_const_map.cpp diff --git a/include/etl/algorithm.h b/include/etl/algorithm.h index 7773ac28..4d6ac1c4 100644 --- a/include/etl/algorithm.h +++ b/include/etl/algorithm.h @@ -1727,6 +1727,90 @@ namespace etl return etl::is_sorted_until(begin, end, compare) == end; } + //*************************************************************************** + /// is_unique_sorted_until + ///\ingroup algorithm + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + TIterator is_unique_sorted_until(TIterator begin, + TIterator end, + TCompare compare) + { + if (begin != end) + { + TIterator next = begin; + + while (++next != end) + { + if (!compare(*begin, *next)) + { + return next; + } + + ++begin; + } + } + + return end; + } + + //*************************************************************************** + /// is_unique_sorted_until + ///\ingroup algorithm + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + TIterator is_unique_sorted_until(TIterator begin, + TIterator end) + { + if (begin != end) + { + TIterator next = begin; + + while (++next != end) + { + if (!(*begin < *next)) + { + return next; + } + + ++begin; + } + } + + return end; + } + + //*************************************************************************** + /// is_unique_sorted + ///\ingroup algorithm + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + bool is_unique_sorted(TIterator begin, + TIterator end) + { + return etl::is_unique_sorted_until(begin, end) == end; + } + + //*************************************************************************** + /// is_unique_sorted + ///\ingroup algorithm + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + bool is_unique_sorted(TIterator begin, + TIterator end, + TCompare compare) + { + return etl::is_unique_sorted_until(begin, end, compare) == end; + } + //*************************************************************************** /// find_if_not ///\ingroup algorithm diff --git a/include/etl/const_map.h b/include/etl/const_map.h new file mode 100644 index 00000000..f8db3bc7 --- /dev/null +++ b/include/etl/const_map.h @@ -0,0 +1,434 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CONST_MAP_INCLUDED +#define ETL_CONST_MAP_INCLUDED + +#include "platform.h" +#include "algorithm.h" +#include "type_traits.h" +#include "functional.h" +#include "initializer_list.h" +#include "nth_type.h" + +//#include "private/minmax_push.h" +#include "private/comparator_is_transparent.h" + +///\defgroup const_map const_map +///\ingroup containers + +namespace etl +{ + template > + class const_map + { + public: + + using key_type = TKey; + using value_type = ETL_OR_STD::pair; + using mapped_type = TMapped ; + using key_compare_type = TKeyCompare; + using reference = const value_type&; + using const_reference = const value_type&; + using rvalue_reference = value_type&&; + using pointer = const value_type*; + using const_pointer = const value_type*; + using iterator = const value_type*; + using const_iterator = const value_type*; + using size_type = size_t; + + /// Defines the parameter types + using const_key_reference = const key_type&; + using rvalue_key_reference = key_type&&; + using const_mapped_reference = const mapped_type&; + + private: + + //********************************************************************* + /// How to compare elements and keys. + //********************************************************************* + class Compare + { + public: + + // Compare two value types. + ETL_CONSTEXPR14 bool operator ()(const value_type& element1, const value_type& element2) const ETL_NOEXCEPT + { + return key_compare(element1.first, element2.first); + } + + ETL_CONSTEXPR14 bool operator ()(const value_type& element, const_key_reference key) const ETL_NOEXCEPT + { + return key_compare(element.first, key); + } + + template ::value, int> = 0> + ETL_CONSTEXPR14 bool operator ()(const value_type& element, const K& key) const ETL_NOEXCEPT + { + return key_compare(element.first, key); + } + + ETL_CONSTEXPR14 bool operator ()(const_key_reference key, const value_type& element) const ETL_NOEXCEPT + { + return key_compare(key, element.first); + } + + template ::value, int> = 0> + ETL_CONSTEXPR14 bool operator ()(const K& key, const value_type& element) const ETL_NOEXCEPT + { + return key_compare(element.first, key); + } + + key_compare_type key_compare; + }; + + public: + + //************************************************************************* + ///\brief Construct a const_map from a variadic list of elements. + /// Static asserts if the element type is not constructible. + /// Static asserts if the elements are not of type value_type. + /// Static asserts if the number of elements is greater than the capacity of the const_map. + //************************************************************************* + template + ETL_CONSTEXPR14 explicit const_map(TElements&&... elements) ETL_NOEXCEPT + : element_list{etl::forward(elements)...} + , element_list_end{element_list + sizeof...(elements)} + { + static_assert((etl::is_default_constructible::value), "value_type must be default constructible"); + static_assert((etl::are_all_same...>::value), "All elements must be value_type"); + static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity"); + } + + //************************************************************************* + /// Check that the elements are valid for a map. + /// The elements must be sorted and contain no duplicates. + /// \return true if the elements are valid for the map. + //************************************************************************* + ETL_CONSTEXPR14 bool is_valid() const ETL_NOEXCEPT + { + return etl::is_unique_sorted(begin(), end(), compare); + } + + //************************************************************************* + ///\brief Returns a const_iterator to the beginning of the map. + //************************************************************************* + ETL_CONSTEXPR14 const_iterator begin() const ETL_NOEXCEPT + { + return element_list; + } + + //************************************************************************* + ///\brief Returns a const_iterator to the beginning of the map. + //************************************************************************* + ETL_CONSTEXPR14 const_iterator cbegin() const ETL_NOEXCEPT + { + return element_list; + } + + //************************************************************************* + ///\brief Returns a const_iterator to the end of the map. + //************************************************************************* + ETL_CONSTEXPR14 const_iterator end() const ETL_NOEXCEPT + { + return element_list_end; + } + + //************************************************************************* + ///\brief Returns a const_iterator to the end of the map. + //************************************************************************* + ETL_CONSTEXPR14 const_iterator cend() const ETL_NOEXCEPT + { + return element_list_end; + } + + //************************************************************************* + ///\brief Returns a const_pointer to the beginning of the map. + //************************************************************************* + ETL_CONSTEXPR14 const_pointer data() const ETL_NOEXCEPT + { + return element_list; + } + + //************************************************************************* + ///\brief Index operator. + ///\return A const_mapped_reference to the mapped value at the index. + /// Undefined behaviour if the key is not in the map. + //************************************************************************* + ETL_CONSTEXPR14 const_mapped_reference operator[](const_key_reference key) const ETL_NOEXCEPT + { + const_iterator itr = find(key); + + return itr->second; + } + + //************************************************************************* + ///\brief Key index operator. + /// Enabled for transparent comparators. + ///\return A const_mapped_reference to the mapped value at the key index. + /// Undefined behaviour if the key is not in the map. + //************************************************************************* + template ::value, int> = 0> + ETL_CONSTEXPR14 const_mapped_reference operator[](const K& key) const ETL_NOEXCEPT + { + const_iterator itr = find(key); + + return itr->second; + } + + //************************************************************************* + ///\brief Gets the mapped value at the key index. + ///\return A const_mapped_reference to the mapped value at the index. + /// Undefined behaviour if the key is not in the map. + //************************************************************************* + ETL_CONSTEXPR14 const_mapped_reference at(const_key_reference key) const ETL_NOEXCEPT + { + const_iterator itr = find(key); + + return itr->second; + } + + //************************************************************************* + template ::value, int> = 0> + ETL_CONSTEXPR14 const_mapped_reference at(const K& key) const ETL_NOEXCEPT + { + const_iterator itr = find(key); + + return itr->second; + } + + //************************************************************************* + ETL_CONSTEXPR14 const_iterator find(const_key_reference key) const ETL_NOEXCEPT + { + iterator itr = lower_bound(key); + + if (itr != end()) + { + if (keys_are_equal(itr->first, key)) + { + return itr; + } + else + { + return end(); + } + } + + return end(); + + } + + //************************************************************************* + template ::value, int> = 0> + ETL_CONSTEXPR14 const_iterator find(const K& key) const ETL_NOEXCEPT + { + iterator itr = lower_bound(key); + + if (itr != end()) + { + if (keys_are_equal(itr->first, key)) + { + return itr; + } + else + { + return end(); + } + } + + return end(); + } + + //************************************************************************* + ETL_CONSTEXPR14 bool contains(const_key_reference key) const ETL_NOEXCEPT + { + return find(key) != end(); + } + + //************************************************************************* + template ::value, int> = 0> + ETL_CONSTEXPR14 bool contains(const K& key) const ETL_NOEXCEPT + { + return find(key) != end(); + } + + //************************************************************************* + ETL_CONSTEXPR14 size_type count(const_key_reference key) const ETL_NOEXCEPT + { + return contains(key) ? 1 : 0; + } + + //************************************************************************* + template ::value, int> = 0> + ETL_CONSTEXPR14 size_type count(const K& key) const ETL_NOEXCEPT + { + return contains(key) ? 1 : 0; + } + + //************************************************************************* + ETL_CONSTEXPR14 ETL_OR_STD::pair equal_range(const_key_reference key) const ETL_NOEXCEPT + { + return etl::equal_range(begin(), end(), key, compare); + } + + //************************************************************************* + template ::value, int> = 0> + ETL_CONSTEXPR14 ETL_OR_STD::pair equal_range(const K& key) const ETL_NOEXCEPT + { + return etl::equal_range(begin(), end(), key, compare); + } + + //************************************************************************* + ETL_CONSTEXPR14 const_iterator lower_bound(const_key_reference key) const ETL_NOEXCEPT + { + const_iterator itr = etl::lower_bound(begin(), end(), key, compare); + + if ((itr != end()) && keys_are_equal(key, itr->first)) + { + return itr; + } + else + { + return end(); + } + } + + //************************************************************************* + template ::value, int> = 0> + ETL_CONSTEXPR14 const_iterator lower_bound(const K& key) const ETL_NOEXCEPT + { + const_iterator itr = etl::lower_bound(begin(), end(), key, compare); + + if ((itr != end()) && keys_are_equal(key, itr->first)) + { + return itr; + } + else + { + return end(); + } + } + + //************************************************************************* + ETL_CONSTEXPR14 const_iterator upper_bound(const_key_reference key) const ETL_NOEXCEPT + { + const_iterator itr = etl::upper_bound(begin(), end(), key, compare); + + if ((itr != end()) && keys_are_equal(key, itr->first)) + { + return itr; + } + else + { + return end(); + } + } + + //************************************************************************* + template ::value, int> = 0> + ETL_CONSTEXPR14 const_iterator upper_bound(const K& key) const ETL_NOEXCEPT + { + const_iterator itr = etl::upper_bound(begin(), end(), key, compare); + + if ((itr != end()) && keys_are_equal(key, itr->first)) + { + return itr; + } + else + { + return end(); + } + } + + //************************************************************************* + ETL_CONSTEXPR14 size_type empty() const ETL_NOEXCEPT + { + return size() == 0U; + } + + //************************************************************************* + ETL_CONSTEXPR14 size_type full() const ETL_NOEXCEPT + { + return size() == Size; + } + + //************************************************************************* + ETL_CONSTEXPR14 size_type size() const ETL_NOEXCEPT + { + return size_type(element_list_end - element_list); + } + + //************************************************************************* + ETL_CONSTEXPR14 size_type max_size() const ETL_NOEXCEPT + { + return Size; + } + + //************************************************************************* + ETL_CONSTEXPR14 size_type capacity() const ETL_NOEXCEPT + { + return Size; + } + + private: + + //********************************************************************* + /// Check to see if the keys are equal. + //********************************************************************* + bool keys_are_equal(const_key_reference key1, const_key_reference key2) const + { + return !key_compare_type()(key1, key2) && !key_compare_type()(key2, key1); + } + + //********************************************************************* + template ::value, int> = 0> + bool keys_are_equal(const K1& key1, const K2& key2) const + { + return !key_compare_type()(key1, key2) && !key_compare_type()(key2, key1); + } + + Compare compare; + + value_type element_list[Size]; + value_type* element_list_end; + }; + + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_USING_CPP17 + template + const_map(TPairs...) -> const_map::first_type, + typename etl::nth_type_t<0, TPairs...>::second_type, + sizeof...(TPairs)>; +#endif +} + +#endif diff --git a/test/test_algorithm.cpp b/test/test_algorithm.cpp index 2d362dd9..eb8f7e3b 100644 --- a/test/test_algorithm.cpp +++ b/test/test_algorithm.cpp @@ -334,6 +334,62 @@ namespace CHECK(!is_sorted); } + //************************************************************************* + TEST(is_unique_sorted_until) + { + int sorted_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + int not_sorted_data[] = { 1, 2, 3, 4, 6, 5, 7, 8, 9, 10 }; + int not_unique_data[] = { 1, 2, 3, 4, 4, 5, 6, 8, 9, 10 }; + + int* p_sorted = etl::is_unique_sorted_until(std::begin(sorted_data), std::end(sorted_data)); + int* p_not_sorted = etl::is_unique_sorted_until(std::begin(not_sorted_data), std::end(not_sorted_data)); + int* p_not_unique = etl::is_unique_sorted_until(std::begin(not_unique_data), std::end(not_unique_data)); + + CHECK_EQUAL(10, std::distance(sorted_data, p_sorted)); + CHECK_EQUAL(5, std::distance(not_sorted_data, p_not_sorted)); + CHECK_EQUAL(4, std::distance(not_unique_data, p_not_unique)); + } + + //************************************************************************* + TEST(is_unique_sorted_until_compare) + { + int sorted_data[] = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; + int not_sorted_data[] = { 10, 9, 8, 7, 5, 6, 4, 3, 2, 1 }; + int not_unique_data[] = { 10, 9, 8, 6, 5, 4, 4, 3, 2, 1 }; + + int* p_sorted = etl::is_unique_sorted_until(std::begin(sorted_data), std::end(sorted_data), std::greater()); + int* p_not_sorted = etl::is_unique_sorted_until(std::begin(not_sorted_data), std::end(not_sorted_data), std::greater()); + int* p_not_unique = etl::is_unique_sorted_until(std::begin(not_unique_data), std::end(not_unique_data), std::greater()); + + CHECK_EQUAL(10, std::distance(sorted_data, p_sorted)); + CHECK_EQUAL(5, std::distance(not_sorted_data, p_not_sorted)); + CHECK_EQUAL(6, std::distance(not_unique_data, p_not_unique)); + } + + //************************************************************************* + TEST(is_unique_sorted) + { + int sorted_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + int not_sorted_data[] = { 1, 2, 3, 4, 6, 5, 7, 8, 9, 10 }; + int not_unique_data[] = { 1, 2, 3, 4, 4, 5, 6, 8, 9, 10 }; + + CHECK_TRUE((etl::is_unique_sorted(std::begin(sorted_data), std::end(sorted_data)))); + CHECK_FALSE((etl::is_unique_sorted(std::begin(not_sorted_data), std::end(not_sorted_data)))); + CHECK_FALSE((etl::is_unique_sorted(std::begin(not_unique_data), std::end(not_unique_data)))); + } + + //************************************************************************* + TEST(is_unique_sorted_compare) + { + int sorted_data[] = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; + int not_sorted_data[] = { 10, 9, 8, 7, 5, 6, 4, 3, 2, 1 }; + int not_unique_data[] = { 10, 9, 8, 6, 5, 4, 4, 3, 2, 1 }; + + CHECK_TRUE((etl::is_unique_sorted(std::begin(sorted_data), std::end(sorted_data), std::greater()))); + CHECK_FALSE((etl::is_unique_sorted(std::begin(not_sorted_data), std::end(not_sorted_data), std::greater()))); + CHECK_FALSE((etl::is_unique_sorted(std::begin(not_unique_data), std::end(not_unique_data), std::greater()))); + } + //************************************************************************* TEST(copy_pod_pointer) { diff --git a/test/test_const_map.cpp b/test/test_const_map.cpp new file mode 100644 index 00000000..609f8588 --- /dev/null +++ b/test/test_const_map.cpp @@ -0,0 +1,799 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove, rlindeman + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the 'Software'), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "etl/const_map.h" +#include "etl/map.h" +#include "etl/string.h" + +#include "data.h" + +namespace +{ + static const size_t Max_Size = 10UL; + + //************************************************************************* + // The key type + //************************************************************************* + struct Key + { + // Default constructor + constexpr Key() + : k(0) + { + } + + // Construct from char key + constexpr explicit Key(char k_) + : k(k_) + { + } + + char k; + }; + + // Less-than operator for Key < Key + constexpr bool operator <(const Key& lhs, const Key& rhs) ETL_NOEXCEPT + { + return (lhs.k < rhs.k); + } + + // Less-than operator for Key < char + constexpr bool operator <(const Key& lhs, char rhs) ETL_NOEXCEPT + { + return (lhs.k < rhs); + } + + // Less-than operator for char < Key + constexpr bool operator <(char lhs, const Key& rhs) ETL_NOEXCEPT + { + return (lhs < rhs.k); + } + + // Greater-than operator for Key > char + constexpr bool operator >(const Key& lhs, const Key& rhs) ETL_NOEXCEPT + { + return (lhs.k > rhs.k); + } + + // Greater-than operator for char > Key + constexpr bool operator ==(const Key& lhs, const Key& rhs) ETL_NOEXCEPT + { + return (lhs.k == rhs.k); + } + + //#define TEST_GREATER_THAN + #ifdef TEST_GREATER_THAN + using Data = etl::const_map>; + using DataTransparentComparator = etl::const_map>; + #else + using Data = etl::const_map>; + using DataTransparentComparator = etl::const_map>; + #endif + + using value_type = Data::value_type; + + using Data_iterator = Data::iterator; + using Data_const_iterator = Data::const_iterator; + + SUITE(test_const_map) + { + //************************************************************************* +#include "etl/private/diagnostic_null_dereference_push.h" + template + bool Check_Equal(T1 begin1, T1 end1, T2 begin2) + { + while (begin1 != end1) + { + if ((begin1->first != begin2->first) || (begin1->second != begin2->second)) + { + return false; + } + + ++begin1; + ++begin2; + } + + return true; + } +#include "etl/private/diagnostic_pop.h" + + //************************************************************************* + TEST(test_default_constructor) + { + static constexpr Data data; + + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr Data::const_iterator begin = data.begin(); + static constexpr Data::const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == 0UL); + CHECK_TRUE(empty); + CHECK_FALSE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_TRUE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_min_size) + { + static constexpr Data data{ value_type{Key('A'), 0 } }; + + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr Data::const_iterator begin = data.begin(); + static constexpr Data::const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == 1U); + CHECK_FALSE(empty); + CHECK_FALSE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_FALSE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_max_size) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + CHECK_TRUE(data.is_valid()); + CHECK_TRUE(data.size() == Max_Size); + CHECK_FALSE(data.empty()); + CHECK_TRUE(data.full()); + CHECK_TRUE(data.capacity() == Max_Size); + CHECK_TRUE(data.max_size() == Max_Size); + CHECK_FALSE(data.begin() == data.end()); + } + + ////************************************************************************* + // Enable to check static_assert "Number of elements exceeds capacity" + ////************************************************************************* + //TEST(test_constructor_excess_size) + //{ + // static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + // value_type{Key('F'), 5 }, value_type{'G'), 6 }, value_type{'H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, + // value_type{Key('K'), 10 } }; + //} + +#if ETL_USING_CPP17 + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + +#ifdef TEST_GREATER_THAN + etl::const_map check{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + etl::const_map check{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + CHECK_TRUE(data.is_valid()); + CHECK_TRUE(data.size() == Max_Size); + CHECK_FALSE(data.empty()); + CHECK_TRUE(data.full()); + CHECK_TRUE(data.capacity() == Max_Size); + CHECK_TRUE(data.max_size() == Max_Size); + CHECK_FALSE(data.begin() == data.end()); + } +#endif + + //************************************************************************* + TEST(test_begin) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + CHECK_TRUE(data.is_valid()); + auto value = *data.begin(); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE((value_type{ Key('J'), 9 }) == value); +#else + CHECK_TRUE((value_type{ Key('A'), 0 }) == value); +#endif + } + + //************************************************************************* + TEST(test_end) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + CHECK_TRUE(data.is_valid()); + CHECK_TRUE(data.end() == (data.begin() + data.size())); + } + + //************************************************************************* + TEST(test_index) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + CHECK_TRUE(data.is_valid()); + CHECK(data[Key('A')] == 0); + CHECK(data[Key('B')] == 1); + CHECK(data[Key('C')] == 2); + CHECK(data[Key('D')] == 3); + CHECK(data[Key('E')] == 4); + CHECK(data[Key('F')] == 5); + CHECK(data[Key('G')] == 6); + CHECK(data[Key('H')] == 7); + CHECK(data[Key('I')] == 8); + CHECK(data[Key('J')] == 9); + } + + //************************************************************************* + TEST(test_index__using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + CHECK_TRUE(data.is_valid()); + CHECK(data['A'] == 0); + CHECK(data['B'] == 1); + CHECK(data['C'] == 2); + CHECK(data['D'] == 3); + CHECK(data['E'] == 4); + CHECK(data['F'] == 5); + CHECK(data['G'] == 6); + CHECK(data['H'] == 7); + CHECK(data['I'] == 8); + CHECK(data['J'] == 9); + } + + //************************************************************************* + TEST(test_at) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + CHECK_TRUE(data.is_valid()); + CHECK(data.at(Key('A')) == 0); + CHECK(data.at(Key('B')) == 1); + CHECK(data.at(Key('C')) == 2); + CHECK(data.at(Key('D')) == 3); + CHECK(data.at(Key('E')) == 4); + CHECK(data.at(Key('F')) == 5); + CHECK(data.at(Key('G')) == 6); + CHECK(data.at(Key('H')) == 7); + CHECK(data.at(Key('I')) == 8); + CHECK(data.at(Key('J')) == 9); + } + + //************************************************************************* + TEST(test_at_using_transparent_comparator) + { + #ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + #else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + #endif + + CHECK_TRUE(data.is_valid()); + CHECK(data.at('A') == 0); + CHECK(data.at('B') == 1); + CHECK(data.at('C') == 2); + CHECK(data.at('D') == 3); + CHECK(data.at('E') == 4); + CHECK(data.at('F') == 5); + CHECK(data.at('G') == 6); + CHECK(data.at('H') == 7); + CHECK(data.at('I') == 8); + CHECK(data.at('J') == 9); + } + +// //************************************************************************* +// TEST(test_equal_range) +// { +// Compare_Data compare_data(random_data.begin(), random_data.end()); +// Data data(random_data.begin(), random_data.end()); +// +// ETL_OR_STD::pair data_result = data.equal_range('2'); +// Data::iterator data_lb = data.lower_bound('2'); +// ETL_OR_STD::pair compare_result = compare_data.equal_range('2'); +// Compare_Data::iterator compare_data_lb = compare_data.lower_bound('2'); +// +// // Check that both return the same return results +// CHECK(data_lb->first == compare_data_lb->first); +// CHECK(data_lb->second == compare_data_lb->second); +// CHECK(data_result.first->first == compare_result.first->first); +// CHECK(data_result.first->second == compare_result.first->second); +// CHECK(data_result.second->first == compare_result.second->first); +// CHECK(data_result.second->second == compare_result.second->second); +// +// bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin()); +// +// CHECK(isEqual); +// } + +// //************************************************************************* +// TEST(test_equal_range_using_transparent_comparator) +// { +// using CMap = std::map>; +// using EMap = etl::map>; +// +// CMap compare_data(random_data.begin(), random_data.end()); +// EMap data(random_data.begin(), random_data.end()); +// +// ETL_OR_STD::pair data_result = data.equal_range(Key('2')); +// EMap::iterator data_lb = data.lower_bound('2'); +// ETL_OR_STD::pair compare_result = compare_data.equal_range('2'); +// CMap::iterator compare_data_lb = compare_data.lower_bound('2'); +// +// // Check that both return the same return results +// CHECK(data_lb->first == compare_data_lb->first); +// CHECK(data_lb->second == compare_data_lb->second); +// CHECK(data_result.first->first == compare_result.first->first); +// CHECK(data_result.first->second == compare_result.first->second); +// CHECK(data_result.second->first == compare_result.second->first); +// CHECK(data_result.second->second == compare_result.second->second); +// +// bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin()); +// +// CHECK(isEqual); +// } + +// //************************************************************************* +// TEST(test_count) +// { +// const Data data(initial_data.begin(), initial_data.end()); +// +// CHECK(data.count('3') == 1UL); +// +// CHECK(data.count(Key('A') == 0UL); +// } + +// //************************************************************************* +// TEST(test_count_using_transparent_comparator) +// { +// using EMap = etl::map>; +// +// const EMap data(initial_data.begin(), initial_data.end()); +// +// CHECK(data.count(Key('3')) == 1UL); +// +// CHECK(data.count(Key(Key('A')) == 0UL); +// } + +// //************************************************************************* +// TEST(test_iterator) +// { +// Compare_Data compare_data(initial_data.begin(), initial_data.end()); +// +// Data data(compare_data.begin(), compare_data.end()); +// +// bool isEqual = Check_Equal(data.begin(), +// data.end(), +// compare_data.begin()); +// +// CHECK(isEqual); +// } + +// //************************************************************************* +// TEST(test_const_iterator) +// { +// Compare_Data compare_data(initial_data.begin(), initial_data.end()); +// +// Data data(compare_data.begin(), compare_data.end()); +// +// bool isEqual = Check_Equal(data.cbegin(), +// data.cend(), +// compare_data.cbegin()); +// +// CHECK(isEqual); +// } + +// //************************************************************************* +// TEST(test_find) +// { +// Data data(initial_data.begin(), initial_data.end()); +// +// Data::iterator it = data.find('3'); +// CHECK(3 == it->second); +// +// it = data.find(Key('A'); +// CHECK(data.end() == it); +// +// it = data.find('!'); +// CHECK(data.end() == it); +// } + +// //************************************************************************* +// TEST(test_find_using_transparent_comparator) +// { +// using EMap = etl::map>; +// +// EMap data(initial_data.begin(), initial_data.end()); +// +// EMap::iterator it = data.find(Key('3')); +// CHECK(3 == it->second); +// +// it = data.find(Key(Key('A')); +// CHECK(data.end() == it); +// +// it = data.find(Key('!')); +// CHECK(data.end() == it); +// } + +// //************************************************************************* +// TEST(test_equal) +// { +// const Data initial1(initial_data.begin(), initial_data.end()); +// const Data initial2(initial_data.begin(), initial_data.end()); +// +// CHECK(initial1 == initial2); +// +// const Data different(different_data.begin(), different_data.end()); +// +// CHECK(!(initial1 == different)); +// } + +// //************************************************************************* +// TEST(test_not_equal) +// { +// const Data initial1(initial_data.begin(), initial_data.end()); +// const Data initial2(initial_data.begin(), initial_data.end()); +// +// CHECK(!(initial1 != initial2)); +// +// const Data different(different_data.begin(), different_data.end()); +// +// CHECK(initial1 != different); +// } + +// //************************************************************************* +// TEST(test_lower_bound) +// { +// Compare_Data compare_data(initial_data.begin(), initial_data.end()); +// Data data(initial_data.begin(), initial_data.end()); +// +// Compare_Data::iterator i_compare = compare_data.lower_bound('8'); +// Data::iterator i_data = data.lower_bound('8'); +// CHECK(i_compare->second == i_data->second); +// +//#ifdef TEST_GREATER_THAN +// i_compare = compare_data.lower_bound('.'); +// CHECK(compare_data.end() == i_compare); +// +// i_data = data.lower_bound('.'); +// CHECK(data.end() == i_data); +// +// i_compare = compare_data.lower_bound(Key('A'); +// i_data = data.lower_bound(Key('A'); +// CHECK(i_compare->second == i_data->second); +//#else +// i_compare = compare_data.lower_bound('.'); +// i_data = data.lower_bound('.'); +// CHECK(i_compare->second == i_data->second); +// +// i_compare = compare_data.lower_bound(Key('A'); +// CHECK(compare_data.end() == i_compare); +// +// i_data = data.lower_bound(Key('A'); +// CHECK(data.end() == i_data); +//#endif +// } + +// //************************************************************************* +// TEST(test_lower_bound_using_transparent_comparator) +// { +// using CMap = std::map>; +// using EMap = etl::map>; +// +// CMap compare_data(initial_data.begin(), initial_data.end()); +// EMap data(initial_data.begin(), initial_data.end()); +// +// CMap::iterator i_compare = compare_data.lower_bound('8'); +// EMap::iterator i_data = data.lower_bound(Key('8')); +// CHECK(i_compare->second == i_data->second); +// +// i_compare = compare_data.lower_bound('.'); +// i_data = data.lower_bound(Key('.')); +// CHECK(i_compare->second == i_data->second); +// +// i_compare = compare_data.lower_bound(Key('A'); +// CHECK(compare_data.end() == i_compare); +// +// i_data = data.lower_bound(Key(Key('A')); +// CHECK(data.end() == i_data); +// } + +// //************************************************************************* +// TEST(test_upper_bound) +// { +// Compare_Data compare_data(initial_data.begin(), initial_data.end()); +// Data data(initial_data.begin(), initial_data.end()); +// +// Compare_Data::iterator i_compare = compare_data.upper_bound('2'); +// Data::iterator i_data = data.upper_bound('2'); +// CHECK(i_compare->second == i_data->second); +// +//#ifdef TEST_GREATER_THAN +// i_compare = compare_data.upper_bound('.'); +// CHECK(compare_data.end() == i_compare); +// +// i_data = data.upper_bound('.'); +// CHECK(data.end() == i_data); +// +// i_compare = compare_data.upper_bound(Key('A'); +// i_data = data.upper_bound(Key('A'); +// CHECK(i_compare->second == i_data->second); +//#else +// i_compare = compare_data.upper_bound('.'); +// i_data = data.upper_bound('.'); +// CHECK(i_compare->second == i_data->second); +// +// i_compare = compare_data.upper_bound(Key('A'); +// CHECK(compare_data.end() == i_compare); +// +// i_data = data.upper_bound(Key('A'); +// CHECK(data.end() == i_data); +//#endif +// } + +// //************************************************************************* +// TEST(test_upper_bound_using_transparent_comparator) +// { +// using CMap = std::map>; +// using EMap = etl::map>; +// +// CMap compare_data(initial_data.begin(), initial_data.end()); +// EMap data(initial_data.begin(), initial_data.end()); +// +// CMap::iterator i_compare = compare_data.upper_bound('2'); +// EMap::iterator i_data = data.upper_bound(Key('2')); +// CHECK(i_compare->second == i_data->second); +// +// i_compare = compare_data.upper_bound('.'); +// i_data = data.upper_bound(Key('.')); +// CHECK(i_compare->second == i_data->second); +// +// i_compare = compare_data.upper_bound(Key('A'); +// CHECK(compare_data.end() == i_compare); +// +// i_data = data.upper_bound(Key(Key('A')); +// CHECK(data.end() == i_data); +// } + +// //************************************************************************* +// TEST(test_key_compare) +// { +// const Data data(initial_data.begin(), initial_data.end()); +// +// Data::key_compare compare = data.key_comp(); +// +// Data::key_type a(Key('A'); +// Data::key_type b(Key('B'); +// +//#ifdef TEST_GREATER_THAN +// CHECK(!compare(a, b)); +// CHECK(compare(b, a)); +//#else +// CHECK(compare(a, b)); +// CHECK(!compare(b, a)); +//#endif +// } + +// //************************************************************************* +// TEST(test_key_compare_using_transparent_comparator) +// { +// using EMap = etl::map>; +// const EMap data(initial_data.begin(), initial_data.end()); +// +// EMap::key_compare compare = data.key_comp(); +// +// char a(Key('A'); +// Key b(Key('B'); +// +// CHECK(compare(a, b)); +// CHECK(!compare(b, a)); +// } + +// //************************************************************************* +// TEST(test_value_compare) +// { +// const Data data(initial_data.begin(), initial_data.end()); +// +// Data::value_compare compare = data.value_comp(); +// +// Data::value_type a(char(Key('A'), 0); +// Data::value_type b(char(Key('B'), 1); +// +//#ifdef TEST_GREATER_THAN +// CHECK(!compare(a, b)); +// CHECK(compare(b, a)); +//#else +// CHECK(compare(a, b)); +// CHECK(!compare(b, a)); +//#endif +// } + +// //************************************************************************* +// TEST(test_compare_lower_upper_bound) +// { +// Data data(initial_data_even.begin(), initial_data_even.end()); +// Compare_Data compare(initial_data_even.begin(), initial_data_even.end()); +// +// std::vector > tab(test_data.begin(), test_data.end()); +// +// //make sure both data and compare contain same elements +// std::vector > data_elements(data.begin(), data.end()); +// std::vector > compare_data_elements(compare.begin(), compare.end()); +// +// CHECK(data_elements == compare_data_elements); +// CHECK(data_elements.size() == Max_Size); +// +// for(std::vector >::iterator it = tab.begin() ; it != tab.end() ; ++it) +// { +// char i = it->first; +// +// //lower_bound +// CHECK((compare.lower_bound(i) == compare.end()) == (data.lower_bound(i) == data.end())); +// //if both end, or none +// if((compare.lower_bound(i) == compare.end()) == (data.lower_bound(i) == data.end())) +// { +// //if both are not end +// if(compare.lower_bound(i) != compare.end()) +// { +// CHECK((*compare.lower_bound(i)) == (*data.lower_bound(i))); +// } +// +// ETL_OR_STD::pair stlret = compare.equal_range(i); +// ETL_OR_STD::pair etlret = data.equal_range(i); +// +// CHECK((stlret.first == compare.end()) == (etlret.first == data.end())); +// if((stlret.first != compare.end()) && (etlret.first != data.end())) +// { +// CHECK((*stlret.first) == (*etlret.first)); +// } +// CHECK((stlret.second == compare.end()) == (etlret.second == data.end())); +// if((stlret.second != compare.end()) && (etlret.second != data.end())) +// { +// CHECK((*stlret.second) == (*etlret.second)); +// } +// } +// +// //upper_bound +// CHECK((compare.upper_bound(i) == compare.end()) == (data.upper_bound(i) == data.end())); +// //if both end, or none +// if((compare.upper_bound(i) == compare.end()) == (data.upper_bound(i) == data.end())) +// { +// //if both are not end +// if(compare.upper_bound(i) != compare.end()) +// { +// CHECK((*compare.upper_bound(i)) == (*data.upper_bound(i))); +// } +// } +// } +// } + +// //************************************************************************* +//#if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) +// TEST(test_map_template_deduction) +// { +// using Pair = std::pair, int>; +// +// etl::map data { Pair{'0', 0}, Pair{'1', 1}, Pair{'2', 2}, Pair{'3', 3}, Pair{'4', 4}, Pair{'5', 5} }; +// +// auto v = *data.begin(); +// using Type = decltype(v); +// CHECK((std::is_same_v)); +// +// CHECK_EQUAL(0, data.at('0')); +// CHECK_EQUAL(1, data.at('1')); +// CHECK_EQUAL(2, data.at('2')); +// CHECK_EQUAL(3, data.at('3')); +// CHECK_EQUAL(4, data.at('4')); +// CHECK_EQUAL(5, data.at('5')); +// } +//#endif + +// //************************************************************************* +// TEST(test_contains) +// { +// Data data(initial_data.begin(), initial_data.end()); +// +// CHECK(data.contains(char('1'))); +// CHECK(!data.contains(char('99'))); +// } + +// //************************************************************************* +// TEST(test_contains_with_transparent_comparator) +// { +// etl::map> data(initial_data.begin(), initial_data.end()); +// +// CHECK(data.contains(char('1'))); +// CHECK(data.contains(Key('1'))); +// +// CHECK(!data.contains(char('99'))); +// CHECK(!data.contains(Key('99'))); +// } + }; +} From 16a61050cad143b505ddbbe8fd30499b3e7000b1 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 15 Jun 2025 17:32:27 +0100 Subject: [PATCH 03/12] Fixed reversed struct greater parameters --- include/etl/functional.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/etl/functional.h b/include/etl/functional.h index 7fb3e415..9f7f811d 100644 --- a/include/etl/functional.h +++ b/include/etl/functional.h @@ -237,7 +237,7 @@ namespace etl template constexpr auto operator()(T1&& lhs, T2&& rhs) const -> decltype(static_cast(lhs) < static_cast(rhs)) { - return static_cast(rhs) < static_cast(lhs); + return static_cast(rhs) < static_cast(lhs); } }; #endif From a2efcd2fe718b06cbbb1ef2e370a47df42b7786b Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 15 Jun 2025 17:32:49 +0100 Subject: [PATCH 04/12] Work in progress --- include/etl/const_map.h | 121 ++- test/test_const_map.cpp | 1685 +++++++++++++++++++++++++++++++-------- 2 files changed, 1428 insertions(+), 378 deletions(-) diff --git a/include/etl/const_map.h b/include/etl/const_map.h index f8db3bc7..25f102ff 100644 --- a/include/etl/const_map.h +++ b/include/etl/const_map.h @@ -35,10 +35,8 @@ SOFTWARE. #include "algorithm.h" #include "type_traits.h" #include "functional.h" -#include "initializer_list.h" #include "nth_type.h" -//#include "private/minmax_push.h" #include "private/comparator_is_transparent.h" ///\defgroup const_map const_map @@ -54,7 +52,7 @@ namespace etl using key_type = TKey; using value_type = ETL_OR_STD::pair; using mapped_type = TMapped ; - using key_compare_type = TKeyCompare; + using key_compare = TKeyCompare; using reference = const value_type&; using const_reference = const value_type&; using rvalue_reference = value_type&&; @@ -69,48 +67,44 @@ namespace etl using rvalue_key_reference = key_type&&; using const_mapped_reference = const mapped_type&; - private: - //********************************************************************* /// How to compare elements and keys. //********************************************************************* - class Compare + class value_compare { public: - // Compare two value types. + // value_compare two value types. ETL_CONSTEXPR14 bool operator ()(const value_type& element1, const value_type& element2) const ETL_NOEXCEPT { - return key_compare(element1.first, element2.first); + return kcompare(element1.first, element2.first); } ETL_CONSTEXPR14 bool operator ()(const value_type& element, const_key_reference key) const ETL_NOEXCEPT { - return key_compare(element.first, key); + return kcompare(element.first, key); } template ::value, int> = 0> ETL_CONSTEXPR14 bool operator ()(const value_type& element, const K& key) const ETL_NOEXCEPT { - return key_compare(element.first, key); + return kcompare(element.first, key); } ETL_CONSTEXPR14 bool operator ()(const_key_reference key, const value_type& element) const ETL_NOEXCEPT { - return key_compare(key, element.first); + return kcompare(key, element.first); } template ::value, int> = 0> ETL_CONSTEXPR14 bool operator ()(const K& key, const value_type& element) const ETL_NOEXCEPT { - return key_compare(element.first, key); + return kcompare(key, element.first); } - key_compare_type key_compare; + key_compare kcompare; }; - public: - //************************************************************************* ///\brief Construct a const_map from a variadic list of elements. /// Static asserts if the element type is not constructible. @@ -134,7 +128,7 @@ namespace etl //************************************************************************* ETL_CONSTEXPR14 bool is_valid() const ETL_NOEXCEPT { - return etl::is_unique_sorted(begin(), end(), compare); + return etl::is_unique_sorted(begin(), end(), vcompare); } //************************************************************************* @@ -295,76 +289,40 @@ namespace etl //************************************************************************* ETL_CONSTEXPR14 ETL_OR_STD::pair equal_range(const_key_reference key) const ETL_NOEXCEPT { - return etl::equal_range(begin(), end(), key, compare); + return etl::equal_range(begin(), end(), key, vcompare); } //************************************************************************* template ::value, int> = 0> ETL_CONSTEXPR14 ETL_OR_STD::pair equal_range(const K& key) const ETL_NOEXCEPT { - return etl::equal_range(begin(), end(), key, compare); + return etl::equal_range(begin(), end(), key, vcompare); } //************************************************************************* ETL_CONSTEXPR14 const_iterator lower_bound(const_key_reference key) const ETL_NOEXCEPT { - const_iterator itr = etl::lower_bound(begin(), end(), key, compare); - - if ((itr != end()) && keys_are_equal(key, itr->first)) - { - return itr; - } - else - { - return end(); - } + return etl::lower_bound(begin(), end(), key, vcompare); } //************************************************************************* template ::value, int> = 0> ETL_CONSTEXPR14 const_iterator lower_bound(const K& key) const ETL_NOEXCEPT { - const_iterator itr = etl::lower_bound(begin(), end(), key, compare); - - if ((itr != end()) && keys_are_equal(key, itr->first)) - { - return itr; - } - else - { - return end(); - } + return etl::lower_bound(begin(), end(), key, vcompare); } //************************************************************************* ETL_CONSTEXPR14 const_iterator upper_bound(const_key_reference key) const ETL_NOEXCEPT { - const_iterator itr = etl::upper_bound(begin(), end(), key, compare); - - if ((itr != end()) && keys_are_equal(key, itr->first)) - { - return itr; - } - else - { - return end(); - } + return etl::upper_bound(begin(), end(), key, vcompare); } //************************************************************************* template ::value, int> = 0> ETL_CONSTEXPR14 const_iterator upper_bound(const K& key) const ETL_NOEXCEPT { - const_iterator itr = etl::upper_bound(begin(), end(), key, compare); - - if ((itr != end()) && keys_are_equal(key, itr->first)) - { - return itr; - } - else - { - return end(); - } + return etl::upper_bound(begin(), end(), key, vcompare); } //************************************************************************* @@ -397,24 +355,40 @@ namespace etl return Size; } + //************************************************************************* + /// How to compare two key elements. + //************************************************************************* + ETL_CONSTEXPR14 key_compare key_comp() const ETL_NOEXCEPT + { + return vcompare.kcompare; + } + + //************************************************************************* + /// How to compare two value elements. + //************************************************************************* + ETL_CONSTEXPR14 value_compare value_comp() const ETL_NOEXCEPT + { + return vcompare; + } + private: //********************************************************************* /// Check to see if the keys are equal. //********************************************************************* - bool keys_are_equal(const_key_reference key1, const_key_reference key2) const + ETL_CONSTEXPR14 bool keys_are_equal(const_key_reference key1, const_key_reference key2) const ETL_NOEXCEPT { - return !key_compare_type()(key1, key2) && !key_compare_type()(key2, key1); + return !key_compare()(key1, key2) && !key_compare()(key2, key1); } //********************************************************************* template ::value, int> = 0> - bool keys_are_equal(const K1& key1, const K2& key2) const + ETL_CONSTEXPR14 bool keys_are_equal(const K1& key1, const K2& key2) const ETL_NOEXCEPT { - return !key_compare_type()(key1, key2) && !key_compare_type()(key2, key1); + return !key_compare()(key1, key2) && !key_compare()(key2, key1); } - Compare compare; + value_compare vcompare; value_type element_list[Size]; value_type* element_list_end; @@ -429,6 +403,27 @@ namespace etl typename etl::nth_type_t<0, TPairs...>::second_type, sizeof...(TPairs)>; #endif + + + //************************************************************************* + /// Equality test. + //************************************************************************* + template + ETL_CONSTEXPR14 bool operator ==(const etl::const_map& lhs, + const etl::const_map& rhs) + { + return etl::equal(lhs.begin(), lhs.end(), rhs.begin()); + } + + //************************************************************************* + /// Inequality test. + //************************************************************************* + template + ETL_CONSTEXPR14 bool operator !=(const etl::const_map& lhs, + const etl::const_map& rhs) + { + return !(lhs == rhs); + } } #endif diff --git a/test/test_const_map.cpp b/test/test_const_map.cpp index 609f8588..d10a1c3e 100644 --- a/test/test_const_map.cpp +++ b/test/test_const_map.cpp @@ -67,39 +67,51 @@ namespace }; // Less-than operator for Key < Key - constexpr bool operator <(const Key& lhs, const Key& rhs) ETL_NOEXCEPT + constexpr bool operator <(const Key& lhs, const Key& rhs) noexcept { return (lhs.k < rhs.k); } // Less-than operator for Key < char - constexpr bool operator <(const Key& lhs, char rhs) ETL_NOEXCEPT + constexpr bool operator <(const Key& lhs, char rhs) noexcept { return (lhs.k < rhs); } // Less-than operator for char < Key - constexpr bool operator <(char lhs, const Key& rhs) ETL_NOEXCEPT + constexpr bool operator <(char lhs, const Key& rhs) noexcept { return (lhs < rhs.k); } - // Greater-than operator for Key > char - constexpr bool operator >(const Key& lhs, const Key& rhs) ETL_NOEXCEPT + // Greater-than operator for Key < Key + constexpr bool operator >(const Key& lhs, const Key& rhs) noexcept { return (lhs.k > rhs.k); } + // Greater-than operator for Key > char + constexpr bool operator >(const Key& lhs, char rhs) noexcept + { + return (lhs.k > rhs); + } + // Greater-than operator for char > Key - constexpr bool operator ==(const Key& lhs, const Key& rhs) ETL_NOEXCEPT + constexpr bool operator >(char lhs, const Key& rhs) noexcept + { + return (lhs > rhs.k); + } + + // Greater-than operator for char > Key + constexpr bool operator ==(const Key& lhs, const Key& rhs) noexcept { return (lhs.k == rhs.k); } //#define TEST_GREATER_THAN #ifdef TEST_GREATER_THAN - using Data = etl::const_map>; - using DataTransparentComparator = etl::const_map>; + using Data = etl::const_map>; + using DataTransparentComparator = etl::const_map>; #else using Data = etl::const_map>; using DataTransparentComparator = etl::const_map>; @@ -113,26 +125,6 @@ namespace SUITE(test_const_map) { //************************************************************************* -#include "etl/private/diagnostic_null_dereference_push.h" - template - bool Check_Equal(T1 begin1, T1 end1, T2 begin2) - { - while (begin1 != end1) - { - if ((begin1->first != begin2->first) || (begin1->second != begin2->second)) - { - return false; - } - - ++begin1; - ++begin2; - } - - return true; - } -#include "etl/private/diagnostic_pop.h" - - //************************************************************************* TEST(test_default_constructor) { static constexpr Data data; @@ -189,13 +181,22 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - CHECK_TRUE(data.is_valid()); - CHECK_TRUE(data.size() == Max_Size); - CHECK_FALSE(data.empty()); - CHECK_TRUE(data.full()); - CHECK_TRUE(data.capacity() == Max_Size); - CHECK_TRUE(data.max_size() == Max_Size); - CHECK_FALSE(data.begin() == data.end()); + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr Data::const_iterator begin = data.begin(); + static constexpr Data::const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == Max_Size); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_FALSE(begin == end); } ////************************************************************************* @@ -259,7 +260,7 @@ namespace } //************************************************************************* - TEST(test_end) + TEST(test_begin_constexpr) { #ifdef TEST_GREATER_THAN static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, @@ -270,9 +271,35 @@ namespace #endif CHECK_TRUE(data.is_valid()); + static constexpr auto value = *data.begin(); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE((value_type{ Key('J'), 9 }) == value); +#else + CHECK_TRUE((value_type{ Key('A'), 0 }) == value); +#endif + } + + //************************************************************************* + TEST(test_end) + { + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + CHECK_TRUE(data.end() == (data.begin() + data.size())); } + //************************************************************************* + TEST(test_end_constexpr) + { + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data::const_iterator end_itr = data.end(); + + CHECK_TRUE(end_itr == (data.begin() + data.size())); + } + //************************************************************************* TEST(test_index) { @@ -298,7 +325,42 @@ namespace } //************************************************************************* - TEST(test_index__using_transparent_comparator) + TEST(test_index_constexpr) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data::mapped_type atA = data[Key('A')]; + static constexpr Data::mapped_type atB = data[Key('B')]; + static constexpr Data::mapped_type atC = data[Key('C')]; + static constexpr Data::mapped_type atD = data[Key('D')]; + static constexpr Data::mapped_type atE = data[Key('E')]; + static constexpr Data::mapped_type atF = data[Key('F')]; + static constexpr Data::mapped_type atG = data[Key('G')]; + static constexpr Data::mapped_type atH = data[Key('H')]; + static constexpr Data::mapped_type atI = data[Key('I')]; + static constexpr Data::mapped_type atJ = data[Key('J')]; + + CHECK_TRUE(data.is_valid()); + CHECK(atA == 0); + CHECK(atB == 1); + CHECK(atC == 2); + CHECK(atD == 3); + CHECK(atE == 4); + CHECK(atF == 5); + CHECK(atG == 6); + CHECK(atH == 7); + CHECK(atI == 8); + CHECK(atJ == 9); + } + + //************************************************************************* + TEST(test_index_using_transparent_comparator) { #ifdef TEST_GREATER_THAN static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, @@ -321,6 +383,41 @@ namespace CHECK(data['J'] == 9); } + //************************************************************************* + TEST(test_index_constexpr_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data::mapped_type atA = data['A']; + static constexpr Data::mapped_type atB = data['B']; + static constexpr Data::mapped_type atC = data['C']; + static constexpr Data::mapped_type atD = data['D']; + static constexpr Data::mapped_type atE = data['E']; + static constexpr Data::mapped_type atF = data['F']; + static constexpr Data::mapped_type atG = data['G']; + static constexpr Data::mapped_type atH = data['H']; + static constexpr Data::mapped_type atI = data['I']; + static constexpr Data::mapped_type atJ = data['J']; + + CHECK_TRUE(data.is_valid()); + CHECK(atA == 0); + CHECK(atB == 1); + CHECK(atC == 2); + CHECK(atD == 3); + CHECK(atE == 4); + CHECK(atF == 5); + CHECK(atG == 6); + CHECK(atH == 7); + CHECK(atI == 8); + CHECK(atJ == 9); + } + //************************************************************************* TEST(test_at) { @@ -345,6 +442,41 @@ namespace CHECK(data.at(Key('J')) == 9); } + //************************************************************************* + TEST(test_at_constexpr) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data::mapped_type atA = data.at(Key('A')); + static constexpr Data::mapped_type atB = data.at(Key('B')); + static constexpr Data::mapped_type atC = data.at(Key('C')); + static constexpr Data::mapped_type atD = data.at(Key('D')); + static constexpr Data::mapped_type atE = data.at(Key('E')); + static constexpr Data::mapped_type atF = data.at(Key('F')); + static constexpr Data::mapped_type atG = data.at(Key('G')); + static constexpr Data::mapped_type atH = data.at(Key('H')); + static constexpr Data::mapped_type atI = data.at(Key('I')); + static constexpr Data::mapped_type atJ = data.at(Key('J')); + + CHECK_TRUE(data.is_valid()); + CHECK(atA == 0); + CHECK(atB == 1); + CHECK(atC == 2); + CHECK(atD == 3); + CHECK(atE == 4); + CHECK(atF == 5); + CHECK(atG == 6); + CHECK(atH == 7); + CHECK(atI == 8); + CHECK(atJ == 9); + } + //************************************************************************* TEST(test_at_using_transparent_comparator) { @@ -369,278 +501,870 @@ namespace CHECK(data.at('J') == 9); } -// //************************************************************************* -// TEST(test_equal_range) -// { -// Compare_Data compare_data(random_data.begin(), random_data.end()); -// Data data(random_data.begin(), random_data.end()); -// -// ETL_OR_STD::pair data_result = data.equal_range('2'); -// Data::iterator data_lb = data.lower_bound('2'); -// ETL_OR_STD::pair compare_result = compare_data.equal_range('2'); -// Compare_Data::iterator compare_data_lb = compare_data.lower_bound('2'); -// -// // Check that both return the same return results -// CHECK(data_lb->first == compare_data_lb->first); -// CHECK(data_lb->second == compare_data_lb->second); -// CHECK(data_result.first->first == compare_result.first->first); -// CHECK(data_result.first->second == compare_result.first->second); -// CHECK(data_result.second->first == compare_result.second->first); -// CHECK(data_result.second->second == compare_result.second->second); -// -// bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin()); -// -// CHECK(isEqual); -// } + //************************************************************************* + TEST(test_at_constexpr_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif -// //************************************************************************* -// TEST(test_equal_range_using_transparent_comparator) -// { -// using CMap = std::map>; -// using EMap = etl::map>; -// -// CMap compare_data(random_data.begin(), random_data.end()); -// EMap data(random_data.begin(), random_data.end()); -// -// ETL_OR_STD::pair data_result = data.equal_range(Key('2')); -// EMap::iterator data_lb = data.lower_bound('2'); -// ETL_OR_STD::pair compare_result = compare_data.equal_range('2'); -// CMap::iterator compare_data_lb = compare_data.lower_bound('2'); -// -// // Check that both return the same return results -// CHECK(data_lb->first == compare_data_lb->first); -// CHECK(data_lb->second == compare_data_lb->second); -// CHECK(data_result.first->first == compare_result.first->first); -// CHECK(data_result.first->second == compare_result.first->second); -// CHECK(data_result.second->first == compare_result.second->first); -// CHECK(data_result.second->second == compare_result.second->second); -// -// bool isEqual = Check_Equal(data.begin(), data.end(), compare_data.begin()); -// -// CHECK(isEqual); -// } + static constexpr Data::mapped_type atA = data.at('A'); + static constexpr Data::mapped_type atB = data.at('B'); + static constexpr Data::mapped_type atC = data.at('C'); + static constexpr Data::mapped_type atD = data.at('D'); + static constexpr Data::mapped_type atE = data.at('E'); + static constexpr Data::mapped_type atF = data.at('F'); + static constexpr Data::mapped_type atG = data.at('G'); + static constexpr Data::mapped_type atH = data.at('H'); + static constexpr Data::mapped_type atI = data.at('I'); + static constexpr Data::mapped_type atJ = data.at('J'); -// //************************************************************************* -// TEST(test_count) -// { -// const Data data(initial_data.begin(), initial_data.end()); -// -// CHECK(data.count('3') == 1UL); -// -// CHECK(data.count(Key('A') == 0UL); -// } + CHECK_TRUE(data.is_valid()); + CHECK(atA == 0); + CHECK(atB == 1); + CHECK(atC == 2); + CHECK(atD == 3); + CHECK(atE == 4); + CHECK(atF == 5); + CHECK(atG == 6); + CHECK(atH == 7); + CHECK(atI == 8); + CHECK(atJ == 9); + } -// //************************************************************************* -// TEST(test_count_using_transparent_comparator) -// { -// using EMap = etl::map>; -// -// const EMap data(initial_data.begin(), initial_data.end()); -// -// CHECK(data.count(Key('3')) == 1UL); -// -// CHECK(data.count(Key(Key('A')) == 0UL); -// } + //************************************************************************* + TEST(test_equal_range) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif -// //************************************************************************* -// TEST(test_iterator) -// { -// Compare_Data compare_data(initial_data.begin(), initial_data.end()); -// -// Data data(compare_data.begin(), compare_data.end()); -// -// bool isEqual = Check_Equal(data.begin(), -// data.end(), -// compare_data.begin()); -// -// CHECK(isEqual); -// } + ETL_OR_STD::pair result0 = data.equal_range(Key('A')); + ETL_OR_STD::pair result1 = data.equal_range(Key('B')); + ETL_OR_STD::pair result2 = data.equal_range(Key('C')); + ETL_OR_STD::pair result3 = data.equal_range(Key('D')); + ETL_OR_STD::pair result4 = data.equal_range(Key('E')); + ETL_OR_STD::pair result5 = data.equal_range(Key('F')); + ETL_OR_STD::pair result6 = data.equal_range(Key('G')); + ETL_OR_STD::pair result7 = data.equal_range(Key('H')); + ETL_OR_STD::pair result8 = data.equal_range(Key('I')); + ETL_OR_STD::pair result9 = data.equal_range(Key('J')); -// //************************************************************************* -// TEST(test_const_iterator) -// { -// Compare_Data compare_data(initial_data.begin(), initial_data.end()); -// -// Data data(compare_data.begin(), compare_data.end()); -// -// bool isEqual = Check_Equal(data.cbegin(), -// data.cend(), -// compare_data.cbegin()); -// -// CHECK(isEqual); -// } +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), result0.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), result1.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), result2.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), result3.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), result4.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), result5.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), result6.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), result7.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), result8.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), result9.first))); -// //************************************************************************* -// TEST(test_find) -// { -// Data data(initial_data.begin(), initial_data.end()); -// -// Data::iterator it = data.find('3'); -// CHECK(3 == it->second); -// -// it = data.find(Key('A'); -// CHECK(data.end() == it); -// -// it = data.find('!'); -// CHECK(data.end() == it); -// } + CHECK_EQUAL(10, (std::distance(data.begin(), result0.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), result1.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), result2.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), result3.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), result4.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), result5.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), result6.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), result7.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), result8.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), result9.second))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), result0.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), result1.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), result2.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), result3.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), result4.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), result5.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), result6.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), result7.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), result8.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), result9.first))); -// //************************************************************************* -// TEST(test_find_using_transparent_comparator) -// { -// using EMap = etl::map>; -// -// EMap data(initial_data.begin(), initial_data.end()); -// -// EMap::iterator it = data.find(Key('3')); -// CHECK(3 == it->second); -// -// it = data.find(Key(Key('A')); -// CHECK(data.end() == it); -// -// it = data.find(Key('!')); -// CHECK(data.end() == it); -// } + CHECK_EQUAL(1, (std::distance(data.begin(), result0.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), result1.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), result2.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), result3.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), result4.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), result5.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), result6.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), result7.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), result8.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), result9.second))); +#endif + } -// //************************************************************************* -// TEST(test_equal) -// { -// const Data initial1(initial_data.begin(), initial_data.end()); -// const Data initial2(initial_data.begin(), initial_data.end()); -// -// CHECK(initial1 == initial2); -// -// const Data different(different_data.begin(), different_data.end()); -// -// CHECK(!(initial1 == different)); -// } + //************************************************************************* + TEST(test_equal_range_constexpr) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif -// //************************************************************************* -// TEST(test_not_equal) -// { -// const Data initial1(initial_data.begin(), initial_data.end()); -// const Data initial2(initial_data.begin(), initial_data.end()); -// -// CHECK(!(initial1 != initial2)); -// -// const Data different(different_data.begin(), different_data.end()); -// -// CHECK(initial1 != different); -// } + static constexpr ETL_OR_STD::pair result0 = data.equal_range(Key('A')); + static constexpr ETL_OR_STD::pair result1 = data.equal_range(Key('B')); + static constexpr ETL_OR_STD::pair result2 = data.equal_range(Key('C')); + static constexpr ETL_OR_STD::pair result3 = data.equal_range(Key('D')); + static constexpr ETL_OR_STD::pair result4 = data.equal_range(Key('E')); + static constexpr ETL_OR_STD::pair result5 = data.equal_range(Key('F')); + static constexpr ETL_OR_STD::pair result6 = data.equal_range(Key('G')); + static constexpr ETL_OR_STD::pair result7 = data.equal_range(Key('H')); + static constexpr ETL_OR_STD::pair result8 = data.equal_range(Key('I')); + static constexpr ETL_OR_STD::pair result9 = data.equal_range(Key('J')); -// //************************************************************************* -// TEST(test_lower_bound) -// { -// Compare_Data compare_data(initial_data.begin(), initial_data.end()); -// Data data(initial_data.begin(), initial_data.end()); -// -// Compare_Data::iterator i_compare = compare_data.lower_bound('8'); -// Data::iterator i_data = data.lower_bound('8'); -// CHECK(i_compare->second == i_data->second); -// -//#ifdef TEST_GREATER_THAN -// i_compare = compare_data.lower_bound('.'); -// CHECK(compare_data.end() == i_compare); -// -// i_data = data.lower_bound('.'); -// CHECK(data.end() == i_data); -// -// i_compare = compare_data.lower_bound(Key('A'); -// i_data = data.lower_bound(Key('A'); -// CHECK(i_compare->second == i_data->second); -//#else -// i_compare = compare_data.lower_bound('.'); -// i_data = data.lower_bound('.'); -// CHECK(i_compare->second == i_data->second); -// -// i_compare = compare_data.lower_bound(Key('A'); -// CHECK(compare_data.end() == i_compare); -// -// i_data = data.lower_bound(Key('A'); -// CHECK(data.end() == i_data); -//#endif -// } +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), result0.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), result1.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), result2.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), result3.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), result4.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), result5.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), result6.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), result7.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), result8.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), result9.first))); -// //************************************************************************* -// TEST(test_lower_bound_using_transparent_comparator) -// { -// using CMap = std::map>; -// using EMap = etl::map>; -// -// CMap compare_data(initial_data.begin(), initial_data.end()); -// EMap data(initial_data.begin(), initial_data.end()); -// -// CMap::iterator i_compare = compare_data.lower_bound('8'); -// EMap::iterator i_data = data.lower_bound(Key('8')); -// CHECK(i_compare->second == i_data->second); -// -// i_compare = compare_data.lower_bound('.'); -// i_data = data.lower_bound(Key('.')); -// CHECK(i_compare->second == i_data->second); -// -// i_compare = compare_data.lower_bound(Key('A'); -// CHECK(compare_data.end() == i_compare); -// -// i_data = data.lower_bound(Key(Key('A')); -// CHECK(data.end() == i_data); -// } + CHECK_EQUAL(10, (std::distance(data.begin(), result0.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), result1.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), result2.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), result3.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), result4.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), result5.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), result6.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), result7.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), result8.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), result9.second))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), result0.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), result1.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), result2.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), result3.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), result4.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), result5.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), result6.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), result7.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), result8.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), result9.first))); -// //************************************************************************* -// TEST(test_upper_bound) -// { -// Compare_Data compare_data(initial_data.begin(), initial_data.end()); -// Data data(initial_data.begin(), initial_data.end()); -// -// Compare_Data::iterator i_compare = compare_data.upper_bound('2'); -// Data::iterator i_data = data.upper_bound('2'); -// CHECK(i_compare->second == i_data->second); -// -//#ifdef TEST_GREATER_THAN -// i_compare = compare_data.upper_bound('.'); -// CHECK(compare_data.end() == i_compare); -// -// i_data = data.upper_bound('.'); -// CHECK(data.end() == i_data); -// -// i_compare = compare_data.upper_bound(Key('A'); -// i_data = data.upper_bound(Key('A'); -// CHECK(i_compare->second == i_data->second); -//#else -// i_compare = compare_data.upper_bound('.'); -// i_data = data.upper_bound('.'); -// CHECK(i_compare->second == i_data->second); -// -// i_compare = compare_data.upper_bound(Key('A'); -// CHECK(compare_data.end() == i_compare); -// -// i_data = data.upper_bound(Key('A'); -// CHECK(data.end() == i_data); -//#endif -// } + CHECK_EQUAL(1, (std::distance(data.begin(), result0.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), result1.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), result2.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), result3.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), result4.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), result5.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), result6.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), result7.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), result8.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), result9.second))); +#endif + } -// //************************************************************************* -// TEST(test_upper_bound_using_transparent_comparator) -// { -// using CMap = std::map>; -// using EMap = etl::map>; -// -// CMap compare_data(initial_data.begin(), initial_data.end()); -// EMap data(initial_data.begin(), initial_data.end()); -// -// CMap::iterator i_compare = compare_data.upper_bound('2'); -// EMap::iterator i_data = data.upper_bound(Key('2')); -// CHECK(i_compare->second == i_data->second); -// -// i_compare = compare_data.upper_bound('.'); -// i_data = data.upper_bound(Key('.')); -// CHECK(i_compare->second == i_data->second); -// -// i_compare = compare_data.upper_bound(Key('A'); -// CHECK(compare_data.end() == i_compare); -// -// i_data = data.upper_bound(Key(Key('A')); -// CHECK(data.end() == i_data); -// } + //************************************************************************* + TEST(test_equal_range_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + ETL_OR_STD::pair result0 = data.equal_range('A'); + ETL_OR_STD::pair result1 = data.equal_range('B'); + ETL_OR_STD::pair result2 = data.equal_range('C'); + ETL_OR_STD::pair result3 = data.equal_range('D'); + ETL_OR_STD::pair result4 = data.equal_range('E'); + ETL_OR_STD::pair result5 = data.equal_range('F'); + ETL_OR_STD::pair result6 = data.equal_range('G'); + ETL_OR_STD::pair result7 = data.equal_range('H'); + ETL_OR_STD::pair result8 = data.equal_range('I'); + ETL_OR_STD::pair result9 = data.equal_range('J'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), result0.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), result1.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), result2.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), result3.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), result4.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), result5.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), result6.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), result7.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), result8.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), result9.first))); + + CHECK_EQUAL(10, (std::distance(data.begin(), result0.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), result1.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), result2.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), result3.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), result4.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), result5.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), result6.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), result7.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), result8.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), result9.second))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), result0.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), result1.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), result2.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), result3.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), result4.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), result5.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), result6.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), result7.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), result8.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), result9.first))); + + CHECK_EQUAL(1, (std::distance(data.begin(), result0.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), result1.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), result2.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), result3.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), result4.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), result5.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), result6.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), result7.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), result8.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), result9.second))); +#endif + } + + //************************************************************************* + TEST(test_equal_range_constexpr_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr ETL_OR_STD::pair result0 = data.equal_range('A'); + static constexpr ETL_OR_STD::pair result1 = data.equal_range('B'); + static constexpr ETL_OR_STD::pair result2 = data.equal_range('C'); + static constexpr ETL_OR_STD::pair result3 = data.equal_range('D'); + static constexpr ETL_OR_STD::pair result4 = data.equal_range('E'); + static constexpr ETL_OR_STD::pair result5 = data.equal_range('F'); + static constexpr ETL_OR_STD::pair result6 = data.equal_range('G'); + static constexpr ETL_OR_STD::pair result7 = data.equal_range('H'); + static constexpr ETL_OR_STD::pair result8 = data.equal_range('I'); + static constexpr ETL_OR_STD::pair result9 = data.equal_range('J'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), result0.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), result1.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), result2.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), result3.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), result4.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), result5.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), result6.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), result7.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), result8.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), result9.first))); + + CHECK_EQUAL(10, (std::distance(data.begin(), result0.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), result1.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), result2.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), result3.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), result4.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), result5.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), result6.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), result7.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), result8.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), result9.second))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), result0.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), result1.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), result2.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), result3.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), result4.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), result5.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), result6.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), result7.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), result8.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), result9.first))); + + CHECK_EQUAL(1, (std::distance(data.begin(), result0.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), result1.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), result2.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), result3.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), result4.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), result5.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), result6.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), result7.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), result8.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), result9.second))); +#endif + } + + //************************************************************************* + TEST(test_lower_bound) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; +#endif + + Data::const_iterator result0 = data.lower_bound(Key('A')); + Data::const_iterator result1 = data.lower_bound(Key('B')); + Data::const_iterator result2 = data.lower_bound(Key('C')); + Data::const_iterator result3 = data.lower_bound(Key('D')); + Data::const_iterator result4 = data.lower_bound(Key('E')); + Data::const_iterator result5 = data.lower_bound(Key('F')); + Data::const_iterator result6 = data.lower_bound(Key('G')); + Data::const_iterator result7 = data.lower_bound(Key('H')); + Data::const_iterator result8 = data.lower_bound(Key('I')); + Data::const_iterator result9 = data.lower_bound(Key('J')); + Data::const_iterator result10 = data.lower_bound(Key('K')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(10, (std::distance(data.begin(), result0))); + CHECK_EQUAL(9, (std::distance(data.begin(), result1))); + CHECK_EQUAL(8, (std::distance(data.begin(), result2))); + CHECK_EQUAL(7, (std::distance(data.begin(), result3))); + CHECK_EQUAL(6, (std::distance(data.begin(), result4))); + CHECK_EQUAL(5, (std::distance(data.begin(), result5))); + CHECK_EQUAL(4, (std::distance(data.begin(), result6))); + CHECK_EQUAL(3, (std::distance(data.begin(), result7))); + CHECK_EQUAL(2, (std::distance(data.begin(), result8))); + CHECK_EQUAL(1, (std::distance(data.begin(), result9))); + CHECK_EQUAL(0, (std::distance(data.begin(), result10))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), result0))); + CHECK_EQUAL(1, (std::distance(data.begin(), result1))); + CHECK_EQUAL(2, (std::distance(data.begin(), result2))); + CHECK_EQUAL(3, (std::distance(data.begin(), result3))); + CHECK_EQUAL(3, (std::distance(data.begin(), result4))); + CHECK_EQUAL(4, (std::distance(data.begin(), result5))); + CHECK_EQUAL(5, (std::distance(data.begin(), result6))); + CHECK_EQUAL(6, (std::distance(data.begin(), result7))); + CHECK_EQUAL(7, (std::distance(data.begin(), result8))); + CHECK_EQUAL(8, (std::distance(data.begin(), result9))); + CHECK_EQUAL(9, (std::distance(data.begin(), result10))); +#endif + } + + //************************************************************************* + TEST(test_lower_bound_constexpr) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; +#endif + + static constexpr Data::const_iterator result0 = data.lower_bound(Key('A')); + static constexpr Data::const_iterator result1 = data.lower_bound(Key('B')); + static constexpr Data::const_iterator result2 = data.lower_bound(Key('C')); + static constexpr Data::const_iterator result3 = data.lower_bound(Key('D')); + static constexpr Data::const_iterator result4 = data.lower_bound(Key('E')); + static constexpr Data::const_iterator result5 = data.lower_bound(Key('F')); + static constexpr Data::const_iterator result6 = data.lower_bound(Key('G')); + static constexpr Data::const_iterator result7 = data.lower_bound(Key('H')); + static constexpr Data::const_iterator result8 = data.lower_bound(Key('I')); + static constexpr Data::const_iterator result9 = data.lower_bound(Key('J')); + static constexpr Data::const_iterator result10 = data.lower_bound(Key('K')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(10, (std::distance(data.begin(), result0))); + CHECK_EQUAL(9, (std::distance(data.begin(), result1))); + CHECK_EQUAL(8, (std::distance(data.begin(), result2))); + CHECK_EQUAL(7, (std::distance(data.begin(), result3))); + CHECK_EQUAL(6, (std::distance(data.begin(), result4))); + CHECK_EQUAL(5, (std::distance(data.begin(), result5))); + CHECK_EQUAL(4, (std::distance(data.begin(), result6))); + CHECK_EQUAL(3, (std::distance(data.begin(), result7))); + CHECK_EQUAL(2, (std::distance(data.begin(), result8))); + CHECK_EQUAL(1, (std::distance(data.begin(), result9))); + CHECK_EQUAL(0, (std::distance(data.begin(), result10))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), result0))); + CHECK_EQUAL(1, (std::distance(data.begin(), result1))); + CHECK_EQUAL(2, (std::distance(data.begin(), result2))); + CHECK_EQUAL(3, (std::distance(data.begin(), result3))); + CHECK_EQUAL(3, (std::distance(data.begin(), result4))); + CHECK_EQUAL(4, (std::distance(data.begin(), result5))); + CHECK_EQUAL(5, (std::distance(data.begin(), result6))); + CHECK_EQUAL(6, (std::distance(data.begin(), result7))); + CHECK_EQUAL(7, (std::distance(data.begin(), result8))); + CHECK_EQUAL(8, (std::distance(data.begin(), result9))); + CHECK_EQUAL(9, (std::distance(data.begin(), result10))); +#endif + } + + //************************************************************************* + TEST(test_lower_bound_using_transparent_comparator) + { + + } + + //************************************************************************* + TEST(test_lower_bound_constexpr_using_transparent_comparator) + { + + } + + //************************************************************************* + TEST(test_upper_bound) + { + } + + //************************************************************************* + TEST(test_upper_bound_constexpr) + { + } + + //************************************************************************* + TEST(test_upper_bound_using_transparent_comparator) + { + } + + //************************************************************************* + TEST(test_upper_bound_constexpr_using_transparent_comparator) + { + } + + //************************************************************************* + TEST(test_count) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + CHECK_EQUAL(1, data.count(Key('A'))); + CHECK_EQUAL(1, data.count(Key('B'))); + CHECK_EQUAL(1, data.count(Key('C'))); + CHECK_EQUAL(1, data.count(Key('D'))); + CHECK_EQUAL(1, data.count(Key('E'))); + CHECK_EQUAL(1, data.count(Key('F'))); + CHECK_EQUAL(1, data.count(Key('G'))); + CHECK_EQUAL(1, data.count(Key('H'))); + CHECK_EQUAL(1, data.count(Key('I'))); + CHECK_EQUAL(1, data.count(Key('J'))); + CHECK_EQUAL(0, data.count(Key('K'))); + } + + //************************************************************************* + TEST(test_count_constexpr) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr size_t countA = data.count(Key('A')); + static constexpr size_t countB = data.count(Key('B')); + static constexpr size_t countC = data.count(Key('C')); + static constexpr size_t countD = data.count(Key('D')); + static constexpr size_t countE = data.count(Key('E')); + static constexpr size_t countF = data.count(Key('F')); + static constexpr size_t countG = data.count(Key('G')); + static constexpr size_t countH = data.count(Key('H')); + static constexpr size_t countI = data.count(Key('I')); + static constexpr size_t countJ = data.count(Key('J')); + static constexpr size_t countK = data.count(Key('K')); + + CHECK_EQUAL(1, countA); + CHECK_EQUAL(1, countB); + CHECK_EQUAL(1, countC); + CHECK_EQUAL(1, countD); + CHECK_EQUAL(1, countE); + CHECK_EQUAL(1, countF); + CHECK_EQUAL(1, countG); + CHECK_EQUAL(1, countH); + CHECK_EQUAL(1, countI); + CHECK_EQUAL(1, countJ); + CHECK_EQUAL(0, countK); + } + + //************************************************************************* + TEST(test_count_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + CHECK_EQUAL(1, data.count('A')); + CHECK_EQUAL(1, data.count('B')); + CHECK_EQUAL(1, data.count('C')); + CHECK_EQUAL(1, data.count('D')); + CHECK_EQUAL(1, data.count('E')); + CHECK_EQUAL(1, data.count('F')); + CHECK_EQUAL(1, data.count('G')); + CHECK_EQUAL(1, data.count('H')); + CHECK_EQUAL(1, data.count('I')); + CHECK_EQUAL(1, data.count('J')); + CHECK_EQUAL(0, data.count('K')); + } + + //************************************************************************* + TEST(test_count_constexpr_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr size_t countA = data.count('A'); + static constexpr size_t countB = data.count('B'); + static constexpr size_t countC = data.count('C'); + static constexpr size_t countD = data.count('D'); + static constexpr size_t countE = data.count('E'); + static constexpr size_t countF = data.count('F'); + static constexpr size_t countG = data.count('G'); + static constexpr size_t countH = data.count('H'); + static constexpr size_t countI = data.count('I'); + static constexpr size_t countJ = data.count('J'); + static constexpr size_t countK = data.count('K'); + + CHECK_EQUAL(1, countA); + CHECK_EQUAL(1, countB); + CHECK_EQUAL(1, countC); + CHECK_EQUAL(1, countD); + CHECK_EQUAL(1, countE); + CHECK_EQUAL(1, countF); + CHECK_EQUAL(1, countG); + CHECK_EQUAL(1, countH); + CHECK_EQUAL(1, countI); + CHECK_EQUAL(1, countJ); + CHECK_EQUAL(0, countK); + } + + //************************************************************************* + TEST(test_iterator) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + Data::iterator itr = data.begin(); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); + CHECK_TRUE((value_type{Key('I'), 8 }) == *itr++); + CHECK_TRUE((value_type{Key('H'), 7 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 6 }) == *itr++); + CHECK_TRUE((value_type{Key('F'), 5 }) == *itr++); + CHECK_TRUE((value_type{Key('E'), 4 }) == *itr++); + CHECK_TRUE((value_type{Key('D'), 3 }) == *itr++); + CHECK_TRUE((value_type{Key('C'), 2 }) == *itr++); + CHECK_TRUE((value_type{Key('B'), 1 }) == *itr++); + CHECK_TRUE((value_type{Key('A'), 0 }) == *itr++); + CHECK_TRUE(itr == data.end()); +#else + CHECK_TRUE((value_type{Key('A'), 0 }) == *itr++); + CHECK_TRUE((value_type{Key('B'), 1 }) == *itr++); + CHECK_TRUE((value_type{Key('C'), 2 }) == *itr++); + CHECK_TRUE((value_type{Key('D'), 3 }) == *itr++); + CHECK_TRUE((value_type{Key('E'), 4 }) == *itr++); + CHECK_TRUE((value_type{Key('F'), 5 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 6 }) == *itr++); + CHECK_TRUE((value_type{Key('H'), 7 }) == *itr++); + CHECK_TRUE((value_type{Key('I'), 8 }) == *itr++); + CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); + CHECK_TRUE(itr == data.end()); +#endif + } + + //************************************************************************* + TEST(test_const_iterator) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + Data::const_iterator itr = data.begin(); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); + CHECK_TRUE((value_type{Key('I'), 8 }) == *itr++); + CHECK_TRUE((value_type{Key('H'), 7 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 6 }) == *itr++); + CHECK_TRUE((value_type{Key('F'), 5 }) == *itr++); + CHECK_TRUE((value_type{Key('E'), 4 }) == *itr++); + CHECK_TRUE((value_type{Key('D'), 3 }) == *itr++); + CHECK_TRUE((value_type{Key('C'), 2 }) == *itr++); + CHECK_TRUE((value_type{Key('B'), 1 }) == *itr++); + CHECK_TRUE((value_type{Key('A'), 0 }) == *itr++); + CHECK_TRUE(itr == data.end()); +#else + CHECK_TRUE((value_type{Key('A'), 0 }) == *itr++); + CHECK_TRUE((value_type{Key('B'), 1 }) == *itr++); + CHECK_TRUE((value_type{Key('C'), 2 }) == *itr++); + CHECK_TRUE((value_type{Key('D'), 3 }) == *itr++); + CHECK_TRUE((value_type{Key('E'), 4 }) == *itr++); + CHECK_TRUE((value_type{Key('F'), 5 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 6 }) == *itr++); + CHECK_TRUE((value_type{Key('H'), 7 }) == *itr++); + CHECK_TRUE((value_type{Key('I'), 8 }) == *itr++); + CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); + CHECK_TRUE(itr == data.end()); +#endif + } + + //************************************************************************* + TEST(test_find) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + Data::const_iterator result0 = data.find(Key('A')); + Data::const_iterator result1 = data.find(Key('B')); + Data::const_iterator result2 = data.find(Key('C')); + Data::const_iterator result3 = data.find(Key('D')); + Data::const_iterator result4 = data.find(Key('E')); + Data::const_iterator result5 = data.find(Key('F')); + Data::const_iterator result6 = data.find(Key('G')); + Data::const_iterator result7 = data.find(Key('H')); + Data::const_iterator result8 = data.find(Key('I')); + Data::const_iterator result9 = data.find(Key('J')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), result0))); + CHECK_EQUAL(8, (std::distance(data.begin(), result1))); + CHECK_EQUAL(7, (std::distance(data.begin(), result2))); + CHECK_EQUAL(6, (std::distance(data.begin(), result3))); + CHECK_EQUAL(5, (std::distance(data.begin(), result4))); + CHECK_EQUAL(4, (std::distance(data.begin(), result5))); + CHECK_EQUAL(3, (std::distance(data.begin(), result6))); + CHECK_EQUAL(2, (std::distance(data.begin(), result7))); + CHECK_EQUAL(1, (std::distance(data.begin(), result8))); + CHECK_EQUAL(0, (std::distance(data.begin(), result9))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), result0))); + CHECK_EQUAL(1, (std::distance(data.begin(), result1))); + CHECK_EQUAL(2, (std::distance(data.begin(), result2))); + CHECK_EQUAL(3, (std::distance(data.begin(), result3))); + CHECK_EQUAL(4, (std::distance(data.begin(), result4))); + CHECK_EQUAL(5, (std::distance(data.begin(), result5))); + CHECK_EQUAL(6, (std::distance(data.begin(), result6))); + CHECK_EQUAL(7, (std::distance(data.begin(), result7))); + CHECK_EQUAL(8, (std::distance(data.begin(), result8))); + CHECK_EQUAL(9, (std::distance(data.begin(), result9))); +#endif + } + + //************************************************************************* + TEST(test_find_constexpr) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data::const_iterator result0 = data.find(Key('A')); + static constexpr Data::const_iterator result1 = data.find(Key('B')); + static constexpr Data::const_iterator result2 = data.find(Key('C')); + static constexpr Data::const_iterator result3 = data.find(Key('D')); + static constexpr Data::const_iterator result4 = data.find(Key('E')); + static constexpr Data::const_iterator result5 = data.find(Key('F')); + static constexpr Data::const_iterator result6 = data.find(Key('G')); + static constexpr Data::const_iterator result7 = data.find(Key('H')); + static constexpr Data::const_iterator result8 = data.find(Key('I')); + static constexpr Data::const_iterator result9 = data.find(Key('J')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), result0))); + CHECK_EQUAL(8, (std::distance(data.begin(), result1))); + CHECK_EQUAL(7, (std::distance(data.begin(), result2))); + CHECK_EQUAL(6, (std::distance(data.begin(), result3))); + CHECK_EQUAL(5, (std::distance(data.begin(), result4))); + CHECK_EQUAL(4, (std::distance(data.begin(), result5))); + CHECK_EQUAL(3, (std::distance(data.begin(), result6))); + CHECK_EQUAL(2, (std::distance(data.begin(), result7))); + CHECK_EQUAL(1, (std::distance(data.begin(), result8))); + CHECK_EQUAL(0, (std::distance(data.begin(), result9))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), result0))); + CHECK_EQUAL(1, (std::distance(data.begin(), result1))); + CHECK_EQUAL(2, (std::distance(data.begin(), result2))); + CHECK_EQUAL(3, (std::distance(data.begin(), result3))); + CHECK_EQUAL(4, (std::distance(data.begin(), result4))); + CHECK_EQUAL(5, (std::distance(data.begin(), result5))); + CHECK_EQUAL(6, (std::distance(data.begin(), result6))); + CHECK_EQUAL(7, (std::distance(data.begin(), result7))); + CHECK_EQUAL(8, (std::distance(data.begin(), result8))); + CHECK_EQUAL(9, (std::distance(data.begin(), result9))); +#endif + } + + //************************************************************************* + TEST(test_find_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + Data::const_iterator result0 = data.find('A'); + Data::const_iterator result1 = data.find('B'); + Data::const_iterator result2 = data.find('C'); + Data::const_iterator result3 = data.find('D'); + Data::const_iterator result4 = data.find('E'); + Data::const_iterator result5 = data.find('F'); + Data::const_iterator result6 = data.find('G'); + Data::const_iterator result7 = data.find('H'); + Data::const_iterator result8 = data.find('I'); + Data::const_iterator result9 = data.find('J'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), result0))); + CHECK_EQUAL(8, (std::distance(data.begin(), result1))); + CHECK_EQUAL(7, (std::distance(data.begin(), result2))); + CHECK_EQUAL(6, (std::distance(data.begin(), result3))); + CHECK_EQUAL(5, (std::distance(data.begin(), result4))); + CHECK_EQUAL(4, (std::distance(data.begin(), result5))); + CHECK_EQUAL(3, (std::distance(data.begin(), result6))); + CHECK_EQUAL(2, (std::distance(data.begin(), result7))); + CHECK_EQUAL(1, (std::distance(data.begin(), result8))); + CHECK_EQUAL(0, (std::distance(data.begin(), result9))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), result0))); + CHECK_EQUAL(1, (std::distance(data.begin(), result1))); + CHECK_EQUAL(2, (std::distance(data.begin(), result2))); + CHECK_EQUAL(3, (std::distance(data.begin(), result3))); + CHECK_EQUAL(4, (std::distance(data.begin(), result4))); + CHECK_EQUAL(5, (std::distance(data.begin(), result5))); + CHECK_EQUAL(6, (std::distance(data.begin(), result6))); + CHECK_EQUAL(7, (std::distance(data.begin(), result7))); + CHECK_EQUAL(8, (std::distance(data.begin(), result8))); + CHECK_EQUAL(9, (std::distance(data.begin(), result9))); +#endif + } + + //************************************************************************* + TEST(test_find_constexpr_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data::const_iterator result0 = data.find('A'); + static constexpr Data::const_iterator result1 = data.find('B'); + static constexpr Data::const_iterator result2 = data.find('C'); + static constexpr Data::const_iterator result3 = data.find('D'); + static constexpr Data::const_iterator result4 = data.find('E'); + static constexpr Data::const_iterator result5 = data.find('F'); + static constexpr Data::const_iterator result6 = data.find('G'); + static constexpr Data::const_iterator result7 = data.find('H'); + static constexpr Data::const_iterator result8 = data.find('I'); + static constexpr Data::const_iterator result9 = data.find('J'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), result0))); + CHECK_EQUAL(8, (std::distance(data.begin(), result1))); + CHECK_EQUAL(7, (std::distance(data.begin(), result2))); + CHECK_EQUAL(6, (std::distance(data.begin(), result3))); + CHECK_EQUAL(5, (std::distance(data.begin(), result4))); + CHECK_EQUAL(4, (std::distance(data.begin(), result5))); + CHECK_EQUAL(3, (std::distance(data.begin(), result6))); + CHECK_EQUAL(2, (std::distance(data.begin(), result7))); + CHECK_EQUAL(1, (std::distance(data.begin(), result8))); + CHECK_EQUAL(0, (std::distance(data.begin(), result9))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), result0))); + CHECK_EQUAL(1, (std::distance(data.begin(), result1))); + CHECK_EQUAL(2, (std::distance(data.begin(), result2))); + CHECK_EQUAL(3, (std::distance(data.begin(), result3))); + CHECK_EQUAL(4, (std::distance(data.begin(), result4))); + CHECK_EQUAL(5, (std::distance(data.begin(), result5))); + CHECK_EQUAL(6, (std::distance(data.begin(), result6))); + CHECK_EQUAL(7, (std::distance(data.begin(), result7))); + CHECK_EQUAL(8, (std::distance(data.begin(), result8))); + CHECK_EQUAL(9, (std::distance(data.begin(), result9))); +#endif + } + + //************************************************************************* + TEST(test_equal) + { + static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + + CHECK_TRUE(data1 == data2); + CHECK_FALSE(data1 == data3); + } + + //************************************************************************* + TEST(test_not_equal) + { + static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + + CHECK_FALSE(data1 != data2); + CHECK_TRUE(data1 != data3); + } // //************************************************************************* // TEST(test_key_compare) @@ -775,25 +1499,356 @@ namespace // } //#endif -// //************************************************************************* -// TEST(test_contains) -// { -// Data data(initial_data.begin(), initial_data.end()); -// -// CHECK(data.contains(char('1'))); -// CHECK(!data.contains(char('99'))); -// } + //************************************************************************* + TEST(test_contains) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif -// //************************************************************************* -// TEST(test_contains_with_transparent_comparator) -// { -// etl::map> data(initial_data.begin(), initial_data.end()); -// -// CHECK(data.contains(char('1'))); -// CHECK(data.contains(Key('1'))); -// -// CHECK(!data.contains(char('99'))); -// CHECK(!data.contains(Key('99'))); -// } + CHECK_TRUE(data.contains(Key('A'))); + CHECK_TRUE(data.contains(Key('B'))); + CHECK_TRUE(data.contains(Key('C'))); + CHECK_TRUE(data.contains(Key('D'))); + CHECK_TRUE(data.contains(Key('E'))); + CHECK_TRUE(data.contains(Key('F'))); + CHECK_TRUE(data.contains(Key('G'))); + CHECK_TRUE(data.contains(Key('H'))); + CHECK_TRUE(data.contains(Key('I'))); + CHECK_TRUE(data.contains(Key('J'))); + CHECK_FALSE(data.contains(Key('K'))); + } + + //************************************************************************* + TEST(test_contains_constexpr) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr bool containsA = data.contains(Key('A')); + static constexpr bool containsB = data.contains(Key('B')); + static constexpr bool containsC = data.contains(Key('C')); + static constexpr bool containsD = data.contains(Key('D')); + static constexpr bool containsE = data.contains(Key('E')); + static constexpr bool containsF = data.contains(Key('F')); + static constexpr bool containsG = data.contains(Key('G')); + static constexpr bool containsH = data.contains(Key('H')); + static constexpr bool containsI = data.contains(Key('I')); + static constexpr bool containsJ = data.contains(Key('J')); + static constexpr bool containsK = data.contains(Key('K')); + + CHECK_TRUE(containsA); + CHECK_TRUE(containsB); + CHECK_TRUE(containsC); + CHECK_TRUE(containsD); + CHECK_TRUE(containsE); + CHECK_TRUE(containsF); + CHECK_TRUE(containsG); + CHECK_TRUE(containsH); + CHECK_TRUE(containsI); + CHECK_TRUE(containsJ); + CHECK_FALSE(containsK); + } + + //************************************************************************* + TEST(test_contains_with_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + CHECK_TRUE(data.contains('A')); + CHECK_TRUE(data.contains('B')); + CHECK_TRUE(data.contains('C')); + CHECK_TRUE(data.contains('D')); + CHECK_TRUE(data.contains('E')); + CHECK_TRUE(data.contains('F')); + CHECK_TRUE(data.contains('G')); + CHECK_TRUE(data.contains('H')); + CHECK_TRUE(data.contains('I')); + CHECK_TRUE(data.contains('J')); + CHECK_FALSE(data.contains('K')); + } + + //************************************************************************* + TEST(test_contains_with_transparent_comparator_constexpr) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr bool containsA = data.contains('A'); + static constexpr bool containsB = data.contains('B'); + static constexpr bool containsC = data.contains('C'); + static constexpr bool containsD = data.contains('D'); + static constexpr bool containsE = data.contains('E'); + static constexpr bool containsF = data.contains('F'); + static constexpr bool containsG = data.contains('G'); + static constexpr bool containsH = data.contains('H'); + static constexpr bool containsI = data.contains('I'); + static constexpr bool containsJ = data.contains('J'); + static constexpr bool containsK = data.contains('K'); + + CHECK_TRUE(containsA); + CHECK_TRUE(containsB); + CHECK_TRUE(containsC); + CHECK_TRUE(containsD); + CHECK_TRUE(containsE); + CHECK_TRUE(containsF); + CHECK_TRUE(containsG); + CHECK_TRUE(containsH); + CHECK_TRUE(containsI); + CHECK_TRUE(containsJ); + CHECK_FALSE(containsK); + } + + //************************************************************************* + TEST(test_key_comp) + { + static constexpr Data data; + static constexpr Data::key_compare compare = data.key_comp(); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(compare(Key{ 'A' }, Key{ 'A' })); + CHECK_TRUE(compare(Key{ 'B' }, Key{ 'A' })); + CHECK_FALSE(compare(Key{ 'A' }, Key{ 'B' })); +#else + CHECK_FALSE(compare(Key{ 'A' }, Key{ 'A' })); + CHECK_FALSE(compare(Key{ 'B' }, Key{ 'A' })); + CHECK_TRUE(compare(Key{ 'A' }, Key{ 'B' })); +#endif + } + + //************************************************************************* + TEST(test_key_comp_transparent_comparator) + { + static constexpr DataTransparentComparator data; + static constexpr DataTransparentComparator::key_compare compare = data.key_comp(); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(compare('A', 'A')); + CHECK_TRUE(compare('B', 'A')); + CHECK_FALSE(compare('A', 'B')); +#else + CHECK_FALSE(compare('A', 'A')); + CHECK_FALSE(compare('B', 'A')); + CHECK_TRUE(compare('A', 'B')); +#endif + } + + //************************************************************************* + TEST(test_key_comp_constexpr) + { + static constexpr Data data; + static constexpr Data::key_compare compare = data.key_comp(); + + static constexpr bool compareAA = compare(Key{ 'A' }, Key{ 'A' }); + static constexpr bool compareBA = compare(Key{ 'B' }, Key{ 'A' }); + static constexpr bool compareAB = compare(Key{ 'A' }, Key{ 'B' }); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA); + CHECK_TRUE(compareBA); + CHECK_FALSE(compareAB); +#else + CHECK_FALSE(compareAA); + CHECK_FALSE(compareBA); + CHECK_TRUE(compareAB); +#endif + } + + //************************************************************************* + TEST(test_key_comp_constexpr_transparent_comparator) + { + static constexpr DataTransparentComparator data; + static constexpr DataTransparentComparator::key_compare compare = data.key_comp(); + + static constexpr bool compareAA = compare('A', 'A'); + static constexpr bool compareBA = compare('B', 'A'); + static constexpr bool compareAB = compare('A', 'B'); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA); + CHECK_TRUE(compareBA); + CHECK_FALSE(compareAB); +#else + CHECK_FALSE(compareAA); + CHECK_FALSE(compareBA); + CHECK_TRUE(compareAB); +#endif + } + + //************************************************************************* + TEST(test_value_comp) + { + static constexpr Data data; + static constexpr Data::value_compare compare = data.value_comp(); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'A' }, 0 })); + CHECK_FALSE(compare(value_type{ Key{ 'A' }, 0 }, Key{ 'A' })); + CHECK_FALSE(compare(Key{ 'A' }, value_type{ Key{ 'A' }, 0 })); + + CHECK_TRUE(compare(value_type{ Key{ 'B' }, 1 }, value_type{ Key{ 'A' }, 0 })); + CHECK_TRUE(compare(value_type{ Key{ 'B' }, 1 }, Key{ 'A' })); + CHECK_TRUE(compare(Key{ 'B' }, value_type{ Key{ 'A' }, 0 })); + + CHECK_FALSE(compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'B' }, 1 })); + CHECK_FALSE(compare(value_type{ Key{ 'A' }, 0 }, Key{ 'B' })); + CHECK_FALSE(compare(Key{ 'A' }, value_type{ Key{ 'B' }, 1 })); +#else + CHECK_FALSE(compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'A' }, 0 })); + CHECK_FALSE(compare(value_type{ Key{ 'A' }, 0 }, Key{ 'A' })); + CHECK_FALSE(compare(Key{ 'A' }, value_type{ Key{ 'A' }, 0 })); + + CHECK_FALSE(compare(value_type{ Key{ 'B' }, 1 }, value_type{ Key{ 'A' }, 0 })); + CHECK_FALSE(compare(value_type{ Key{ 'B' }, 1 }, Key{ 'A' })); + CHECK_FALSE(compare(Key{ 'B' }, value_type{ Key{ 'A' }, 0 })); + + CHECK_TRUE(compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'B' }, 1 })); + CHECK_TRUE(compare(value_type{ Key{ 'A' }, 0 }, Key{ 'B' })); + CHECK_TRUE(compare(Key{ 'A' }, value_type{ Key{ 'B' }, 1 })); +#endif + } + + //************************************************************************* + TEST(test_value_comp_transparent_comparator) + { + static constexpr DataTransparentComparator data; + static constexpr DataTransparentComparator::value_compare compare = data.value_comp(); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(compare(value_type{ 'A', 0 }, value_type{ 'A', 0 })); + CHECK_FALSE(compare(value_type{ 'A', 0 }, 'A')); + CHECK_FALSE(compare('A', value_type{ 'A', 0 })); + + CHECK_TRUE(compare(value_type{ 'B', 1 }, value_type{ 'A', 0 })); + CHECK_TRUE(compare(value_type{ 'B', 1 }, 'A')); + CHECK_TRUE(compare('B', value_type{ 'A', 0 })); + + CHECK_FALSE(compare(value_type{ 'A', 0 }, value_type{ 'B', 1 })); + CHECK_FALSE(compare(value_type{ 'A', 0 }, 'B')); + CHECK_FALSE(compare('A', value_type{ 'B', 1 })); +#else + CHECK_FALSE(compare(value_type{ 'A', 0 }, value_type{ 'A', 0 })); + CHECK_FALSE(compare(value_type{ 'A', 0 }, 'A')); + CHECK_FALSE(compare('A', value_type{ 'A', 0 })); + + CHECK_FALSE(compare(value_type{ 'B', 1 }, value_type{ 'A', 0 })); + CHECK_FALSE(compare(value_type{ 'B', 1 }, 'A')); + CHECK_FALSE(compare('B', value_type{ 'A', 0 })); + + CHECK_TRUE(compare(value_type{ 'A', 0 }, value_type{ 'B', 1 })); + CHECK_TRUE(compare(value_type{ 'A', 0 }, 'B')); + CHECK_TRUE(compare('A', value_type{ 'B', 1 })); +#endif + } + + //************************************************************************* + TEST(test_value_comp_constexpr) + { + static constexpr Data data; + static constexpr Data::value_compare compare = data.value_comp(); + + static constexpr bool compareAA1 = compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'A' }, 0 }); + static constexpr bool compareAA2 = compare(value_type{ Key{ 'A' }, 0 }, Key{ 'A' }); + static constexpr bool compareAA3 = compare(Key{ 'A' }, value_type{ Key{ 'A' }, 0 }); + + static constexpr bool compareBA1 = compare(value_type{ Key{ 'B' }, 0 }, value_type{ Key{ 'A' }, 0 }); + static constexpr bool compareBA2 = compare(value_type{ Key{ 'B' }, 0 }, Key{ 'A' }); + static constexpr bool compareBA3 = compare(Key{ 'B' }, value_type{ Key{ 'A' }, 0 }); + + static constexpr bool compareAB1 = compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'B' }, 0 }); + static constexpr bool compareAB2 = compare(value_type{ Key{ 'A' }, 0 }, Key{ 'B' }); + static constexpr bool compareAB3 = compare(Key{ 'A' }, value_type{ Key{ 'B' }, 0 });; + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_TRUE(compareBA1); + CHECK_TRUE(compareBA2); + CHECK_TRUE(compareBA3); + + CHECK_FALSE(compareAB1); + CHECK_FALSE(compareAB2); + CHECK_FALSE(compareAB3); +#else + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_FALSE(compareBA1); + CHECK_FALSE(compareBA2); + CHECK_FALSE(compareBA3); + + CHECK_TRUE(compareAB1); + CHECK_TRUE(compareAB2); + CHECK_TRUE(compareAB3); +#endif + } + + //************************************************************************* + TEST(test_value_comp_constexpr_transparent_comparator) + { + static constexpr DataTransparentComparator data; + static constexpr DataTransparentComparator::value_compare compare = data.value_comp(); + + static constexpr bool compareAA1 = compare(value_type{ 'A', 0 }, value_type{ 'A', 0 }); + static constexpr bool compareAA2 = compare(value_type{ 'A', 0 }, 'A'); + static constexpr bool compareAA3 = compare('A', value_type{ 'A', 0 }); + + static constexpr bool compareBA1 = compare(value_type{ 'B', 0 }, value_type{ 'A', 0 }); + static constexpr bool compareBA2 = compare(value_type{ 'B', 0 }, 'A'); + static constexpr bool compareBA3 = compare('B', value_type{ 'A', 0 }); + + static constexpr bool compareAB1 = compare(value_type{ 'A', 0 }, value_type{ 'B', 0 }); + static constexpr bool compareAB2 = compare(value_type{ 'A', 0 }, 'B'); + static constexpr bool compareAB3 = compare('A', value_type{ 'B', 0 });; + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_TRUE(compareBA1); + CHECK_TRUE(compareBA2); + CHECK_TRUE(compareBA3); + + CHECK_FALSE(compareAB1); + CHECK_FALSE(compareAB2); + CHECK_FALSE(compareAB3); +#else + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_FALSE(compareBA1); + CHECK_FALSE(compareBA2); + CHECK_FALSE(compareBA3); + + CHECK_TRUE(compareAB1); + CHECK_TRUE(compareAB2); + CHECK_TRUE(compareAB3); +#endif + } }; } From 609dc3dc2d26a9b38b9743efa05fa30364c4ceb8 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 15 Jun 2025 20:11:08 +0100 Subject: [PATCH 05/12] etl::const_map completed --- include/etl/const_map.h | 4 ++-- test/test_map.cpp | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/etl/const_map.h b/include/etl/const_map.h index 25f102ff..a9a8dc1c 100644 --- a/include/etl/const_map.h +++ b/include/etl/const_map.h @@ -64,7 +64,6 @@ namespace etl /// Defines the parameter types using const_key_reference = const key_type&; - using rvalue_key_reference = key_type&&; using const_mapped_reference = const mapped_type&; //********************************************************************* @@ -116,7 +115,8 @@ namespace etl : element_list{etl::forward(elements)...} , element_list_end{element_list + sizeof...(elements)} { - static_assert((etl::is_default_constructible::value), "value_type must be default constructible"); + static_assert((etl::is_default_constructible::value), "key_type must be default constructible"); + static_assert((etl::is_default_constructible::value), "mapped_type must be default constructible"); static_assert((etl::are_all_same...>::value), "All elements must be value_type"); static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity"); } diff --git a/test/test_map.cpp b/test/test_map.cpp index 2c19e4e4..776031a9 100644 --- a/test/test_map.cpp +++ b/test/test_map.cpp @@ -501,10 +501,12 @@ namespace CMap compare_data(initial_data.begin(), initial_data.end()); EMap data(initial_data.begin(), initial_data.end()); + auto v = data.at("3"); + CHECK(data.at(Key("0")) == compare_data.at("0")); CHECK(data.at(Key("1")) == compare_data.at("1")); CHECK(data.at(Key("2")) == compare_data.at("2")); - CHECK(data.at(Key("3")) == compare_data.at("3")); + CHECK(data.at("3") == compare_data.at("3")); CHECK(data.at(Key("4")) == compare_data.at("4")); CHECK(data.at(Key("5")) == compare_data.at("5")); CHECK(data.at(Key("6")) == compare_data.at("6")); From eb6df0ec82de415e71c1a654360cb89cee727b53 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 16 Jun 2025 08:30:35 +0100 Subject: [PATCH 06/12] Removed non-const iterator and pointer types Updated Doxygen comments --- include/etl/const_map.h | 134 +++- test/test_const_map.cpp | 1084 +++++++++++++++++++------------ test/vs2022/etl.vcxproj | 2 + test/vs2022/etl.vcxproj.filters | 6 + 4 files changed, 772 insertions(+), 454 deletions(-) diff --git a/include/etl/const_map.h b/include/etl/const_map.h index a9a8dc1c..e31c9641 100644 --- a/include/etl/const_map.h +++ b/include/etl/const_map.h @@ -53,12 +53,8 @@ namespace etl using value_type = ETL_OR_STD::pair; using mapped_type = TMapped ; using key_compare = TKeyCompare; - using reference = const value_type&; using const_reference = const value_type&; - using rvalue_reference = value_type&&; - using pointer = const value_type*; using const_pointer = const value_type*; - using iterator = const value_type*; using const_iterator = const value_type*; using size_type = size_t; @@ -73,28 +69,34 @@ namespace etl { public: - // value_compare two value types. + // Compare two value types. ETL_CONSTEXPR14 bool operator ()(const value_type& element1, const value_type& element2) const ETL_NOEXCEPT { return kcompare(element1.first, element2.first); } + // Compare value type and key. ETL_CONSTEXPR14 bool operator ()(const value_type& element, const_key_reference key) const ETL_NOEXCEPT { return kcompare(element.first, key); } + // Compare value types and key. + // Enabled for transparent comparators. template ::value, int> = 0> ETL_CONSTEXPR14 bool operator ()(const value_type& element, const K& key) const ETL_NOEXCEPT { return kcompare(element.first, key); } + // Compare key and value type. ETL_CONSTEXPR14 bool operator ()(const_key_reference key, const value_type& element) const ETL_NOEXCEPT { return kcompare(key, element.first); } + // Compare key and value type. + // Enabled for transparent comparators. template ::value, int> = 0> ETL_CONSTEXPR14 bool operator ()(const K& key, const value_type& element) const ETL_NOEXCEPT { @@ -173,6 +175,7 @@ namespace etl //************************************************************************* ///\brief Index operator. + ///\param key The key of the element to return. ///\return A const_mapped_reference to the mapped value at the index. /// Undefined behaviour if the key is not in the map. //************************************************************************* @@ -186,6 +189,7 @@ namespace etl //************************************************************************* ///\brief Key index operator. /// Enabled for transparent comparators. + ///\param key The key of the element to return. ///\return A const_mapped_reference to the mapped value at the key index. /// Undefined behaviour if the key is not in the map. //************************************************************************* @@ -199,6 +203,7 @@ namespace etl //************************************************************************* ///\brief Gets the mapped value at the key index. + ///\param key The key of the element to return. ///\return A const_mapped_reference to the mapped value at the index. /// Undefined behaviour if the key is not in the map. //************************************************************************* @@ -209,6 +214,12 @@ namespace etl return itr->second; } + //************************************************************************* + ///\brief Gets the mapped value at the key index. + /// Enabled if the comparator is transparent. + ///\param key The key of the element to return. + ///\return A const_mapped_reference to the mapped value at the index. + /// Undefined behaviour if the key is not in the map. //************************************************************************* template ::value, int> = 0> ETL_CONSTEXPR14 const_mapped_reference at(const K& key) const ETL_NOEXCEPT @@ -218,54 +229,60 @@ namespace etl return itr->second; } + //************************************************************************* + ///\brief Gets a const_iterator to the mapped value at the key index. + ///\param key The key of the element to find. + ///\return A const_iterator to the mapped value at the index, + /// or end() if not found. //************************************************************************* ETL_CONSTEXPR14 const_iterator find(const_key_reference key) const ETL_NOEXCEPT { - iterator itr = lower_bound(key); + const_iterator itr = lower_bound(key); - if (itr != end()) + if ((itr != end()) && (keys_are_equal(itr->first, key))) { - if (keys_are_equal(itr->first, key)) - { - return itr; - } - else - { - return end(); - } + return itr; } return end(); } + //************************************************************************* + ///\brief Gets a const_iterator to the mapped value at the key index. + /// Enabled if the comparator is transparent. + ///\param key The key of the element to find. + ///\return A const_iterator to the mapped value at the index, + /// or end() if not found. //************************************************************************* template ::value, int> = 0> ETL_CONSTEXPR14 const_iterator find(const K& key) const ETL_NOEXCEPT { - iterator itr = lower_bound(key); + const_iterator itr = lower_bound(key); - if (itr != end()) + if ((itr != end()) && (keys_are_equal(itr->first, key))) { - if (keys_are_equal(itr->first, key)) - { - return itr; - } - else - { - return end(); - } + return itr; } return end(); } + //************************************************************************* + ///\brief Checks if the map contains an element with key. + ///\param key The key of the element to check. + ///\return true if the map contains an element with key. //************************************************************************* ETL_CONSTEXPR14 bool contains(const_key_reference key) const ETL_NOEXCEPT { return find(key) != end(); } + //************************************************************************* + ///\brief Checks if the map contains an element with key. + /// Enabled if the comparator is transparent. + ///\param key The key of the element to check. + ///\return true if the map contains an element with key. //************************************************************************* template ::value, int> = 0> ETL_CONSTEXPR14 bool contains(const K& key) const ETL_NOEXCEPT @@ -273,12 +290,21 @@ namespace etl return find(key) != end(); } + //************************************************************************* + ///\brief Counts the numbeer elements with key. + ///\param key The key of the element to count. + ///\return 0 or 1 //************************************************************************* ETL_CONSTEXPR14 size_type count(const_key_reference key) const ETL_NOEXCEPT { return contains(key) ? 1 : 0; } + //************************************************************************* + ///\brief Counts the numbeer elements with key. + /// Enabled if the comparator is transparent. + ///\param key The key of the element to count. + ///\return 0 or 1 //************************************************************************* template ::value, int> = 0> ETL_CONSTEXPR14 size_type count(const K& key) const ETL_NOEXCEPT @@ -286,12 +312,27 @@ namespace etl return contains(key) ? 1 : 0; } + //************************************************************************* + ///\brief Returns a range containing all elements with the key. + /// The range is defined by a pair of two iterators, one to the + /// first element that is not less than the key and second to the first + /// element greater than the key. + ///\param key The key of the element + ///\return etl::pair or std::pair containing a pair of iterators. //************************************************************************* ETL_CONSTEXPR14 ETL_OR_STD::pair equal_range(const_key_reference key) const ETL_NOEXCEPT { return etl::equal_range(begin(), end(), key, vcompare); } + //************************************************************************* + ///\brief Returns a range containing all elements with the key. + /// The range is defined by a pair of two iterators, one to the + /// first element that is not less than the key and second to the first + /// element greater than the key. + /// Enabled if the comparator is transparent. + ///\param key The key of the element + ///\return etl::pair or std::pair containing a pair of iterators. //************************************************************************* template ::value, int> = 0> ETL_CONSTEXPR14 ETL_OR_STD::pair equal_range(const K& key) const ETL_NOEXCEPT @@ -299,12 +340,23 @@ namespace etl return etl::equal_range(begin(), end(), key, vcompare); } + //************************************************************************* + ///\brief Returns a const_iterator to the first element that is not less than the key. + /// Returns a const_iterator to the first element that is not less than the key. + ///\param key The key of the element + ///\return const_iterator to the element or end() //************************************************************************* ETL_CONSTEXPR14 const_iterator lower_bound(const_key_reference key) const ETL_NOEXCEPT { return etl::lower_bound(begin(), end(), key, vcompare); } + //************************************************************************* + ///\brief Returns a const_iterator to the first element that is not less than the key. + /// Returns a const_iterator to the first element that is not less than the key. + /// Enabled if the comparator is transparent. + ///\param key The key of the element + ///\return const_iterator to the element or end() //************************************************************************* template ::value, int> = 0> ETL_CONSTEXPR14 const_iterator lower_bound(const K& key) const ETL_NOEXCEPT @@ -312,12 +364,23 @@ namespace etl return etl::lower_bound(begin(), end(), key, vcompare); } + //************************************************************************* + ///\brief Returns a const_iterator to the first element that is greater than the key. + /// Returns a const_iterator to the first element that is greater than the key. + ///\param key The key of the element + ///\return const_iterator to the element or end() //************************************************************************* ETL_CONSTEXPR14 const_iterator upper_bound(const_key_reference key) const ETL_NOEXCEPT { return etl::upper_bound(begin(), end(), key, vcompare); } + //************************************************************************* + ///\brief Returns a const_iterator to the first element that is greater than the key. + /// Returns a const_iterator to the first element that is greater than the key. + /// Enabled if the comparator is transparent. + ///\param key The key of the element + ///\return const_iterator to the element or end() //************************************************************************* template ::value, int> = 0> ETL_CONSTEXPR14 const_iterator upper_bound(const K& key) const ETL_NOEXCEPT @@ -325,30 +388,46 @@ namespace etl return etl::upper_bound(begin(), end(), key, vcompare); } + //************************************************************************* + /// Checks if the map is empty. + ///\return true if the map is empty. //************************************************************************* ETL_CONSTEXPR14 size_type empty() const ETL_NOEXCEPT { return size() == 0U; } + //************************************************************************* + /// Checks if the map is full. + ///\return true if the map is full. //************************************************************************* ETL_CONSTEXPR14 size_type full() const ETL_NOEXCEPT { return size() == Size; } + //************************************************************************* + /// Gets the size of the map. + ///\return The size of the map. //************************************************************************* ETL_CONSTEXPR14 size_type size() const ETL_NOEXCEPT { return size_type(element_list_end - element_list); } + //************************************************************************* + /// Gets the maximum size of the map. + ///\return The maximum size of the map. //************************************************************************* ETL_CONSTEXPR14 size_type max_size() const ETL_NOEXCEPT { return Size; } + //************************************************************************* + /// Gets the capacity of the map. + /// This is always equal to max_size(). + ///\return The capacity of the map. //************************************************************************* ETL_CONSTEXPR14 size_type capacity() const ETL_NOEXCEPT { @@ -357,6 +436,7 @@ namespace etl //************************************************************************* /// How to compare two key elements. + ///\return An instance of the key_compare type. //************************************************************************* ETL_CONSTEXPR14 key_compare key_comp() const ETL_NOEXCEPT { @@ -365,6 +445,7 @@ namespace etl //************************************************************************* /// How to compare two value elements. + ///\return An instance of the value_compare type. //************************************************************************* ETL_CONSTEXPR14 value_compare value_comp() const ETL_NOEXCEPT { @@ -381,6 +462,9 @@ namespace etl return !key_compare()(key1, key2) && !key_compare()(key2, key1); } + //********************************************************************* + /// Check to see if the keys are equal. + /// Enabled if the comparator is transparent. //********************************************************************* template ::value, int> = 0> ETL_CONSTEXPR14 bool keys_are_equal(const K1& key1, const K2& key2) const ETL_NOEXCEPT diff --git a/test/test_const_map.cpp b/test/test_const_map.cpp index d10a1c3e..082efe99 100644 --- a/test/test_const_map.cpp +++ b/test/test_const_map.cpp @@ -108,7 +108,7 @@ namespace return (lhs.k == rhs.k); } - //#define TEST_GREATER_THAN + #define TEST_GREATER_THAN #ifdef TEST_GREATER_THAN using Data = etl::const_map>; using DataTransparentComparator = etl::const_map>; @@ -118,8 +118,6 @@ namespace #endif using value_type = Data::value_type; - - using Data_iterator = Data::iterator; using Data_const_iterator = Data::const_iterator; SUITE(test_const_map) @@ -547,61 +545,61 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - ETL_OR_STD::pair result0 = data.equal_range(Key('A')); - ETL_OR_STD::pair result1 = data.equal_range(Key('B')); - ETL_OR_STD::pair result2 = data.equal_range(Key('C')); - ETL_OR_STD::pair result3 = data.equal_range(Key('D')); - ETL_OR_STD::pair result4 = data.equal_range(Key('E')); - ETL_OR_STD::pair result5 = data.equal_range(Key('F')); - ETL_OR_STD::pair result6 = data.equal_range(Key('G')); - ETL_OR_STD::pair result7 = data.equal_range(Key('H')); - ETL_OR_STD::pair result8 = data.equal_range(Key('I')); - ETL_OR_STD::pair result9 = data.equal_range(Key('J')); + ETL_OR_STD::pair resultA = data.equal_range(Key('A')); + ETL_OR_STD::pair resultB = data.equal_range(Key('B')); + ETL_OR_STD::pair resultC = data.equal_range(Key('C')); + ETL_OR_STD::pair resultD = data.equal_range(Key('D')); + ETL_OR_STD::pair resultE = data.equal_range(Key('E')); + ETL_OR_STD::pair resultF = data.equal_range(Key('F')); + ETL_OR_STD::pair resultG = data.equal_range(Key('G')); + ETL_OR_STD::pair resultH = data.equal_range(Key('H')); + ETL_OR_STD::pair resultI = data.equal_range(Key('I')); + ETL_OR_STD::pair resultJ = data.equal_range(Key('J')); #ifdef TEST_GREATER_THAN - CHECK_EQUAL(9, (std::distance(data.begin(), result0.first))); - CHECK_EQUAL(8, (std::distance(data.begin(), result1.first))); - CHECK_EQUAL(7, (std::distance(data.begin(), result2.first))); - CHECK_EQUAL(6, (std::distance(data.begin(), result3.first))); - CHECK_EQUAL(5, (std::distance(data.begin(), result4.first))); - CHECK_EQUAL(4, (std::distance(data.begin(), result5.first))); - CHECK_EQUAL(3, (std::distance(data.begin(), result6.first))); - CHECK_EQUAL(2, (std::distance(data.begin(), result7.first))); - CHECK_EQUAL(1, (std::distance(data.begin(), result8.first))); - CHECK_EQUAL(0, (std::distance(data.begin(), result9.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ.first))); - CHECK_EQUAL(10, (std::distance(data.begin(), result0.second))); - CHECK_EQUAL(9, (std::distance(data.begin(), result1.second))); - CHECK_EQUAL(8, (std::distance(data.begin(), result2.second))); - CHECK_EQUAL(7, (std::distance(data.begin(), result3.second))); - CHECK_EQUAL(6, (std::distance(data.begin(), result4.second))); - CHECK_EQUAL(5, (std::distance(data.begin(), result5.second))); - CHECK_EQUAL(4, (std::distance(data.begin(), result6.second))); - CHECK_EQUAL(3, (std::distance(data.begin(), result7.second))); - CHECK_EQUAL(2, (std::distance(data.begin(), result8.second))); - CHECK_EQUAL(1, (std::distance(data.begin(), result9.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ.second))); #else - CHECK_EQUAL(0, (std::distance(data.begin(), result0.first))); - CHECK_EQUAL(1, (std::distance(data.begin(), result1.first))); - CHECK_EQUAL(2, (std::distance(data.begin(), result2.first))); - CHECK_EQUAL(3, (std::distance(data.begin(), result3.first))); - CHECK_EQUAL(4, (std::distance(data.begin(), result4.first))); - CHECK_EQUAL(5, (std::distance(data.begin(), result5.first))); - CHECK_EQUAL(6, (std::distance(data.begin(), result6.first))); - CHECK_EQUAL(7, (std::distance(data.begin(), result7.first))); - CHECK_EQUAL(8, (std::distance(data.begin(), result8.first))); - CHECK_EQUAL(9, (std::distance(data.begin(), result9.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ.first))); - CHECK_EQUAL(1, (std::distance(data.begin(), result0.second))); - CHECK_EQUAL(2, (std::distance(data.begin(), result1.second))); - CHECK_EQUAL(3, (std::distance(data.begin(), result2.second))); - CHECK_EQUAL(4, (std::distance(data.begin(), result3.second))); - CHECK_EQUAL(5, (std::distance(data.begin(), result4.second))); - CHECK_EQUAL(6, (std::distance(data.begin(), result5.second))); - CHECK_EQUAL(7, (std::distance(data.begin(), result6.second))); - CHECK_EQUAL(8, (std::distance(data.begin(), result7.second))); - CHECK_EQUAL(9, (std::distance(data.begin(), result8.second))); - CHECK_EQUAL(10, (std::distance(data.begin(), result9.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ.second))); #endif } @@ -616,61 +614,61 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr ETL_OR_STD::pair result0 = data.equal_range(Key('A')); - static constexpr ETL_OR_STD::pair result1 = data.equal_range(Key('B')); - static constexpr ETL_OR_STD::pair result2 = data.equal_range(Key('C')); - static constexpr ETL_OR_STD::pair result3 = data.equal_range(Key('D')); - static constexpr ETL_OR_STD::pair result4 = data.equal_range(Key('E')); - static constexpr ETL_OR_STD::pair result5 = data.equal_range(Key('F')); - static constexpr ETL_OR_STD::pair result6 = data.equal_range(Key('G')); - static constexpr ETL_OR_STD::pair result7 = data.equal_range(Key('H')); - static constexpr ETL_OR_STD::pair result8 = data.equal_range(Key('I')); - static constexpr ETL_OR_STD::pair result9 = data.equal_range(Key('J')); + static constexpr ETL_OR_STD::pair resultA = data.equal_range(Key('A')); + static constexpr ETL_OR_STD::pair resultB = data.equal_range(Key('B')); + static constexpr ETL_OR_STD::pair resultC = data.equal_range(Key('C')); + static constexpr ETL_OR_STD::pair resultD = data.equal_range(Key('D')); + static constexpr ETL_OR_STD::pair resultE = data.equal_range(Key('E')); + static constexpr ETL_OR_STD::pair resultF = data.equal_range(Key('F')); + static constexpr ETL_OR_STD::pair resultG = data.equal_range(Key('G')); + static constexpr ETL_OR_STD::pair resultH = data.equal_range(Key('H')); + static constexpr ETL_OR_STD::pair resultI = data.equal_range(Key('I')); + static constexpr ETL_OR_STD::pair resultJ = data.equal_range(Key('J')); #ifdef TEST_GREATER_THAN - CHECK_EQUAL(9, (std::distance(data.begin(), result0.first))); - CHECK_EQUAL(8, (std::distance(data.begin(), result1.first))); - CHECK_EQUAL(7, (std::distance(data.begin(), result2.first))); - CHECK_EQUAL(6, (std::distance(data.begin(), result3.first))); - CHECK_EQUAL(5, (std::distance(data.begin(), result4.first))); - CHECK_EQUAL(4, (std::distance(data.begin(), result5.first))); - CHECK_EQUAL(3, (std::distance(data.begin(), result6.first))); - CHECK_EQUAL(2, (std::distance(data.begin(), result7.first))); - CHECK_EQUAL(1, (std::distance(data.begin(), result8.first))); - CHECK_EQUAL(0, (std::distance(data.begin(), result9.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ.first))); - CHECK_EQUAL(10, (std::distance(data.begin(), result0.second))); - CHECK_EQUAL(9, (std::distance(data.begin(), result1.second))); - CHECK_EQUAL(8, (std::distance(data.begin(), result2.second))); - CHECK_EQUAL(7, (std::distance(data.begin(), result3.second))); - CHECK_EQUAL(6, (std::distance(data.begin(), result4.second))); - CHECK_EQUAL(5, (std::distance(data.begin(), result5.second))); - CHECK_EQUAL(4, (std::distance(data.begin(), result6.second))); - CHECK_EQUAL(3, (std::distance(data.begin(), result7.second))); - CHECK_EQUAL(2, (std::distance(data.begin(), result8.second))); - CHECK_EQUAL(1, (std::distance(data.begin(), result9.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ.second))); #else - CHECK_EQUAL(0, (std::distance(data.begin(), result0.first))); - CHECK_EQUAL(1, (std::distance(data.begin(), result1.first))); - CHECK_EQUAL(2, (std::distance(data.begin(), result2.first))); - CHECK_EQUAL(3, (std::distance(data.begin(), result3.first))); - CHECK_EQUAL(4, (std::distance(data.begin(), result4.first))); - CHECK_EQUAL(5, (std::distance(data.begin(), result5.first))); - CHECK_EQUAL(6, (std::distance(data.begin(), result6.first))); - CHECK_EQUAL(7, (std::distance(data.begin(), result7.first))); - CHECK_EQUAL(8, (std::distance(data.begin(), result8.first))); - CHECK_EQUAL(9, (std::distance(data.begin(), result9.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ.first))); - CHECK_EQUAL(1, (std::distance(data.begin(), result0.second))); - CHECK_EQUAL(2, (std::distance(data.begin(), result1.second))); - CHECK_EQUAL(3, (std::distance(data.begin(), result2.second))); - CHECK_EQUAL(4, (std::distance(data.begin(), result3.second))); - CHECK_EQUAL(5, (std::distance(data.begin(), result4.second))); - CHECK_EQUAL(6, (std::distance(data.begin(), result5.second))); - CHECK_EQUAL(7, (std::distance(data.begin(), result6.second))); - CHECK_EQUAL(8, (std::distance(data.begin(), result7.second))); - CHECK_EQUAL(9, (std::distance(data.begin(), result8.second))); - CHECK_EQUAL(10, (std::distance(data.begin(), result9.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ.second))); #endif } @@ -685,61 +683,61 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - ETL_OR_STD::pair result0 = data.equal_range('A'); - ETL_OR_STD::pair result1 = data.equal_range('B'); - ETL_OR_STD::pair result2 = data.equal_range('C'); - ETL_OR_STD::pair result3 = data.equal_range('D'); - ETL_OR_STD::pair result4 = data.equal_range('E'); - ETL_OR_STD::pair result5 = data.equal_range('F'); - ETL_OR_STD::pair result6 = data.equal_range('G'); - ETL_OR_STD::pair result7 = data.equal_range('H'); - ETL_OR_STD::pair result8 = data.equal_range('I'); - ETL_OR_STD::pair result9 = data.equal_range('J'); + ETL_OR_STD::pair resultA = data.equal_range('A'); + ETL_OR_STD::pair resultB = data.equal_range('B'); + ETL_OR_STD::pair resultC = data.equal_range('C'); + ETL_OR_STD::pair resultD = data.equal_range('D'); + ETL_OR_STD::pair resultE = data.equal_range('E'); + ETL_OR_STD::pair resultF = data.equal_range('F'); + ETL_OR_STD::pair resultG = data.equal_range('G'); + ETL_OR_STD::pair resultH = data.equal_range('H'); + ETL_OR_STD::pair resultI = data.equal_range('I'); + ETL_OR_STD::pair resultJ = data.equal_range('J'); #ifdef TEST_GREATER_THAN - CHECK_EQUAL(9, (std::distance(data.begin(), result0.first))); - CHECK_EQUAL(8, (std::distance(data.begin(), result1.first))); - CHECK_EQUAL(7, (std::distance(data.begin(), result2.first))); - CHECK_EQUAL(6, (std::distance(data.begin(), result3.first))); - CHECK_EQUAL(5, (std::distance(data.begin(), result4.first))); - CHECK_EQUAL(4, (std::distance(data.begin(), result5.first))); - CHECK_EQUAL(3, (std::distance(data.begin(), result6.first))); - CHECK_EQUAL(2, (std::distance(data.begin(), result7.first))); - CHECK_EQUAL(1, (std::distance(data.begin(), result8.first))); - CHECK_EQUAL(0, (std::distance(data.begin(), result9.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ.first))); - CHECK_EQUAL(10, (std::distance(data.begin(), result0.second))); - CHECK_EQUAL(9, (std::distance(data.begin(), result1.second))); - CHECK_EQUAL(8, (std::distance(data.begin(), result2.second))); - CHECK_EQUAL(7, (std::distance(data.begin(), result3.second))); - CHECK_EQUAL(6, (std::distance(data.begin(), result4.second))); - CHECK_EQUAL(5, (std::distance(data.begin(), result5.second))); - CHECK_EQUAL(4, (std::distance(data.begin(), result6.second))); - CHECK_EQUAL(3, (std::distance(data.begin(), result7.second))); - CHECK_EQUAL(2, (std::distance(data.begin(), result8.second))); - CHECK_EQUAL(1, (std::distance(data.begin(), result9.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ.second))); #else - CHECK_EQUAL(0, (std::distance(data.begin(), result0.first))); - CHECK_EQUAL(1, (std::distance(data.begin(), result1.first))); - CHECK_EQUAL(2, (std::distance(data.begin(), result2.first))); - CHECK_EQUAL(3, (std::distance(data.begin(), result3.first))); - CHECK_EQUAL(4, (std::distance(data.begin(), result4.first))); - CHECK_EQUAL(5, (std::distance(data.begin(), result5.first))); - CHECK_EQUAL(6, (std::distance(data.begin(), result6.first))); - CHECK_EQUAL(7, (std::distance(data.begin(), result7.first))); - CHECK_EQUAL(8, (std::distance(data.begin(), result8.first))); - CHECK_EQUAL(9, (std::distance(data.begin(), result9.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ.first))); - CHECK_EQUAL(1, (std::distance(data.begin(), result0.second))); - CHECK_EQUAL(2, (std::distance(data.begin(), result1.second))); - CHECK_EQUAL(3, (std::distance(data.begin(), result2.second))); - CHECK_EQUAL(4, (std::distance(data.begin(), result3.second))); - CHECK_EQUAL(5, (std::distance(data.begin(), result4.second))); - CHECK_EQUAL(6, (std::distance(data.begin(), result5.second))); - CHECK_EQUAL(7, (std::distance(data.begin(), result6.second))); - CHECK_EQUAL(8, (std::distance(data.begin(), result7.second))); - CHECK_EQUAL(9, (std::distance(data.begin(), result8.second))); - CHECK_EQUAL(10, (std::distance(data.begin(), result9.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ.second))); #endif } @@ -754,61 +752,61 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr ETL_OR_STD::pair result0 = data.equal_range('A'); - static constexpr ETL_OR_STD::pair result1 = data.equal_range('B'); - static constexpr ETL_OR_STD::pair result2 = data.equal_range('C'); - static constexpr ETL_OR_STD::pair result3 = data.equal_range('D'); - static constexpr ETL_OR_STD::pair result4 = data.equal_range('E'); - static constexpr ETL_OR_STD::pair result5 = data.equal_range('F'); - static constexpr ETL_OR_STD::pair result6 = data.equal_range('G'); - static constexpr ETL_OR_STD::pair result7 = data.equal_range('H'); - static constexpr ETL_OR_STD::pair result8 = data.equal_range('I'); - static constexpr ETL_OR_STD::pair result9 = data.equal_range('J'); + static constexpr ETL_OR_STD::pair resultA = data.equal_range('A'); + static constexpr ETL_OR_STD::pair resultB = data.equal_range('B'); + static constexpr ETL_OR_STD::pair resultC = data.equal_range('C'); + static constexpr ETL_OR_STD::pair resultD = data.equal_range('D'); + static constexpr ETL_OR_STD::pair resultE = data.equal_range('E'); + static constexpr ETL_OR_STD::pair resultF = data.equal_range('F'); + static constexpr ETL_OR_STD::pair resultG = data.equal_range('G'); + static constexpr ETL_OR_STD::pair resultH = data.equal_range('H'); + static constexpr ETL_OR_STD::pair resultI = data.equal_range('I'); + static constexpr ETL_OR_STD::pair resultJ = data.equal_range('J'); #ifdef TEST_GREATER_THAN - CHECK_EQUAL(9, (std::distance(data.begin(), result0.first))); - CHECK_EQUAL(8, (std::distance(data.begin(), result1.first))); - CHECK_EQUAL(7, (std::distance(data.begin(), result2.first))); - CHECK_EQUAL(6, (std::distance(data.begin(), result3.first))); - CHECK_EQUAL(5, (std::distance(data.begin(), result4.first))); - CHECK_EQUAL(4, (std::distance(data.begin(), result5.first))); - CHECK_EQUAL(3, (std::distance(data.begin(), result6.first))); - CHECK_EQUAL(2, (std::distance(data.begin(), result7.first))); - CHECK_EQUAL(1, (std::distance(data.begin(), result8.first))); - CHECK_EQUAL(0, (std::distance(data.begin(), result9.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ.first))); - CHECK_EQUAL(10, (std::distance(data.begin(), result0.second))); - CHECK_EQUAL(9, (std::distance(data.begin(), result1.second))); - CHECK_EQUAL(8, (std::distance(data.begin(), result2.second))); - CHECK_EQUAL(7, (std::distance(data.begin(), result3.second))); - CHECK_EQUAL(6, (std::distance(data.begin(), result4.second))); - CHECK_EQUAL(5, (std::distance(data.begin(), result5.second))); - CHECK_EQUAL(4, (std::distance(data.begin(), result6.second))); - CHECK_EQUAL(3, (std::distance(data.begin(), result7.second))); - CHECK_EQUAL(2, (std::distance(data.begin(), result8.second))); - CHECK_EQUAL(1, (std::distance(data.begin(), result9.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ.second))); #else - CHECK_EQUAL(0, (std::distance(data.begin(), result0.first))); - CHECK_EQUAL(1, (std::distance(data.begin(), result1.first))); - CHECK_EQUAL(2, (std::distance(data.begin(), result2.first))); - CHECK_EQUAL(3, (std::distance(data.begin(), result3.first))); - CHECK_EQUAL(4, (std::distance(data.begin(), result4.first))); - CHECK_EQUAL(5, (std::distance(data.begin(), result5.first))); - CHECK_EQUAL(6, (std::distance(data.begin(), result6.first))); - CHECK_EQUAL(7, (std::distance(data.begin(), result7.first))); - CHECK_EQUAL(8, (std::distance(data.begin(), result8.first))); - CHECK_EQUAL(9, (std::distance(data.begin(), result9.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ.first))); - CHECK_EQUAL(1, (std::distance(data.begin(), result0.second))); - CHECK_EQUAL(2, (std::distance(data.begin(), result1.second))); - CHECK_EQUAL(3, (std::distance(data.begin(), result2.second))); - CHECK_EQUAL(4, (std::distance(data.begin(), result3.second))); - CHECK_EQUAL(5, (std::distance(data.begin(), result4.second))); - CHECK_EQUAL(6, (std::distance(data.begin(), result5.second))); - CHECK_EQUAL(7, (std::distance(data.begin(), result6.second))); - CHECK_EQUAL(8, (std::distance(data.begin(), result7.second))); - CHECK_EQUAL(9, (std::distance(data.begin(), result8.second))); - CHECK_EQUAL(10, (std::distance(data.begin(), result9.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ.second))); #endif } @@ -823,42 +821,42 @@ namespace value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; #endif - Data::const_iterator result0 = data.lower_bound(Key('A')); - Data::const_iterator result1 = data.lower_bound(Key('B')); - Data::const_iterator result2 = data.lower_bound(Key('C')); - Data::const_iterator result3 = data.lower_bound(Key('D')); - Data::const_iterator result4 = data.lower_bound(Key('E')); - Data::const_iterator result5 = data.lower_bound(Key('F')); - Data::const_iterator result6 = data.lower_bound(Key('G')); - Data::const_iterator result7 = data.lower_bound(Key('H')); - Data::const_iterator result8 = data.lower_bound(Key('I')); - Data::const_iterator result9 = data.lower_bound(Key('J')); - Data::const_iterator result10 = data.lower_bound(Key('K')); + Data::const_iterator resultA = data.lower_bound(Key('A')); + Data::const_iterator resultB = data.lower_bound(Key('B')); + Data::const_iterator resultC = data.lower_bound(Key('C')); + Data::const_iterator resultD = data.lower_bound(Key('D')); + Data::const_iterator resultE = data.lower_bound(Key('E')); + Data::const_iterator resultF = data.lower_bound(Key('F')); + Data::const_iterator resultG = data.lower_bound(Key('G')); + Data::const_iterator resultH = data.lower_bound(Key('H')); + Data::const_iterator resultI = data.lower_bound(Key('I')); + Data::const_iterator resultJ = data.lower_bound(Key('J')); + Data::const_iterator resultK = data.lower_bound(Key('K')); #ifdef TEST_GREATER_THAN - CHECK_EQUAL(10, (std::distance(data.begin(), result0))); - CHECK_EQUAL(9, (std::distance(data.begin(), result1))); - CHECK_EQUAL(8, (std::distance(data.begin(), result2))); - CHECK_EQUAL(7, (std::distance(data.begin(), result3))); - CHECK_EQUAL(6, (std::distance(data.begin(), result4))); - CHECK_EQUAL(5, (std::distance(data.begin(), result5))); - CHECK_EQUAL(4, (std::distance(data.begin(), result6))); - CHECK_EQUAL(3, (std::distance(data.begin(), result7))); - CHECK_EQUAL(2, (std::distance(data.begin(), result8))); - CHECK_EQUAL(1, (std::distance(data.begin(), result9))); - CHECK_EQUAL(0, (std::distance(data.begin(), result10))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); #else - CHECK_EQUAL(0, (std::distance(data.begin(), result0))); - CHECK_EQUAL(1, (std::distance(data.begin(), result1))); - CHECK_EQUAL(2, (std::distance(data.begin(), result2))); - CHECK_EQUAL(3, (std::distance(data.begin(), result3))); - CHECK_EQUAL(3, (std::distance(data.begin(), result4))); - CHECK_EQUAL(4, (std::distance(data.begin(), result5))); - CHECK_EQUAL(5, (std::distance(data.begin(), result6))); - CHECK_EQUAL(6, (std::distance(data.begin(), result7))); - CHECK_EQUAL(7, (std::distance(data.begin(), result8))); - CHECK_EQUAL(8, (std::distance(data.begin(), result9))); - CHECK_EQUAL(9, (std::distance(data.begin(), result10))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultK))); #endif } @@ -873,75 +871,343 @@ namespace value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; #endif - static constexpr Data::const_iterator result0 = data.lower_bound(Key('A')); - static constexpr Data::const_iterator result1 = data.lower_bound(Key('B')); - static constexpr Data::const_iterator result2 = data.lower_bound(Key('C')); - static constexpr Data::const_iterator result3 = data.lower_bound(Key('D')); - static constexpr Data::const_iterator result4 = data.lower_bound(Key('E')); - static constexpr Data::const_iterator result5 = data.lower_bound(Key('F')); - static constexpr Data::const_iterator result6 = data.lower_bound(Key('G')); - static constexpr Data::const_iterator result7 = data.lower_bound(Key('H')); - static constexpr Data::const_iterator result8 = data.lower_bound(Key('I')); - static constexpr Data::const_iterator result9 = data.lower_bound(Key('J')); - static constexpr Data::const_iterator result10 = data.lower_bound(Key('K')); + static constexpr Data::const_iterator resultA = data.lower_bound(Key('A')); + static constexpr Data::const_iterator resultB = data.lower_bound(Key('B')); + static constexpr Data::const_iterator resultC = data.lower_bound(Key('C')); + static constexpr Data::const_iterator resultD = data.lower_bound(Key('D')); + static constexpr Data::const_iterator resultE = data.lower_bound(Key('E')); + static constexpr Data::const_iterator resultF = data.lower_bound(Key('F')); + static constexpr Data::const_iterator resultG = data.lower_bound(Key('G')); + static constexpr Data::const_iterator resultH = data.lower_bound(Key('H')); + static constexpr Data::const_iterator resultI = data.lower_bound(Key('I')); + static constexpr Data::const_iterator resultJ = data.lower_bound(Key('J')); + static constexpr Data::const_iterator resultK = data.lower_bound(Key('K')); #ifdef TEST_GREATER_THAN - CHECK_EQUAL(10, (std::distance(data.begin(), result0))); - CHECK_EQUAL(9, (std::distance(data.begin(), result1))); - CHECK_EQUAL(8, (std::distance(data.begin(), result2))); - CHECK_EQUAL(7, (std::distance(data.begin(), result3))); - CHECK_EQUAL(6, (std::distance(data.begin(), result4))); - CHECK_EQUAL(5, (std::distance(data.begin(), result5))); - CHECK_EQUAL(4, (std::distance(data.begin(), result6))); - CHECK_EQUAL(3, (std::distance(data.begin(), result7))); - CHECK_EQUAL(2, (std::distance(data.begin(), result8))); - CHECK_EQUAL(1, (std::distance(data.begin(), result9))); - CHECK_EQUAL(0, (std::distance(data.begin(), result10))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); #else - CHECK_EQUAL(0, (std::distance(data.begin(), result0))); - CHECK_EQUAL(1, (std::distance(data.begin(), result1))); - CHECK_EQUAL(2, (std::distance(data.begin(), result2))); - CHECK_EQUAL(3, (std::distance(data.begin(), result3))); - CHECK_EQUAL(3, (std::distance(data.begin(), result4))); - CHECK_EQUAL(4, (std::distance(data.begin(), result5))); - CHECK_EQUAL(5, (std::distance(data.begin(), result6))); - CHECK_EQUAL(6, (std::distance(data.begin(), result7))); - CHECK_EQUAL(7, (std::distance(data.begin(), result8))); - CHECK_EQUAL(8, (std::distance(data.begin(), result9))); - CHECK_EQUAL(9, (std::distance(data.begin(), result10))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultK))); #endif } //************************************************************************* TEST(test_lower_bound_using_transparent_comparator) { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; +#endif + Data::const_iterator resultA = data.lower_bound('A'); + Data::const_iterator resultB = data.lower_bound('B'); + Data::const_iterator resultC = data.lower_bound('C'); + Data::const_iterator resultD = data.lower_bound('D'); + Data::const_iterator resultE = data.lower_bound('E'); + Data::const_iterator resultF = data.lower_bound('F'); + Data::const_iterator resultG = data.lower_bound('G'); + Data::const_iterator resultH = data.lower_bound('H'); + Data::const_iterator resultI = data.lower_bound('I'); + Data::const_iterator resultJ = data.lower_bound('J'); + Data::const_iterator resultK = data.lower_bound('K'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultK))); +#endif } //************************************************************************* TEST(test_lower_bound_constexpr_using_transparent_comparator) { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; +#endif + static constexpr Data::const_iterator resultA = data.lower_bound('A'); + static constexpr Data::const_iterator resultB = data.lower_bound('B'); + static constexpr Data::const_iterator resultC = data.lower_bound('C'); + static constexpr Data::const_iterator resultD = data.lower_bound('D'); + static constexpr Data::const_iterator resultE = data.lower_bound('E'); + static constexpr Data::const_iterator resultF = data.lower_bound('F'); + static constexpr Data::const_iterator resultG = data.lower_bound('G'); + static constexpr Data::const_iterator resultH = data.lower_bound('H'); + static constexpr Data::const_iterator resultI = data.lower_bound('I'); + static constexpr Data::const_iterator resultJ = data.lower_bound('J'); + static constexpr Data::const_iterator resultK = data.lower_bound('K'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultK))); +#endif } //************************************************************************* TEST(test_upper_bound) { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; +#endif + + Data::const_iterator resultA = data.upper_bound(Key('A')); + Data::const_iterator resultB = data.upper_bound(Key('B')); + Data::const_iterator resultC = data.upper_bound(Key('C')); + Data::const_iterator resultD = data.upper_bound(Key('D')); + Data::const_iterator resultE = data.upper_bound(Key('E')); + Data::const_iterator resultF = data.upper_bound(Key('F')); + Data::const_iterator resultG = data.upper_bound(Key('G')); + Data::const_iterator resultH = data.upper_bound(Key('H')); + Data::const_iterator resultI = data.upper_bound(Key('I')); + Data::const_iterator resultJ = data.upper_bound(Key('J')); + Data::const_iterator resultK = data.upper_bound(Key('K')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(1, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif } //************************************************************************* TEST(test_upper_bound_constexpr) { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; +#endif + + static constexpr Data::const_iterator resultA = data.upper_bound(Key('A')); + static constexpr Data::const_iterator resultB = data.upper_bound(Key('B')); + static constexpr Data::const_iterator resultC = data.upper_bound(Key('C')); + static constexpr Data::const_iterator resultD = data.upper_bound(Key('D')); + static constexpr Data::const_iterator resultE = data.upper_bound(Key('E')); + static constexpr Data::const_iterator resultF = data.upper_bound(Key('F')); + static constexpr Data::const_iterator resultG = data.upper_bound(Key('G')); + static constexpr Data::const_iterator resultH = data.upper_bound(Key('H')); + static constexpr Data::const_iterator resultI = data.upper_bound(Key('I')); + static constexpr Data::const_iterator resultJ = data.upper_bound(Key('J')); + static constexpr Data::const_iterator resultK = data.upper_bound(Key('K')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(1, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif } //************************************************************************* TEST(test_upper_bound_using_transparent_comparator) { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; +#endif + + Data::const_iterator resultA = data.upper_bound('A'); + Data::const_iterator resultB = data.upper_bound('B'); + Data::const_iterator resultC = data.upper_bound('C'); + Data::const_iterator resultD = data.upper_bound('D'); + Data::const_iterator resultE = data.upper_bound('E'); + Data::const_iterator resultF = data.upper_bound('F'); + Data::const_iterator resultG = data.upper_bound('G'); + Data::const_iterator resultH = data.upper_bound('H'); + Data::const_iterator resultI = data.upper_bound('I'); + Data::const_iterator resultJ = data.upper_bound('J'); + Data::const_iterator resultK = data.upper_bound('K'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(1, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif } //************************************************************************* TEST(test_upper_bound_constexpr_using_transparent_comparator) { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; +#endif + + static constexpr Data::const_iterator resultA = data.upper_bound('A'); + static constexpr Data::const_iterator resultB = data.upper_bound('B'); + static constexpr Data::const_iterator resultC = data.upper_bound('C'); + static constexpr Data::const_iterator resultD = data.upper_bound('D'); + static constexpr Data::const_iterator resultE = data.upper_bound('E'); + static constexpr Data::const_iterator resultF = data.upper_bound('F'); + static constexpr Data::const_iterator resultG = data.upper_bound('G'); + static constexpr Data::const_iterator resultH = data.upper_bound('H'); + static constexpr Data::const_iterator resultI = data.upper_bound('I'); + static constexpr Data::const_iterator resultJ = data.upper_bound('J'); + static constexpr Data::const_iterator resultK = data.upper_bound('K'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(1, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif } //************************************************************************* @@ -1064,46 +1330,6 @@ namespace CHECK_EQUAL(0, countK); } - //************************************************************************* - TEST(test_iterator) - { -#ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; -#endif - - Data::iterator itr = data.begin(); - -#ifdef TEST_GREATER_THAN - CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); - CHECK_TRUE((value_type{Key('I'), 8 }) == *itr++); - CHECK_TRUE((value_type{Key('H'), 7 }) == *itr++); - CHECK_TRUE((value_type{Key('G'), 6 }) == *itr++); - CHECK_TRUE((value_type{Key('F'), 5 }) == *itr++); - CHECK_TRUE((value_type{Key('E'), 4 }) == *itr++); - CHECK_TRUE((value_type{Key('D'), 3 }) == *itr++); - CHECK_TRUE((value_type{Key('C'), 2 }) == *itr++); - CHECK_TRUE((value_type{Key('B'), 1 }) == *itr++); - CHECK_TRUE((value_type{Key('A'), 0 }) == *itr++); - CHECK_TRUE(itr == data.end()); -#else - CHECK_TRUE((value_type{Key('A'), 0 }) == *itr++); - CHECK_TRUE((value_type{Key('B'), 1 }) == *itr++); - CHECK_TRUE((value_type{Key('C'), 2 }) == *itr++); - CHECK_TRUE((value_type{Key('D'), 3 }) == *itr++); - CHECK_TRUE((value_type{Key('E'), 4 }) == *itr++); - CHECK_TRUE((value_type{Key('F'), 5 }) == *itr++); - CHECK_TRUE((value_type{Key('G'), 6 }) == *itr++); - CHECK_TRUE((value_type{Key('H'), 7 }) == *itr++); - CHECK_TRUE((value_type{Key('I'), 8 }) == *itr++); - CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); - CHECK_TRUE(itr == data.end()); -#endif - } - //************************************************************************* TEST(test_const_iterator) { @@ -1155,39 +1381,39 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - Data::const_iterator result0 = data.find(Key('A')); - Data::const_iterator result1 = data.find(Key('B')); - Data::const_iterator result2 = data.find(Key('C')); - Data::const_iterator result3 = data.find(Key('D')); - Data::const_iterator result4 = data.find(Key('E')); - Data::const_iterator result5 = data.find(Key('F')); - Data::const_iterator result6 = data.find(Key('G')); - Data::const_iterator result7 = data.find(Key('H')); - Data::const_iterator result8 = data.find(Key('I')); - Data::const_iterator result9 = data.find(Key('J')); + Data::const_iterator resultA = data.find(Key('A')); + Data::const_iterator resultB = data.find(Key('B')); + Data::const_iterator resultC = data.find(Key('C')); + Data::const_iterator resultD = data.find(Key('D')); + Data::const_iterator resultE = data.find(Key('E')); + Data::const_iterator resultF = data.find(Key('F')); + Data::const_iterator resultG = data.find(Key('G')); + Data::const_iterator resultH = data.find(Key('H')); + Data::const_iterator resultI = data.find(Key('I')); + Data::const_iterator resultJ = data.find(Key('J')); #ifdef TEST_GREATER_THAN - CHECK_EQUAL(9, (std::distance(data.begin(), result0))); - CHECK_EQUAL(8, (std::distance(data.begin(), result1))); - CHECK_EQUAL(7, (std::distance(data.begin(), result2))); - CHECK_EQUAL(6, (std::distance(data.begin(), result3))); - CHECK_EQUAL(5, (std::distance(data.begin(), result4))); - CHECK_EQUAL(4, (std::distance(data.begin(), result5))); - CHECK_EQUAL(3, (std::distance(data.begin(), result6))); - CHECK_EQUAL(2, (std::distance(data.begin(), result7))); - CHECK_EQUAL(1, (std::distance(data.begin(), result8))); - CHECK_EQUAL(0, (std::distance(data.begin(), result9))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); #else - CHECK_EQUAL(0, (std::distance(data.begin(), result0))); - CHECK_EQUAL(1, (std::distance(data.begin(), result1))); - CHECK_EQUAL(2, (std::distance(data.begin(), result2))); - CHECK_EQUAL(3, (std::distance(data.begin(), result3))); - CHECK_EQUAL(4, (std::distance(data.begin(), result4))); - CHECK_EQUAL(5, (std::distance(data.begin(), result5))); - CHECK_EQUAL(6, (std::distance(data.begin(), result6))); - CHECK_EQUAL(7, (std::distance(data.begin(), result7))); - CHECK_EQUAL(8, (std::distance(data.begin(), result8))); - CHECK_EQUAL(9, (std::distance(data.begin(), result9))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); #endif } @@ -1202,39 +1428,39 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr Data::const_iterator result0 = data.find(Key('A')); - static constexpr Data::const_iterator result1 = data.find(Key('B')); - static constexpr Data::const_iterator result2 = data.find(Key('C')); - static constexpr Data::const_iterator result3 = data.find(Key('D')); - static constexpr Data::const_iterator result4 = data.find(Key('E')); - static constexpr Data::const_iterator result5 = data.find(Key('F')); - static constexpr Data::const_iterator result6 = data.find(Key('G')); - static constexpr Data::const_iterator result7 = data.find(Key('H')); - static constexpr Data::const_iterator result8 = data.find(Key('I')); - static constexpr Data::const_iterator result9 = data.find(Key('J')); + static constexpr Data::const_iterator resultA = data.find(Key('A')); + static constexpr Data::const_iterator resultB = data.find(Key('B')); + static constexpr Data::const_iterator resultC = data.find(Key('C')); + static constexpr Data::const_iterator resultD = data.find(Key('D')); + static constexpr Data::const_iterator resultE = data.find(Key('E')); + static constexpr Data::const_iterator resultF = data.find(Key('F')); + static constexpr Data::const_iterator resultG = data.find(Key('G')); + static constexpr Data::const_iterator resultH = data.find(Key('H')); + static constexpr Data::const_iterator resultI = data.find(Key('I')); + static constexpr Data::const_iterator resultJ = data.find(Key('J')); #ifdef TEST_GREATER_THAN - CHECK_EQUAL(9, (std::distance(data.begin(), result0))); - CHECK_EQUAL(8, (std::distance(data.begin(), result1))); - CHECK_EQUAL(7, (std::distance(data.begin(), result2))); - CHECK_EQUAL(6, (std::distance(data.begin(), result3))); - CHECK_EQUAL(5, (std::distance(data.begin(), result4))); - CHECK_EQUAL(4, (std::distance(data.begin(), result5))); - CHECK_EQUAL(3, (std::distance(data.begin(), result6))); - CHECK_EQUAL(2, (std::distance(data.begin(), result7))); - CHECK_EQUAL(1, (std::distance(data.begin(), result8))); - CHECK_EQUAL(0, (std::distance(data.begin(), result9))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); #else - CHECK_EQUAL(0, (std::distance(data.begin(), result0))); - CHECK_EQUAL(1, (std::distance(data.begin(), result1))); - CHECK_EQUAL(2, (std::distance(data.begin(), result2))); - CHECK_EQUAL(3, (std::distance(data.begin(), result3))); - CHECK_EQUAL(4, (std::distance(data.begin(), result4))); - CHECK_EQUAL(5, (std::distance(data.begin(), result5))); - CHECK_EQUAL(6, (std::distance(data.begin(), result6))); - CHECK_EQUAL(7, (std::distance(data.begin(), result7))); - CHECK_EQUAL(8, (std::distance(data.begin(), result8))); - CHECK_EQUAL(9, (std::distance(data.begin(), result9))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); #endif } @@ -1249,39 +1475,39 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - Data::const_iterator result0 = data.find('A'); - Data::const_iterator result1 = data.find('B'); - Data::const_iterator result2 = data.find('C'); - Data::const_iterator result3 = data.find('D'); - Data::const_iterator result4 = data.find('E'); - Data::const_iterator result5 = data.find('F'); - Data::const_iterator result6 = data.find('G'); - Data::const_iterator result7 = data.find('H'); - Data::const_iterator result8 = data.find('I'); - Data::const_iterator result9 = data.find('J'); + Data::const_iterator resultA = data.find('A'); + Data::const_iterator resultB = data.find('B'); + Data::const_iterator resultC = data.find('C'); + Data::const_iterator resultD = data.find('D'); + Data::const_iterator resultE = data.find('E'); + Data::const_iterator resultF = data.find('F'); + Data::const_iterator resultG = data.find('G'); + Data::const_iterator resultH = data.find('H'); + Data::const_iterator resultI = data.find('I'); + Data::const_iterator resultJ = data.find('J'); #ifdef TEST_GREATER_THAN - CHECK_EQUAL(9, (std::distance(data.begin(), result0))); - CHECK_EQUAL(8, (std::distance(data.begin(), result1))); - CHECK_EQUAL(7, (std::distance(data.begin(), result2))); - CHECK_EQUAL(6, (std::distance(data.begin(), result3))); - CHECK_EQUAL(5, (std::distance(data.begin(), result4))); - CHECK_EQUAL(4, (std::distance(data.begin(), result5))); - CHECK_EQUAL(3, (std::distance(data.begin(), result6))); - CHECK_EQUAL(2, (std::distance(data.begin(), result7))); - CHECK_EQUAL(1, (std::distance(data.begin(), result8))); - CHECK_EQUAL(0, (std::distance(data.begin(), result9))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); #else - CHECK_EQUAL(0, (std::distance(data.begin(), result0))); - CHECK_EQUAL(1, (std::distance(data.begin(), result1))); - CHECK_EQUAL(2, (std::distance(data.begin(), result2))); - CHECK_EQUAL(3, (std::distance(data.begin(), result3))); - CHECK_EQUAL(4, (std::distance(data.begin(), result4))); - CHECK_EQUAL(5, (std::distance(data.begin(), result5))); - CHECK_EQUAL(6, (std::distance(data.begin(), result6))); - CHECK_EQUAL(7, (std::distance(data.begin(), result7))); - CHECK_EQUAL(8, (std::distance(data.begin(), result8))); - CHECK_EQUAL(9, (std::distance(data.begin(), result9))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); #endif } @@ -1296,39 +1522,39 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr Data::const_iterator result0 = data.find('A'); - static constexpr Data::const_iterator result1 = data.find('B'); - static constexpr Data::const_iterator result2 = data.find('C'); - static constexpr Data::const_iterator result3 = data.find('D'); - static constexpr Data::const_iterator result4 = data.find('E'); - static constexpr Data::const_iterator result5 = data.find('F'); - static constexpr Data::const_iterator result6 = data.find('G'); - static constexpr Data::const_iterator result7 = data.find('H'); - static constexpr Data::const_iterator result8 = data.find('I'); - static constexpr Data::const_iterator result9 = data.find('J'); + static constexpr Data::const_iterator resultA = data.find('A'); + static constexpr Data::const_iterator resultB = data.find('B'); + static constexpr Data::const_iterator resultC = data.find('C'); + static constexpr Data::const_iterator resultD = data.find('D'); + static constexpr Data::const_iterator resultE = data.find('E'); + static constexpr Data::const_iterator resultF = data.find('F'); + static constexpr Data::const_iterator resultG = data.find('G'); + static constexpr Data::const_iterator resultH = data.find('H'); + static constexpr Data::const_iterator resultI = data.find('I'); + static constexpr Data::const_iterator resultJ = data.find('J'); #ifdef TEST_GREATER_THAN - CHECK_EQUAL(9, (std::distance(data.begin(), result0))); - CHECK_EQUAL(8, (std::distance(data.begin(), result1))); - CHECK_EQUAL(7, (std::distance(data.begin(), result2))); - CHECK_EQUAL(6, (std::distance(data.begin(), result3))); - CHECK_EQUAL(5, (std::distance(data.begin(), result4))); - CHECK_EQUAL(4, (std::distance(data.begin(), result5))); - CHECK_EQUAL(3, (std::distance(data.begin(), result6))); - CHECK_EQUAL(2, (std::distance(data.begin(), result7))); - CHECK_EQUAL(1, (std::distance(data.begin(), result8))); - CHECK_EQUAL(0, (std::distance(data.begin(), result9))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); #else - CHECK_EQUAL(0, (std::distance(data.begin(), result0))); - CHECK_EQUAL(1, (std::distance(data.begin(), result1))); - CHECK_EQUAL(2, (std::distance(data.begin(), result2))); - CHECK_EQUAL(3, (std::distance(data.begin(), result3))); - CHECK_EQUAL(4, (std::distance(data.begin(), result4))); - CHECK_EQUAL(5, (std::distance(data.begin(), result5))); - CHECK_EQUAL(6, (std::distance(data.begin(), result6))); - CHECK_EQUAL(7, (std::distance(data.begin(), result7))); - CHECK_EQUAL(8, (std::distance(data.begin(), result8))); - CHECK_EQUAL(9, (std::distance(data.begin(), result9))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); #endif } diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index b5583df4..0bb7285f 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -3291,6 +3291,7 @@ + @@ -9270,6 +9271,7 @@ + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 3743da7b..00d27413 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1512,6 +1512,9 @@ ETL\Private\chrono + + ETL\Containers + @@ -3593,6 +3596,9 @@ Tests\Chrono + + Tests\Containers + From 62ffe81c1f79bf246a20d01d126ed7474f1cf2ee Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 22 Jun 2025 11:13:07 +0100 Subject: [PATCH 07/12] Modified to have iconst_map base type --- include/etl/const_map.h | 129 +++++++++++++--- test/test_const_map.cpp | 316 ++++++++++++++++++++++++---------------- 2 files changed, 293 insertions(+), 152 deletions(-) diff --git a/include/etl/const_map.h b/include/etl/const_map.h index e31c9641..fd5f9606 100644 --- a/include/etl/const_map.h +++ b/include/etl/const_map.h @@ -44,8 +44,8 @@ SOFTWARE. namespace etl { - template > - class const_map + template + class iconst_map { public: @@ -106,23 +106,6 @@ namespace etl key_compare kcompare; }; - //************************************************************************* - ///\brief Construct a const_map from a variadic list of elements. - /// Static asserts if the element type is not constructible. - /// Static asserts if the elements are not of type value_type. - /// Static asserts if the number of elements is greater than the capacity of the const_map. - //************************************************************************* - template - ETL_CONSTEXPR14 explicit const_map(TElements&&... elements) ETL_NOEXCEPT - : element_list{etl::forward(elements)...} - , element_list_end{element_list + sizeof...(elements)} - { - static_assert((etl::is_default_constructible::value), "key_type must be default constructible"); - static_assert((etl::is_default_constructible::value), "mapped_type must be default constructible"); - static_assert((etl::are_all_same...>::value), "All elements must be value_type"); - static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity"); - } - //************************************************************************* /// Check that the elements are valid for a map. /// The elements must be sorted and contain no duplicates. @@ -403,7 +386,7 @@ namespace etl //************************************************************************* ETL_CONSTEXPR14 size_type full() const ETL_NOEXCEPT { - return size() == Size; + return size() == max_elements; } //************************************************************************* @@ -421,7 +404,7 @@ namespace etl //************************************************************************* ETL_CONSTEXPR14 size_type max_size() const ETL_NOEXCEPT { - return Size; + return max_elements; } //************************************************************************* @@ -431,7 +414,7 @@ namespace etl //************************************************************************* ETL_CONSTEXPR14 size_type capacity() const ETL_NOEXCEPT { - return Size; + return max_elements; } //************************************************************************* @@ -452,6 +435,19 @@ namespace etl return vcompare; } + protected: + + //************************************************************************* + /// Constructor + //************************************************************************* + template + ETL_CONSTEXPR14 explicit iconst_map(value_type* element_list_, size_type size_, size_type max_elements_) ETL_NOEXCEPT + : element_list(element_list_) + , element_list_end{element_list_ + size_} + , max_elements(max_elements_) + { + } + private: //********************************************************************* @@ -474,8 +470,54 @@ namespace etl value_compare vcompare; - value_type element_list[Size]; + value_type* element_list; value_type* element_list_end; + size_type max_elements; + }; + + //********************************************************************* + /// + //********************************************************************* + template > + class const_map : public etl::iconst_map + { + public: + + using base_t = etl::iconst_map; + + using key_type = base_t::key_type; + using value_type = base_t::value_type; + using mapped_type = base_t::mapped_type ; + using key_compare = base_t::key_compare; + using const_reference = base_t::const_reference; + using const_pointer = base_t::const_pointer; + using const_iterator = base_t::const_iterator; + using size_type = base_t::size_type; + + /// Defines the parameter types + using const_key_reference = const key_type&; + using const_mapped_reference = const mapped_type&; + + //************************************************************************* + ///\brief Construct a const_map from a variadic list of elements. + /// Static asserts if the element type is not constructible. + /// Static asserts if the elements are not of type value_type. + /// Static asserts if the number of elements is greater than the capacity of the const_map. + //************************************************************************* + template + ETL_CONSTEXPR14 explicit const_map(TElements&&... elements) ETL_NOEXCEPT + : iconst_map(element_list, sizeof...(elements), Size) + , element_list{etl::forward(elements)...} + { + static_assert((etl::is_default_constructible::value), "key_type must be default constructible"); + static_assert((etl::is_default_constructible::value), "mapped_type must be default constructible"); + static_assert((etl::are_all_same...>::value), "All elements must be value_type"); + static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity"); + } + + private: + + value_type element_list[Size]; }; //************************************************************************* @@ -488,7 +530,6 @@ namespace etl sizeof...(TPairs)>; #endif - //************************************************************************* /// Equality test. //************************************************************************* @@ -508,6 +549,46 @@ namespace etl { return !(lhs == rhs); } + + //************************************************************************* + /// Less-than. + //************************************************************************* + template + ETL_CONSTEXPR14 bool operator <(const etl::const_map& lhs, + const etl::const_map& rhs) + { + return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), TKeyCompare()); + } + + //************************************************************************* + /// Greater-than. + //************************************************************************* + template + ETL_CONSTEXPR14 bool operator >(const etl::const_map& lhs, + const etl::const_map& rhs) + { + return (rhs < lhs); + } + + //************************************************************************* + /// Less-than-equal. + //************************************************************************* + template + ETL_CONSTEXPR14 bool operator <=(const etl::const_map& lhs, + const etl::const_map& rhs) + { + return !(rhs < lhs); + } + + //************************************************************************* + /// Greater-than-equal. + //************************************************************************* + template + ETL_CONSTEXPR14 bool operator >=(const etl::const_map& lhs, + const etl::const_map& rhs) + { + return !(lhs < rhs); + } } #endif diff --git a/test/test_const_map.cpp b/test/test_const_map.cpp index 082efe99..bf46b579 100644 --- a/test/test_const_map.cpp +++ b/test/test_const_map.cpp @@ -111,6 +111,7 @@ namespace #define TEST_GREATER_THAN #ifdef TEST_GREATER_THAN using Data = etl::const_map>; + using IData = etl::iconst_map>; using DataTransparentComparator = etl::const_map>; #else using Data = etl::const_map>; @@ -197,6 +198,37 @@ namespace CHECK_FALSE(begin == end); } + //************************************************************************* + TEST(test_constructor_max_size_status_from_iconst_map) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr const IData& idata = data; + + static constexpr bool is_valid = idata.is_valid(); + static constexpr size_t size = idata.size(); + static constexpr bool empty = idata.empty(); + static constexpr bool full = idata.full(); + static constexpr size_t capacity = idata.capacity(); + static constexpr size_t max_size = idata.max_size(); + static constexpr Data::const_iterator begin = idata.begin(); + static constexpr Data::const_iterator end = idata.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == Max_Size); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_FALSE(begin == end); + } + ////************************************************************************* // Enable to check static_assert "Number of elements exceeds capacity" ////************************************************************************* @@ -1592,138 +1624,62 @@ namespace CHECK_TRUE(data1 != data3); } -// //************************************************************************* -// TEST(test_key_compare) -// { -// const Data data(initial_data.begin(), initial_data.end()); -// -// Data::key_compare compare = data.key_comp(); -// -// Data::key_type a(Key('A'); -// Data::key_type b(Key('B'); -// -//#ifdef TEST_GREATER_THAN -// CHECK(!compare(a, b)); -// CHECK(compare(b, a)); -//#else -// CHECK(compare(a, b)); -// CHECK(!compare(b, a)); -//#endif -// } + //************************************************************************* + TEST(test_key_compare) + { + static constexpr Data data; -// //************************************************************************* -// TEST(test_key_compare_using_transparent_comparator) -// { -// using EMap = etl::map>; -// const EMap data(initial_data.begin(), initial_data.end()); -// -// EMap::key_compare compare = data.key_comp(); -// -// char a(Key('A'); -// Key b(Key('B'); -// -// CHECK(compare(a, b)); -// CHECK(!compare(b, a)); -// } + static constexpr Data::key_compare compare = data.key_comp(); -// //************************************************************************* -// TEST(test_value_compare) -// { -// const Data data(initial_data.begin(), initial_data.end()); -// -// Data::value_compare compare = data.value_comp(); -// -// Data::value_type a(char(Key('A'), 0); -// Data::value_type b(char(Key('B'), 1); -// -//#ifdef TEST_GREATER_THAN -// CHECK(!compare(a, b)); -// CHECK(compare(b, a)); -//#else -// CHECK(compare(a, b)); -// CHECK(!compare(b, a)); -//#endif -// } + static constexpr Data::key_type a(Key('A')); + static constexpr Data::key_type b(Key('B')); -// //************************************************************************* -// TEST(test_compare_lower_upper_bound) -// { -// Data data(initial_data_even.begin(), initial_data_even.end()); -// Compare_Data compare(initial_data_even.begin(), initial_data_even.end()); -// -// std::vector > tab(test_data.begin(), test_data.end()); -// -// //make sure both data and compare contain same elements -// std::vector > data_elements(data.begin(), data.end()); -// std::vector > compare_data_elements(compare.begin(), compare.end()); -// -// CHECK(data_elements == compare_data_elements); -// CHECK(data_elements.size() == Max_Size); -// -// for(std::vector >::iterator it = tab.begin() ; it != tab.end() ; ++it) -// { -// char i = it->first; -// -// //lower_bound -// CHECK((compare.lower_bound(i) == compare.end()) == (data.lower_bound(i) == data.end())); -// //if both end, or none -// if((compare.lower_bound(i) == compare.end()) == (data.lower_bound(i) == data.end())) -// { -// //if both are not end -// if(compare.lower_bound(i) != compare.end()) -// { -// CHECK((*compare.lower_bound(i)) == (*data.lower_bound(i))); -// } -// -// ETL_OR_STD::pair stlret = compare.equal_range(i); -// ETL_OR_STD::pair etlret = data.equal_range(i); -// -// CHECK((stlret.first == compare.end()) == (etlret.first == data.end())); -// if((stlret.first != compare.end()) && (etlret.first != data.end())) -// { -// CHECK((*stlret.first) == (*etlret.first)); -// } -// CHECK((stlret.second == compare.end()) == (etlret.second == data.end())); -// if((stlret.second != compare.end()) && (etlret.second != data.end())) -// { -// CHECK((*stlret.second) == (*etlret.second)); -// } -// } -// -// //upper_bound -// CHECK((compare.upper_bound(i) == compare.end()) == (data.upper_bound(i) == data.end())); -// //if both end, or none -// if((compare.upper_bound(i) == compare.end()) == (data.upper_bound(i) == data.end())) -// { -// //if both are not end -// if(compare.upper_bound(i) != compare.end()) -// { -// CHECK((*compare.upper_bound(i)) == (*data.upper_bound(i))); -// } -// } -// } -// } +#ifdef TEST_GREATER_THAN + CHECK(!compare(a, b)); + CHECK(compare(b, a)); +#else + CHECK(compare(a, b)); + CHECK(!compare(b, a)); +#endif + } -// //************************************************************************* -//#if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) -// TEST(test_map_template_deduction) -// { -// using Pair = std::pair, int>; -// -// etl::map data { Pair{'0', 0}, Pair{'1', 1}, Pair{'2', 2}, Pair{'3', 3}, Pair{'4', 4}, Pair{'5', 5} }; -// -// auto v = *data.begin(); -// using Type = decltype(v); -// CHECK((std::is_same_v)); -// -// CHECK_EQUAL(0, data.at('0')); -// CHECK_EQUAL(1, data.at('1')); -// CHECK_EQUAL(2, data.at('2')); -// CHECK_EQUAL(3, data.at('3')); -// CHECK_EQUAL(4, data.at('4')); -// CHECK_EQUAL(5, data.at('5')); -// } -//#endif + //************************************************************************* + TEST(test_key_compare_using_transparent_comparator) + { + static constexpr DataTransparentComparator data; + + static constexpr DataTransparentComparator::key_compare compare = data.key_comp(); + + static constexpr DataTransparentComparator::key_type a(Key('A')); + static constexpr DataTransparentComparator::key_type b(Key('B')); + +#ifdef TEST_GREATER_THAN + CHECK(!compare(a, b)); + CHECK(compare(b, a)); +#else + CHECK(compare(a, b)); + CHECK(!compare(b, a)); +#endif + } + + //************************************************************************* + TEST(test_value_compare) + { + static constexpr Data data; + + static constexpr Data::value_compare compare = data.value_comp(); + + static constexpr Data::value_type a(Key('A'), 0); + static constexpr Data::value_type b(Key('B'), 1); + +#ifdef TEST_GREATER_THAN + CHECK(!compare(a, b)); + CHECK(compare(b, a)); +#else + CHECK(compare(a, b)); + CHECK(!compare(b, a)); +#endif + } //************************************************************************* TEST(test_contains) @@ -2074,6 +2030,110 @@ namespace CHECK_TRUE(compareAB1); CHECK_TRUE(compareAB2); CHECK_TRUE(compareAB3); +#endif + } + + //************************************************************************* + TEST(test_less_than) + { + static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(data1 < data2); + CHECK_FALSE(data2 < data3); + CHECK_TRUE(data2 < data1); + CHECK_TRUE(data3 < data2); +#else + CHECK_TRUE(data1 < data2); + CHECK_TRUE(data2 < data3); + CHECK_FALSE(data2 < data1); + CHECK_FALSE(data3 < data2); +#endif + } + + //************************************************************************* + TEST(test_less_than_equal) + { + static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(data1 <= data2); + CHECK_FALSE(data2 <= data3); + CHECK_TRUE(data2 <= data1); + CHECK_TRUE(data3 <= data2); + CHECK_TRUE(data1 <= data1); +#else + CHECK_TRUE(data1 <= data2); + CHECK_TRUE(data2 <= data3); + CHECK_FALSE(data2 <= data1); + CHECK_FALSE(data3 <= data2); + CHECK_TRUE(data1 <= data1); +#endif + } + + //************************************************************************* + TEST(test_greater_than) + { + static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(data1 > data2); + CHECK_TRUE(data2 > data3); + CHECK_FALSE(data2 > data1); + CHECK_FALSE(data3 > data2); +#else + CHECK_FALSE(data1 > data2); + CHECK_FALSE(data2 > data3); + CHECK_TRUE(data2 > data1); + CHECK_TRUE(data3 > data2); +#endif + } + + //************************************************************************* + TEST(test_greater_than_equal) + { + static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(data1 >= data2); + CHECK_TRUE(data2 >= data3); + CHECK_FALSE(data2 >= data1); + CHECK_FALSE(data3 >= data2); + CHECK_TRUE(data1 <= data1); +#else + CHECK_FALSE(data1 >= data2); + CHECK_FALSE(data2 >= data3); + CHECK_TRUE(data2 >= data1); + CHECK_TRUE(data3 >= data2); + CHECK_TRUE(data1 <= data1); #endif } }; From d458811c263a0a237ca73ecff2922bad3b94b654 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 24 Jun 2025 13:19:56 +0100 Subject: [PATCH 08/12] Added value_compare to lexicographical_compare call --- include/etl/map.h | 4 +++- include/etl/multimap.h | 4 +++- include/etl/multiset.h | 7 +++---- include/etl/set.h | 4 +++- test/test_map.cpp | 2 -- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/etl/map.h b/include/etl/map.h index abad1aaf..4e3b4cfc 100644 --- a/include/etl/map.h +++ b/include/etl/map.h @@ -2859,7 +2859,9 @@ namespace etl template bool operator <(const etl::imap& lhs, const etl::imap& rhs) { - return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); + return etl::lexicographical_compare(lhs.begin(), lhs.end(), + rhs.begin(), rhs.end(), + lhs.value_comp()); } //************************************************************************* diff --git a/include/etl/multimap.h b/include/etl/multimap.h index 1bb7235a..59f0d001 100644 --- a/include/etl/multimap.h +++ b/include/etl/multimap.h @@ -2506,7 +2506,9 @@ namespace etl template bool operator <(const etl::imultimap& lhs, const etl::imultimap& rhs) { - return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); + return etl::lexicographical_compare(lhs.begin(), lhs.end(), + rhs.begin(), rhs.end(), + lhs.value_comp()); } //************************************************************************* diff --git a/include/etl/multiset.h b/include/etl/multiset.h index 46b3aa85..a44fe751 100644 --- a/include/etl/multiset.h +++ b/include/etl/multiset.h @@ -2486,10 +2486,9 @@ namespace etl template bool operator <(const etl::imultiset& lhs, const etl::imultiset& rhs) { - return ETL_OR_STD::lexicographical_compare(lhs.begin(), - lhs.end(), - rhs.begin(), - rhs.end()); + return ETL_OR_STD::lexicographical_compare(lhs.begin(), lhs.end(), + rhs.begin(), rhs.end(), + etl::imultiset::value_compare()); } //************************************************************************* diff --git a/include/etl/set.h b/include/etl/set.h index ff8823c1..fa7d077a 100644 --- a/include/etl/set.h +++ b/include/etl/set.h @@ -2737,7 +2737,9 @@ namespace etl template bool operator <(const etl::iset& lhs, const etl::iset& rhs) { - return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); + return etl::lexicographical_compare(lhs.begin(), lhs.end(), + rhs.begin(), rhs.end(), + etl::iset::value_compare()); } //************************************************************************* diff --git a/test/test_map.cpp b/test/test_map.cpp index 776031a9..c2e4527c 100644 --- a/test/test_map.cpp +++ b/test/test_map.cpp @@ -501,8 +501,6 @@ namespace CMap compare_data(initial_data.begin(), initial_data.end()); EMap data(initial_data.begin(), initial_data.end()); - auto v = data.at("3"); - CHECK(data.at(Key("0")) == compare_data.at("0")); CHECK(data.at(Key("1")) == compare_data.at("1")); CHECK(data.at(Key("2")) == compare_data.at("2")); From e84be139c5a58ff199f03a6229002818ed9698ed Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 24 Jun 2025 13:24:17 +0100 Subject: [PATCH 09/12] Split classes into ETL standard top level and 'i' base classes. Split into const and constexpr unit tests files --- include/etl/const_map.h | 67 +- include/etl/const_multimap.h | 569 ++++++++ test/CMakeLists.txt | 4 + test/test_const_map.cpp | 1811 ++++++++---------------- test/test_const_map_constexpr.cpp | 1565 ++++++++++++++++++++ test/test_const_multimap.cpp | 1270 +++++++++++++++++ test/test_const_multimap_constexpr.cpp | 1243 ++++++++++++++++ test/vs2022/etl.vcxproj | 4 + test/vs2022/etl.vcxproj.filters | 12 + 9 files changed, 5320 insertions(+), 1225 deletions(-) create mode 100644 include/etl/const_multimap.h create mode 100644 test/test_const_map_constexpr.cpp create mode 100644 test/test_const_multimap.cpp create mode 100644 test/test_const_multimap_constexpr.cpp diff --git a/include/etl/const_map.h b/include/etl/const_map.h index fd5f9606..01a2830d 100644 --- a/include/etl/const_map.h +++ b/include/etl/const_map.h @@ -32,6 +32,11 @@ SOFTWARE. #define ETL_CONST_MAP_INCLUDED #include "platform.h" + +#if ETL_NOT_USING_CPP11 + #error NOT SUPPORTED FOR C++03 OR BELOW +#endif + #include "algorithm.h" #include "type_traits.h" #include "functional.h" @@ -476,23 +481,23 @@ namespace etl }; //********************************************************************* - /// + /// Map type designed for constexpr. //********************************************************************* template > - class const_map : public etl::iconst_map + class const_map : public iconst_map { public: - using base_t = etl::iconst_map; + using base_t = iconst_map; - using key_type = base_t::key_type; - using value_type = base_t::value_type; - using mapped_type = base_t::mapped_type ; - using key_compare = base_t::key_compare; - using const_reference = base_t::const_reference; - using const_pointer = base_t::const_pointer; - using const_iterator = base_t::const_iterator; - using size_type = base_t::size_type; + using key_type = typename base_t::key_type; + using value_type = typename base_t::value_type; + using mapped_type = typename base_t::mapped_type ; + using key_compare = typename base_t::key_compare; + using const_reference = typename base_t::const_reference; + using const_pointer = typename base_t::const_pointer; + using const_iterator = typename base_t::const_iterator; + using size_type = typename base_t::size_type; /// Defines the parameter types using const_key_reference = const key_type&; @@ -533,9 +538,9 @@ namespace etl //************************************************************************* /// Equality test. //************************************************************************* - template - ETL_CONSTEXPR14 bool operator ==(const etl::const_map& lhs, - const etl::const_map& rhs) + template + ETL_CONSTEXPR14 bool operator ==(const etl::iconst_map& lhs, + const etl::iconst_map& rhs) { return etl::equal(lhs.begin(), lhs.end(), rhs.begin()); } @@ -543,9 +548,9 @@ namespace etl //************************************************************************* /// Inequality test. //************************************************************************* - template - ETL_CONSTEXPR14 bool operator !=(const etl::const_map& lhs, - const etl::const_map& rhs) + template + ETL_CONSTEXPR14 bool operator !=(const etl::iconst_map& lhs, + const etl::iconst_map& rhs) { return !(lhs == rhs); } @@ -553,19 +558,21 @@ namespace etl //************************************************************************* /// Less-than. //************************************************************************* - template - ETL_CONSTEXPR14 bool operator <(const etl::const_map& lhs, - const etl::const_map& rhs) + template + ETL_CONSTEXPR14 bool operator <(const etl::iconst_map& lhs, + const etl::iconst_map& rhs) { - return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), TKeyCompare()); + return etl::lexicographical_compare(lhs.begin(), lhs.end(), + rhs.begin(), rhs.end(), + lhs.value_comp()); } //************************************************************************* /// Greater-than. //************************************************************************* - template - ETL_CONSTEXPR14 bool operator >(const etl::const_map& lhs, - const etl::const_map& rhs) + template + ETL_CONSTEXPR14 bool operator >(const etl::iconst_map& lhs, + const etl::iconst_map& rhs) { return (rhs < lhs); } @@ -573,9 +580,9 @@ namespace etl //************************************************************************* /// Less-than-equal. //************************************************************************* - template - ETL_CONSTEXPR14 bool operator <=(const etl::const_map& lhs, - const etl::const_map& rhs) + template + ETL_CONSTEXPR14 bool operator <=(const etl::iconst_map& lhs, + const etl::iconst_map& rhs) { return !(rhs < lhs); } @@ -583,9 +590,9 @@ namespace etl //************************************************************************* /// Greater-than-equal. //************************************************************************* - template - ETL_CONSTEXPR14 bool operator >=(const etl::const_map& lhs, - const etl::const_map& rhs) + template + ETL_CONSTEXPR14 bool operator >=(const etl::iconst_map& lhs, + const etl::iconst_map& rhs) { return !(lhs < rhs); } diff --git a/include/etl/const_multimap.h b/include/etl/const_multimap.h new file mode 100644 index 00000000..dd27984b --- /dev/null +++ b/include/etl/const_multimap.h @@ -0,0 +1,569 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CONST_MULTIMAP_INCLUDED +#define ETL_CONST_MULTIMAP_INCLUDED + +#include "platform.h" + +#if ETL_NOT_USING_CPP11 + #error NOT SUPPORTED FOR C++03 OR BELOW +#endif + +#include "algorithm.h" +#include "type_traits.h" +#include "functional.h" +#include "nth_type.h" + +#include "private/comparator_is_transparent.h" + +///\defgroup const_multimap const_multimap +///\ingroup containers + +namespace etl +{ + template > + class iconst_multimap + { + public: + + using key_type = TKey; + using value_type = ETL_OR_STD::pair; + using mapped_type = TMapped ; + using key_compare = TKeyCompare; + using const_reference = const value_type&; + using const_pointer = const value_type*; + using const_iterator = const value_type*; + using size_type = size_t; + + /// Defines the parameter types + using const_key_reference = const key_type&; + using const_mapped_reference = const mapped_type&; + + //********************************************************************* + /// How to compare elements and keys. + //********************************************************************* + class value_compare + { + public: + + // Compare two value types. + ETL_CONSTEXPR14 bool operator ()(const value_type& element1, const value_type& element2) const ETL_NOEXCEPT + { + return kcompare(element1.first, element2.first); + } + + // Compare value type and key. + ETL_CONSTEXPR14 bool operator ()(const value_type& element, const_key_reference key) const ETL_NOEXCEPT + { + return kcompare(element.first, key); + } + + // Compare value types and key. + // Enabled for transparent comparators. + template ::value, int> = 0> + ETL_CONSTEXPR14 bool operator ()(const value_type& element, const K& key) const ETL_NOEXCEPT + { + return kcompare(element.first, key); + } + + // Compare key and value type. + ETL_CONSTEXPR14 bool operator ()(const_key_reference key, const value_type& element) const ETL_NOEXCEPT + { + return kcompare(key, element.first); + } + + // Compare key and value type. + // Enabled for transparent comparators. + template ::value, int> = 0> + ETL_CONSTEXPR14 bool operator ()(const K& key, const value_type& element) const ETL_NOEXCEPT + { + return kcompare(key, element.first); + } + + key_compare kcompare; + }; + + //************************************************************************* + /// Check that the elements are valid for a multimap. + /// The elements must be sorted. + /// \return true if the elements are valid for the map. + //************************************************************************* + ETL_CONSTEXPR14 bool is_valid() const ETL_NOEXCEPT + { + return etl::is_sorted(begin(), end(), vcompare); + } + + //************************************************************************* + ///\brief Gets the beginning of the map. + ///\return const_iterator to the beginning of the map. + //************************************************************************* + ETL_CONSTEXPR14 const_iterator begin() const ETL_NOEXCEPT + { + return element_list; + } + + //************************************************************************* + ///\brief Gets the beginning of the map. + ///\return const_iterator to the beginning of the map. + //************************************************************************* + ETL_CONSTEXPR14 const_iterator cbegin() const ETL_NOEXCEPT + { + return element_list; + } + + //************************************************************************* + ///\brief Gets the end of the map. + ///\return const_iterator to the end of the map. + //************************************************************************* + ETL_CONSTEXPR14 const_iterator end() const ETL_NOEXCEPT + { + return element_list_end; + } + + //************************************************************************* + ///\brief Gets the end of the map. + ///\return const_iterator to the end of the map. + //************************************************************************* + ETL_CONSTEXPR14 const_iterator cend() const ETL_NOEXCEPT + { + return element_list_end; + } + + //************************************************************************* + ///\brief Gets the beginning of the map. + ///\return const_pointer to the beginning of the map. + //************************************************************************* + ETL_CONSTEXPR14 const_pointer data() const ETL_NOEXCEPT + { + return element_list; + } + + //************************************************************************* + ///\brief Gets a const_iterator to the mapped value at the key index. + ///\param key The key of the element to find. + ///\return A const_iterator to the mapped value at the index, + /// or end() if not found. + //************************************************************************* + ETL_CONSTEXPR14 const_iterator find(const_key_reference key) const ETL_NOEXCEPT + { + const_iterator itr = lower_bound(key); + + if ((itr != end()) && (keys_are_equal(itr->first, key))) + { + return itr; + } + + return end(); + } + + //************************************************************************* + ///\brief Gets a const_iterator to the mapped value at the key index. + /// Enabled if the comparator is transparent. + ///\param key The key of the element to find. + ///\return A const_iterator to the mapped value at the index, + /// or end() if not found. + //************************************************************************* + template ::value, int> = 0> + ETL_CONSTEXPR14 const_iterator find(const K& key) const ETL_NOEXCEPT + { + const_iterator itr = lower_bound(key); + + if ((itr != end()) && (keys_are_equal(itr->first, key))) + { + return itr; + } + + return end(); + } + + //************************************************************************* + ///\brief Checks if the map contains an element with key. + ///\param key The key of the element to check. + ///\return true if the map contains an element with key. + //************************************************************************* + ETL_CONSTEXPR14 bool contains(const_key_reference key) const ETL_NOEXCEPT + { + return find(key) != end(); + } + + //************************************************************************* + ///\brief Checks if the map contains an element with key. + /// Enabled if the comparator is transparent. + ///\param key The key of the element to check. + ///\return true if the map contains an element with key. + //************************************************************************* + template ::value, int> = 0> + ETL_CONSTEXPR14 bool contains(const K& key) const ETL_NOEXCEPT + { + return find(key) != end(); + } + + //************************************************************************* + ///\brief Counts the numbeer elements with key. + ///\param key The key of the element to count. + ///\return 0 or 1 + //************************************************************************* + ETL_CONSTEXPR14 size_type count(const_key_reference key) const ETL_NOEXCEPT + { + auto range = equal_range(key); + + return size_type(etl::distance(range.first, range.second)); + } + + //************************************************************************* + ///\brief Counts the numbeer elements with key. + /// Enabled if the comparator is transparent. + ///\param key The key of the element to count. + ///\return 0 or 1 + //************************************************************************* + template ::value, int> = 0> + ETL_CONSTEXPR14 size_type count(const K& key) const ETL_NOEXCEPT + { + auto range = equal_range(key); + + return size_type(etl::distance(range.first, range.second)); + } + + //************************************************************************* + ///\brief Returns a range containing all elements with the key. + /// The range is defined by a pair of two iterators, one to the + /// first element that is not less than the key and second to the first + /// element greater than the key. + ///\param key The key of the element + ///\return etl::pair or std::pair containing a pair of iterators. + //************************************************************************* + ETL_CONSTEXPR14 ETL_OR_STD::pair equal_range(const_key_reference key) const ETL_NOEXCEPT + { + return etl::equal_range(begin(), end(), key, vcompare); + } + + //************************************************************************* + ///\brief Returns a range containing all elements with the key. + /// The range is defined by a pair of two iterators, one to the + /// first element that is not less than the key and second to the first + /// element greater than the key. + /// Enabled if the comparator is transparent. + ///\param key The key of the element + ///\return etl::pair or std::pair containing a pair of iterators. + //************************************************************************* + template ::value, int> = 0> + ETL_CONSTEXPR14 ETL_OR_STD::pair equal_range(const K& key) const ETL_NOEXCEPT + { + return etl::equal_range(begin(), end(), key, vcompare); + } + + //************************************************************************* + ///\brief Returns a const_iterator to the first element that is not less than the key. + /// Returns a const_iterator to the first element that is not less than the key. + ///\param key The key of the element + ///\return const_iterator to the element or end() + //************************************************************************* + ETL_CONSTEXPR14 const_iterator lower_bound(const_key_reference key) const ETL_NOEXCEPT + { + return etl::lower_bound(begin(), end(), key, vcompare); + } + + //************************************************************************* + ///\brief Returns a const_iterator to the first element that is not less than the key. + /// Returns a const_iterator to the first element that is not less than the key. + /// Enabled if the comparator is transparent. + ///\param key The key of the element + ///\return const_iterator to the element or end() + //************************************************************************* + template ::value, int> = 0> + ETL_CONSTEXPR14 const_iterator lower_bound(const K& key) const ETL_NOEXCEPT + { + return etl::lower_bound(begin(), end(), key, vcompare); + } + + //************************************************************************* + ///\brief Returns a const_iterator to the first element that is greater than the key. + /// Returns a const_iterator to the first element that is greater than the key. + ///\param key The key of the element + ///\return const_iterator to the element or end() + //************************************************************************* + ETL_CONSTEXPR14 const_iterator upper_bound(const_key_reference key) const ETL_NOEXCEPT + { + return etl::upper_bound(begin(), end(), key, vcompare); + } + + //************************************************************************* + ///\brief Returns a const_iterator to the first element that is greater than the key. + /// Returns a const_iterator to the first element that is greater than the key. + /// Enabled if the comparator is transparent. + ///\param key The key of the element + ///\return const_iterator to the element or end() + //************************************************************************* + template ::value, int> = 0> + ETL_CONSTEXPR14 const_iterator upper_bound(const K& key) const ETL_NOEXCEPT + { + return etl::upper_bound(begin(), end(), key, vcompare); + } + + //************************************************************************* + /// Checks if the map is empty. + ///\return true if the map is empty. + //************************************************************************* + ETL_CONSTEXPR14 size_type empty() const ETL_NOEXCEPT + { + return size() == 0U; + } + + //************************************************************************* + /// Checks if the map is full. + ///\return true if the map is full. + //************************************************************************* + ETL_CONSTEXPR14 size_type full() const ETL_NOEXCEPT + { + return size() == max_elements; + } + + //************************************************************************* + /// Gets the size of the map. + ///\return The size of the map. + //************************************************************************* + ETL_CONSTEXPR14 size_type size() const ETL_NOEXCEPT + { + return size_type(element_list_end - element_list); + } + + //************************************************************************* + /// Gets the maximum size of the map. + ///\return The maximum size of the map. + //************************************************************************* + ETL_CONSTEXPR14 size_type max_size() const ETL_NOEXCEPT + { + return max_elements; + } + + //************************************************************************* + /// Gets the capacity of the map. + /// This is always equal to max_size(). + ///\return The capacity of the map. + //************************************************************************* + ETL_CONSTEXPR14 size_type capacity() const ETL_NOEXCEPT + { + return max_elements; + } + + //************************************************************************* + /// How to compare two key elements. + ///\return An instance of the key_compare type. + //************************************************************************* + ETL_CONSTEXPR14 key_compare key_comp() const ETL_NOEXCEPT + { + return vcompare.kcompare; + } + + //************************************************************************* + /// How to compare two value elements. + ///\return An instance of the value_compare type. + //************************************************************************* + ETL_CONSTEXPR14 value_compare value_comp() const ETL_NOEXCEPT + { + return vcompare; + } + + protected: + + //************************************************************************* + /// Constructor + //************************************************************************* + template + ETL_CONSTEXPR14 explicit iconst_multimap(value_type* element_list_, size_type size_, size_type max_elements_) ETL_NOEXCEPT + : element_list(element_list_) + , element_list_end{element_list_ + size_} + , max_elements(max_elements_) + { + } + + private: + + //********************************************************************* + /// Check to see if the keys are equal. + //********************************************************************* + ETL_CONSTEXPR14 bool keys_are_equal(const_key_reference key1, const_key_reference key2) const ETL_NOEXCEPT + { + return !key_compare()(key1, key2) && !key_compare()(key2, key1); + } + + //********************************************************************* + /// Check to see if the keys are equal. + /// Enabled if the comparator is transparent. + //********************************************************************* + template ::value, int> = 0> + ETL_CONSTEXPR14 bool keys_are_equal(const K1& key1, const K2& key2) const ETL_NOEXCEPT + { + return !key_compare()(key1, key2) && !key_compare()(key2, key1); + } + + value_compare vcompare; + + value_type* element_list; + value_type* element_list_end; + size_type max_elements; + }; + + //************************************************************************* + /// Multimap type designed for constexpr. + //************************************************************************* + template > + class const_multimap : public iconst_multimap + { + public: + + using base_t = iconst_multimap; + + using key_type = typename base_t::key_type; + using value_type = typename base_t::value_type; + using mapped_type = typename base_t::mapped_type; + using key_compare = typename base_t::key_compare; + using const_reference = typename base_t::const_reference; + using const_pointer = typename base_t::const_pointer; + using const_iterator = typename base_t::const_iterator; + using size_type = typename base_t::size_type; + + /// Defines the parameter types + using const_key_reference = const key_type&; + using const_mapped_reference = const mapped_type&; + + //************************************************************************* + ///\brief Construct a const_map from a variadic list of elements. + /// Static asserts if the element type is not constructible. + /// Static asserts if the elements are not of type value_type. + /// Static asserts if the number of elements is greater than the capacity of the const_map. + //************************************************************************* + template + ETL_CONSTEXPR14 explicit const_multimap(TElements&&... elements) ETL_NOEXCEPT + : iconst_multimap(element_list, sizeof...(elements), Size) + , element_list{etl::forward(elements)...} + { + static_assert((etl::is_default_constructible::value), "key_type must be default constructible"); + static_assert((etl::is_default_constructible::value), "mapped_type must be default constructible"); + static_assert((etl::are_all_same...>::value), "All elements must be value_type"); + static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity"); + } + + private: + + value_type element_list[Size]; + }; + + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_USING_CPP17 + template + const_multimap(TPairs...) -> const_multimap::first_type, + typename etl::nth_type_t<0, TPairs...>::second_type, + sizeof...(TPairs)>; +#endif + + //************************************************************************* + /// Equality test. + //************************************************************************* + template + ETL_CONSTEXPR14 bool operator ==(const etl::iconst_multimap& lhs, + const etl::iconst_multimap& rhs) + { + return etl::equal(lhs.begin(), lhs.end(), rhs.begin()); + } + + //************************************************************************* + /// Inequality test. + //************************************************************************* + template + ETL_CONSTEXPR14 bool operator !=(const etl::iconst_multimap& lhs, + const etl::iconst_multimap& rhs) + { + return !(lhs == rhs); + } + + //************************************************************************* + /// Less than operator. + ///\param lhs Reference to the first list. + ///\param rhs Reference to the second list. + ///\return true if the first list is lexicographically less than the + /// second, otherwise false. + //************************************************************************* + template + ETL_CONSTEXPR14 bool operator <(const etl::iconst_multimap& lhs, + const etl::iconst_multimap& rhs) ETL_NOEXCEPT + { + return etl::lexicographical_compare(lhs.begin(), lhs.end(), + rhs.begin(), rhs.end(), + lhs.value_comp()); + } + + //************************************************************************* + /// Greater than operator. + ///\param lhs Reference to the first list. + ///\param rhs Reference to the second list. + ///\return true if the first list is lexicographically greater than the + /// second, otherwise false. + //************************************************************************* + template + ETL_CONSTEXPR14 bool operator >(const etl::iconst_multimap& lhs, + const etl::iconst_multimap& rhs) ETL_NOEXCEPT + { + return (rhs < lhs); + } + + //************************************************************************* + /// Less than or equal operator. + ///\param lhs Reference to the first list. + ///\param rhs Reference to the second list. + ///\return true if the first list is lexicographically less than or equal + /// to the second, otherwise false. + //************************************************************************* + template + ETL_CONSTEXPR14 bool operator <=(const etl::iconst_multimap& lhs, + const etl::iconst_multimap& rhs) ETL_NOEXCEPT + { + return !(rhs < lhs); + } + + //************************************************************************* + /// Greater than or equal operator. + ///\param lhs Reference to the first list. + ///\param rhs Reference to the second list. + ///\return true if the first list is lexicographically greater than or + /// equal to the second, otherwise false. + //************************************************************************* + template + ETL_CONSTEXPR14 bool operator >=(const etl::iconst_multimap& lhs, + const etl::iconst_multimap& rhs) ETL_NOEXCEPT + { + return !(lhs < rhs); + } +} + +#endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 79c21682..fb1fafb8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -56,6 +56,10 @@ add_executable(etl_tests test_callback_timer_atomic.cpp test_callback_timer_interrupt.cpp test_callback_timer_locked.cpp + test_const_map.cpp + test_const_map_constexpr.cpp + test_const_multimap.cpp + test_const_multimap_constexpr.cpp test_char_traits.cpp test_checksum.cpp test_chrono_clocks.cpp diff --git a/test/test_const_map.cpp b/test/test_const_map.cpp index bf46b579..40624772 100644 --- a/test/test_const_map.cpp +++ b/test/test_const_map.cpp @@ -84,24 +84,6 @@ namespace return (lhs < rhs.k); } - // Greater-than operator for Key < Key - constexpr bool operator >(const Key& lhs, const Key& rhs) noexcept - { - return (lhs.k > rhs.k); - } - - // Greater-than operator for Key > char - constexpr bool operator >(const Key& lhs, char rhs) noexcept - { - return (lhs.k > rhs); - } - - // Greater-than operator for char > Key - constexpr bool operator >(char lhs, const Key& rhs) noexcept - { - return (lhs > rhs.k); - } - // Greater-than operator for char > Key constexpr bool operator ==(const Key& lhs, const Key& rhs) noexcept { @@ -110,12 +92,15 @@ namespace #define TEST_GREATER_THAN #ifdef TEST_GREATER_THAN - using Data = etl::const_map>; - using IData = etl::iconst_map>; - using DataTransparentComparator = etl::const_map>; + using Data = etl::const_map>; + using IData = etl::iconst_map>; + using DataTransparentComparator = etl::const_map>; + using IDataTransparentComparator = etl::iconst_map>; #else - using Data = etl::const_map>; - using DataTransparentComparator = etl::const_map>; + using Data = etl::const_map>; + using IData = etl::iconst_map>; + using DataTransparentComparator = etl::const_map>; + using IDataTransparentComparator = etl::iconst_map>; #endif using value_type = Data::value_type; @@ -126,16 +111,16 @@ namespace //************************************************************************* TEST(test_default_constructor) { - static constexpr Data data; + static const Data data; - static constexpr bool is_valid = data.is_valid(); - static constexpr size_t size = data.size(); - static constexpr bool empty = data.empty(); - static constexpr bool full = data.full(); - static constexpr size_t capacity = data.capacity(); - static constexpr size_t max_size = data.max_size(); - static constexpr Data::const_iterator begin = data.begin(); - static constexpr Data::const_iterator end = data.end(); + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const Data::const_iterator begin = data.begin(); + static const Data::const_iterator end = data.end(); CHECK_TRUE(is_valid); CHECK_TRUE(size == 0UL); @@ -149,16 +134,16 @@ namespace //************************************************************************* TEST(test_constructor_min_size) { - static constexpr Data data{ value_type{Key('A'), 0 } }; + static const Data data{ value_type{Key('A'), 0 } }; - static constexpr bool is_valid = data.is_valid(); - static constexpr size_t size = data.size(); - static constexpr bool empty = data.empty(); - static constexpr bool full = data.full(); - static constexpr size_t capacity = data.capacity(); - static constexpr size_t max_size = data.max_size(); - static constexpr Data::const_iterator begin = data.begin(); - static constexpr Data::const_iterator end = data.end(); + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const Data::const_iterator begin = data.begin(); + static const Data::const_iterator end = data.end(); CHECK_TRUE(is_valid); CHECK_TRUE(size == 1U); @@ -173,21 +158,21 @@ namespace TEST(test_constructor_max_size) { #ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + static const Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr bool is_valid = data.is_valid(); - static constexpr size_t size = data.size(); - static constexpr bool empty = data.empty(); - static constexpr bool full = data.full(); - static constexpr size_t capacity = data.capacity(); - static constexpr size_t max_size = data.max_size(); - static constexpr Data::const_iterator begin = data.begin(); - static constexpr Data::const_iterator end = data.end(); + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const Data::const_iterator begin = data.begin(); + static const Data::const_iterator end = data.end(); CHECK_TRUE(is_valid); CHECK_TRUE(size == Max_Size); @@ -202,23 +187,23 @@ namespace TEST(test_constructor_max_size_status_from_iconst_map) { #ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + static const Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr const IData& idata = data; + static const IData& idata = data; - static constexpr bool is_valid = idata.is_valid(); - static constexpr size_t size = idata.size(); - static constexpr bool empty = idata.empty(); - static constexpr bool full = idata.full(); - static constexpr size_t capacity = idata.capacity(); - static constexpr size_t max_size = idata.max_size(); - static constexpr Data::const_iterator begin = idata.begin(); - static constexpr Data::const_iterator end = idata.end(); + static const bool is_valid = idata.is_valid(); + static const size_t size = idata.size(); + static const bool empty = idata.empty(); + static const bool full = idata.full(); + static const size_t capacity = idata.capacity(); + static const size_t max_size = idata.max_size(); + static const Data::const_iterator begin = idata.begin(); + static const Data::const_iterator end = idata.end(); CHECK_TRUE(is_valid); CHECK_TRUE(size == Max_Size); @@ -234,9 +219,9 @@ namespace ////************************************************************************* //TEST(test_constructor_excess_size) //{ - // static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - // value_type{Key('F'), 5 }, value_type{'G'), 6 }, value_type{'H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, - // value_type{Key('K'), 10 } }; + // static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + // value_type{Key('F'), 5 }, value_type{'G'), 6 }, value_type{'H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, + // value_type{Key('K'), 10 } }; //} #if ETL_USING_CPP17 @@ -244,11 +229,11 @@ namespace TEST(test_cpp17_deduced_constructor) { #ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + static const Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif #ifdef TEST_GREATER_THAN @@ -272,15 +257,15 @@ namespace TEST(test_begin) { #ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + static const Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif CHECK_TRUE(data.is_valid()); - auto value = *data.begin(); + static const auto value = *data.begin(); #ifdef TEST_GREATER_THAN CHECK_TRUE((value_type{ Key('J'), 9 }) == value); @@ -290,42 +275,12 @@ namespace } //************************************************************************* - TEST(test_begin_constexpr) + TEST(test_end_const) { -#ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; -#endif - - CHECK_TRUE(data.is_valid()); - static constexpr auto value = *data.begin(); - -#ifdef TEST_GREATER_THAN - CHECK_TRUE((value_type{ Key('J'), 9 }) == value); -#else - CHECK_TRUE((value_type{ Key('A'), 0 }) == value); -#endif - } - - //************************************************************************* - TEST(test_end) - { - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - CHECK_TRUE(data.end() == (data.begin() + data.size())); - } - - //************************************************************************* - TEST(test_end_constexpr) - { - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - - static constexpr Data::const_iterator end_itr = data.end(); + static const Data::const_iterator end_itr = data.end(); CHECK_TRUE(end_itr == (data.begin() + data.size())); } @@ -334,47 +289,23 @@ namespace TEST(test_index) { #ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + static const Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - CHECK_TRUE(data.is_valid()); - CHECK(data[Key('A')] == 0); - CHECK(data[Key('B')] == 1); - CHECK(data[Key('C')] == 2); - CHECK(data[Key('D')] == 3); - CHECK(data[Key('E')] == 4); - CHECK(data[Key('F')] == 5); - CHECK(data[Key('G')] == 6); - CHECK(data[Key('H')] == 7); - CHECK(data[Key('I')] == 8); - CHECK(data[Key('J')] == 9); - } - - //************************************************************************* - TEST(test_index_constexpr) - { -#ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; -#endif - - static constexpr Data::mapped_type atA = data[Key('A')]; - static constexpr Data::mapped_type atB = data[Key('B')]; - static constexpr Data::mapped_type atC = data[Key('C')]; - static constexpr Data::mapped_type atD = data[Key('D')]; - static constexpr Data::mapped_type atE = data[Key('E')]; - static constexpr Data::mapped_type atF = data[Key('F')]; - static constexpr Data::mapped_type atG = data[Key('G')]; - static constexpr Data::mapped_type atH = data[Key('H')]; - static constexpr Data::mapped_type atI = data[Key('I')]; - static constexpr Data::mapped_type atJ = data[Key('J')]; + static const Data::mapped_type atA = data[Key('A')]; + static const Data::mapped_type atB = data[Key('B')]; + static const Data::mapped_type atC = data[Key('C')]; + static const Data::mapped_type atD = data[Key('D')]; + static const Data::mapped_type atE = data[Key('E')]; + static const Data::mapped_type atF = data[Key('F')]; + static const Data::mapped_type atG = data[Key('G')]; + static const Data::mapped_type atH = data[Key('H')]; + static const Data::mapped_type atI = data[Key('I')]; + static const Data::mapped_type atJ = data[Key('J')]; CHECK_TRUE(data.is_valid()); CHECK(atA == 0); @@ -393,47 +324,23 @@ namespace TEST(test_index_using_transparent_comparator) { #ifdef TEST_GREATER_THAN - static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - CHECK_TRUE(data.is_valid()); - CHECK(data['A'] == 0); - CHECK(data['B'] == 1); - CHECK(data['C'] == 2); - CHECK(data['D'] == 3); - CHECK(data['E'] == 4); - CHECK(data['F'] == 5); - CHECK(data['G'] == 6); - CHECK(data['H'] == 7); - CHECK(data['I'] == 8); - CHECK(data['J'] == 9); - } - - //************************************************************************* - TEST(test_index_constexpr_using_transparent_comparator) - { -#ifdef TEST_GREATER_THAN - static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else - static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; -#endif - - static constexpr Data::mapped_type atA = data['A']; - static constexpr Data::mapped_type atB = data['B']; - static constexpr Data::mapped_type atC = data['C']; - static constexpr Data::mapped_type atD = data['D']; - static constexpr Data::mapped_type atE = data['E']; - static constexpr Data::mapped_type atF = data['F']; - static constexpr Data::mapped_type atG = data['G']; - static constexpr Data::mapped_type atH = data['H']; - static constexpr Data::mapped_type atI = data['I']; - static constexpr Data::mapped_type atJ = data['J']; + static const Data::mapped_type atA = data['A']; + static const Data::mapped_type atB = data['B']; + static const Data::mapped_type atC = data['C']; + static const Data::mapped_type atD = data['D']; + static const Data::mapped_type atE = data['E']; + static const Data::mapped_type atF = data['F']; + static const Data::mapped_type atG = data['G']; + static const Data::mapped_type atH = data['H']; + static const Data::mapped_type atI = data['I']; + static const Data::mapped_type atJ = data['J']; CHECK_TRUE(data.is_valid()); CHECK(atA == 0); @@ -452,47 +359,23 @@ namespace TEST(test_at) { #ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + static const Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - CHECK_TRUE(data.is_valid()); - CHECK(data.at(Key('A')) == 0); - CHECK(data.at(Key('B')) == 1); - CHECK(data.at(Key('C')) == 2); - CHECK(data.at(Key('D')) == 3); - CHECK(data.at(Key('E')) == 4); - CHECK(data.at(Key('F')) == 5); - CHECK(data.at(Key('G')) == 6); - CHECK(data.at(Key('H')) == 7); - CHECK(data.at(Key('I')) == 8); - CHECK(data.at(Key('J')) == 9); - } - - //************************************************************************* - TEST(test_at_constexpr) - { -#ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; -#endif - - static constexpr Data::mapped_type atA = data.at(Key('A')); - static constexpr Data::mapped_type atB = data.at(Key('B')); - static constexpr Data::mapped_type atC = data.at(Key('C')); - static constexpr Data::mapped_type atD = data.at(Key('D')); - static constexpr Data::mapped_type atE = data.at(Key('E')); - static constexpr Data::mapped_type atF = data.at(Key('F')); - static constexpr Data::mapped_type atG = data.at(Key('G')); - static constexpr Data::mapped_type atH = data.at(Key('H')); - static constexpr Data::mapped_type atI = data.at(Key('I')); - static constexpr Data::mapped_type atJ = data.at(Key('J')); + static const Data::mapped_type atA = data.at(Key('A')); + static const Data::mapped_type atB = data.at(Key('B')); + static const Data::mapped_type atC = data.at(Key('C')); + static const Data::mapped_type atD = data.at(Key('D')); + static const Data::mapped_type atE = data.at(Key('E')); + static const Data::mapped_type atF = data.at(Key('F')); + static const Data::mapped_type atG = data.at(Key('G')); + static const Data::mapped_type atH = data.at(Key('H')); + static const Data::mapped_type atI = data.at(Key('I')); + static const Data::mapped_type atJ = data.at(Key('J')); CHECK_TRUE(data.is_valid()); CHECK(atA == 0); @@ -510,48 +393,24 @@ namespace //************************************************************************* TEST(test_at_using_transparent_comparator) { - #ifdef TEST_GREATER_THAN - static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; - #else - static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - #endif - - CHECK_TRUE(data.is_valid()); - CHECK(data.at('A') == 0); - CHECK(data.at('B') == 1); - CHECK(data.at('C') == 2); - CHECK(data.at('D') == 3); - CHECK(data.at('E') == 4); - CHECK(data.at('F') == 5); - CHECK(data.at('G') == 6); - CHECK(data.at('H') == 7); - CHECK(data.at('I') == 8); - CHECK(data.at('J') == 9); - } - - //************************************************************************* - TEST(test_at_constexpr_using_transparent_comparator) - { #ifdef TEST_GREATER_THAN - static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr Data::mapped_type atA = data.at('A'); - static constexpr Data::mapped_type atB = data.at('B'); - static constexpr Data::mapped_type atC = data.at('C'); - static constexpr Data::mapped_type atD = data.at('D'); - static constexpr Data::mapped_type atE = data.at('E'); - static constexpr Data::mapped_type atF = data.at('F'); - static constexpr Data::mapped_type atG = data.at('G'); - static constexpr Data::mapped_type atH = data.at('H'); - static constexpr Data::mapped_type atI = data.at('I'); - static constexpr Data::mapped_type atJ = data.at('J'); + static const Data::mapped_type atA = data.at('A'); + static const Data::mapped_type atB = data.at('B'); + static const Data::mapped_type atC = data.at('C'); + static const Data::mapped_type atD = data.at('D'); + static const Data::mapped_type atE = data.at('E'); + static const Data::mapped_type atF = data.at('F'); + static const Data::mapped_type atG = data.at('G'); + static const Data::mapped_type atH = data.at('H'); + static const Data::mapped_type atI = data.at('I'); + static const Data::mapped_type atJ = data.at('J'); CHECK_TRUE(data.is_valid()); CHECK(atA == 0); @@ -570,92 +429,23 @@ namespace TEST(test_equal_range) { #ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + static const Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - ETL_OR_STD::pair resultA = data.equal_range(Key('A')); - ETL_OR_STD::pair resultB = data.equal_range(Key('B')); - ETL_OR_STD::pair resultC = data.equal_range(Key('C')); - ETL_OR_STD::pair resultD = data.equal_range(Key('D')); - ETL_OR_STD::pair resultE = data.equal_range(Key('E')); - ETL_OR_STD::pair resultF = data.equal_range(Key('F')); - ETL_OR_STD::pair resultG = data.equal_range(Key('G')); - ETL_OR_STD::pair resultH = data.equal_range(Key('H')); - ETL_OR_STD::pair resultI = data.equal_range(Key('I')); - ETL_OR_STD::pair resultJ = data.equal_range(Key('J')); - -#ifdef TEST_GREATER_THAN - CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); - CHECK_EQUAL(8, (std::distance(data.begin(), resultB.first))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultC.first))); - CHECK_EQUAL(6, (std::distance(data.begin(), resultD.first))); - CHECK_EQUAL(5, (std::distance(data.begin(), resultE.first))); - CHECK_EQUAL(4, (std::distance(data.begin(), resultF.first))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultG.first))); - CHECK_EQUAL(2, (std::distance(data.begin(), resultH.first))); - CHECK_EQUAL(1, (std::distance(data.begin(), resultI.first))); - CHECK_EQUAL(0, (std::distance(data.begin(), resultJ.first))); - - CHECK_EQUAL(10, (std::distance(data.begin(), resultA.second))); - CHECK_EQUAL(9, (std::distance(data.begin(), resultB.second))); - CHECK_EQUAL(8, (std::distance(data.begin(), resultC.second))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultD.second))); - CHECK_EQUAL(6, (std::distance(data.begin(), resultE.second))); - CHECK_EQUAL(5, (std::distance(data.begin(), resultF.second))); - CHECK_EQUAL(4, (std::distance(data.begin(), resultG.second))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultH.second))); - CHECK_EQUAL(2, (std::distance(data.begin(), resultI.second))); - CHECK_EQUAL(1, (std::distance(data.begin(), resultJ.second))); -#else - CHECK_EQUAL(0, (std::distance(data.begin(), resultA.first))); - CHECK_EQUAL(1, (std::distance(data.begin(), resultB.first))); - CHECK_EQUAL(2, (std::distance(data.begin(), resultC.first))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultD.first))); - CHECK_EQUAL(4, (std::distance(data.begin(), resultE.first))); - CHECK_EQUAL(5, (std::distance(data.begin(), resultF.first))); - CHECK_EQUAL(6, (std::distance(data.begin(), resultG.first))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultH.first))); - CHECK_EQUAL(8, (std::distance(data.begin(), resultI.first))); - CHECK_EQUAL(9, (std::distance(data.begin(), resultJ.first))); - - CHECK_EQUAL(1, (std::distance(data.begin(), resultA.second))); - CHECK_EQUAL(2, (std::distance(data.begin(), resultB.second))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultC.second))); - CHECK_EQUAL(4, (std::distance(data.begin(), resultD.second))); - CHECK_EQUAL(5, (std::distance(data.begin(), resultE.second))); - CHECK_EQUAL(6, (std::distance(data.begin(), resultF.second))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultG.second))); - CHECK_EQUAL(8, (std::distance(data.begin(), resultH.second))); - CHECK_EQUAL(9, (std::distance(data.begin(), resultI.second))); - CHECK_EQUAL(10, (std::distance(data.begin(), resultJ.second))); -#endif - } - - //************************************************************************* - TEST(test_equal_range_constexpr) - { -#ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; -#endif - - static constexpr ETL_OR_STD::pair resultA = data.equal_range(Key('A')); - static constexpr ETL_OR_STD::pair resultB = data.equal_range(Key('B')); - static constexpr ETL_OR_STD::pair resultC = data.equal_range(Key('C')); - static constexpr ETL_OR_STD::pair resultD = data.equal_range(Key('D')); - static constexpr ETL_OR_STD::pair resultE = data.equal_range(Key('E')); - static constexpr ETL_OR_STD::pair resultF = data.equal_range(Key('F')); - static constexpr ETL_OR_STD::pair resultG = data.equal_range(Key('G')); - static constexpr ETL_OR_STD::pair resultH = data.equal_range(Key('H')); - static constexpr ETL_OR_STD::pair resultI = data.equal_range(Key('I')); - static constexpr ETL_OR_STD::pair resultJ = data.equal_range(Key('J')); + static const ETL_OR_STD::pair resultA = data.equal_range(Key('A')); + static const ETL_OR_STD::pair resultB = data.equal_range(Key('B')); + static const ETL_OR_STD::pair resultC = data.equal_range(Key('C')); + static const ETL_OR_STD::pair resultD = data.equal_range(Key('D')); + static const ETL_OR_STD::pair resultE = data.equal_range(Key('E')); + static const ETL_OR_STD::pair resultF = data.equal_range(Key('F')); + static const ETL_OR_STD::pair resultG = data.equal_range(Key('G')); + static const ETL_OR_STD::pair resultH = data.equal_range(Key('H')); + static const ETL_OR_STD::pair resultI = data.equal_range(Key('I')); + static const ETL_OR_STD::pair resultJ = data.equal_range(Key('J')); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); @@ -708,92 +498,23 @@ namespace TEST(test_equal_range_using_transparent_comparator) { #ifdef TEST_GREATER_THAN - static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - ETL_OR_STD::pair resultA = data.equal_range('A'); - ETL_OR_STD::pair resultB = data.equal_range('B'); - ETL_OR_STD::pair resultC = data.equal_range('C'); - ETL_OR_STD::pair resultD = data.equal_range('D'); - ETL_OR_STD::pair resultE = data.equal_range('E'); - ETL_OR_STD::pair resultF = data.equal_range('F'); - ETL_OR_STD::pair resultG = data.equal_range('G'); - ETL_OR_STD::pair resultH = data.equal_range('H'); - ETL_OR_STD::pair resultI = data.equal_range('I'); - ETL_OR_STD::pair resultJ = data.equal_range('J'); - -#ifdef TEST_GREATER_THAN - CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); - CHECK_EQUAL(8, (std::distance(data.begin(), resultB.first))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultC.first))); - CHECK_EQUAL(6, (std::distance(data.begin(), resultD.first))); - CHECK_EQUAL(5, (std::distance(data.begin(), resultE.first))); - CHECK_EQUAL(4, (std::distance(data.begin(), resultF.first))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultG.first))); - CHECK_EQUAL(2, (std::distance(data.begin(), resultH.first))); - CHECK_EQUAL(1, (std::distance(data.begin(), resultI.first))); - CHECK_EQUAL(0, (std::distance(data.begin(), resultJ.first))); - - CHECK_EQUAL(10, (std::distance(data.begin(), resultA.second))); - CHECK_EQUAL(9, (std::distance(data.begin(), resultB.second))); - CHECK_EQUAL(8, (std::distance(data.begin(), resultC.second))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultD.second))); - CHECK_EQUAL(6, (std::distance(data.begin(), resultE.second))); - CHECK_EQUAL(5, (std::distance(data.begin(), resultF.second))); - CHECK_EQUAL(4, (std::distance(data.begin(), resultG.second))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultH.second))); - CHECK_EQUAL(2, (std::distance(data.begin(), resultI.second))); - CHECK_EQUAL(1, (std::distance(data.begin(), resultJ.second))); -#else - CHECK_EQUAL(0, (std::distance(data.begin(), resultA.first))); - CHECK_EQUAL(1, (std::distance(data.begin(), resultB.first))); - CHECK_EQUAL(2, (std::distance(data.begin(), resultC.first))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultD.first))); - CHECK_EQUAL(4, (std::distance(data.begin(), resultE.first))); - CHECK_EQUAL(5, (std::distance(data.begin(), resultF.first))); - CHECK_EQUAL(6, (std::distance(data.begin(), resultG.first))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultH.first))); - CHECK_EQUAL(8, (std::distance(data.begin(), resultI.first))); - CHECK_EQUAL(9, (std::distance(data.begin(), resultJ.first))); - - CHECK_EQUAL(1, (std::distance(data.begin(), resultA.second))); - CHECK_EQUAL(2, (std::distance(data.begin(), resultB.second))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultC.second))); - CHECK_EQUAL(4, (std::distance(data.begin(), resultD.second))); - CHECK_EQUAL(5, (std::distance(data.begin(), resultE.second))); - CHECK_EQUAL(6, (std::distance(data.begin(), resultF.second))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultG.second))); - CHECK_EQUAL(8, (std::distance(data.begin(), resultH.second))); - CHECK_EQUAL(9, (std::distance(data.begin(), resultI.second))); - CHECK_EQUAL(10, (std::distance(data.begin(), resultJ.second))); -#endif - } - - //************************************************************************* - TEST(test_equal_range_constexpr_using_transparent_comparator) - { -#ifdef TEST_GREATER_THAN - static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else - static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; -#endif - - static constexpr ETL_OR_STD::pair resultA = data.equal_range('A'); - static constexpr ETL_OR_STD::pair resultB = data.equal_range('B'); - static constexpr ETL_OR_STD::pair resultC = data.equal_range('C'); - static constexpr ETL_OR_STD::pair resultD = data.equal_range('D'); - static constexpr ETL_OR_STD::pair resultE = data.equal_range('E'); - static constexpr ETL_OR_STD::pair resultF = data.equal_range('F'); - static constexpr ETL_OR_STD::pair resultG = data.equal_range('G'); - static constexpr ETL_OR_STD::pair resultH = data.equal_range('H'); - static constexpr ETL_OR_STD::pair resultI = data.equal_range('I'); - static constexpr ETL_OR_STD::pair resultJ = data.equal_range('J'); + static const ETL_OR_STD::pair resultA = data.equal_range('A'); + static const ETL_OR_STD::pair resultB = data.equal_range('B'); + static const ETL_OR_STD::pair resultC = data.equal_range('C'); + static const ETL_OR_STD::pair resultD = data.equal_range('D'); + static const ETL_OR_STD::pair resultE = data.equal_range('E'); + static const ETL_OR_STD::pair resultF = data.equal_range('F'); + static const ETL_OR_STD::pair resultG = data.equal_range('G'); + static const ETL_OR_STD::pair resultH = data.equal_range('H'); + static const ETL_OR_STD::pair resultI = data.equal_range('I'); + static const ETL_OR_STD::pair resultJ = data.equal_range('J'); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); @@ -846,74 +567,24 @@ namespace TEST(test_lower_bound) { #ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + static const Data data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; #endif - Data::const_iterator resultA = data.lower_bound(Key('A')); - Data::const_iterator resultB = data.lower_bound(Key('B')); - Data::const_iterator resultC = data.lower_bound(Key('C')); - Data::const_iterator resultD = data.lower_bound(Key('D')); - Data::const_iterator resultE = data.lower_bound(Key('E')); - Data::const_iterator resultF = data.lower_bound(Key('F')); - Data::const_iterator resultG = data.lower_bound(Key('G')); - Data::const_iterator resultH = data.lower_bound(Key('H')); - Data::const_iterator resultI = data.lower_bound(Key('I')); - Data::const_iterator resultJ = data.lower_bound(Key('J')); - Data::const_iterator resultK = data.lower_bound(Key('K')); - -#ifdef TEST_GREATER_THAN - CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); - CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); - CHECK_EQUAL(6, (std::distance(data.begin(), resultE))); - CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); - CHECK_EQUAL(4, (std::distance(data.begin(), resultG))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultH))); - CHECK_EQUAL(2, (std::distance(data.begin(), resultI))); - CHECK_EQUAL(1, (std::distance(data.begin(), resultJ))); - CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); -#else - CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); - CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); - CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultE))); - CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); - CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); - CHECK_EQUAL(6, (std::distance(data.begin(), resultH))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultI))); - CHECK_EQUAL(8, (std::distance(data.begin(), resultJ))); - CHECK_EQUAL(9, (std::distance(data.begin(), resultK))); -#endif - } - - //************************************************************************* - TEST(test_lower_bound_constexpr) - { -#ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, - value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, - value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; -#endif - - static constexpr Data::const_iterator resultA = data.lower_bound(Key('A')); - static constexpr Data::const_iterator resultB = data.lower_bound(Key('B')); - static constexpr Data::const_iterator resultC = data.lower_bound(Key('C')); - static constexpr Data::const_iterator resultD = data.lower_bound(Key('D')); - static constexpr Data::const_iterator resultE = data.lower_bound(Key('E')); - static constexpr Data::const_iterator resultF = data.lower_bound(Key('F')); - static constexpr Data::const_iterator resultG = data.lower_bound(Key('G')); - static constexpr Data::const_iterator resultH = data.lower_bound(Key('H')); - static constexpr Data::const_iterator resultI = data.lower_bound(Key('I')); - static constexpr Data::const_iterator resultJ = data.lower_bound(Key('J')); - static constexpr Data::const_iterator resultK = data.lower_bound(Key('K')); + static const Data::const_iterator resultA = data.lower_bound(Key('A')); + static const Data::const_iterator resultB = data.lower_bound(Key('B')); + static const Data::const_iterator resultC = data.lower_bound(Key('C')); + static const Data::const_iterator resultD = data.lower_bound(Key('D')); + static const Data::const_iterator resultE = data.lower_bound(Key('E')); + static const Data::const_iterator resultF = data.lower_bound(Key('F')); + static const Data::const_iterator resultG = data.lower_bound(Key('G')); + static const Data::const_iterator resultH = data.lower_bound(Key('H')); + static const Data::const_iterator resultI = data.lower_bound(Key('I')); + static const Data::const_iterator resultJ = data.lower_bound(Key('J')); + static const Data::const_iterator resultK = data.lower_bound(Key('K')); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); @@ -946,74 +617,24 @@ namespace TEST(test_lower_bound_using_transparent_comparator) { #ifdef TEST_GREATER_THAN - static constexpr DataTransparentComparator data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + static const DataTransparentComparator data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; #endif - Data::const_iterator resultA = data.lower_bound('A'); - Data::const_iterator resultB = data.lower_bound('B'); - Data::const_iterator resultC = data.lower_bound('C'); - Data::const_iterator resultD = data.lower_bound('D'); - Data::const_iterator resultE = data.lower_bound('E'); - Data::const_iterator resultF = data.lower_bound('F'); - Data::const_iterator resultG = data.lower_bound('G'); - Data::const_iterator resultH = data.lower_bound('H'); - Data::const_iterator resultI = data.lower_bound('I'); - Data::const_iterator resultJ = data.lower_bound('J'); - Data::const_iterator resultK = data.lower_bound('K'); - -#ifdef TEST_GREATER_THAN - CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); - CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); - CHECK_EQUAL(6, (std::distance(data.begin(), resultE))); - CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); - CHECK_EQUAL(4, (std::distance(data.begin(), resultG))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultH))); - CHECK_EQUAL(2, (std::distance(data.begin(), resultI))); - CHECK_EQUAL(1, (std::distance(data.begin(), resultJ))); - CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); -#else - CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); - CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); - CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultE))); - CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); - CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); - CHECK_EQUAL(6, (std::distance(data.begin(), resultH))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultI))); - CHECK_EQUAL(8, (std::distance(data.begin(), resultJ))); - CHECK_EQUAL(9, (std::distance(data.begin(), resultK))); -#endif - } - - //************************************************************************* - TEST(test_lower_bound_constexpr_using_transparent_comparator) - { -#ifdef TEST_GREATER_THAN - static constexpr DataTransparentComparator data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, - value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else - static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, - value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; -#endif - - static constexpr Data::const_iterator resultA = data.lower_bound('A'); - static constexpr Data::const_iterator resultB = data.lower_bound('B'); - static constexpr Data::const_iterator resultC = data.lower_bound('C'); - static constexpr Data::const_iterator resultD = data.lower_bound('D'); - static constexpr Data::const_iterator resultE = data.lower_bound('E'); - static constexpr Data::const_iterator resultF = data.lower_bound('F'); - static constexpr Data::const_iterator resultG = data.lower_bound('G'); - static constexpr Data::const_iterator resultH = data.lower_bound('H'); - static constexpr Data::const_iterator resultI = data.lower_bound('I'); - static constexpr Data::const_iterator resultJ = data.lower_bound('J'); - static constexpr Data::const_iterator resultK = data.lower_bound('K'); + static const Data::const_iterator resultA = data.lower_bound('A'); + static const Data::const_iterator resultB = data.lower_bound('B'); + static const Data::const_iterator resultC = data.lower_bound('C'); + static const Data::const_iterator resultD = data.lower_bound('D'); + static const Data::const_iterator resultE = data.lower_bound('E'); + static const Data::const_iterator resultF = data.lower_bound('F'); + static const Data::const_iterator resultG = data.lower_bound('G'); + static const Data::const_iterator resultH = data.lower_bound('H'); + static const Data::const_iterator resultI = data.lower_bound('I'); + static const Data::const_iterator resultJ = data.lower_bound('J'); + static const Data::const_iterator resultK = data.lower_bound('K'); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); @@ -1046,74 +667,24 @@ namespace TEST(test_upper_bound) { #ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + static const Data data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; #endif - Data::const_iterator resultA = data.upper_bound(Key('A')); - Data::const_iterator resultB = data.upper_bound(Key('B')); - Data::const_iterator resultC = data.upper_bound(Key('C')); - Data::const_iterator resultD = data.upper_bound(Key('D')); - Data::const_iterator resultE = data.upper_bound(Key('E')); - Data::const_iterator resultF = data.upper_bound(Key('F')); - Data::const_iterator resultG = data.upper_bound(Key('G')); - Data::const_iterator resultH = data.upper_bound(Key('H')); - Data::const_iterator resultI = data.upper_bound(Key('I')); - Data::const_iterator resultJ = data.upper_bound(Key('J')); - Data::const_iterator resultK = data.upper_bound(Key('K')); - -#ifdef TEST_GREATER_THAN - CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); - CHECK_EQUAL(9, (std::distance(data.begin(), resultB))); - CHECK_EQUAL(8, (std::distance(data.begin(), resultC))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultE))); - CHECK_EQUAL(6, (std::distance(data.begin(), resultF))); - CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); - CHECK_EQUAL(4, (std::distance(data.begin(), resultH))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultI))); - CHECK_EQUAL(2, (std::distance(data.begin(), resultJ))); - CHECK_EQUAL(1, (std::distance(data.begin(), resultK))); -#else - CHECK_EQUAL(1, (std::distance(data.begin(), resultA))); - CHECK_EQUAL(2, (std::distance(data.begin(), resultB))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultC))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); - CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); - CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); - CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); - CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); - CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); - CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); -#endif - } - - //************************************************************************* - TEST(test_upper_bound_constexpr) - { -#ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, - value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, - value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; -#endif - - static constexpr Data::const_iterator resultA = data.upper_bound(Key('A')); - static constexpr Data::const_iterator resultB = data.upper_bound(Key('B')); - static constexpr Data::const_iterator resultC = data.upper_bound(Key('C')); - static constexpr Data::const_iterator resultD = data.upper_bound(Key('D')); - static constexpr Data::const_iterator resultE = data.upper_bound(Key('E')); - static constexpr Data::const_iterator resultF = data.upper_bound(Key('F')); - static constexpr Data::const_iterator resultG = data.upper_bound(Key('G')); - static constexpr Data::const_iterator resultH = data.upper_bound(Key('H')); - static constexpr Data::const_iterator resultI = data.upper_bound(Key('I')); - static constexpr Data::const_iterator resultJ = data.upper_bound(Key('J')); - static constexpr Data::const_iterator resultK = data.upper_bound(Key('K')); + static const Data::const_iterator resultA = data.upper_bound(Key('A')); + static const Data::const_iterator resultB = data.upper_bound(Key('B')); + static const Data::const_iterator resultC = data.upper_bound(Key('C')); + static const Data::const_iterator resultD = data.upper_bound(Key('D')); + static const Data::const_iterator resultE = data.upper_bound(Key('E')); + static const Data::const_iterator resultF = data.upper_bound(Key('F')); + static const Data::const_iterator resultG = data.upper_bound(Key('G')); + static const Data::const_iterator resultH = data.upper_bound(Key('H')); + static const Data::const_iterator resultI = data.upper_bound(Key('I')); + static const Data::const_iterator resultJ = data.upper_bound(Key('J')); + static const Data::const_iterator resultK = data.upper_bound(Key('K')); #ifdef TEST_GREATER_THAN CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); @@ -1146,74 +717,24 @@ namespace TEST(test_upper_bound_using_transparent_comparator) { #ifdef TEST_GREATER_THAN - static constexpr DataTransparentComparator data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + static const DataTransparentComparator data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; #endif - Data::const_iterator resultA = data.upper_bound('A'); - Data::const_iterator resultB = data.upper_bound('B'); - Data::const_iterator resultC = data.upper_bound('C'); - Data::const_iterator resultD = data.upper_bound('D'); - Data::const_iterator resultE = data.upper_bound('E'); - Data::const_iterator resultF = data.upper_bound('F'); - Data::const_iterator resultG = data.upper_bound('G'); - Data::const_iterator resultH = data.upper_bound('H'); - Data::const_iterator resultI = data.upper_bound('I'); - Data::const_iterator resultJ = data.upper_bound('J'); - Data::const_iterator resultK = data.upper_bound('K'); - -#ifdef TEST_GREATER_THAN - CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); - CHECK_EQUAL(9, (std::distance(data.begin(), resultB))); - CHECK_EQUAL(8, (std::distance(data.begin(), resultC))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultE))); - CHECK_EQUAL(6, (std::distance(data.begin(), resultF))); - CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); - CHECK_EQUAL(4, (std::distance(data.begin(), resultH))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultI))); - CHECK_EQUAL(2, (std::distance(data.begin(), resultJ))); - CHECK_EQUAL(1, (std::distance(data.begin(), resultK))); -#else - CHECK_EQUAL(1, (std::distance(data.begin(), resultA))); - CHECK_EQUAL(2, (std::distance(data.begin(), resultB))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultC))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); - CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); - CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); - CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); - CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); - CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); - CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); -#endif - } - - //************************************************************************* - TEST(test_upper_bound_constexpr_using_transparent_comparator) - { -#ifdef TEST_GREATER_THAN - static constexpr DataTransparentComparator data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, - value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else - static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, - value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; -#endif - - static constexpr Data::const_iterator resultA = data.upper_bound('A'); - static constexpr Data::const_iterator resultB = data.upper_bound('B'); - static constexpr Data::const_iterator resultC = data.upper_bound('C'); - static constexpr Data::const_iterator resultD = data.upper_bound('D'); - static constexpr Data::const_iterator resultE = data.upper_bound('E'); - static constexpr Data::const_iterator resultF = data.upper_bound('F'); - static constexpr Data::const_iterator resultG = data.upper_bound('G'); - static constexpr Data::const_iterator resultH = data.upper_bound('H'); - static constexpr Data::const_iterator resultI = data.upper_bound('I'); - static constexpr Data::const_iterator resultJ = data.upper_bound('J'); - static constexpr Data::const_iterator resultK = data.upper_bound('K'); + static const Data::const_iterator resultA = data.upper_bound('A'); + static const Data::const_iterator resultB = data.upper_bound('B'); + static const Data::const_iterator resultC = data.upper_bound('C'); + static const Data::const_iterator resultD = data.upper_bound('D'); + static const Data::const_iterator resultE = data.upper_bound('E'); + static const Data::const_iterator resultF = data.upper_bound('F'); + static const Data::const_iterator resultG = data.upper_bound('G'); + static const Data::const_iterator resultH = data.upper_bound('H'); + static const Data::const_iterator resultI = data.upper_bound('I'); + static const Data::const_iterator resultJ = data.upper_bound('J'); + static const Data::const_iterator resultK = data.upper_bound('K'); #ifdef TEST_GREATER_THAN CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); @@ -1246,48 +767,24 @@ namespace TEST(test_count) { #ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + static const Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - CHECK_EQUAL(1, data.count(Key('A'))); - CHECK_EQUAL(1, data.count(Key('B'))); - CHECK_EQUAL(1, data.count(Key('C'))); - CHECK_EQUAL(1, data.count(Key('D'))); - CHECK_EQUAL(1, data.count(Key('E'))); - CHECK_EQUAL(1, data.count(Key('F'))); - CHECK_EQUAL(1, data.count(Key('G'))); - CHECK_EQUAL(1, data.count(Key('H'))); - CHECK_EQUAL(1, data.count(Key('I'))); - CHECK_EQUAL(1, data.count(Key('J'))); - CHECK_EQUAL(0, data.count(Key('K'))); - } - - //************************************************************************* - TEST(test_count_constexpr) - { -#ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; -#endif - - static constexpr size_t countA = data.count(Key('A')); - static constexpr size_t countB = data.count(Key('B')); - static constexpr size_t countC = data.count(Key('C')); - static constexpr size_t countD = data.count(Key('D')); - static constexpr size_t countE = data.count(Key('E')); - static constexpr size_t countF = data.count(Key('F')); - static constexpr size_t countG = data.count(Key('G')); - static constexpr size_t countH = data.count(Key('H')); - static constexpr size_t countI = data.count(Key('I')); - static constexpr size_t countJ = data.count(Key('J')); - static constexpr size_t countK = data.count(Key('K')); + static const size_t countA = data.count(Key('A')); + static const size_t countB = data.count(Key('B')); + static const size_t countC = data.count(Key('C')); + static const size_t countD = data.count(Key('D')); + static const size_t countE = data.count(Key('E')); + static const size_t countF = data.count(Key('F')); + static const size_t countG = data.count(Key('G')); + static const size_t countH = data.count(Key('H')); + static const size_t countI = data.count(Key('I')); + static const size_t countJ = data.count(Key('J')); + static const size_t countK = data.count(Key('K')); CHECK_EQUAL(1, countA); CHECK_EQUAL(1, countB); @@ -1306,48 +803,24 @@ namespace TEST(test_count_using_transparent_comparator) { #ifdef TEST_GREATER_THAN - static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - CHECK_EQUAL(1, data.count('A')); - CHECK_EQUAL(1, data.count('B')); - CHECK_EQUAL(1, data.count('C')); - CHECK_EQUAL(1, data.count('D')); - CHECK_EQUAL(1, data.count('E')); - CHECK_EQUAL(1, data.count('F')); - CHECK_EQUAL(1, data.count('G')); - CHECK_EQUAL(1, data.count('H')); - CHECK_EQUAL(1, data.count('I')); - CHECK_EQUAL(1, data.count('J')); - CHECK_EQUAL(0, data.count('K')); - } - - //************************************************************************* - TEST(test_count_constexpr_using_transparent_comparator) - { -#ifdef TEST_GREATER_THAN - static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else - static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; -#endif - - static constexpr size_t countA = data.count('A'); - static constexpr size_t countB = data.count('B'); - static constexpr size_t countC = data.count('C'); - static constexpr size_t countD = data.count('D'); - static constexpr size_t countE = data.count('E'); - static constexpr size_t countF = data.count('F'); - static constexpr size_t countG = data.count('G'); - static constexpr size_t countH = data.count('H'); - static constexpr size_t countI = data.count('I'); - static constexpr size_t countJ = data.count('J'); - static constexpr size_t countK = data.count('K'); + static const size_t countA = data.count('A'); + static const size_t countB = data.count('B'); + static const size_t countC = data.count('C'); + static const size_t countD = data.count('D'); + static const size_t countE = data.count('E'); + static const size_t countF = data.count('F'); + static const size_t countG = data.count('G'); + static const size_t countH = data.count('H'); + static const size_t countI = data.count('I'); + static const size_t countJ = data.count('J'); + static const size_t countK = data.count('K'); CHECK_EQUAL(1, countA); CHECK_EQUAL(1, countB); @@ -1366,10 +839,10 @@ namespace TEST(test_const_iterator) { #ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + static const Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif @@ -1406,70 +879,23 @@ namespace TEST(test_find) { #ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + static const Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - Data::const_iterator resultA = data.find(Key('A')); - Data::const_iterator resultB = data.find(Key('B')); - Data::const_iterator resultC = data.find(Key('C')); - Data::const_iterator resultD = data.find(Key('D')); - Data::const_iterator resultE = data.find(Key('E')); - Data::const_iterator resultF = data.find(Key('F')); - Data::const_iterator resultG = data.find(Key('G')); - Data::const_iterator resultH = data.find(Key('H')); - Data::const_iterator resultI = data.find(Key('I')); - Data::const_iterator resultJ = data.find(Key('J')); - -#ifdef TEST_GREATER_THAN - CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); - CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); - CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); - CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); - CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultG))); - CHECK_EQUAL(2, (std::distance(data.begin(), resultH))); - CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); - CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); -#else - CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); - CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); - CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); - CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); - CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); - CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); - CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); - CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); -#endif - } - - //************************************************************************* - TEST(test_find_constexpr) - { -#ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; -#endif - - static constexpr Data::const_iterator resultA = data.find(Key('A')); - static constexpr Data::const_iterator resultB = data.find(Key('B')); - static constexpr Data::const_iterator resultC = data.find(Key('C')); - static constexpr Data::const_iterator resultD = data.find(Key('D')); - static constexpr Data::const_iterator resultE = data.find(Key('E')); - static constexpr Data::const_iterator resultF = data.find(Key('F')); - static constexpr Data::const_iterator resultG = data.find(Key('G')); - static constexpr Data::const_iterator resultH = data.find(Key('H')); - static constexpr Data::const_iterator resultI = data.find(Key('I')); - static constexpr Data::const_iterator resultJ = data.find(Key('J')); + static const Data::const_iterator resultA = data.find(Key('A')); + static const Data::const_iterator resultB = data.find(Key('B')); + static const Data::const_iterator resultC = data.find(Key('C')); + static const Data::const_iterator resultD = data.find(Key('D')); + static const Data::const_iterator resultE = data.find(Key('E')); + static const Data::const_iterator resultF = data.find(Key('F')); + static const Data::const_iterator resultG = data.find(Key('G')); + static const Data::const_iterator resultH = data.find(Key('H')); + static const Data::const_iterator resultI = data.find(Key('I')); + static const Data::const_iterator resultJ = data.find(Key('J')); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); @@ -1500,23 +926,23 @@ namespace TEST(test_find_using_transparent_comparator) { #ifdef TEST_GREATER_THAN - static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - Data::const_iterator resultA = data.find('A'); - Data::const_iterator resultB = data.find('B'); - Data::const_iterator resultC = data.find('C'); - Data::const_iterator resultD = data.find('D'); - Data::const_iterator resultE = data.find('E'); - Data::const_iterator resultF = data.find('F'); - Data::const_iterator resultG = data.find('G'); - Data::const_iterator resultH = data.find('H'); - Data::const_iterator resultI = data.find('I'); - Data::const_iterator resultJ = data.find('J'); + static const Data::const_iterator resultA = data.find('A'); + static const Data::const_iterator resultB = data.find('B'); + static const Data::const_iterator resultC = data.find('C'); + static const Data::const_iterator resultD = data.find('D'); + static const Data::const_iterator resultE = data.find('E'); + static const Data::const_iterator resultF = data.find('F'); + static const Data::const_iterator resultG = data.find('G'); + static const Data::const_iterator resultH = data.find('H'); + static const Data::const_iterator resultI = data.find('I'); + static const Data::const_iterator resultJ = data.find('J'); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); @@ -1543,96 +969,15 @@ namespace #endif } - //************************************************************************* - TEST(test_find_constexpr_using_transparent_comparator) - { -#ifdef TEST_GREATER_THAN - static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else - static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; -#endif - - static constexpr Data::const_iterator resultA = data.find('A'); - static constexpr Data::const_iterator resultB = data.find('B'); - static constexpr Data::const_iterator resultC = data.find('C'); - static constexpr Data::const_iterator resultD = data.find('D'); - static constexpr Data::const_iterator resultE = data.find('E'); - static constexpr Data::const_iterator resultF = data.find('F'); - static constexpr Data::const_iterator resultG = data.find('G'); - static constexpr Data::const_iterator resultH = data.find('H'); - static constexpr Data::const_iterator resultI = data.find('I'); - static constexpr Data::const_iterator resultJ = data.find('J'); - -#ifdef TEST_GREATER_THAN - CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); - CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); - CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); - CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); - CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultG))); - CHECK_EQUAL(2, (std::distance(data.begin(), resultH))); - CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); - CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); -#else - CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); - CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); - CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); - CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); - CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); - CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); - CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); - CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); - CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); - CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); -#endif - } - - //************************************************************************* - TEST(test_equal) - { - static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - - static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - - static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - - - CHECK_TRUE(data1 == data2); - CHECK_FALSE(data1 == data3); - } - - //************************************************************************* - TEST(test_not_equal) - { - static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - - static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - - static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - - - CHECK_FALSE(data1 != data2); - CHECK_TRUE(data1 != data3); - } - //************************************************************************* TEST(test_key_compare) { - static constexpr Data data; + static const Data data; - static constexpr Data::key_compare compare = data.key_comp(); + static const Data::key_compare compare = data.key_comp(); - static constexpr Data::key_type a(Key('A')); - static constexpr Data::key_type b(Key('B')); + static const Data::key_type a(Key('A')); + static const Data::key_type b(Key('B')); #ifdef TEST_GREATER_THAN CHECK(!compare(a, b)); @@ -1646,12 +991,12 @@ namespace //************************************************************************* TEST(test_key_compare_using_transparent_comparator) { - static constexpr DataTransparentComparator data; + static const DataTransparentComparator data; - static constexpr DataTransparentComparator::key_compare compare = data.key_comp(); + static const DataTransparentComparator::key_compare compare = data.key_comp(); - static constexpr DataTransparentComparator::key_type a(Key('A')); - static constexpr DataTransparentComparator::key_type b(Key('B')); + static const DataTransparentComparator::key_type a(Key('A')); + static const DataTransparentComparator::key_type b(Key('B')); #ifdef TEST_GREATER_THAN CHECK(!compare(a, b)); @@ -1665,12 +1010,12 @@ namespace //************************************************************************* TEST(test_value_compare) { - static constexpr Data data; + static const Data data; - static constexpr Data::value_compare compare = data.value_comp(); + static const Data::value_compare compare = data.value_comp(); - static constexpr Data::value_type a(Key('A'), 0); - static constexpr Data::value_type b(Key('B'), 1); + static const Data::value_type a(Key('A'), 0); + static const Data::value_type b(Key('B'), 1); #ifdef TEST_GREATER_THAN CHECK(!compare(a, b)); @@ -1685,48 +1030,24 @@ namespace TEST(test_contains) { #ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; -#endif - - CHECK_TRUE(data.contains(Key('A'))); - CHECK_TRUE(data.contains(Key('B'))); - CHECK_TRUE(data.contains(Key('C'))); - CHECK_TRUE(data.contains(Key('D'))); - CHECK_TRUE(data.contains(Key('E'))); - CHECK_TRUE(data.contains(Key('F'))); - CHECK_TRUE(data.contains(Key('G'))); - CHECK_TRUE(data.contains(Key('H'))); - CHECK_TRUE(data.contains(Key('I'))); - CHECK_TRUE(data.contains(Key('J'))); - CHECK_FALSE(data.contains(Key('K'))); - } - - //************************************************************************* - TEST(test_contains_constexpr) - { -#ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + static const Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr bool containsA = data.contains(Key('A')); - static constexpr bool containsB = data.contains(Key('B')); - static constexpr bool containsC = data.contains(Key('C')); - static constexpr bool containsD = data.contains(Key('D')); - static constexpr bool containsE = data.contains(Key('E')); - static constexpr bool containsF = data.contains(Key('F')); - static constexpr bool containsG = data.contains(Key('G')); - static constexpr bool containsH = data.contains(Key('H')); - static constexpr bool containsI = data.contains(Key('I')); - static constexpr bool containsJ = data.contains(Key('J')); - static constexpr bool containsK = data.contains(Key('K')); + static const bool containsA = data.contains(Key('A')); + static const bool containsB = data.contains(Key('B')); + static const bool containsC = data.contains(Key('C')); + static const bool containsD = data.contains(Key('D')); + static const bool containsE = data.contains(Key('E')); + static const bool containsF = data.contains(Key('F')); + static const bool containsG = data.contains(Key('G')); + static const bool containsH = data.contains(Key('H')); + static const bool containsI = data.contains(Key('I')); + static const bool containsJ = data.contains(Key('J')); + static const bool containsK = data.contains(Key('K')); CHECK_TRUE(containsA); CHECK_TRUE(containsB); @@ -1745,48 +1066,24 @@ namespace TEST(test_contains_with_transparent_comparator) { #ifdef TEST_GREATER_THAN - static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - CHECK_TRUE(data.contains('A')); - CHECK_TRUE(data.contains('B')); - CHECK_TRUE(data.contains('C')); - CHECK_TRUE(data.contains('D')); - CHECK_TRUE(data.contains('E')); - CHECK_TRUE(data.contains('F')); - CHECK_TRUE(data.contains('G')); - CHECK_TRUE(data.contains('H')); - CHECK_TRUE(data.contains('I')); - CHECK_TRUE(data.contains('J')); - CHECK_FALSE(data.contains('K')); - } - - //************************************************************************* - TEST(test_contains_with_transparent_comparator_constexpr) - { -#ifdef TEST_GREATER_THAN - static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else - static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; -#endif - - static constexpr bool containsA = data.contains('A'); - static constexpr bool containsB = data.contains('B'); - static constexpr bool containsC = data.contains('C'); - static constexpr bool containsD = data.contains('D'); - static constexpr bool containsE = data.contains('E'); - static constexpr bool containsF = data.contains('F'); - static constexpr bool containsG = data.contains('G'); - static constexpr bool containsH = data.contains('H'); - static constexpr bool containsI = data.contains('I'); - static constexpr bool containsJ = data.contains('J'); - static constexpr bool containsK = data.contains('K'); + static const bool containsA = data.contains('A'); + static const bool containsB = data.contains('B'); + static const bool containsC = data.contains('C'); + static const bool containsD = data.contains('D'); + static const bool containsE = data.contains('E'); + static const bool containsF = data.contains('F'); + static const bool containsG = data.contains('G'); + static const bool containsH = data.contains('H'); + static const bool containsI = data.contains('I'); + static const bool containsJ = data.contains('J'); + static const bool containsK = data.contains('K'); CHECK_TRUE(containsA); CHECK_TRUE(containsB); @@ -1804,46 +1101,12 @@ namespace //************************************************************************* TEST(test_key_comp) { - static constexpr Data data; - static constexpr Data::key_compare compare = data.key_comp(); + static const Data data; + static const Data::key_compare compare = data.key_comp(); -#ifdef TEST_GREATER_THAN - CHECK_FALSE(compare(Key{ 'A' }, Key{ 'A' })); - CHECK_TRUE(compare(Key{ 'B' }, Key{ 'A' })); - CHECK_FALSE(compare(Key{ 'A' }, Key{ 'B' })); -#else - CHECK_FALSE(compare(Key{ 'A' }, Key{ 'A' })); - CHECK_FALSE(compare(Key{ 'B' }, Key{ 'A' })); - CHECK_TRUE(compare(Key{ 'A' }, Key{ 'B' })); -#endif - } - - //************************************************************************* - TEST(test_key_comp_transparent_comparator) - { - static constexpr DataTransparentComparator data; - static constexpr DataTransparentComparator::key_compare compare = data.key_comp(); - -#ifdef TEST_GREATER_THAN - CHECK_FALSE(compare('A', 'A')); - CHECK_TRUE(compare('B', 'A')); - CHECK_FALSE(compare('A', 'B')); -#else - CHECK_FALSE(compare('A', 'A')); - CHECK_FALSE(compare('B', 'A')); - CHECK_TRUE(compare('A', 'B')); -#endif - } - - //************************************************************************* - TEST(test_key_comp_constexpr) - { - static constexpr Data data; - static constexpr Data::key_compare compare = data.key_comp(); - - static constexpr bool compareAA = compare(Key{ 'A' }, Key{ 'A' }); - static constexpr bool compareBA = compare(Key{ 'B' }, Key{ 'A' }); - static constexpr bool compareAB = compare(Key{ 'A' }, Key{ 'B' }); + static const bool compareAA = compare(Key{ 'A' }, Key{ 'A' }); + static const bool compareBA = compare(Key{ 'B' }, Key{ 'A' }); + static const bool compareAB = compare(Key{ 'A' }, Key{ 'B' }); #ifdef TEST_GREATER_THAN CHECK_FALSE(compareAA); @@ -1857,14 +1120,14 @@ namespace } //************************************************************************* - TEST(test_key_comp_constexpr_transparent_comparator) + TEST(test_key_comp_transparent_comparator) { - static constexpr DataTransparentComparator data; - static constexpr DataTransparentComparator::key_compare compare = data.key_comp(); + static const DataTransparentComparator data; + static const DataTransparentComparator::key_compare compare = data.key_comp(); - static constexpr bool compareAA = compare('A', 'A'); - static constexpr bool compareBA = compare('B', 'A'); - static constexpr bool compareAB = compare('A', 'B'); + static const bool compareAA = compare('A', 'A'); + static const bool compareBA = compare('B', 'A'); + static const bool compareAB = compare('A', 'B'); #ifdef TEST_GREATER_THAN CHECK_FALSE(compareAA); @@ -1880,86 +1143,65 @@ namespace //************************************************************************* TEST(test_value_comp) { - static constexpr Data data; - static constexpr Data::value_compare compare = data.value_comp(); + static const Data data; + static const Data::value_compare compare = data.value_comp(); + + static const bool compareAA1 = compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'A' }, 0 }); + static const bool compareAA2 = compare(value_type{ Key{ 'A' }, 0 }, Key{ 'A' }); + static const bool compareAA3 = compare(Key{ 'A' }, value_type{ Key{ 'A' }, 0 }); + + static const bool compareBA1 = compare(value_type{ Key{ 'B' }, 0 }, value_type{ Key{ 'A' }, 0 }); + static const bool compareBA2 = compare(value_type{ Key{ 'B' }, 0 }, Key{ 'A' }); + static const bool compareBA3 = compare(Key{ 'B' }, value_type{ Key{ 'A' }, 0 }); + + static const bool compareAB1 = compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'B' }, 0 }); + static const bool compareAB2 = compare(value_type{ Key{ 'A' }, 0 }, Key{ 'B' }); + static const bool compareAB3 = compare(Key{ 'A' }, value_type{ Key{ 'B' }, 0 });; #ifdef TEST_GREATER_THAN - CHECK_FALSE(compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'A' }, 0 })); - CHECK_FALSE(compare(value_type{ Key{ 'A' }, 0 }, Key{ 'A' })); - CHECK_FALSE(compare(Key{ 'A' }, value_type{ Key{ 'A' }, 0 })); + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); - CHECK_TRUE(compare(value_type{ Key{ 'B' }, 1 }, value_type{ Key{ 'A' }, 0 })); - CHECK_TRUE(compare(value_type{ Key{ 'B' }, 1 }, Key{ 'A' })); - CHECK_TRUE(compare(Key{ 'B' }, value_type{ Key{ 'A' }, 0 })); + CHECK_TRUE(compareBA1); + CHECK_TRUE(compareBA2); + CHECK_TRUE(compareBA3); - CHECK_FALSE(compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'B' }, 1 })); - CHECK_FALSE(compare(value_type{ Key{ 'A' }, 0 }, Key{ 'B' })); - CHECK_FALSE(compare(Key{ 'A' }, value_type{ Key{ 'B' }, 1 })); + CHECK_FALSE(compareAB1); + CHECK_FALSE(compareAB2); + CHECK_FALSE(compareAB3); #else - CHECK_FALSE(compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'A' }, 0 })); - CHECK_FALSE(compare(value_type{ Key{ 'A' }, 0 }, Key{ 'A' })); - CHECK_FALSE(compare(Key{ 'A' }, value_type{ Key{ 'A' }, 0 })); + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); - CHECK_FALSE(compare(value_type{ Key{ 'B' }, 1 }, value_type{ Key{ 'A' }, 0 })); - CHECK_FALSE(compare(value_type{ Key{ 'B' }, 1 }, Key{ 'A' })); - CHECK_FALSE(compare(Key{ 'B' }, value_type{ Key{ 'A' }, 0 })); + CHECK_FALSE(compareBA1); + CHECK_FALSE(compareBA2); + CHECK_FALSE(compareBA3); - CHECK_TRUE(compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'B' }, 1 })); - CHECK_TRUE(compare(value_type{ Key{ 'A' }, 0 }, Key{ 'B' })); - CHECK_TRUE(compare(Key{ 'A' }, value_type{ Key{ 'B' }, 1 })); + CHECK_TRUE(compareAB1); + CHECK_TRUE(compareAB2); + CHECK_TRUE(compareAB3); #endif } //************************************************************************* TEST(test_value_comp_transparent_comparator) { - static constexpr DataTransparentComparator data; - static constexpr DataTransparentComparator::value_compare compare = data.value_comp(); + static const DataTransparentComparator data; + static const DataTransparentComparator::value_compare compare = data.value_comp(); -#ifdef TEST_GREATER_THAN - CHECK_FALSE(compare(value_type{ 'A', 0 }, value_type{ 'A', 0 })); - CHECK_FALSE(compare(value_type{ 'A', 0 }, 'A')); - CHECK_FALSE(compare('A', value_type{ 'A', 0 })); + static const bool compareAA1 = compare(value_type{ 'A', 0 }, value_type{ 'A', 0 }); + static const bool compareAA2 = compare(value_type{ 'A', 0 }, 'A'); + static const bool compareAA3 = compare('A', value_type{ 'A', 0 }); - CHECK_TRUE(compare(value_type{ 'B', 1 }, value_type{ 'A', 0 })); - CHECK_TRUE(compare(value_type{ 'B', 1 }, 'A')); - CHECK_TRUE(compare('B', value_type{ 'A', 0 })); + static const bool compareBA1 = compare(value_type{ 'B', 0 }, value_type{ 'A', 0 }); + static const bool compareBA2 = compare(value_type{ 'B', 0 }, 'A'); + static const bool compareBA3 = compare('B', value_type{ 'A', 0 }); - CHECK_FALSE(compare(value_type{ 'A', 0 }, value_type{ 'B', 1 })); - CHECK_FALSE(compare(value_type{ 'A', 0 }, 'B')); - CHECK_FALSE(compare('A', value_type{ 'B', 1 })); -#else - CHECK_FALSE(compare(value_type{ 'A', 0 }, value_type{ 'A', 0 })); - CHECK_FALSE(compare(value_type{ 'A', 0 }, 'A')); - CHECK_FALSE(compare('A', value_type{ 'A', 0 })); - - CHECK_FALSE(compare(value_type{ 'B', 1 }, value_type{ 'A', 0 })); - CHECK_FALSE(compare(value_type{ 'B', 1 }, 'A')); - CHECK_FALSE(compare('B', value_type{ 'A', 0 })); - - CHECK_TRUE(compare(value_type{ 'A', 0 }, value_type{ 'B', 1 })); - CHECK_TRUE(compare(value_type{ 'A', 0 }, 'B')); - CHECK_TRUE(compare('A', value_type{ 'B', 1 })); -#endif - } - - //************************************************************************* - TEST(test_value_comp_constexpr) - { - static constexpr Data data; - static constexpr Data::value_compare compare = data.value_comp(); - - static constexpr bool compareAA1 = compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'A' }, 0 }); - static constexpr bool compareAA2 = compare(value_type{ Key{ 'A' }, 0 }, Key{ 'A' }); - static constexpr bool compareAA3 = compare(Key{ 'A' }, value_type{ Key{ 'A' }, 0 }); - - static constexpr bool compareBA1 = compare(value_type{ Key{ 'B' }, 0 }, value_type{ Key{ 'A' }, 0 }); - static constexpr bool compareBA2 = compare(value_type{ Key{ 'B' }, 0 }, Key{ 'A' }); - static constexpr bool compareBA3 = compare(Key{ 'B' }, value_type{ Key{ 'A' }, 0 }); - - static constexpr bool compareAB1 = compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'B' }, 0 }); - static constexpr bool compareAB2 = compare(value_type{ Key{ 'A' }, 0 }, Key{ 'B' }); - static constexpr bool compareAB3 = compare(Key{ 'A' }, value_type{ Key{ 'B' }, 0 });; + static const bool compareAB1 = compare(value_type{ 'A', 0 }, value_type{ 'B', 0 }); + static const bool compareAB2 = compare(value_type{ 'A', 0 }, 'B'); + static const bool compareAB3 = compare('A', value_type{ 'B', 0 });; #ifdef TEST_GREATER_THAN CHECK_FALSE(compareAA1); @@ -1989,151 +1231,330 @@ namespace } //************************************************************************* - TEST(test_value_comp_constexpr_transparent_comparator) + TEST(test_equal) { - static constexpr DataTransparentComparator data; - static constexpr DataTransparentComparator::value_compare compare = data.value_comp(); + static const Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - static constexpr bool compareAA1 = compare(value_type{ 'A', 0 }, value_type{ 'A', 0 }); - static constexpr bool compareAA2 = compare(value_type{ 'A', 0 }, 'A'); - static constexpr bool compareAA3 = compare('A', value_type{ 'A', 0 }); + static const Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - static constexpr bool compareBA1 = compare(value_type{ 'B', 0 }, value_type{ 'A', 0 }); - static constexpr bool compareBA2 = compare(value_type{ 'B', 0 }, 'A'); - static constexpr bool compareBA3 = compare('B', value_type{ 'A', 0 }); + static const Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - static constexpr bool compareAB1 = compare(value_type{ 'A', 0 }, value_type{ 'B', 0 }); - static constexpr bool compareAB2 = compare(value_type{ 'A', 0 }, 'B'); - static constexpr bool compareAB3 = compare('A', value_type{ 'B', 0 });; + static const bool equal12 = (data1 == data2); + static const bool equal13 = (data1 == data3); -#ifdef TEST_GREATER_THAN - CHECK_FALSE(compareAA1); - CHECK_FALSE(compareAA2); - CHECK_FALSE(compareAA3); + CHECK_TRUE(equal12); + CHECK_FALSE(equal13); + } - CHECK_TRUE(compareBA1); - CHECK_TRUE(compareBA2); - CHECK_TRUE(compareBA3); + //************************************************************************* + TEST(test_equal_with_transparent_comparator) + { + static const DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - CHECK_FALSE(compareAB1); - CHECK_FALSE(compareAB2); - CHECK_FALSE(compareAB3); -#else - CHECK_FALSE(compareAA1); - CHECK_FALSE(compareAA2); - CHECK_FALSE(compareAA3); + static const DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - CHECK_FALSE(compareBA1); - CHECK_FALSE(compareBA2); - CHECK_FALSE(compareBA3); + static const DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - CHECK_TRUE(compareAB1); - CHECK_TRUE(compareAB2); - CHECK_TRUE(compareAB3); -#endif + static const bool equal12 = (data1 == data2); + static const bool equal13 = (data1 == data3); + + CHECK_TRUE(equal12); + CHECK_FALSE(equal13); + } + + //************************************************************************* + TEST(test_not_equal) + { + static const Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const bool not_equal12 = (data1 != data2); + static const bool not_equal13 = (data1 != data3); + + CHECK_FALSE(not_equal12); + CHECK_TRUE(not_equal13); + } + + //************************************************************************* + TEST(test_not_equal_with_transparent_comparator) + { + static const DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const bool not_equal12 = (data1 != data2); + static const bool not_equal13 = (data1 != data3); + + CHECK_FALSE(not_equal12); + CHECK_TRUE(not_equal13); } //************************************************************************* TEST(test_less_than) { - static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + static const Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + static const Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + static const Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const bool less_than12 = (data1 < data2); + static const bool less_than23 = (data2 < data3); + static const bool less_than21 = (data2 < data1); + static const bool less_than32 = (data3 < data2); #ifdef TEST_GREATER_THAN - CHECK_FALSE(data1 < data2); - CHECK_FALSE(data2 < data3); - CHECK_TRUE(data2 < data1); - CHECK_TRUE(data3 < data2); + CHECK_FALSE(less_than12); + CHECK_FALSE(less_than23); + CHECK_TRUE(less_than21); + CHECK_TRUE(less_than32); #else - CHECK_TRUE(data1 < data2); - CHECK_TRUE(data2 < data3); - CHECK_FALSE(data2 < data1); - CHECK_FALSE(data3 < data2); + CHECK_TRUE(less_than12); + CHECK_TRUE(less_than23); + CHECK_FALSE(less_than21); + CHECK_FALSE(less_than32); +#endif + } + + //************************************************************************* + TEST(test_less_than_with_transparent_comparator) + { + static const DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const bool less_than12 = (data1 < data2); + static const bool less_than23 = (data2 < data3); + static const bool less_than21 = (data2 < data1); + static const bool less_than32 = (data3 < data2); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than12); + CHECK_FALSE(less_than23); + CHECK_TRUE(less_than21); + CHECK_TRUE(less_than32); +#else + CHECK_TRUE(less_than12); + CHECK_TRUE(less_than23); + CHECK_FALSE(less_than21); + CHECK_FALSE(less_than32); #endif } //************************************************************************* TEST(test_less_than_equal) { - static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + static const Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + static const Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + static const Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const bool less_than_equal12 = (data1 <= data2); + static const bool less_than_equal23 = (data2 <= data3); + static const bool less_than_equal21 = (data2 <= data1); + static const bool less_than_equal32 = (data3 <= data2); + static const bool less_than_equal11 = (data1 <= data1); #ifdef TEST_GREATER_THAN - CHECK_FALSE(data1 <= data2); - CHECK_FALSE(data2 <= data3); - CHECK_TRUE(data2 <= data1); - CHECK_TRUE(data3 <= data2); - CHECK_TRUE(data1 <= data1); + CHECK_FALSE(less_than_equal12); + CHECK_FALSE(less_than_equal23); + CHECK_TRUE(less_than_equal21); + CHECK_TRUE(less_than_equal32); + CHECK_TRUE(less_than_equal11); #else - CHECK_TRUE(data1 <= data2); - CHECK_TRUE(data2 <= data3); - CHECK_FALSE(data2 <= data1); - CHECK_FALSE(data3 <= data2); - CHECK_TRUE(data1 <= data1); + CHECK_TRUE(less_than_equal12); + CHECK_TRUE(less_than_equal23); + CHECK_FALSE(less_than_equal21); + CHECK_FALSE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_less_than_equal_with_transparent_comparator) + { + static const DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const bool less_than_equal12 = (data1 <= data2); + static const bool less_than_equal23 = (data2 <= data3); + static const bool less_than_equal21 = (data2 <= data1); + static const bool less_than_equal32 = (data3 <= data2); + static const bool less_than_equal11 = (data1 <= data1); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than_equal12); + CHECK_FALSE(less_than_equal23); + CHECK_TRUE(less_than_equal21); + CHECK_TRUE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#else + CHECK_TRUE(less_than_equal12); + CHECK_TRUE(less_than_equal23); + CHECK_FALSE(less_than_equal21); + CHECK_FALSE(less_than_equal32); + CHECK_TRUE(less_than_equal11); #endif } //************************************************************************* TEST(test_greater_than) { - static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + static const Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + static const Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + static const Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const bool greater_than12 = (data1 > data2); + static const bool greater_than23 = (data2 > data3); + static const bool greater_than21 = (data2 > data1); + static const bool greater_than32 = (data3 > data2); #ifdef TEST_GREATER_THAN - CHECK_TRUE(data1 > data2); - CHECK_TRUE(data2 > data3); - CHECK_FALSE(data2 > data1); - CHECK_FALSE(data3 > data2); + CHECK_TRUE(greater_than12); + CHECK_TRUE(greater_than23); + CHECK_FALSE(greater_than21); + CHECK_FALSE(greater_than32); #else - CHECK_FALSE(data1 > data2); - CHECK_FALSE(data2 > data3); - CHECK_TRUE(data2 > data1); - CHECK_TRUE(data3 > data2); + CHECK_FALSE(greater_than12); + CHECK_FALSE(greater_than23); + CHECK_TRUE(greater_than21); + CHECK_TRUE(greater_than32); +#endif + } + + //************************************************************************* + TEST(test_greater_than_with_transparent_comparator) + { + static const DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const bool greater_than12 = (data1 > data2); + static const bool greater_than23 = (data2 > data3); + static const bool greater_than21 = (data2 > data1); + static const bool greater_than32 = (data3 > data2); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than12); + CHECK_TRUE(greater_than23); + CHECK_FALSE(greater_than21); + CHECK_FALSE(greater_than32); +#else + CHECK_FALSE(greater_than12); + CHECK_FALSE(greater_than23); + CHECK_TRUE(greater_than21); + CHECK_TRUE(greater_than32); #endif } //************************************************************************* TEST(test_greater_than_equal) { - static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + static const Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + static const Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + static const Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const bool greater_than_equal12 = (data1 >= data2); + static const bool greater_than_equal23 = (data2 >= data3); + static const bool greater_than_equal21 = (data2 >= data1); + static const bool greater_than_equal32 = (data3 >= data2); + static const bool greater_than_equal11 = (data1 >= data1); #ifdef TEST_GREATER_THAN - CHECK_TRUE(data1 >= data2); - CHECK_TRUE(data2 >= data3); - CHECK_FALSE(data2 >= data1); - CHECK_FALSE(data3 >= data2); - CHECK_TRUE(data1 <= data1); + CHECK_TRUE(greater_than_equal12); + CHECK_TRUE(greater_than_equal23); + CHECK_FALSE(greater_than_equal21); + CHECK_FALSE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); #else - CHECK_FALSE(data1 >= data2); - CHECK_FALSE(data2 >= data3); - CHECK_TRUE(data2 >= data1); - CHECK_TRUE(data3 >= data2); - CHECK_TRUE(data1 <= data1); + CHECK_FALSE(greater_than_equal12); + CHECK_FALSE(greater_than_equal23); + CHECK_TRUE(greater_than_equal21); + CHECK_TRUE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_greater_than_equal_with_transparent_comparator) + { + static const DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const bool greater_than_equal12 = (data1 >= data2); + static const bool greater_than_equal23 = (data2 >= data3); + static const bool greater_than_equal21 = (data2 >= data1); + static const bool greater_than_equal32 = (data3 >= data2); + static const bool greater_than_equal11 = (data1 >= data1); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than_equal12); + CHECK_TRUE(greater_than_equal23); + CHECK_FALSE(greater_than_equal21); + CHECK_FALSE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#else + CHECK_FALSE(greater_than_equal12); + CHECK_FALSE(greater_than_equal23); + CHECK_TRUE(greater_than_equal21); + CHECK_TRUE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); #endif } }; diff --git a/test/test_const_map_constexpr.cpp b/test/test_const_map_constexpr.cpp new file mode 100644 index 00000000..6296cf6c --- /dev/null +++ b/test/test_const_map_constexpr.cpp @@ -0,0 +1,1565 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove, rlindeman + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the 'Software'), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "etl/const_map.h" +#include "etl/map.h" +#include "etl/string.h" + +#include "data.h" + +#if ETL_USING_CPP14 + +namespace +{ + static const size_t Max_Size = 10UL; + + //************************************************************************* + // The key type + //************************************************************************* + struct Key + { + // Default constructor + constexpr Key() + : k(0) + { + } + + // Construct from char key + constexpr explicit Key(char k_) + : k(k_) + { + } + + char k; + }; + + // Less-than operator for Key < Key + constexpr bool operator <(const Key& lhs, const Key& rhs) noexcept + { + return (lhs.k < rhs.k); + } + + // Less-than operator for Key < char + constexpr bool operator <(const Key& lhs, char rhs) noexcept + { + return (lhs.k < rhs); + } + + // Less-than operator for char < Key + constexpr bool operator <(char lhs, const Key& rhs) noexcept + { + return (lhs < rhs.k); + } + + // Greater-than operator for char > Key + constexpr bool operator ==(const Key& lhs, const Key& rhs) noexcept + { + return (lhs.k == rhs.k); + } + + #define TEST_GREATER_THAN + #ifdef TEST_GREATER_THAN + using Data = etl::const_map>; + using IData = etl::iconst_map>; + using DataTransparentComparator = etl::const_map>; + using IDataTransparentComparator = etl::iconst_map>; + #else + using Data = etl::const_map>; + using IData = etl::iconst_map>; + using DataTransparentComparator = etl::const_map>; + using IDataTransparentComparator = etl::iconst_map>; + #endif + + using value_type = Data::value_type; + using Data_const_iterator = Data::const_iterator; + + SUITE(test_const_map) + { + //************************************************************************* + TEST(test_default_constructor) + { + static constexpr Data data; + + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr Data::const_iterator begin = data.begin(); + static constexpr Data::const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == 0UL); + CHECK_TRUE(empty); + CHECK_FALSE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_TRUE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_min_size) + { + static constexpr Data data{ value_type{Key('A'), 0 } }; + + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr Data::const_iterator begin = data.begin(); + static constexpr Data::const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == 1U); + CHECK_FALSE(empty); + CHECK_FALSE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_FALSE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_max_size) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr Data::const_iterator begin = data.begin(); + static constexpr Data::const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == Max_Size); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_FALSE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_max_size_status_from_iconst_map) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr const IData& idata = data; + + static constexpr bool is_valid = idata.is_valid(); + static constexpr size_t size = idata.size(); + static constexpr bool empty = idata.empty(); + static constexpr bool full = idata.full(); + static constexpr size_t capacity = idata.capacity(); + static constexpr size_t max_size = idata.max_size(); + static constexpr Data::const_iterator begin = idata.begin(); + static constexpr Data::const_iterator end = idata.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == Max_Size); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_FALSE(begin == end); + } + + ////************************************************************************* + // Enable to check static_assert "Number of elements exceeds capacity" + ////************************************************************************* + //TEST(test_constructor_excess_size) + //{ + // static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + // value_type{Key('F'), 5 }, value_type{'G'), 6 }, value_type{'H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, + // value_type{Key('K'), 10 } }; + //} + +#if ETL_USING_CPP17 + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + +#ifdef TEST_GREATER_THAN + etl::const_map check{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + etl::const_map check{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + CHECK_TRUE(data.is_valid()); + CHECK_TRUE(data.size() == Max_Size); + CHECK_FALSE(data.empty()); + CHECK_TRUE(data.full()); + CHECK_TRUE(data.capacity() == Max_Size); + CHECK_TRUE(data.max_size() == Max_Size); + CHECK_FALSE(data.begin() == data.end()); + } +#endif + + //************************************************************************* + TEST(test_begin) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + CHECK_TRUE(data.is_valid()); + static constexpr auto value = *data.begin(); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE((value_type{ Key('J'), 9 }) == value); +#else + CHECK_TRUE((value_type{ Key('A'), 0 }) == value); +#endif + } + + //************************************************************************* + TEST(test_end) + { + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data::const_iterator end_itr = data.end(); + + CHECK_TRUE(end_itr == (data.begin() + data.size())); + } + + //************************************************************************* + TEST(test_index) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data::mapped_type atA = data[Key('A')]; + static constexpr Data::mapped_type atB = data[Key('B')]; + static constexpr Data::mapped_type atC = data[Key('C')]; + static constexpr Data::mapped_type atD = data[Key('D')]; + static constexpr Data::mapped_type atE = data[Key('E')]; + static constexpr Data::mapped_type atF = data[Key('F')]; + static constexpr Data::mapped_type atG = data[Key('G')]; + static constexpr Data::mapped_type atH = data[Key('H')]; + static constexpr Data::mapped_type atI = data[Key('I')]; + static constexpr Data::mapped_type atJ = data[Key('J')]; + + CHECK_TRUE(data.is_valid()); + CHECK(atA == 0); + CHECK(atB == 1); + CHECK(atC == 2); + CHECK(atD == 3); + CHECK(atE == 4); + CHECK(atF == 5); + CHECK(atG == 6); + CHECK(atH == 7); + CHECK(atI == 8); + CHECK(atJ == 9); + } + + //************************************************************************* + TEST(test_index_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data::mapped_type atA = data['A']; + static constexpr Data::mapped_type atB = data['B']; + static constexpr Data::mapped_type atC = data['C']; + static constexpr Data::mapped_type atD = data['D']; + static constexpr Data::mapped_type atE = data['E']; + static constexpr Data::mapped_type atF = data['F']; + static constexpr Data::mapped_type atG = data['G']; + static constexpr Data::mapped_type atH = data['H']; + static constexpr Data::mapped_type atI = data['I']; + static constexpr Data::mapped_type atJ = data['J']; + + CHECK_TRUE(data.is_valid()); + CHECK(atA == 0); + CHECK(atB == 1); + CHECK(atC == 2); + CHECK(atD == 3); + CHECK(atE == 4); + CHECK(atF == 5); + CHECK(atG == 6); + CHECK(atH == 7); + CHECK(atI == 8); + CHECK(atJ == 9); + } + + //************************************************************************* + TEST(test_at) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data::mapped_type atA = data.at(Key('A')); + static constexpr Data::mapped_type atB = data.at(Key('B')); + static constexpr Data::mapped_type atC = data.at(Key('C')); + static constexpr Data::mapped_type atD = data.at(Key('D')); + static constexpr Data::mapped_type atE = data.at(Key('E')); + static constexpr Data::mapped_type atF = data.at(Key('F')); + static constexpr Data::mapped_type atG = data.at(Key('G')); + static constexpr Data::mapped_type atH = data.at(Key('H')); + static constexpr Data::mapped_type atI = data.at(Key('I')); + static constexpr Data::mapped_type atJ = data.at(Key('J')); + + CHECK_TRUE(data.is_valid()); + CHECK(atA == 0); + CHECK(atB == 1); + CHECK(atC == 2); + CHECK(atD == 3); + CHECK(atE == 4); + CHECK(atF == 5); + CHECK(atG == 6); + CHECK(atH == 7); + CHECK(atI == 8); + CHECK(atJ == 9); + } + + //************************************************************************* + TEST(test_at_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data::mapped_type atA = data.at('A'); + static constexpr Data::mapped_type atB = data.at('B'); + static constexpr Data::mapped_type atC = data.at('C'); + static constexpr Data::mapped_type atD = data.at('D'); + static constexpr Data::mapped_type atE = data.at('E'); + static constexpr Data::mapped_type atF = data.at('F'); + static constexpr Data::mapped_type atG = data.at('G'); + static constexpr Data::mapped_type atH = data.at('H'); + static constexpr Data::mapped_type atI = data.at('I'); + static constexpr Data::mapped_type atJ = data.at('J'); + + CHECK_TRUE(data.is_valid()); + CHECK(atA == 0); + CHECK(atB == 1); + CHECK(atC == 2); + CHECK(atD == 3); + CHECK(atE == 4); + CHECK(atF == 5); + CHECK(atG == 6); + CHECK(atH == 7); + CHECK(atI == 8); + CHECK(atJ == 9); + } + + //************************************************************************* + TEST(test_equal_range) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr ETL_OR_STD::pair resultA = data.equal_range(Key('A')); + static constexpr ETL_OR_STD::pair resultB = data.equal_range(Key('B')); + static constexpr ETL_OR_STD::pair resultC = data.equal_range(Key('C')); + static constexpr ETL_OR_STD::pair resultD = data.equal_range(Key('D')); + static constexpr ETL_OR_STD::pair resultE = data.equal_range(Key('E')); + static constexpr ETL_OR_STD::pair resultF = data.equal_range(Key('F')); + static constexpr ETL_OR_STD::pair resultG = data.equal_range(Key('G')); + static constexpr ETL_OR_STD::pair resultH = data.equal_range(Key('H')); + static constexpr ETL_OR_STD::pair resultI = data.equal_range(Key('I')); + static constexpr ETL_OR_STD::pair resultJ = data.equal_range(Key('J')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(10, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ.second))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(1, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ.second))); +#endif + } + + //************************************************************************* + TEST(test_equal_range_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr ETL_OR_STD::pair resultA = data.equal_range('A'); + static constexpr ETL_OR_STD::pair resultB = data.equal_range('B'); + static constexpr ETL_OR_STD::pair resultC = data.equal_range('C'); + static constexpr ETL_OR_STD::pair resultD = data.equal_range('D'); + static constexpr ETL_OR_STD::pair resultE = data.equal_range('E'); + static constexpr ETL_OR_STD::pair resultF = data.equal_range('F'); + static constexpr ETL_OR_STD::pair resultG = data.equal_range('G'); + static constexpr ETL_OR_STD::pair resultH = data.equal_range('H'); + static constexpr ETL_OR_STD::pair resultI = data.equal_range('I'); + static constexpr ETL_OR_STD::pair resultJ = data.equal_range('J'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(10, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ.second))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(1, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ.second))); +#endif + } + + //************************************************************************* + TEST(test_lower_bound) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; +#endif + + static constexpr Data::const_iterator resultA = data.lower_bound(Key('A')); + static constexpr Data::const_iterator resultB = data.lower_bound(Key('B')); + static constexpr Data::const_iterator resultC = data.lower_bound(Key('C')); + static constexpr Data::const_iterator resultD = data.lower_bound(Key('D')); + static constexpr Data::const_iterator resultE = data.lower_bound(Key('E')); + static constexpr Data::const_iterator resultF = data.lower_bound(Key('F')); + static constexpr Data::const_iterator resultG = data.lower_bound(Key('G')); + static constexpr Data::const_iterator resultH = data.lower_bound(Key('H')); + static constexpr Data::const_iterator resultI = data.lower_bound(Key('I')); + static constexpr Data::const_iterator resultJ = data.lower_bound(Key('J')); + static constexpr Data::const_iterator resultK = data.lower_bound(Key('K')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_lower_bound_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; +#endif + + static constexpr Data::const_iterator resultA = data.lower_bound('A'); + static constexpr Data::const_iterator resultB = data.lower_bound('B'); + static constexpr Data::const_iterator resultC = data.lower_bound('C'); + static constexpr Data::const_iterator resultD = data.lower_bound('D'); + static constexpr Data::const_iterator resultE = data.lower_bound('E'); + static constexpr Data::const_iterator resultF = data.lower_bound('F'); + static constexpr Data::const_iterator resultG = data.lower_bound('G'); + static constexpr Data::const_iterator resultH = data.lower_bound('H'); + static constexpr Data::const_iterator resultI = data.lower_bound('I'); + static constexpr Data::const_iterator resultJ = data.lower_bound('J'); + static constexpr Data::const_iterator resultK = data.lower_bound('K'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_upper_bound) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; +#endif + + static constexpr Data::const_iterator resultA = data.upper_bound(Key('A')); + static constexpr Data::const_iterator resultB = data.upper_bound(Key('B')); + static constexpr Data::const_iterator resultC = data.upper_bound(Key('C')); + static constexpr Data::const_iterator resultD = data.upper_bound(Key('D')); + static constexpr Data::const_iterator resultE = data.upper_bound(Key('E')); + static constexpr Data::const_iterator resultF = data.upper_bound(Key('F')); + static constexpr Data::const_iterator resultG = data.upper_bound(Key('G')); + static constexpr Data::const_iterator resultH = data.upper_bound(Key('H')); + static constexpr Data::const_iterator resultI = data.upper_bound(Key('I')); + static constexpr Data::const_iterator resultJ = data.upper_bound(Key('J')); + static constexpr Data::const_iterator resultK = data.upper_bound(Key('K')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(1, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_upper_bound_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; +#endif + + static constexpr Data::const_iterator resultA = data.upper_bound('A'); + static constexpr Data::const_iterator resultB = data.upper_bound('B'); + static constexpr Data::const_iterator resultC = data.upper_bound('C'); + static constexpr Data::const_iterator resultD = data.upper_bound('D'); + static constexpr Data::const_iterator resultE = data.upper_bound('E'); + static constexpr Data::const_iterator resultF = data.upper_bound('F'); + static constexpr Data::const_iterator resultG = data.upper_bound('G'); + static constexpr Data::const_iterator resultH = data.upper_bound('H'); + static constexpr Data::const_iterator resultI = data.upper_bound('I'); + static constexpr Data::const_iterator resultJ = data.upper_bound('J'); + static constexpr Data::const_iterator resultK = data.upper_bound('K'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(1, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_count) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr size_t countA = data.count(Key('A')); + static constexpr size_t countB = data.count(Key('B')); + static constexpr size_t countC = data.count(Key('C')); + static constexpr size_t countD = data.count(Key('D')); + static constexpr size_t countE = data.count(Key('E')); + static constexpr size_t countF = data.count(Key('F')); + static constexpr size_t countG = data.count(Key('G')); + static constexpr size_t countH = data.count(Key('H')); + static constexpr size_t countI = data.count(Key('I')); + static constexpr size_t countJ = data.count(Key('J')); + static constexpr size_t countK = data.count(Key('K')); + + CHECK_EQUAL(1, countA); + CHECK_EQUAL(1, countB); + CHECK_EQUAL(1, countC); + CHECK_EQUAL(1, countD); + CHECK_EQUAL(1, countE); + CHECK_EQUAL(1, countF); + CHECK_EQUAL(1, countG); + CHECK_EQUAL(1, countH); + CHECK_EQUAL(1, countI); + CHECK_EQUAL(1, countJ); + CHECK_EQUAL(0, countK); + } + + //************************************************************************* + TEST(test_count_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr size_t countA = data.count('A'); + static constexpr size_t countB = data.count('B'); + static constexpr size_t countC = data.count('C'); + static constexpr size_t countD = data.count('D'); + static constexpr size_t countE = data.count('E'); + static constexpr size_t countF = data.count('F'); + static constexpr size_t countG = data.count('G'); + static constexpr size_t countH = data.count('H'); + static constexpr size_t countI = data.count('I'); + static constexpr size_t countJ = data.count('J'); + static constexpr size_t countK = data.count('K'); + + CHECK_EQUAL(1, countA); + CHECK_EQUAL(1, countB); + CHECK_EQUAL(1, countC); + CHECK_EQUAL(1, countD); + CHECK_EQUAL(1, countE); + CHECK_EQUAL(1, countF); + CHECK_EQUAL(1, countG); + CHECK_EQUAL(1, countH); + CHECK_EQUAL(1, countI); + CHECK_EQUAL(1, countJ); + CHECK_EQUAL(0, countK); + } + + //************************************************************************* + TEST(test_const_iterator) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + Data::const_iterator itr = data.begin(); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); + CHECK_TRUE((value_type{Key('I'), 8 }) == *itr++); + CHECK_TRUE((value_type{Key('H'), 7 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 6 }) == *itr++); + CHECK_TRUE((value_type{Key('F'), 5 }) == *itr++); + CHECK_TRUE((value_type{Key('E'), 4 }) == *itr++); + CHECK_TRUE((value_type{Key('D'), 3 }) == *itr++); + CHECK_TRUE((value_type{Key('C'), 2 }) == *itr++); + CHECK_TRUE((value_type{Key('B'), 1 }) == *itr++); + CHECK_TRUE((value_type{Key('A'), 0 }) == *itr++); + CHECK_TRUE(itr == data.end()); +#else + CHECK_TRUE((value_type{Key('A'), 0 }) == *itr++); + CHECK_TRUE((value_type{Key('B'), 1 }) == *itr++); + CHECK_TRUE((value_type{Key('C'), 2 }) == *itr++); + CHECK_TRUE((value_type{Key('D'), 3 }) == *itr++); + CHECK_TRUE((value_type{Key('E'), 4 }) == *itr++); + CHECK_TRUE((value_type{Key('F'), 5 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 6 }) == *itr++); + CHECK_TRUE((value_type{Key('H'), 7 }) == *itr++); + CHECK_TRUE((value_type{Key('I'), 8 }) == *itr++); + CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); + CHECK_TRUE(itr == data.end()); +#endif + } + + //************************************************************************* + TEST(test_find) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data::const_iterator resultA = data.find(Key('A')); + static constexpr Data::const_iterator resultB = data.find(Key('B')); + static constexpr Data::const_iterator resultC = data.find(Key('C')); + static constexpr Data::const_iterator resultD = data.find(Key('D')); + static constexpr Data::const_iterator resultE = data.find(Key('E')); + static constexpr Data::const_iterator resultF = data.find(Key('F')); + static constexpr Data::const_iterator resultG = data.find(Key('G')); + static constexpr Data::const_iterator resultH = data.find(Key('H')); + static constexpr Data::const_iterator resultI = data.find(Key('I')); + static constexpr Data::const_iterator resultJ = data.find(Key('J')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); +#endif + } + + //************************************************************************* + TEST(test_find_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data::const_iterator resultA = data.find('A'); + static constexpr Data::const_iterator resultB = data.find('B'); + static constexpr Data::const_iterator resultC = data.find('C'); + static constexpr Data::const_iterator resultD = data.find('D'); + static constexpr Data::const_iterator resultE = data.find('E'); + static constexpr Data::const_iterator resultF = data.find('F'); + static constexpr Data::const_iterator resultG = data.find('G'); + static constexpr Data::const_iterator resultH = data.find('H'); + static constexpr Data::const_iterator resultI = data.find('I'); + static constexpr Data::const_iterator resultJ = data.find('J'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); +#endif + } + + //************************************************************************* + TEST(test_key_compare) + { + static constexpr Data data; + + static constexpr Data::key_compare compare = data.key_comp(); + + static constexpr Data::key_type a(Key('A')); + static constexpr Data::key_type b(Key('B')); + +#ifdef TEST_GREATER_THAN + CHECK(!compare(a, b)); + CHECK(compare(b, a)); +#else + CHECK(compare(a, b)); + CHECK(!compare(b, a)); +#endif + } + + //************************************************************************* + TEST(test_key_compare_using_transparent_comparator) + { + static constexpr DataTransparentComparator data; + + static constexpr DataTransparentComparator::key_compare compare = data.key_comp(); + + static constexpr DataTransparentComparator::key_type a(Key('A')); + static constexpr DataTransparentComparator::key_type b(Key('B')); + +#ifdef TEST_GREATER_THAN + CHECK(!compare(a, b)); + CHECK(compare(b, a)); +#else + CHECK(compare(a, b)); + CHECK(!compare(b, a)); +#endif + } + + //************************************************************************* + TEST(test_value_compare) + { + static constexpr Data data; + + static constexpr Data::value_compare compare = data.value_comp(); + + static constexpr Data::value_type a(Key('A'), 0); + static constexpr Data::value_type b(Key('B'), 1); + +#ifdef TEST_GREATER_THAN + CHECK(!compare(a, b)); + CHECK(compare(b, a)); +#else + CHECK(compare(a, b)); + CHECK(!compare(b, a)); +#endif + } + + //************************************************************************* + TEST(test_contains) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr bool containsA = data.contains(Key('A')); + static constexpr bool containsB = data.contains(Key('B')); + static constexpr bool containsC = data.contains(Key('C')); + static constexpr bool containsD = data.contains(Key('D')); + static constexpr bool containsE = data.contains(Key('E')); + static constexpr bool containsF = data.contains(Key('F')); + static constexpr bool containsG = data.contains(Key('G')); + static constexpr bool containsH = data.contains(Key('H')); + static constexpr bool containsI = data.contains(Key('I')); + static constexpr bool containsJ = data.contains(Key('J')); + static constexpr bool containsK = data.contains(Key('K')); + + CHECK_TRUE(containsA); + CHECK_TRUE(containsB); + CHECK_TRUE(containsC); + CHECK_TRUE(containsD); + CHECK_TRUE(containsE); + CHECK_TRUE(containsF); + CHECK_TRUE(containsG); + CHECK_TRUE(containsH); + CHECK_TRUE(containsI); + CHECK_TRUE(containsJ); + CHECK_FALSE(containsK); + } + + //************************************************************************* + TEST(test_contains_with_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr bool containsA = data.contains('A'); + static constexpr bool containsB = data.contains('B'); + static constexpr bool containsC = data.contains('C'); + static constexpr bool containsD = data.contains('D'); + static constexpr bool containsE = data.contains('E'); + static constexpr bool containsF = data.contains('F'); + static constexpr bool containsG = data.contains('G'); + static constexpr bool containsH = data.contains('H'); + static constexpr bool containsI = data.contains('I'); + static constexpr bool containsJ = data.contains('J'); + static constexpr bool containsK = data.contains('K'); + + CHECK_TRUE(containsA); + CHECK_TRUE(containsB); + CHECK_TRUE(containsC); + CHECK_TRUE(containsD); + CHECK_TRUE(containsE); + CHECK_TRUE(containsF); + CHECK_TRUE(containsG); + CHECK_TRUE(containsH); + CHECK_TRUE(containsI); + CHECK_TRUE(containsJ); + CHECK_FALSE(containsK); + } + + //************************************************************************* + TEST(test_key_comp) + { + static constexpr Data data; + static constexpr Data::key_compare compare = data.key_comp(); + + static constexpr bool compareAA = compare(Key{ 'A' }, Key{ 'A' }); + static constexpr bool compareBA = compare(Key{ 'B' }, Key{ 'A' }); + static constexpr bool compareAB = compare(Key{ 'A' }, Key{ 'B' }); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA); + CHECK_TRUE(compareBA); + CHECK_FALSE(compareAB); +#else + CHECK_FALSE(compareAA); + CHECK_FALSE(compareBA); + CHECK_TRUE(compareAB); +#endif + } + + //************************************************************************* + TEST(test_key_comp_transparent_comparator) + { + static constexpr DataTransparentComparator data; + static constexpr DataTransparentComparator::key_compare compare = data.key_comp(); + + static constexpr bool compareAA = compare('A', 'A'); + static constexpr bool compareBA = compare('B', 'A'); + static constexpr bool compareAB = compare('A', 'B'); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA); + CHECK_TRUE(compareBA); + CHECK_FALSE(compareAB); +#else + CHECK_FALSE(compareAA); + CHECK_FALSE(compareBA); + CHECK_TRUE(compareAB); +#endif + } + + //************************************************************************* + TEST(test_value_comp) + { + static constexpr Data data; + static constexpr Data::value_compare compare = data.value_comp(); + + static constexpr bool compareAA1 = compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'A' }, 0 }); + static constexpr bool compareAA2 = compare(value_type{ Key{ 'A' }, 0 }, Key{ 'A' }); + static constexpr bool compareAA3 = compare(Key{ 'A' }, value_type{ Key{ 'A' }, 0 }); + + static constexpr bool compareBA1 = compare(value_type{ Key{ 'B' }, 0 }, value_type{ Key{ 'A' }, 0 }); + static constexpr bool compareBA2 = compare(value_type{ Key{ 'B' }, 0 }, Key{ 'A' }); + static constexpr bool compareBA3 = compare(Key{ 'B' }, value_type{ Key{ 'A' }, 0 }); + + static constexpr bool compareAB1 = compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'B' }, 0 }); + static constexpr bool compareAB2 = compare(value_type{ Key{ 'A' }, 0 }, Key{ 'B' }); + static constexpr bool compareAB3 = compare(Key{ 'A' }, value_type{ Key{ 'B' }, 0 });; + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_TRUE(compareBA1); + CHECK_TRUE(compareBA2); + CHECK_TRUE(compareBA3); + + CHECK_FALSE(compareAB1); + CHECK_FALSE(compareAB2); + CHECK_FALSE(compareAB3); +#else + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_FALSE(compareBA1); + CHECK_FALSE(compareBA2); + CHECK_FALSE(compareBA3); + + CHECK_TRUE(compareAB1); + CHECK_TRUE(compareAB2); + CHECK_TRUE(compareAB3); +#endif + } + + //************************************************************************* + TEST(test_value_comp_transparent_comparator) + { + static constexpr DataTransparentComparator data; + static constexpr DataTransparentComparator::value_compare compare = data.value_comp(); + + static constexpr bool compareAA1 = compare(value_type{ 'A', 0 }, value_type{ 'A', 0 }); + static constexpr bool compareAA2 = compare(value_type{ 'A', 0 }, 'A'); + static constexpr bool compareAA3 = compare('A', value_type{ 'A', 0 }); + + static constexpr bool compareBA1 = compare(value_type{ 'B', 0 }, value_type{ 'A', 0 }); + static constexpr bool compareBA2 = compare(value_type{ 'B', 0 }, 'A'); + static constexpr bool compareBA3 = compare('B', value_type{ 'A', 0 }); + + static constexpr bool compareAB1 = compare(value_type{ 'A', 0 }, value_type{ 'B', 0 }); + static constexpr bool compareAB2 = compare(value_type{ 'A', 0 }, 'B'); + static constexpr bool compareAB3 = compare('A', value_type{ 'B', 0 });; + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_TRUE(compareBA1); + CHECK_TRUE(compareBA2); + CHECK_TRUE(compareBA3); + + CHECK_FALSE(compareAB1); + CHECK_FALSE(compareAB2); + CHECK_FALSE(compareAB3); +#else + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_FALSE(compareBA1); + CHECK_FALSE(compareBA2); + CHECK_FALSE(compareBA3); + + CHECK_TRUE(compareAB1); + CHECK_TRUE(compareAB2); + CHECK_TRUE(compareAB3); +#endif + } + + //************************************************************************* + TEST(test_equal) + { + static constexpr Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool equal12 = (data1 == data2); + static constexpr bool equal13 = (data1 == data3); + + CHECK_TRUE(equal12); + CHECK_FALSE(equal13); + } + + //************************************************************************* + TEST(test_equal_with_transparent_comparator) + { + static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool equal12 = (data1 == data2); + static constexpr bool equal13 = (data1 == data3); + + CHECK_TRUE(equal12); + CHECK_FALSE(equal13); + } + + //************************************************************************* + TEST(test_not_equal) + { + static constexpr Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool not_equal12 = (data1 != data2); + static constexpr bool not_equal13 = (data1 != data3); + + CHECK_FALSE(not_equal12); + CHECK_TRUE(not_equal13); + } + + //************************************************************************* + TEST(test_not_equal_with_transparent_comparator) + { + static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool not_equal12 = (data1 != data2); + static constexpr bool not_equal13 = (data1 != data3); + + CHECK_FALSE(not_equal12); + CHECK_TRUE(not_equal13); + } + + //************************************************************************* + TEST(test_less_than) + { + static constexpr Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool less_than12 = (data1 < data2); + static constexpr bool less_than23 = (data2 < data3); + static constexpr bool less_than21 = (data2 < data1); + static constexpr bool less_than32 = (data3 < data2); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than12); + CHECK_FALSE(less_than23); + CHECK_TRUE(less_than21); + CHECK_TRUE(less_than32); +#else + CHECK_TRUE(less_than12); + CHECK_TRUE(less_than23); + CHECK_FALSE(less_than21); + CHECK_FALSE(less_than32); +#endif + } + + //************************************************************************* + TEST(test_less_than_with_transparent_comparator) + { + static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool less_than12 = (data1 < data2); + static constexpr bool less_than23 = (data2 < data3); + static constexpr bool less_than21 = (data2 < data1); + static constexpr bool less_than32 = (data3 < data2); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than12); + CHECK_FALSE(less_than23); + CHECK_TRUE(less_than21); + CHECK_TRUE(less_than32); +#else + CHECK_TRUE(less_than12); + CHECK_TRUE(less_than23); + CHECK_FALSE(less_than21); + CHECK_FALSE(less_than32); +#endif + } + + //************************************************************************* + TEST(test_less_than_equal) + { + static constexpr Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool less_than_equal12 = (data1 <= data2); + static constexpr bool less_than_equal23 = (data2 <= data3); + static constexpr bool less_than_equal21 = (data2 <= data1); + static constexpr bool less_than_equal32 = (data3 <= data2); + static constexpr bool less_than_equal11 = (data1 <= data1); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than_equal12); + CHECK_FALSE(less_than_equal23); + CHECK_TRUE(less_than_equal21); + CHECK_TRUE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#else + CHECK_TRUE(less_than_equal12); + CHECK_TRUE(less_than_equal23); + CHECK_FALSE(less_than_equal21); + CHECK_FALSE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_less_than_equal_with_transparent_comparator) + { + static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool less_than_equal12 = (data1 <= data2); + static constexpr bool less_than_equal23 = (data2 <= data3); + static constexpr bool less_than_equal21 = (data2 <= data1); + static constexpr bool less_than_equal32 = (data3 <= data2); + static constexpr bool less_than_equal11 = (data1 <= data1); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than_equal12); + CHECK_FALSE(less_than_equal23); + CHECK_TRUE(less_than_equal21); + CHECK_TRUE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#else + CHECK_TRUE(less_than_equal12); + CHECK_TRUE(less_than_equal23); + CHECK_FALSE(less_than_equal21); + CHECK_FALSE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_greater_than) + { + static constexpr Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool greater_than12 = (data1 > data2); + static constexpr bool greater_than23 = (data2 > data3); + static constexpr bool greater_than21 = (data2 > data1); + static constexpr bool greater_than32 = (data3 > data2); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than12); + CHECK_TRUE(greater_than23); + CHECK_FALSE(greater_than21); + CHECK_FALSE(greater_than32); +#else + CHECK_FALSE(greater_than12); + CHECK_FALSE(greater_than23); + CHECK_TRUE(greater_than21); + CHECK_TRUE(greater_than32); +#endif + } + + //************************************************************************* + TEST(test_greater_than_with_transparent_comparator) + { + static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool greater_than12 = (data1 > data2); + static constexpr bool greater_than23 = (data2 > data3); + static constexpr bool greater_than21 = (data2 > data1); + static constexpr bool greater_than32 = (data3 > data2); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than12); + CHECK_TRUE(greater_than23); + CHECK_FALSE(greater_than21); + CHECK_FALSE(greater_than32); +#else + CHECK_FALSE(greater_than12); + CHECK_FALSE(greater_than23); + CHECK_TRUE(greater_than21); + CHECK_TRUE(greater_than32); +#endif + } + + //************************************************************************* + TEST(test_greater_than_equal) + { + static constexpr Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool greater_than_equal12 = (data1 >= data2); + static constexpr bool greater_than_equal23 = (data2 >= data3); + static constexpr bool greater_than_equal21 = (data2 >= data1); + static constexpr bool greater_than_equal32 = (data3 >= data2); + static constexpr bool greater_than_equal11 = (data1 >= data1); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than_equal12); + CHECK_TRUE(greater_than_equal23); + CHECK_FALSE(greater_than_equal21); + CHECK_FALSE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#else + CHECK_FALSE(greater_than_equal12); + CHECK_FALSE(greater_than_equal23); + CHECK_TRUE(greater_than_equal21); + CHECK_TRUE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_greater_than_equal_with_transparent_comparator) + { + static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool greater_than_equal12 = (data1 >= data2); + static constexpr bool greater_than_equal23 = (data2 >= data3); + static constexpr bool greater_than_equal21 = (data2 >= data1); + static constexpr bool greater_than_equal32 = (data3 >= data2); + static constexpr bool greater_than_equal11 = (data1 >= data1); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than_equal12); + CHECK_TRUE(greater_than_equal23); + CHECK_FALSE(greater_than_equal21); + CHECK_FALSE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#else + CHECK_FALSE(greater_than_equal12); + CHECK_FALSE(greater_than_equal23); + CHECK_TRUE(greater_than_equal21); + CHECK_TRUE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#endif + } + }; +} + +#endif diff --git a/test/test_const_multimap.cpp b/test/test_const_multimap.cpp new file mode 100644 index 00000000..d3c8bd7b --- /dev/null +++ b/test/test_const_multimap.cpp @@ -0,0 +1,1270 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove, rlindeman + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the 'Software'), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "etl/const_multimap.h" +#include "etl/string.h" + +#include "data.h" + +namespace +{ + static const size_t Max_Size = 10UL; + + //************************************************************************* + // The key type + //************************************************************************* + struct Key + { + // Default constructor + constexpr Key() + : k(0) + { + } + + // Construct from char key + constexpr explicit Key(char k_) + : k(k_) + { + } + + char k; + }; + + // Less-than operator for Key < Key + constexpr bool operator <(const Key& lhs, const Key& rhs) noexcept + { + return (lhs.k < rhs.k); + } + + // Less-than operator for Key < char + constexpr bool operator <(const Key& lhs, char rhs) noexcept + { + return (lhs.k < rhs); + } + + // Less-than operator for char < Key + constexpr bool operator <(char lhs, const Key& rhs) noexcept + { + return (lhs < rhs.k); + } + + // Greater-than operator for char > Key + constexpr bool operator ==(const Key& lhs, const Key& rhs) noexcept + { + return (lhs.k == rhs.k); + } + +#define TEST_GREATER_THAN +#ifdef TEST_GREATER_THAN + using Data = etl::const_multimap>; + using IData = etl::iconst_multimap>; + using DataTransparentComparator = etl::const_multimap>; + using IDataTransparentComparator = etl::iconst_multimap>; +#else + using Data = etl::const_multimap>; + using IData = etl::iconst_multimap>; + using DataTransparentComparator = etl::const_multimap>; + using IDataTransparentComparator = etl::iconst_multimap>; +#endif + + using value_type = Data::value_type; + using Data_const_iterator = Data::const_iterator; + + SUITE(test_const_multimap) + { + //************************************************************************* + TEST(test_default_constructor) + { + static const Data data; + + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const Data::const_iterator begin = data.begin(); + static const Data::const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == 0UL); + CHECK_TRUE(empty); + CHECK_FALSE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_TRUE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_min_size) + { + static const Data data{ value_type{Key('A'), 0 } }; + + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const Data::const_iterator begin = data.begin(); + static const Data::const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == 1U); + CHECK_FALSE(empty); + CHECK_FALSE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_FALSE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_max_size) + { +#ifdef TEST_GREATER_THAN + static const Data data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const Data::const_iterator begin = data.begin(); + static const Data::const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == Max_Size); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_FALSE(begin == end); + } + + //************************************************************************* + // Enable to check static_assert "Number of elements exceeds capacity" + //************************************************************************* + //TEST(test_constructor_excess_size) + //{ + // static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + // value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G')), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 }, + // value_type{Key('K'), 10 } }; + //} + +#if ETL_USING_CPP17 + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { +#ifdef TEST_GREATER_THAN + static const Data data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + +#ifdef TEST_GREATER_THAN + etl::const_multimap check{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + etl::const_multimap check{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + CHECK_TRUE(data.is_valid()); + CHECK_TRUE(data.size() == Max_Size); + CHECK_FALSE(data.empty()); + CHECK_TRUE(data.full()); + CHECK_TRUE(data.capacity() == Max_Size); + CHECK_TRUE(data.max_size() == Max_Size); + CHECK_FALSE(data.begin() == data.end()); + } +#endif + + //************************************************************************* + TEST(test_begin_const) + { +#ifdef TEST_GREATER_THAN + static const Data data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + CHECK_TRUE(data.is_valid()); + static const auto value = *data.begin(); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE((value_type{ Key('J'), 9 }) == value); +#else + CHECK_TRUE((value_type{ Key('A'), 0 }) == value); +#endif + } + + //************************************************************************* + TEST(test_end_const) + { + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; + + static const Data::const_iterator end_itr = data.end(); + + CHECK_TRUE(end_itr == (data.begin() + data.size())); + } + + //************************************************************************* + TEST(test_equal_range_const) + { +#ifdef TEST_GREATER_THAN + static const Data data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const ETL_OR_STD::pair resultA = data.equal_range(Key('A')); + static const ETL_OR_STD::pair resultB = data.equal_range(Key('B')); + static const ETL_OR_STD::pair resultC = data.equal_range(Key('C')); + static const ETL_OR_STD::pair resultD = data.equal_range(Key('D')); + static const ETL_OR_STD::pair resultE = data.equal_range(Key('E')); + static const ETL_OR_STD::pair resultF = data.equal_range(Key('F')); + static const ETL_OR_STD::pair resultG = data.equal_range(Key('G')); + static const ETL_OR_STD::pair resultH = data.equal_range(Key('H')); + static const ETL_OR_STD::pair resultI = data.equal_range(Key('I')); + static const ETL_OR_STD::pair resultJ = data.equal_range(Key('J')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(10, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ.second))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(1, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ.second))); +#endif + } + + //************************************************************************* + TEST(test_equal_range_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const ETL_OR_STD::pair resultA = data.equal_range('A'); + static const ETL_OR_STD::pair resultB = data.equal_range('B'); + static const ETL_OR_STD::pair resultC = data.equal_range('C'); + static const ETL_OR_STD::pair resultD = data.equal_range('D'); + static const ETL_OR_STD::pair resultE = data.equal_range('E'); + static const ETL_OR_STD::pair resultF = data.equal_range('F'); + static const ETL_OR_STD::pair resultG = data.equal_range('G'); + static const ETL_OR_STD::pair resultH = data.equal_range('H'); + static const ETL_OR_STD::pair resultI = data.equal_range('I'); + static const ETL_OR_STD::pair resultJ = data.equal_range('J'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(10, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ.second))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(1, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ.second))); +#endif + } + + //************************************************************************* + TEST(test_lower_bound_const) + { +#ifdef TEST_GREATER_THAN + static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data::const_iterator resultA = data.lower_bound(Key('A')); + static const Data::const_iterator resultB = data.lower_bound(Key('B')); + static const Data::const_iterator resultC = data.lower_bound(Key('C')); + static const Data::const_iterator resultD = data.lower_bound(Key('D')); + static const Data::const_iterator resultE = data.lower_bound(Key('E')); + static const Data::const_iterator resultF = data.lower_bound(Key('F')); + static const Data::const_iterator resultG = data.lower_bound(Key('G')); + static const Data::const_iterator resultH = data.lower_bound(Key('H')); + static const Data::const_iterator resultI = data.lower_bound(Key('I')); + static const Data::const_iterator resultJ = data.lower_bound(Key('J')); + static const Data::const_iterator resultK = data.lower_bound(Key('K')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_lower_bound_const_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data::const_iterator resultA = data.lower_bound('A'); + static const Data::const_iterator resultB = data.lower_bound('B'); + static const Data::const_iterator resultC = data.lower_bound('C'); + static const Data::const_iterator resultD = data.lower_bound('D'); + static const Data::const_iterator resultE = data.lower_bound('E'); + static const Data::const_iterator resultF = data.lower_bound('F'); + static const Data::const_iterator resultG = data.lower_bound('G'); + static const Data::const_iterator resultH = data.lower_bound('H'); + static const Data::const_iterator resultI = data.lower_bound('I'); + static const Data::const_iterator resultJ = data.lower_bound('J'); + static const Data::const_iterator resultK = data.lower_bound('K'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_upper_bound_const) + { +#ifdef TEST_GREATER_THAN + static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data::const_iterator resultA = data.upper_bound(Key('A')); + static const Data::const_iterator resultB = data.upper_bound(Key('B')); + static const Data::const_iterator resultC = data.upper_bound(Key('C')); + static const Data::const_iterator resultD = data.upper_bound(Key('D')); + static const Data::const_iterator resultE = data.upper_bound(Key('E')); + static const Data::const_iterator resultF = data.upper_bound(Key('F')); + static const Data::const_iterator resultG = data.upper_bound(Key('G')); + static const Data::const_iterator resultH = data.upper_bound(Key('H')); + static const Data::const_iterator resultI = data.upper_bound(Key('I')); + static const Data::const_iterator resultJ = data.upper_bound(Key('J')); + static const Data::const_iterator resultK = data.upper_bound(Key('K')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(1, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_upper_bound_const_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data::const_iterator resultA = data.upper_bound('A'); + static const Data::const_iterator resultB = data.upper_bound('B'); + static const Data::const_iterator resultC = data.upper_bound('C'); + static const Data::const_iterator resultD = data.upper_bound('D'); + static const Data::const_iterator resultE = data.upper_bound('E'); + static const Data::const_iterator resultF = data.upper_bound('F'); + static const Data::const_iterator resultG = data.upper_bound('G'); + static const Data::const_iterator resultH = data.upper_bound('H'); + static const Data::const_iterator resultI = data.upper_bound('I'); + static const Data::const_iterator resultJ = data.upper_bound('J'); + static const Data::const_iterator resultK = data.upper_bound('K'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(1, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_count_const) + { +#ifdef TEST_GREATER_THAN + static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + CHECK_EQUAL(1, data.count(Key('A'))); + CHECK_EQUAL(1, data.count(Key('B'))); + CHECK_EQUAL(1, data.count(Key('C'))); + CHECK_EQUAL(1, data.count(Key('D'))); + CHECK_EQUAL(1, data.count(Key('E'))); + CHECK_EQUAL(1, data.count(Key('F'))); + CHECK_EQUAL(3, data.count(Key('G'))); + CHECK_EQUAL(0, data.count(Key('H'))); + CHECK_EQUAL(0, data.count(Key('I'))); + CHECK_EQUAL(1, data.count(Key('J'))); + CHECK_EQUAL(0, data.count(Key('K'))); + } + + //************************************************************************* + TEST(test_count_const_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + CHECK_EQUAL(1, data.count('A')); + CHECK_EQUAL(1, data.count('B')); + CHECK_EQUAL(1, data.count('C')); + CHECK_EQUAL(1, data.count('D')); + CHECK_EQUAL(1, data.count('E')); + CHECK_EQUAL(1, data.count('F')); + CHECK_EQUAL(3, data.count('G')); + CHECK_EQUAL(0, data.count('H')); + CHECK_EQUAL(0, data.count('I')); + CHECK_EQUAL(1, data.count('J')); + CHECK_EQUAL(0, data.count('K')); + } + + //************************************************************************* + TEST(test_const_iterator) + { +#ifdef TEST_GREATER_THAN + static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + Data::const_iterator itr = data.begin(); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 8 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 7 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 6 }) == *itr++); + CHECK_TRUE((value_type{Key('F'), 5 }) == *itr++); + CHECK_TRUE((value_type{Key('E'), 4 }) == *itr++); + CHECK_TRUE((value_type{Key('D'), 3 }) == *itr++); + CHECK_TRUE((value_type{Key('C'), 2 }) == *itr++); + CHECK_TRUE((value_type{Key('B'), 1 }) == *itr++); + CHECK_TRUE((value_type{Key('A'), 0 }) == *itr++); + CHECK_TRUE(itr == data.end()); +#else + CHECK_TRUE((value_type{Key('A'), 0 }) == *itr++); + CHECK_TRUE((value_type{Key('B'), 1 }) == *itr++); + CHECK_TRUE((value_type{Key('C'), 2 }) == *itr++); + CHECK_TRUE((value_type{Key('D'), 3 }) == *itr++); + CHECK_TRUE((value_type{Key('E'), 4 }) == *itr++); + CHECK_TRUE((value_type{Key('F'), 5 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 6 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 7 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 8 }) == *itr++); + CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); + CHECK_TRUE(itr == data.end()); +#endif + } + + //************************************************************************* + TEST(test_find_const) + { +#ifdef TEST_GREATER_THAN + static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data::const_iterator resultA = data.find(Key('A')); + static const Data::const_iterator resultB = data.find(Key('B')); + static const Data::const_iterator resultC = data.find(Key('C')); + static const Data::const_iterator resultD = data.find(Key('D')); + static const Data::const_iterator resultE = data.find(Key('E')); + static const Data::const_iterator resultF = data.find(Key('F')); + static const Data::const_iterator resultG = data.find(Key('G')); + static const Data::const_iterator resultH = data.find(Key('H')); + static const Data::const_iterator resultI = data.find(Key('I')); + static const Data::const_iterator resultJ = data.find(Key('J')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); +#endif + } + + //************************************************************************* + TEST(test_find_const_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data::const_iterator resultA = data.find('A'); + static const Data::const_iterator resultB = data.find('B'); + static const Data::const_iterator resultC = data.find('C'); + static const Data::const_iterator resultD = data.find('D'); + static const Data::const_iterator resultE = data.find('E'); + static const Data::const_iterator resultF = data.find('F'); + static const Data::const_iterator resultG = data.find('G'); + static const Data::const_iterator resultH = data.find('H'); + static const Data::const_iterator resultI = data.find('I'); + static const Data::const_iterator resultJ = data.find('J'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); +#endif + } + + //************************************************************************* + TEST(test_contains_const) + { +#ifdef TEST_GREATER_THAN + static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const bool containsA = data.contains(Key('A')); + static const bool containsB = data.contains(Key('B')); + static const bool containsC = data.contains(Key('C')); + static const bool containsD = data.contains(Key('D')); + static const bool containsE = data.contains(Key('E')); + static const bool containsF = data.contains(Key('F')); + static const bool containsG = data.contains(Key('G')); + static const bool containsH = data.contains(Key('H')); + static const bool containsI = data.contains(Key('I')); + static const bool containsJ = data.contains(Key('J')); + static const bool containsK = data.contains(Key('K')); + + CHECK_TRUE(containsA); + CHECK_TRUE(containsB); + CHECK_TRUE(containsC); + CHECK_TRUE(containsD); + CHECK_TRUE(containsE); + CHECK_TRUE(containsF); + CHECK_TRUE(containsG); + CHECK_FALSE(containsH); + CHECK_FALSE(containsI); + CHECK_TRUE(containsJ); + CHECK_FALSE(containsK); + } + + //************************************************************************* + TEST(test_contains_with_transparent_comparator_const) + { +#ifdef TEST_GREATER_THAN + static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const bool containsA = data.contains('A'); + static const bool containsB = data.contains('B'); + static const bool containsC = data.contains('C'); + static const bool containsD = data.contains('D'); + static const bool containsE = data.contains('E'); + static const bool containsF = data.contains('F'); + static const bool containsG = data.contains('G'); + static const bool containsH = data.contains('H'); + static const bool containsI = data.contains('I'); + static const bool containsJ = data.contains('J'); + static const bool containsK = data.contains('K'); + + CHECK_TRUE(containsA); + CHECK_TRUE(containsB); + CHECK_TRUE(containsC); + CHECK_TRUE(containsD); + CHECK_TRUE(containsE); + CHECK_TRUE(containsF); + CHECK_TRUE(containsG); + CHECK_FALSE(containsH); + CHECK_FALSE(containsI); + CHECK_TRUE(containsJ); + CHECK_FALSE(containsK); + } + + //************************************************************************* + TEST(test_key_comp_const) + { + static const Data data; + static const Data::key_compare compare = data.key_comp(); + + static const bool compareAA = compare(Key{ 'A' }, Key{ 'A' }); + static const bool compareBA = compare(Key{ 'B' }, Key{ 'A' }); + static const bool compareAB = compare(Key{ 'A' }, Key{ 'B' }); + + #ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA); + CHECK_TRUE(compareBA); + CHECK_FALSE(compareAB); + #else + CHECK_FALSE(compareAA); + CHECK_FALSE(compareBA); + CHECK_TRUE(compareAB); + #endif + } + + //************************************************************************* + TEST(test_key_comp_const_transparent_comparator) + { + static const DataTransparentComparator data; + static const DataTransparentComparator::key_compare compare = data.key_comp(); + + static const bool compareAA = compare('A', 'A'); + static const bool compareBA = compare('B', 'A'); + static const bool compareAB = compare('A', 'B'); + + #ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA); + CHECK_TRUE(compareBA); + CHECK_FALSE(compareAB); + #else + CHECK_FALSE(compareAA); + CHECK_FALSE(compareBA); + CHECK_TRUE(compareAB); + #endif + } + + //************************************************************************* + TEST(test_value_comp_const) + { + static const Data data; + static const Data::value_compare compare = data.value_comp(); + + static const bool compareAA1 = compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'A' }, 0 }); + static const bool compareAA2 = compare(value_type{ Key{ 'A' }, 0 }, Key{ 'A' }); + static const bool compareAA3 = compare(Key{ 'A' }, value_type{ Key{ 'A' }, 0 }); + + static const bool compareBA1 = compare(value_type{ Key{ 'B' }, 0 }, value_type{ Key{ 'A' }, 0 }); + static const bool compareBA2 = compare(value_type{ Key{ 'B' }, 0 }, Key{ 'A' }); + static const bool compareBA3 = compare(Key{ 'B' }, value_type{ Key{ 'A' }, 0 }); + + static const bool compareAB1 = compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'B' }, 0 }); + static const bool compareAB2 = compare(value_type{ Key{ 'A' }, 0 }, Key{ 'B' }); + static const bool compareAB3 = compare(Key{ 'A' }, value_type{ Key{ 'B' }, 0 });; + + #ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_TRUE(compareBA1); + CHECK_TRUE(compareBA2); + CHECK_TRUE(compareBA3); + + CHECK_FALSE(compareAB1); + CHECK_FALSE(compareAB2); + CHECK_FALSE(compareAB3); + #else + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_FALSE(compareBA1); + CHECK_FALSE(compareBA2); + CHECK_FALSE(compareBA3); + + CHECK_TRUE(compareAB1); + CHECK_TRUE(compareAB2); + CHECK_TRUE(compareAB3); + #endif + } + + //************************************************************************* + TEST(test_value_comp_const_transparent_comparator) + { + static const DataTransparentComparator data; + static const DataTransparentComparator::value_compare compare = data.value_comp(); + + static const bool compareAA1 = compare(value_type{ 'A', 0 }, value_type{ 'A', 0 }); + static const bool compareAA2 = compare(value_type{ 'A', 0 }, 'A'); + static const bool compareAA3 = compare('A', value_type{ 'A', 0 }); + + static const bool compareBA1 = compare(value_type{ 'B', 0 }, value_type{ 'A', 0 }); + static const bool compareBA2 = compare(value_type{ 'B', 0 }, 'A'); + static const bool compareBA3 = compare('B', value_type{ 'A', 0 }); + + static const bool compareAB1 = compare(value_type{ 'A', 0 }, value_type{ 'B', 0 }); + static const bool compareAB2 = compare(value_type{ 'A', 0 }, 'B'); + static const bool compareAB3 = compare('A', value_type{ 'B', 0 });; + + #ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_TRUE(compareBA1); + CHECK_TRUE(compareBA2); + CHECK_TRUE(compareBA3); + + CHECK_FALSE(compareAB1); + CHECK_FALSE(compareAB2); + CHECK_FALSE(compareAB3); + #else + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_FALSE(compareBA1); + CHECK_FALSE(compareBA2); + CHECK_FALSE(compareBA3); + + CHECK_TRUE(compareAB1); + CHECK_TRUE(compareAB2); + CHECK_TRUE(compareAB3); + #endif + } + + //************************************************************************* + TEST(test_not_equal) + { + static const Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const bool not_equal12 = (data1 != data2); + static const bool not_equal13 = (data1 != data3); + + CHECK_FALSE(not_equal12); + CHECK_TRUE(not_equal13); + } + + //************************************************************************* + TEST(test_not_equal_with_transparent_comparator) + { + static const DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const bool not_equal12 = (data1 != data2); + static const bool not_equal13 = (data1 != data3); + + CHECK_FALSE(not_equal12); + CHECK_TRUE(not_equal13); + } + + //************************************************************************* + TEST(test_less_than) + { + static const Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const bool less_than12 = (data1 < data2); + static const bool less_than23 = (data2 < data3); + static const bool less_than21 = (data2 < data1); + static const bool less_than32 = (data3 < data2); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than12); + CHECK_FALSE(less_than23); + CHECK_TRUE(less_than21); + CHECK_TRUE(less_than32); +#else + CHECK_TRUE(less_than12); + CHECK_TRUE(less_than23); + CHECK_FALSE(less_than21); + CHECK_FALSE(less_than32); +#endif + } + + //************************************************************************* + TEST(test_less_than_with_transparent_comparator) + { + static const DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const bool less_than12 = (data1 < data2); + static const bool less_than23 = (data2 < data3); + static const bool less_than21 = (data2 < data1); + static const bool less_than32 = (data3 < data2); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than12); + CHECK_FALSE(less_than23); + CHECK_TRUE(less_than21); + CHECK_TRUE(less_than32); +#else + CHECK_TRUE(less_than12); + CHECK_TRUE(less_than23); + CHECK_FALSE(less_than21); + CHECK_FALSE(less_than32); +#endif + } + + //************************************************************************* + TEST(test_less_than_equal) + { + static const Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const bool less_than_equal12 = (data1 <= data2); + static const bool less_than_equal23 = (data2 <= data3); + static const bool less_than_equal21 = (data2 <= data1); + static const bool less_than_equal32 = (data3 <= data2); + static const bool less_than_equal11 = (data1 <= data1); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than_equal12); + CHECK_FALSE(less_than_equal23); + CHECK_TRUE(less_than_equal21); + CHECK_TRUE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#else + CHECK_TRUE(less_than_equal12); + CHECK_TRUE(less_than_equal23); + CHECK_FALSE(less_than_equal21); + CHECK_FALSE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_less_than_equal_with_transparent_comparator) + { + static const DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const bool less_than_equal12 = (data1 <= data2); + static const bool less_than_equal23 = (data2 <= data3); + static const bool less_than_equal21 = (data2 <= data1); + static const bool less_than_equal32 = (data3 <= data2); + static const bool less_than_equal11 = (data1 <= data1); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than_equal12); + CHECK_FALSE(less_than_equal23); + CHECK_TRUE(less_than_equal21); + CHECK_TRUE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#else + CHECK_TRUE(less_than_equal12); + CHECK_TRUE(less_than_equal23); + CHECK_FALSE(less_than_equal21); + CHECK_FALSE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_greater_than) + { + static const Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const bool greater_than12 = (data1 > data2); + static const bool greater_than23 = (data2 > data3); + static const bool greater_than21 = (data2 > data1); + static const bool greater_than32 = (data3 > data2); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than12); + CHECK_TRUE(greater_than23); + CHECK_FALSE(greater_than21); + CHECK_FALSE(greater_than32); +#else + CHECK_FALSE(greater_than12); + CHECK_FALSE(greater_than23); + CHECK_TRUE(greater_than21); + CHECK_TRUE(greater_than32); +#endif + } + + //************************************************************************* + TEST(test_greater_than_with_transparent_comparator) + { + static const DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const bool greater_than12 = (data1 > data2); + static const bool greater_than23 = (data2 > data3); + static const bool greater_than21 = (data2 > data1); + static const bool greater_than32 = (data3 > data2); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than12); + CHECK_TRUE(greater_than23); + CHECK_FALSE(greater_than21); + CHECK_FALSE(greater_than32); +#else + CHECK_FALSE(greater_than12); + CHECK_FALSE(greater_than23); + CHECK_TRUE(greater_than21); + CHECK_TRUE(greater_than32); +#endif + } + + //************************************************************************* + TEST(test_greater_than_equal) + { + static const Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const bool greater_than_equal12 = (data1 >= data2); + static const bool greater_than_equal23 = (data2 >= data3); + static const bool greater_than_equal21 = (data2 >= data1); + static const bool greater_than_equal32 = (data3 >= data2); + static const bool greater_than_equal11 = (data1 >= data1); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than_equal12); + CHECK_TRUE(greater_than_equal23); + CHECK_FALSE(greater_than_equal21); + CHECK_FALSE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#else + CHECK_FALSE(greater_than_equal12); + CHECK_FALSE(greater_than_equal23); + CHECK_TRUE(greater_than_equal21); + CHECK_TRUE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_greater_than_equal_with_transparent_comparator) + { + static const DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const bool greater_than_equal12 = (data1 >= data2); + static const bool greater_than_equal23 = (data2 >= data3); + static const bool greater_than_equal21 = (data2 >= data1); + static const bool greater_than_equal32 = (data3 >= data2); + static const bool greater_than_equal11 = (data1 >= data1); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than_equal12); + CHECK_TRUE(greater_than_equal23); + CHECK_FALSE(greater_than_equal21); + CHECK_FALSE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#else + CHECK_FALSE(greater_than_equal12); + CHECK_FALSE(greater_than_equal23); + CHECK_TRUE(greater_than_equal21); + CHECK_TRUE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#endif + } + }; +} diff --git a/test/test_const_multimap_constexpr.cpp b/test/test_const_multimap_constexpr.cpp new file mode 100644 index 00000000..dd7d4036 --- /dev/null +++ b/test/test_const_multimap_constexpr.cpp @@ -0,0 +1,1243 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove, rlindeman + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the 'Software'), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "etl/const_multimap.h" +#include "etl/string.h" + +#include "data.h" + +#if ETL_USING_CPP14 + +namespace +{ + static const size_t Max_Size = 10UL; + + //************************************************************************* + // The key type + //************************************************************************* + struct Key + { + // Default constructor + constexpr Key() + : k(0) + { + } + + // Construct from char key + constexpr explicit Key(char k_) + : k(k_) + { + } + + char k; + }; + + // Less-than operator for Key < Key + constexpr bool operator <(const Key& lhs, const Key& rhs) noexcept + { + return (lhs.k < rhs.k); + } + + // Less-than operator for Key < char + constexpr bool operator <(const Key& lhs, char rhs) noexcept + { + return (lhs.k < rhs); + } + + // Less-than operator for char < Key + constexpr bool operator <(char lhs, const Key& rhs) noexcept + { + return (lhs < rhs.k); + } + + // Greater-than operator for char > Key + constexpr bool operator ==(const Key& lhs, const Key& rhs) noexcept + { + return (lhs.k == rhs.k); + } + +#define TEST_GREATER_THAN +#ifdef TEST_GREATER_THAN + using Data = etl::const_multimap>; + using IData = etl::iconst_multimap>; + using DataTransparentComparator = etl::const_multimap>; + using IDataTransparentComparator = etl::iconst_multimap>; +#else + using Data = etl::const_multimap>; + using IData = etl::iconst_multimap>; + using DataTransparentComparator = etl::const_multimap>; + using IDataTransparentComparator = etl::iconst_multimap>; +#endif + + using value_type = Data::value_type; + using Data_const_iterator = Data::const_iterator; + + SUITE(test_const_multimap) + { + //************************************************************************* + TEST(test_default_constructor) + { + static constexpr Data data; + + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr Data::const_iterator begin = data.begin(); + static constexpr Data::const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == 0UL); + CHECK_TRUE(empty); + CHECK_FALSE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_TRUE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_min_size) + { + static constexpr Data data{ value_type{Key('A'), 0 } }; + + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr Data::const_iterator begin = data.begin(); + static constexpr Data::const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == 1U); + CHECK_FALSE(empty); + CHECK_FALSE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_FALSE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_max_size) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr Data::const_iterator begin = data.begin(); + static constexpr Data::const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == Max_Size); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_FALSE(begin == end); + } + + //************************************************************************* + // Enable to check static_assert "Number of elements exceeds capacity" + //************************************************************************* + //TEST(test_constructor_excess_size) + //{ + // static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + // value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G')), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 }, + // value_type{Key('K'), 10 } }; + //} + +#if ETL_USING_CPP17 + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + +#ifdef TEST_GREATER_THAN + etl::const_multimap check{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + etl::const_multimap check{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + CHECK_TRUE(data.is_valid()); + CHECK_TRUE(data.size() == Max_Size); + CHECK_FALSE(data.empty()); + CHECK_TRUE(data.full()); + CHECK_TRUE(data.capacity() == Max_Size); + CHECK_TRUE(data.max_size() == Max_Size); + CHECK_FALSE(data.begin() == data.end()); + } +#endif + + //************************************************************************* + TEST(test_begin) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + CHECK_TRUE(data.is_valid()); + static constexpr auto value = *data.begin(); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE((value_type{ Key('J'), 9 }) == value); +#else + CHECK_TRUE((value_type{ Key('A'), 0 }) == value); +#endif + } + + //************************************************************************* + TEST(test_end) + { + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data::const_iterator end_itr = data.end(); + + CHECK_TRUE(end_itr == (data.begin() + data.size())); + } + + //************************************************************************* + TEST(test_equal_range) + { +#ifdef TEST_GREATER_THAN + static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr ETL_OR_STD::pair resultA = data.equal_range(Key('A')); + static constexpr ETL_OR_STD::pair resultB = data.equal_range(Key('B')); + static constexpr ETL_OR_STD::pair resultC = data.equal_range(Key('C')); + static constexpr ETL_OR_STD::pair resultD = data.equal_range(Key('D')); + static constexpr ETL_OR_STD::pair resultE = data.equal_range(Key('E')); + static constexpr ETL_OR_STD::pair resultF = data.equal_range(Key('F')); + static constexpr ETL_OR_STD::pair resultG = data.equal_range(Key('G')); + static constexpr ETL_OR_STD::pair resultH = data.equal_range(Key('H')); + static constexpr ETL_OR_STD::pair resultI = data.equal_range(Key('I')); + static constexpr ETL_OR_STD::pair resultJ = data.equal_range(Key('J')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(10, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ.second))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(1, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ.second))); +#endif + } + + //************************************************************************* + TEST(test_lower_bound) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data::const_iterator resultA = data.lower_bound(Key('A')); + static constexpr Data::const_iterator resultB = data.lower_bound(Key('B')); + static constexpr Data::const_iterator resultC = data.lower_bound(Key('C')); + static constexpr Data::const_iterator resultD = data.lower_bound(Key('D')); + static constexpr Data::const_iterator resultE = data.lower_bound(Key('E')); + static constexpr Data::const_iterator resultF = data.lower_bound(Key('F')); + static constexpr Data::const_iterator resultG = data.lower_bound(Key('G')); + static constexpr Data::const_iterator resultH = data.lower_bound(Key('H')); + static constexpr Data::const_iterator resultI = data.lower_bound(Key('I')); + static constexpr Data::const_iterator resultJ = data.lower_bound(Key('J')); + static constexpr Data::const_iterator resultK = data.lower_bound(Key('K')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_lower_bound_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data::const_iterator resultA = data.lower_bound('A'); + static constexpr Data::const_iterator resultB = data.lower_bound('B'); + static constexpr Data::const_iterator resultC = data.lower_bound('C'); + static constexpr Data::const_iterator resultD = data.lower_bound('D'); + static constexpr Data::const_iterator resultE = data.lower_bound('E'); + static constexpr Data::const_iterator resultF = data.lower_bound('F'); + static constexpr Data::const_iterator resultG = data.lower_bound('G'); + static constexpr Data::const_iterator resultH = data.lower_bound('H'); + static constexpr Data::const_iterator resultI = data.lower_bound('I'); + static constexpr Data::const_iterator resultJ = data.lower_bound('J'); + static constexpr Data::const_iterator resultK = data.lower_bound('K'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_upper_bound) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data::const_iterator resultA = data.upper_bound(Key('A')); + static constexpr Data::const_iterator resultB = data.upper_bound(Key('B')); + static constexpr Data::const_iterator resultC = data.upper_bound(Key('C')); + static constexpr Data::const_iterator resultD = data.upper_bound(Key('D')); + static constexpr Data::const_iterator resultE = data.upper_bound(Key('E')); + static constexpr Data::const_iterator resultF = data.upper_bound(Key('F')); + static constexpr Data::const_iterator resultG = data.upper_bound(Key('G')); + static constexpr Data::const_iterator resultH = data.upper_bound(Key('H')); + static constexpr Data::const_iterator resultI = data.upper_bound(Key('I')); + static constexpr Data::const_iterator resultJ = data.upper_bound(Key('J')); + static constexpr Data::const_iterator resultK = data.upper_bound(Key('K')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(1, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_upper_bound_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data::const_iterator resultA = data.upper_bound('A'); + static constexpr Data::const_iterator resultB = data.upper_bound('B'); + static constexpr Data::const_iterator resultC = data.upper_bound('C'); + static constexpr Data::const_iterator resultD = data.upper_bound('D'); + static constexpr Data::const_iterator resultE = data.upper_bound('E'); + static constexpr Data::const_iterator resultF = data.upper_bound('F'); + static constexpr Data::const_iterator resultG = data.upper_bound('G'); + static constexpr Data::const_iterator resultH = data.upper_bound('H'); + static constexpr Data::const_iterator resultI = data.upper_bound('I'); + static constexpr Data::const_iterator resultJ = data.upper_bound('J'); + static constexpr Data::const_iterator resultK = data.upper_bound('K'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(1, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_count) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + CHECK_EQUAL(1, data.count(Key('A'))); + CHECK_EQUAL(1, data.count(Key('B'))); + CHECK_EQUAL(1, data.count(Key('C'))); + CHECK_EQUAL(1, data.count(Key('D'))); + CHECK_EQUAL(1, data.count(Key('E'))); + CHECK_EQUAL(1, data.count(Key('F'))); + CHECK_EQUAL(3, data.count(Key('G'))); + CHECK_EQUAL(0, data.count(Key('H'))); + CHECK_EQUAL(0, data.count(Key('I'))); + CHECK_EQUAL(1, data.count(Key('J'))); + CHECK_EQUAL(0, data.count(Key('K'))); + } + + //************************************************************************* + TEST(test_count_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + CHECK_EQUAL(1, data.count('A')); + CHECK_EQUAL(1, data.count('B')); + CHECK_EQUAL(1, data.count('C')); + CHECK_EQUAL(1, data.count('D')); + CHECK_EQUAL(1, data.count('E')); + CHECK_EQUAL(1, data.count('F')); + CHECK_EQUAL(3, data.count('G')); + CHECK_EQUAL(0, data.count('H')); + CHECK_EQUAL(0, data.count('I')); + CHECK_EQUAL(1, data.count('J')); + CHECK_EQUAL(0, data.count('K')); + } + + //************************************************************************* + TEST(test_const_iterator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + Data::const_iterator itr = data.begin(); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 8 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 7 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 6 }) == *itr++); + CHECK_TRUE((value_type{Key('F'), 5 }) == *itr++); + CHECK_TRUE((value_type{Key('E'), 4 }) == *itr++); + CHECK_TRUE((value_type{Key('D'), 3 }) == *itr++); + CHECK_TRUE((value_type{Key('C'), 2 }) == *itr++); + CHECK_TRUE((value_type{Key('B'), 1 }) == *itr++); + CHECK_TRUE((value_type{Key('A'), 0 }) == *itr++); + CHECK_TRUE(itr == data.end()); +#else + CHECK_TRUE((value_type{Key('A'), 0 }) == *itr++); + CHECK_TRUE((value_type{Key('B'), 1 }) == *itr++); + CHECK_TRUE((value_type{Key('C'), 2 }) == *itr++); + CHECK_TRUE((value_type{Key('D'), 3 }) == *itr++); + CHECK_TRUE((value_type{Key('E'), 4 }) == *itr++); + CHECK_TRUE((value_type{Key('F'), 5 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 6 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 7 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 8 }) == *itr++); + CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); + CHECK_TRUE(itr == data.end()); +#endif + } + + //************************************************************************* + TEST(test_find) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data::const_iterator resultA = data.find(Key('A')); + static constexpr Data::const_iterator resultB = data.find(Key('B')); + static constexpr Data::const_iterator resultC = data.find(Key('C')); + static constexpr Data::const_iterator resultD = data.find(Key('D')); + static constexpr Data::const_iterator resultE = data.find(Key('E')); + static constexpr Data::const_iterator resultF = data.find(Key('F')); + static constexpr Data::const_iterator resultG = data.find(Key('G')); + static constexpr Data::const_iterator resultH = data.find(Key('H')); + static constexpr Data::const_iterator resultI = data.find(Key('I')); + static constexpr Data::const_iterator resultJ = data.find(Key('J')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); +#endif + } + + //************************************************************************* + TEST(test_find_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data::const_iterator resultA = data.find('A'); + static constexpr Data::const_iterator resultB = data.find('B'); + static constexpr Data::const_iterator resultC = data.find('C'); + static constexpr Data::const_iterator resultD = data.find('D'); + static constexpr Data::const_iterator resultE = data.find('E'); + static constexpr Data::const_iterator resultF = data.find('F'); + static constexpr Data::const_iterator resultG = data.find('G'); + static constexpr Data::const_iterator resultH = data.find('H'); + static constexpr Data::const_iterator resultI = data.find('I'); + static constexpr Data::const_iterator resultJ = data.find('J'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); +#endif + } + + //************************************************************************* + TEST(test_contains) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr bool containsA = data.contains(Key('A')); + static constexpr bool containsB = data.contains(Key('B')); + static constexpr bool containsC = data.contains(Key('C')); + static constexpr bool containsD = data.contains(Key('D')); + static constexpr bool containsE = data.contains(Key('E')); + static constexpr bool containsF = data.contains(Key('F')); + static constexpr bool containsG = data.contains(Key('G')); + static constexpr bool containsH = data.contains(Key('H')); + static constexpr bool containsI = data.contains(Key('I')); + static constexpr bool containsJ = data.contains(Key('J')); + static constexpr bool containsK = data.contains(Key('K')); + + CHECK_TRUE(containsA); + CHECK_TRUE(containsB); + CHECK_TRUE(containsC); + CHECK_TRUE(containsD); + CHECK_TRUE(containsE); + CHECK_TRUE(containsF); + CHECK_TRUE(containsG); + CHECK_FALSE(containsH); + CHECK_FALSE(containsI); + CHECK_TRUE(containsJ); + CHECK_FALSE(containsK); + } + + //************************************************************************* + TEST(test_contains_with_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr bool containsA = data.contains('A'); + static constexpr bool containsB = data.contains('B'); + static constexpr bool containsC = data.contains('C'); + static constexpr bool containsD = data.contains('D'); + static constexpr bool containsE = data.contains('E'); + static constexpr bool containsF = data.contains('F'); + static constexpr bool containsG = data.contains('G'); + static constexpr bool containsH = data.contains('H'); + static constexpr bool containsI = data.contains('I'); + static constexpr bool containsJ = data.contains('J'); + static constexpr bool containsK = data.contains('K'); + + CHECK_TRUE(containsA); + CHECK_TRUE(containsB); + CHECK_TRUE(containsC); + CHECK_TRUE(containsD); + CHECK_TRUE(containsE); + CHECK_TRUE(containsF); + CHECK_TRUE(containsG); + CHECK_FALSE(containsH); + CHECK_FALSE(containsI); + CHECK_TRUE(containsJ); + CHECK_FALSE(containsK); + } + + //************************************************************************* + TEST(test_key_comp) + { + static constexpr Data data; + static constexpr Data::key_compare compare = data.key_comp(); + + static constexpr bool compareAA = compare(Key{ 'A' }, Key{ 'A' }); + static constexpr bool compareBA = compare(Key{ 'B' }, Key{ 'A' }); + static constexpr bool compareAB = compare(Key{ 'A' }, Key{ 'B' }); + + #ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA); + CHECK_TRUE(compareBA); + CHECK_FALSE(compareAB); + #else + CHECK_FALSE(compareAA); + CHECK_FALSE(compareBA); + CHECK_TRUE(compareAB); + #endif + } + + //************************************************************************* + TEST(test_key_comp_transparent_comparator) + { + static constexpr DataTransparentComparator data; + static constexpr DataTransparentComparator::key_compare compare = data.key_comp(); + + static constexpr bool compareAA = compare('A', 'A'); + static constexpr bool compareBA = compare('B', 'A'); + static constexpr bool compareAB = compare('A', 'B'); + + #ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA); + CHECK_TRUE(compareBA); + CHECK_FALSE(compareAB); + #else + CHECK_FALSE(compareAA); + CHECK_FALSE(compareBA); + CHECK_TRUE(compareAB); + #endif + } + + //************************************************************************* + TEST(test_value_comp) + { + static constexpr Data data; + static constexpr Data::value_compare compare = data.value_comp(); + + static constexpr bool compareAA1 = compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'A' }, 0 }); + static constexpr bool compareAA2 = compare(value_type{ Key{ 'A' }, 0 }, Key{ 'A' }); + static constexpr bool compareAA3 = compare(Key{ 'A' }, value_type{ Key{ 'A' }, 0 }); + + static constexpr bool compareBA1 = compare(value_type{ Key{ 'B' }, 0 }, value_type{ Key{ 'A' }, 0 }); + static constexpr bool compareBA2 = compare(value_type{ Key{ 'B' }, 0 }, Key{ 'A' }); + static constexpr bool compareBA3 = compare(Key{ 'B' }, value_type{ Key{ 'A' }, 0 }); + + static constexpr bool compareAB1 = compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'B' }, 0 }); + static constexpr bool compareAB2 = compare(value_type{ Key{ 'A' }, 0 }, Key{ 'B' }); + static constexpr bool compareAB3 = compare(Key{ 'A' }, value_type{ Key{ 'B' }, 0 });; + + #ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_TRUE(compareBA1); + CHECK_TRUE(compareBA2); + CHECK_TRUE(compareBA3); + + CHECK_FALSE(compareAB1); + CHECK_FALSE(compareAB2); + CHECK_FALSE(compareAB3); + #else + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_FALSE(compareBA1); + CHECK_FALSE(compareBA2); + CHECK_FALSE(compareBA3); + + CHECK_TRUE(compareAB1); + CHECK_TRUE(compareAB2); + CHECK_TRUE(compareAB3); + #endif + } + + //************************************************************************* + TEST(test_value_comp_transparent_comparator) + { + static constexpr DataTransparentComparator data; + static constexpr DataTransparentComparator::value_compare compare = data.value_comp(); + + static constexpr bool compareAA1 = compare(value_type{ 'A', 0 }, value_type{ 'A', 0 }); + static constexpr bool compareAA2 = compare(value_type{ 'A', 0 }, 'A'); + static constexpr bool compareAA3 = compare('A', value_type{ 'A', 0 }); + + static constexpr bool compareBA1 = compare(value_type{ 'B', 0 }, value_type{ 'A', 0 }); + static constexpr bool compareBA2 = compare(value_type{ 'B', 0 }, 'A'); + static constexpr bool compareBA3 = compare('B', value_type{ 'A', 0 }); + + static constexpr bool compareAB1 = compare(value_type{ 'A', 0 }, value_type{ 'B', 0 }); + static constexpr bool compareAB2 = compare(value_type{ 'A', 0 }, 'B'); + static constexpr bool compareAB3 = compare('A', value_type{ 'B', 0 });; + + #ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_TRUE(compareBA1); + CHECK_TRUE(compareBA2); + CHECK_TRUE(compareBA3); + + CHECK_FALSE(compareAB1); + CHECK_FALSE(compareAB2); + CHECK_FALSE(compareAB3); + #else + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_FALSE(compareBA1); + CHECK_FALSE(compareBA2); + CHECK_FALSE(compareBA3); + + CHECK_TRUE(compareAB1); + CHECK_TRUE(compareAB2); + CHECK_TRUE(compareAB3); + #endif + } + + //************************************************************************* + TEST(test_equal) + { + static constexpr Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool equal12 = (data1 == data2); + static constexpr bool equal13 = (data1 == data3); + + CHECK_TRUE(equal12); + CHECK_FALSE(equal13); + } + + //************************************************************************* + TEST(test_equal_with_transparent_comparator) + { + static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool equal12 = (data1 == data2); + static constexpr bool equal13 = (data1 == data3); + + CHECK_TRUE(equal12); + CHECK_FALSE(equal13); + } + + //************************************************************************* + TEST(test_not_equal) + { + static constexpr Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool not_equal12 = (data1 != data2); + static constexpr bool not_equal13 = (data1 != data3); + + CHECK_FALSE(not_equal12); + CHECK_TRUE(not_equal13); + } + + //************************************************************************* + TEST(test_not_equal_with_transparent_comparator) + { + static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool not_equal12 = (data1 != data2); + static constexpr bool not_equal13 = (data1 != data3); + + CHECK_FALSE(not_equal12); + CHECK_TRUE(not_equal13); + } + + //************************************************************************* + TEST(test_less_than) + { + static constexpr Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool less_than12 = (data1 < data2); + static constexpr bool less_than23 = (data2 < data3); + static constexpr bool less_than21 = (data2 < data1); + static constexpr bool less_than32 = (data3 < data2); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than12); + CHECK_FALSE(less_than23); + CHECK_TRUE(less_than21); + CHECK_TRUE(less_than32); +#else + CHECK_TRUE(less_than12); + CHECK_TRUE(less_than23); + CHECK_FALSE(less_than21); + CHECK_FALSE(less_than32); +#endif + } + + //************************************************************************* + TEST(test_less_than_with_transparent_comparator) + { + static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool less_than12 = (data1 < data2); + static constexpr bool less_than23 = (data2 < data3); + static constexpr bool less_than21 = (data2 < data1); + static constexpr bool less_than32 = (data3 < data2); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than12); + CHECK_FALSE(less_than23); + CHECK_TRUE(less_than21); + CHECK_TRUE(less_than32); +#else + CHECK_TRUE(less_than12); + CHECK_TRUE(less_than23); + CHECK_FALSE(less_than21); + CHECK_FALSE(less_than32); +#endif + } + + //************************************************************************* + TEST(test_less_than_equal) + { + static constexpr Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool less_than_equal12 = (data1 <= data2); + static constexpr bool less_than_equal23 = (data2 <= data3); + static constexpr bool less_than_equal21 = (data2 <= data1); + static constexpr bool less_than_equal32 = (data3 <= data2); + static constexpr bool less_than_equal11 = (data1 <= data1); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than_equal12); + CHECK_FALSE(less_than_equal23); + CHECK_TRUE(less_than_equal21); + CHECK_TRUE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#else + CHECK_TRUE(less_than_equal12); + CHECK_TRUE(less_than_equal23); + CHECK_FALSE(less_than_equal21); + CHECK_FALSE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_less_than_equal_with_transparent_comparator) + { + static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool less_than_equal12 = (data1 <= data2); + static constexpr bool less_than_equal23 = (data2 <= data3); + static constexpr bool less_than_equal21 = (data2 <= data1); + static constexpr bool less_than_equal32 = (data3 <= data2); + static constexpr bool less_than_equal11 = (data1 <= data1); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than_equal12); + CHECK_FALSE(less_than_equal23); + CHECK_TRUE(less_than_equal21); + CHECK_TRUE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#else + CHECK_TRUE(less_than_equal12); + CHECK_TRUE(less_than_equal23); + CHECK_FALSE(less_than_equal21); + CHECK_FALSE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_greater_than) + { + static constexpr Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool greater_than12 = (data1 > data2); + static constexpr bool greater_than23 = (data2 > data3); + static constexpr bool greater_than21 = (data2 > data1); + static constexpr bool greater_than32 = (data3 > data2); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than12); + CHECK_TRUE(greater_than23); + CHECK_FALSE(greater_than21); + CHECK_FALSE(greater_than32); +#else + CHECK_FALSE(greater_than12); + CHECK_FALSE(greater_than23); + CHECK_TRUE(greater_than21); + CHECK_TRUE(greater_than32); +#endif + } + + //************************************************************************* + TEST(test_greater_than_with_transparent_comparator) + { + static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool greater_than12 = (data1 > data2); + static constexpr bool greater_than23 = (data2 > data3); + static constexpr bool greater_than21 = (data2 > data1); + static constexpr bool greater_than32 = (data3 > data2); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than12); + CHECK_TRUE(greater_than23); + CHECK_FALSE(greater_than21); + CHECK_FALSE(greater_than32); +#else + CHECK_FALSE(greater_than12); + CHECK_FALSE(greater_than23); + CHECK_TRUE(greater_than21); + CHECK_TRUE(greater_than32); +#endif + } + + //************************************************************************* + TEST(test_greater_than_equal) + { + static constexpr Data data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool greater_than_equal12 = (data1 >= data2); + static constexpr bool greater_than_equal23 = (data2 >= data3); + static constexpr bool greater_than_equal21 = (data2 >= data1); + static constexpr bool greater_than_equal32 = (data3 >= data2); + static constexpr bool greater_than_equal11 = (data1 >= data1); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than_equal12); + CHECK_TRUE(greater_than_equal23); + CHECK_FALSE(greater_than_equal21); + CHECK_FALSE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#else + CHECK_FALSE(greater_than_equal12); + CHECK_FALSE(greater_than_equal23); + CHECK_TRUE(greater_than_equal21); + CHECK_TRUE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_greater_than_equal_with_transparent_comparator) + { + static constexpr DataTransparentComparator data1{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data2{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data3{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr bool greater_than_equal12 = (data1 >= data2); + static constexpr bool greater_than_equal23 = (data2 >= data3); + static constexpr bool greater_than_equal21 = (data2 >= data1); + static constexpr bool greater_than_equal32 = (data3 >= data2); + static constexpr bool greater_than_equal11 = (data1 >= data1); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than_equal12); + CHECK_TRUE(greater_than_equal23); + CHECK_FALSE(greater_than_equal21); + CHECK_FALSE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#else + CHECK_FALSE(greater_than_equal12); + CHECK_FALSE(greater_than_equal23); + CHECK_TRUE(greater_than_equal21); + CHECK_TRUE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#endif + } + }; +} + +#endif diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 0bb7285f..41cfa582 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -3292,6 +3292,7 @@ + @@ -9272,6 +9273,9 @@ + + + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 00d27413..9874dd7e 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1515,6 +1515,9 @@ ETL\Containers + + UnitTest++\Header Files + @@ -3599,6 +3602,15 @@ Tests\Containers + + Tests\Containers + + + Tests\Containers + + + Tests\Containers + From 64eb9742f0c9e3694345b3f17691b1c5d4792233 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 25 Jun 2025 14:47:47 +0100 Subject: [PATCH 10/12] Added const_map_ext and const_multimap_ext --- .gitignore | 1 + include/etl/const_map.h | 117 +- include/etl/const_multimap.h | 104 +- test/test_const_map.cpp | 388 +++-- test/test_const_map_constexpr.cpp | 339 ++-- test/test_const_map_ext.cpp | 1689 ++++++++++++++++++++ test/test_const_map_ext_constexpr.cpp | 1689 ++++++++++++++++++++ test/test_const_multimap.cpp | 293 ++-- test/test_const_multimap_constexpr.cpp | 221 ++- test/test_const_multimap_ext.cpp | 1495 +++++++++++++++++ test/test_const_multimap_ext_constexpr.cpp | 1484 +++++++++++++++++ test/vs2022/etl.vcxproj | 4 + test/vs2022/etl.vcxproj.filters | 14 +- 13 files changed, 7157 insertions(+), 681 deletions(-) create mode 100644 test/test_const_map_ext.cpp create mode 100644 test/test_const_map_ext_constexpr.cpp create mode 100644 test/test_const_multimap_ext.cpp create mode 100644 test/test_const_multimap_ext_constexpr.cpp diff --git a/.gitignore b/.gitignore index 79641999..a1decab8 100644 --- a/.gitignore +++ b/.gitignore @@ -402,3 +402,4 @@ test/etl_error_handler/assert_function/build-make test/syntax_check/bgcc test/vs2022/Debug MSVC C++23 test/vs2022/Debug MSVC C++23 - No STL +.vs diff --git a/include/etl/const_map.h b/include/etl/const_map.h index 01a2830d..af9905f7 100644 --- a/include/etl/const_map.h +++ b/include/etl/const_map.h @@ -41,6 +41,7 @@ SOFTWARE. #include "type_traits.h" #include "functional.h" #include "nth_type.h" +#include "span.h" #include "private/comparator_is_transparent.h" @@ -391,7 +392,7 @@ namespace etl //************************************************************************* ETL_CONSTEXPR14 size_type full() const ETL_NOEXCEPT { - return size() == max_elements; + return (max_elements != 0) && (size() == max_elements); } //************************************************************************* @@ -446,7 +447,7 @@ namespace etl /// Constructor //************************************************************************* template - ETL_CONSTEXPR14 explicit iconst_map(value_type* element_list_, size_type size_, size_type max_elements_) ETL_NOEXCEPT + ETL_CONSTEXPR14 explicit iconst_map(const value_type* element_list_, size_type size_, size_type max_elements_) ETL_NOEXCEPT : element_list(element_list_) , element_list_end{element_list_ + size_} , max_elements(max_elements_) @@ -475,9 +476,9 @@ namespace etl value_compare vcompare; - value_type* element_list; - value_type* element_list_end; - size_type max_elements; + const value_type* element_list; + const value_type* element_list_end; + size_type max_elements; }; //********************************************************************* @@ -490,22 +491,24 @@ namespace etl using base_t = iconst_map; - using key_type = typename base_t::key_type; - using value_type = typename base_t::value_type; - using mapped_type = typename base_t::mapped_type ; - using key_compare = typename base_t::key_compare; - using const_reference = typename base_t::const_reference; - using const_pointer = typename base_t::const_pointer; - using const_iterator = typename base_t::const_iterator; - using size_type = typename base_t::size_type; + using key_type = typename base_t::key_type; + using value_type = typename base_t::value_type; + using mapped_type = typename base_t::mapped_type ; + using key_compare = typename base_t::key_compare; + using const_reference = typename base_t::const_reference; + using const_pointer = typename base_t::const_pointer; + using const_iterator = typename base_t::const_iterator; + using size_type = typename base_t::size_type; /// Defines the parameter types using const_key_reference = const key_type&; using const_mapped_reference = const mapped_type&; + static_assert((etl::is_default_constructible::value), "key_type must be default constructible"); + static_assert((etl::is_default_constructible::value), "mapped_type must be default constructible"); + //************************************************************************* ///\brief Construct a const_map from a variadic list of elements. - /// Static asserts if the element type is not constructible. /// Static asserts if the elements are not of type value_type. /// Static asserts if the number of elements is greater than the capacity of the const_map. //************************************************************************* @@ -514,8 +517,6 @@ namespace etl : iconst_map(element_list, sizeof...(elements), Size) , element_list{etl::forward(elements)...} { - static_assert((etl::is_default_constructible::value), "key_type must be default constructible"); - static_assert((etl::is_default_constructible::value), "mapped_type must be default constructible"); static_assert((etl::are_all_same...>::value), "All elements must be value_type"); static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity"); } @@ -529,10 +530,74 @@ namespace etl /// Template deduction guides. //************************************************************************* #if ETL_USING_CPP17 - template - const_map(TPairs...) -> const_map::first_type, - typename etl::nth_type_t<0, TPairs...>::second_type, - sizeof...(TPairs)>; + template + const_map(TElements...) -> const_map::first_type, + typename etl::nth_type_t<0, TElements...>::second_type, + sizeof...(TElements)>; +#endif + + //********************************************************************* + /// Map type designed for constexpr. + //********************************************************************* + template > + class const_map_ext : public iconst_map + { + public: + + using base_t = iconst_map; + + using key_type = typename base_t::key_type; + using value_type = typename base_t::value_type; + using mapped_type = typename base_t::mapped_type ; + using key_compare = typename base_t::key_compare; + using const_reference = typename base_t::const_reference; + using const_pointer = typename base_t::const_pointer; + using const_iterator = typename base_t::const_iterator; + using size_type = typename base_t::size_type; + + /// Defines the parameter types + using const_key_reference = const key_type&; + using const_mapped_reference = const mapped_type&; + + static_assert((etl::is_default_constructible::value), "key_type must be default constructible"); + static_assert((etl::is_default_constructible::value), "mapped_type must be default constructible"); + + //************************************************************************* + ///\brief Default construct a const_map. + //************************************************************************* + ETL_CONSTEXPR14 const_map_ext() ETL_NOEXCEPT + : iconst_map(nullptr, 0, 0) + { + } + + //************************************************************************* + ///\brief Construct a const_map from a variadic list of elements. + //************************************************************************* + template + ETL_CONSTEXPR14 explicit const_map_ext(const etl::span& sp) ETL_NOEXCEPT + : iconst_map(sp.data(), Size, Size) + { + } + + //************************************************************************* + ///\brief Construct a const_map from an array. + //************************************************************************* + template + ETL_CONSTEXPR14 explicit const_map_ext(const value_type(&begin_)[Size]) ETL_NOEXCEPT + : iconst_map(begin_, Size, Size) + { + } + }; + + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_USING_CPP17 + template + const_map_ext(const etl::span&) -> const_map_ext; + + template + const_map_ext(const TElements(&)[N]) -> const_map_ext; #endif //************************************************************************* @@ -540,7 +605,7 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR14 bool operator ==(const etl::iconst_map& lhs, - const etl::iconst_map& rhs) + const etl::iconst_map& rhs) ETL_NOEXCEPT { return etl::equal(lhs.begin(), lhs.end(), rhs.begin()); } @@ -550,7 +615,7 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR14 bool operator !=(const etl::iconst_map& lhs, - const etl::iconst_map& rhs) + const etl::iconst_map& rhs) ETL_NOEXCEPT { return !(lhs == rhs); } @@ -560,7 +625,7 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR14 bool operator <(const etl::iconst_map& lhs, - const etl::iconst_map& rhs) + const etl::iconst_map& rhs) ETL_NOEXCEPT { return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), @@ -572,7 +637,7 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR14 bool operator >(const etl::iconst_map& lhs, - const etl::iconst_map& rhs) + const etl::iconst_map& rhs) ETL_NOEXCEPT { return (rhs < lhs); } @@ -582,7 +647,7 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR14 bool operator <=(const etl::iconst_map& lhs, - const etl::iconst_map& rhs) + const etl::iconst_map& rhs) ETL_NOEXCEPT { return !(rhs < lhs); } @@ -592,7 +657,7 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR14 bool operator >=(const etl::iconst_map& lhs, - const etl::iconst_map& rhs) + const etl::iconst_map& rhs) ETL_NOEXCEPT { return !(lhs < rhs); } diff --git a/include/etl/const_multimap.h b/include/etl/const_multimap.h index dd27984b..7b7c3968 100644 --- a/include/etl/const_multimap.h +++ b/include/etl/const_multimap.h @@ -31,7 +31,7 @@ SOFTWARE. #ifndef ETL_CONST_MULTIMAP_INCLUDED #define ETL_CONST_MULTIMAP_INCLUDED -#include "platform.h" +#include "platform.h" #if ETL_NOT_USING_CPP11 #error NOT SUPPORTED FOR C++03 OR BELOW @@ -41,6 +41,7 @@ SOFTWARE. #include "type_traits.h" #include "functional.h" #include "nth_type.h" +#include "span.h" #include "private/comparator_is_transparent.h" @@ -54,14 +55,14 @@ namespace etl { public: - using key_type = TKey; - using value_type = ETL_OR_STD::pair; - using mapped_type = TMapped ; - using key_compare = TKeyCompare; - using const_reference = const value_type&; - using const_pointer = const value_type*; - using const_iterator = const value_type*; - using size_type = size_t; + using key_type = TKey; + using value_type = ETL_OR_STD::pair; + using mapped_type = TMapped ; + using key_compare = TKeyCompare; + using const_reference = const value_type&; + using const_pointer = const value_type*; + using const_iterator = const value_type*; + using size_type = size_t; /// Defines the parameter types using const_key_reference = const key_type&; @@ -343,7 +344,7 @@ namespace etl //************************************************************************* ETL_CONSTEXPR14 size_type full() const ETL_NOEXCEPT { - return size() == max_elements; + return (max_elements != 0) && (size() == max_elements); } //************************************************************************* @@ -398,7 +399,7 @@ namespace etl /// Constructor //************************************************************************* template - ETL_CONSTEXPR14 explicit iconst_multimap(value_type* element_list_, size_type size_, size_type max_elements_) ETL_NOEXCEPT + ETL_CONSTEXPR14 explicit iconst_multimap(const value_type* element_list_, size_type size_, size_type max_elements_) ETL_NOEXCEPT : element_list(element_list_) , element_list_end{element_list_ + size_} , max_elements(max_elements_) @@ -427,8 +428,8 @@ namespace etl value_compare vcompare; - value_type* element_list; - value_type* element_list_end; + const value_type* element_list; + const value_type* element_list_end; size_type max_elements; }; @@ -455,6 +456,9 @@ namespace etl using const_key_reference = const key_type&; using const_mapped_reference = const mapped_type&; + static_assert((etl::is_default_constructible::value), "key_type must be default constructible"); + static_assert((etl::is_default_constructible::value), "mapped_type must be default constructible"); + //************************************************************************* ///\brief Construct a const_map from a variadic list of elements. /// Static asserts if the element type is not constructible. @@ -466,8 +470,6 @@ namespace etl : iconst_multimap(element_list, sizeof...(elements), Size) , element_list{etl::forward(elements)...} { - static_assert((etl::is_default_constructible::value), "key_type must be default constructible"); - static_assert((etl::is_default_constructible::value), "mapped_type must be default constructible"); static_assert((etl::are_all_same...>::value), "All elements must be value_type"); static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity"); } @@ -483,8 +485,72 @@ namespace etl #if ETL_USING_CPP17 template const_multimap(TPairs...) -> const_multimap::first_type, - typename etl::nth_type_t<0, TPairs...>::second_type, - sizeof...(TPairs)>; + typename etl::nth_type_t<0, TPairs...>::second_type, + sizeof...(TPairs)>; +#endif + + //********************************************************************* + /// Map type designed for constexpr. + //********************************************************************* + template > + class const_multimap_ext : public iconst_multimap + { + public: + + using base_t = iconst_multimap; + + using key_type = typename base_t::key_type; + using value_type = typename base_t::value_type; + using mapped_type = typename base_t::mapped_type ; + using key_compare = typename base_t::key_compare; + using const_reference = typename base_t::const_reference; + using const_pointer = typename base_t::const_pointer; + using const_iterator = typename base_t::const_iterator; + using size_type = typename base_t::size_type; + + /// Defines the parameter types + using const_key_reference = const key_type&; + using const_mapped_reference = const mapped_type&; + + static_assert((etl::is_default_constructible::value), "key_type must be default constructible"); + static_assert((etl::is_default_constructible::value), "mapped_type must be default constructible"); + + //************************************************************************* + ///\brief Default construct a const_map. + //************************************************************************* + ETL_CONSTEXPR14 const_multimap_ext() ETL_NOEXCEPT + : iconst_multimap(nullptr, 0, 0) + { + } + + //************************************************************************* + ///\brief Construct a const_map from a variadic list of elements. + //************************************************************************* + template + ETL_CONSTEXPR14 explicit const_multimap_ext(const etl::span& sp) ETL_NOEXCEPT + : iconst_multimap(sp.data(), Size, Size) + { + } + + //************************************************************************* + ///\brief Construct a const_map from an array. + //************************************************************************* + template + ETL_CONSTEXPR14 explicit const_multimap_ext(const value_type(&begin_)[Size]) ETL_NOEXCEPT + : iconst_multimap(begin_, Size, Size) + { + } + }; + + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_USING_CPP17 + template + const_multimap_ext(const etl::span&) -> const_multimap_ext; + + template + const_multimap_ext(const TElements(&)[N]) -> const_multimap_ext; #endif //************************************************************************* @@ -492,7 +558,7 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR14 bool operator ==(const etl::iconst_multimap& lhs, - const etl::iconst_multimap& rhs) + const etl::iconst_multimap& rhs) ETL_NOEXCEPT { return etl::equal(lhs.begin(), lhs.end(), rhs.begin()); } @@ -502,7 +568,7 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR14 bool operator !=(const etl::iconst_multimap& lhs, - const etl::iconst_multimap& rhs) + const etl::iconst_multimap& rhs) ETL_NOEXCEPT { return !(lhs == rhs); } diff --git a/test/test_const_map.cpp b/test/test_const_map.cpp index 40624772..19fb9980 100644 --- a/test/test_const_map.cpp +++ b/test/test_const_map.cpp @@ -103,8 +103,10 @@ namespace using IDataTransparentComparator = etl::iconst_map>; #endif - using value_type = Data::value_type; - using Data_const_iterator = Data::const_iterator; + using value_type = Data::value_type; + using key_type = Data::key_type; + using mapped_type = Data::mapped_type; + using const_iterator = Data::const_iterator; SUITE(test_const_map) { @@ -113,14 +115,14 @@ namespace { static const Data data; - static const bool is_valid = data.is_valid(); - static const size_t size = data.size(); - static const bool empty = data.empty(); - static const bool full = data.full(); - static const size_t capacity = data.capacity(); - static const size_t max_size = data.max_size(); - static const Data::const_iterator begin = data.begin(); - static const Data::const_iterator end = data.end(); + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const const_iterator begin = data.begin(); + static const const_iterator end = data.end(); CHECK_TRUE(is_valid); CHECK_TRUE(size == 0UL); @@ -136,14 +138,14 @@ namespace { static const Data data{ value_type{Key('A'), 0 } }; - static const bool is_valid = data.is_valid(); - static const size_t size = data.size(); - static const bool empty = data.empty(); - static const bool full = data.full(); - static const size_t capacity = data.capacity(); - static const size_t max_size = data.max_size(); - static const Data::const_iterator begin = data.begin(); - static const Data::const_iterator end = data.end(); + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const const_iterator begin = data.begin(); + static const const_iterator end = data.end(); CHECK_TRUE(is_valid); CHECK_TRUE(size == 1U); @@ -165,14 +167,14 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static const bool is_valid = data.is_valid(); - static const size_t size = data.size(); - static const bool empty = data.empty(); - static const bool full = data.full(); - static const size_t capacity = data.capacity(); - static const size_t max_size = data.max_size(); - static const Data::const_iterator begin = data.begin(); - static const Data::const_iterator end = data.end(); + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const const_iterator begin = data.begin(); + static const const_iterator end = data.end(); CHECK_TRUE(is_valid); CHECK_TRUE(size == Max_Size); @@ -196,14 +198,14 @@ namespace static const IData& idata = data; - static const bool is_valid = idata.is_valid(); - static const size_t size = idata.size(); - static const bool empty = idata.empty(); - static const bool full = idata.full(); - static const size_t capacity = idata.capacity(); - static const size_t max_size = idata.max_size(); - static const Data::const_iterator begin = idata.begin(); - static const Data::const_iterator end = idata.end(); + static const bool is_valid = idata.is_valid(); + static const size_t size = idata.size(); + static const bool empty = idata.empty(); + static const bool full = idata.full(); + static const size_t capacity = idata.capacity(); + static const size_t max_size = idata.max_size(); + static const const_iterator begin = idata.begin(); + static const const_iterator end = idata.end(); CHECK_TRUE(is_valid); CHECK_TRUE(size == Max_Size); @@ -228,21 +230,11 @@ namespace //************************************************************************* TEST(test_cpp17_deduced_constructor) { -#ifdef TEST_GREATER_THAN - static const Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else - static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; -#endif - -#ifdef TEST_GREATER_THAN - etl::const_map check{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else + static const etl::const_map data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; etl::const_map check{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; -#endif + CHECK_TRUE(data.is_valid()); CHECK_TRUE(data.size() == Max_Size); CHECK_FALSE(data.empty()); @@ -278,9 +270,9 @@ namespace TEST(test_end_const) { static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - static const Data::const_iterator end_itr = data.end(); + static const const_iterator end_itr = data.end(); CHECK_TRUE(end_itr == (data.begin() + data.size())); } @@ -296,16 +288,16 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static const Data::mapped_type atA = data[Key('A')]; - static const Data::mapped_type atB = data[Key('B')]; - static const Data::mapped_type atC = data[Key('C')]; - static const Data::mapped_type atD = data[Key('D')]; - static const Data::mapped_type atE = data[Key('E')]; - static const Data::mapped_type atF = data[Key('F')]; - static const Data::mapped_type atG = data[Key('G')]; - static const Data::mapped_type atH = data[Key('H')]; - static const Data::mapped_type atI = data[Key('I')]; - static const Data::mapped_type atJ = data[Key('J')]; + static const mapped_type atA = data[Key('A')]; + static const mapped_type atB = data[Key('B')]; + static const mapped_type atC = data[Key('C')]; + static const mapped_type atD = data[Key('D')]; + static const mapped_type atE = data[Key('E')]; + static const mapped_type atF = data[Key('F')]; + static const mapped_type atG = data[Key('G')]; + static const mapped_type atH = data[Key('H')]; + static const mapped_type atI = data[Key('I')]; + static const mapped_type atJ = data[Key('J')]; CHECK_TRUE(data.is_valid()); CHECK(atA == 0); @@ -331,16 +323,16 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static const Data::mapped_type atA = data['A']; - static const Data::mapped_type atB = data['B']; - static const Data::mapped_type atC = data['C']; - static const Data::mapped_type atD = data['D']; - static const Data::mapped_type atE = data['E']; - static const Data::mapped_type atF = data['F']; - static const Data::mapped_type atG = data['G']; - static const Data::mapped_type atH = data['H']; - static const Data::mapped_type atI = data['I']; - static const Data::mapped_type atJ = data['J']; + static const mapped_type atA = data['A']; + static const mapped_type atB = data['B']; + static const mapped_type atC = data['C']; + static const mapped_type atD = data['D']; + static const mapped_type atE = data['E']; + static const mapped_type atF = data['F']; + static const mapped_type atG = data['G']; + static const mapped_type atH = data['H']; + static const mapped_type atI = data['I']; + static const mapped_type atJ = data['J']; CHECK_TRUE(data.is_valid()); CHECK(atA == 0); @@ -366,16 +358,16 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static const Data::mapped_type atA = data.at(Key('A')); - static const Data::mapped_type atB = data.at(Key('B')); - static const Data::mapped_type atC = data.at(Key('C')); - static const Data::mapped_type atD = data.at(Key('D')); - static const Data::mapped_type atE = data.at(Key('E')); - static const Data::mapped_type atF = data.at(Key('F')); - static const Data::mapped_type atG = data.at(Key('G')); - static const Data::mapped_type atH = data.at(Key('H')); - static const Data::mapped_type atI = data.at(Key('I')); - static const Data::mapped_type atJ = data.at(Key('J')); + static const mapped_type atA = data.at(Key('A')); + static const mapped_type atB = data.at(Key('B')); + static const mapped_type atC = data.at(Key('C')); + static const mapped_type atD = data.at(Key('D')); + static const mapped_type atE = data.at(Key('E')); + static const mapped_type atF = data.at(Key('F')); + static const mapped_type atG = data.at(Key('G')); + static const mapped_type atH = data.at(Key('H')); + static const mapped_type atI = data.at(Key('I')); + static const mapped_type atJ = data.at(Key('J')); CHECK_TRUE(data.is_valid()); CHECK(atA == 0); @@ -401,16 +393,16 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static const Data::mapped_type atA = data.at('A'); - static const Data::mapped_type atB = data.at('B'); - static const Data::mapped_type atC = data.at('C'); - static const Data::mapped_type atD = data.at('D'); - static const Data::mapped_type atE = data.at('E'); - static const Data::mapped_type atF = data.at('F'); - static const Data::mapped_type atG = data.at('G'); - static const Data::mapped_type atH = data.at('H'); - static const Data::mapped_type atI = data.at('I'); - static const Data::mapped_type atJ = data.at('J'); + static const mapped_type atA = data.at('A'); + static const mapped_type atB = data.at('B'); + static const mapped_type atC = data.at('C'); + static const mapped_type atD = data.at('D'); + static const mapped_type atE = data.at('E'); + static const mapped_type atF = data.at('F'); + static const mapped_type atG = data.at('G'); + static const mapped_type atH = data.at('H'); + static const mapped_type atI = data.at('I'); + static const mapped_type atJ = data.at('J'); CHECK_TRUE(data.is_valid()); CHECK(atA == 0); @@ -436,16 +428,16 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static const ETL_OR_STD::pair resultA = data.equal_range(Key('A')); - static const ETL_OR_STD::pair resultB = data.equal_range(Key('B')); - static const ETL_OR_STD::pair resultC = data.equal_range(Key('C')); - static const ETL_OR_STD::pair resultD = data.equal_range(Key('D')); - static const ETL_OR_STD::pair resultE = data.equal_range(Key('E')); - static const ETL_OR_STD::pair resultF = data.equal_range(Key('F')); - static const ETL_OR_STD::pair resultG = data.equal_range(Key('G')); - static const ETL_OR_STD::pair resultH = data.equal_range(Key('H')); - static const ETL_OR_STD::pair resultI = data.equal_range(Key('I')); - static const ETL_OR_STD::pair resultJ = data.equal_range(Key('J')); + static const ETL_OR_STD::pair resultA = data.equal_range(Key('A')); + static const ETL_OR_STD::pair resultB = data.equal_range(Key('B')); + static const ETL_OR_STD::pair resultC = data.equal_range(Key('C')); + static const ETL_OR_STD::pair resultD = data.equal_range(Key('D')); + static const ETL_OR_STD::pair resultE = data.equal_range(Key('E')); + static const ETL_OR_STD::pair resultF = data.equal_range(Key('F')); + static const ETL_OR_STD::pair resultG = data.equal_range(Key('G')); + static const ETL_OR_STD::pair resultH = data.equal_range(Key('H')); + static const ETL_OR_STD::pair resultI = data.equal_range(Key('I')); + static const ETL_OR_STD::pair resultJ = data.equal_range(Key('J')); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); @@ -499,22 +491,22 @@ namespace { #ifdef TEST_GREATER_THAN static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static const ETL_OR_STD::pair resultA = data.equal_range('A'); - static const ETL_OR_STD::pair resultB = data.equal_range('B'); - static const ETL_OR_STD::pair resultC = data.equal_range('C'); - static const ETL_OR_STD::pair resultD = data.equal_range('D'); - static const ETL_OR_STD::pair resultE = data.equal_range('E'); - static const ETL_OR_STD::pair resultF = data.equal_range('F'); - static const ETL_OR_STD::pair resultG = data.equal_range('G'); - static const ETL_OR_STD::pair resultH = data.equal_range('H'); - static const ETL_OR_STD::pair resultI = data.equal_range('I'); - static const ETL_OR_STD::pair resultJ = data.equal_range('J'); + static const ETL_OR_STD::pair resultA = data.equal_range('A'); + static const ETL_OR_STD::pair resultB = data.equal_range('B'); + static const ETL_OR_STD::pair resultC = data.equal_range('C'); + static const ETL_OR_STD::pair resultD = data.equal_range('D'); + static const ETL_OR_STD::pair resultE = data.equal_range('E'); + static const ETL_OR_STD::pair resultF = data.equal_range('F'); + static const ETL_OR_STD::pair resultG = data.equal_range('G'); + static const ETL_OR_STD::pair resultH = data.equal_range('H'); + static const ETL_OR_STD::pair resultI = data.equal_range('I'); + static const ETL_OR_STD::pair resultJ = data.equal_range('J'); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); @@ -568,23 +560,23 @@ namespace { #ifdef TEST_GREATER_THAN static const Data data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, - value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, - value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; #endif - static const Data::const_iterator resultA = data.lower_bound(Key('A')); - static const Data::const_iterator resultB = data.lower_bound(Key('B')); - static const Data::const_iterator resultC = data.lower_bound(Key('C')); - static const Data::const_iterator resultD = data.lower_bound(Key('D')); - static const Data::const_iterator resultE = data.lower_bound(Key('E')); - static const Data::const_iterator resultF = data.lower_bound(Key('F')); - static const Data::const_iterator resultG = data.lower_bound(Key('G')); - static const Data::const_iterator resultH = data.lower_bound(Key('H')); - static const Data::const_iterator resultI = data.lower_bound(Key('I')); - static const Data::const_iterator resultJ = data.lower_bound(Key('J')); - static const Data::const_iterator resultK = data.lower_bound(Key('K')); + static const const_iterator resultA = data.lower_bound(Key('A')); + static const const_iterator resultB = data.lower_bound(Key('B')); + static const const_iterator resultC = data.lower_bound(Key('C')); + static const const_iterator resultD = data.lower_bound(Key('D')); + static const const_iterator resultE = data.lower_bound(Key('E')); + static const const_iterator resultF = data.lower_bound(Key('F')); + static const const_iterator resultG = data.lower_bound(Key('G')); + static const const_iterator resultH = data.lower_bound(Key('H')); + static const const_iterator resultI = data.lower_bound(Key('I')); + static const const_iterator resultJ = data.lower_bound(Key('J')); + static const const_iterator resultK = data.lower_bound(Key('K')); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); @@ -618,23 +610,23 @@ namespace { #ifdef TEST_GREATER_THAN static const DataTransparentComparator data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, - value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, - value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; #endif - static const Data::const_iterator resultA = data.lower_bound('A'); - static const Data::const_iterator resultB = data.lower_bound('B'); - static const Data::const_iterator resultC = data.lower_bound('C'); - static const Data::const_iterator resultD = data.lower_bound('D'); - static const Data::const_iterator resultE = data.lower_bound('E'); - static const Data::const_iterator resultF = data.lower_bound('F'); - static const Data::const_iterator resultG = data.lower_bound('G'); - static const Data::const_iterator resultH = data.lower_bound('H'); - static const Data::const_iterator resultI = data.lower_bound('I'); - static const Data::const_iterator resultJ = data.lower_bound('J'); - static const Data::const_iterator resultK = data.lower_bound('K'); + static const const_iterator resultA = data.lower_bound('A'); + static const const_iterator resultB = data.lower_bound('B'); + static const const_iterator resultC = data.lower_bound('C'); + static const const_iterator resultD = data.lower_bound('D'); + static const const_iterator resultE = data.lower_bound('E'); + static const const_iterator resultF = data.lower_bound('F'); + static const const_iterator resultG = data.lower_bound('G'); + static const const_iterator resultH = data.lower_bound('H'); + static const const_iterator resultI = data.lower_bound('I'); + static const const_iterator resultJ = data.lower_bound('J'); + static const const_iterator resultK = data.lower_bound('K'); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); @@ -668,23 +660,23 @@ namespace { #ifdef TEST_GREATER_THAN static const Data data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, - value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, - value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; #endif - static const Data::const_iterator resultA = data.upper_bound(Key('A')); - static const Data::const_iterator resultB = data.upper_bound(Key('B')); - static const Data::const_iterator resultC = data.upper_bound(Key('C')); - static const Data::const_iterator resultD = data.upper_bound(Key('D')); - static const Data::const_iterator resultE = data.upper_bound(Key('E')); - static const Data::const_iterator resultF = data.upper_bound(Key('F')); - static const Data::const_iterator resultG = data.upper_bound(Key('G')); - static const Data::const_iterator resultH = data.upper_bound(Key('H')); - static const Data::const_iterator resultI = data.upper_bound(Key('I')); - static const Data::const_iterator resultJ = data.upper_bound(Key('J')); - static const Data::const_iterator resultK = data.upper_bound(Key('K')); + static const const_iterator resultA = data.upper_bound(Key('A')); + static const const_iterator resultB = data.upper_bound(Key('B')); + static const const_iterator resultC = data.upper_bound(Key('C')); + static const const_iterator resultD = data.upper_bound(Key('D')); + static const const_iterator resultE = data.upper_bound(Key('E')); + static const const_iterator resultF = data.upper_bound(Key('F')); + static const const_iterator resultG = data.upper_bound(Key('G')); + static const const_iterator resultH = data.upper_bound(Key('H')); + static const const_iterator resultI = data.upper_bound(Key('I')); + static const const_iterator resultJ = data.upper_bound(Key('J')); + static const const_iterator resultK = data.upper_bound(Key('K')); #ifdef TEST_GREATER_THAN CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); @@ -718,23 +710,23 @@ namespace { #ifdef TEST_GREATER_THAN static const DataTransparentComparator data{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, - value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, - value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; #endif - static const Data::const_iterator resultA = data.upper_bound('A'); - static const Data::const_iterator resultB = data.upper_bound('B'); - static const Data::const_iterator resultC = data.upper_bound('C'); - static const Data::const_iterator resultD = data.upper_bound('D'); - static const Data::const_iterator resultE = data.upper_bound('E'); - static const Data::const_iterator resultF = data.upper_bound('F'); - static const Data::const_iterator resultG = data.upper_bound('G'); - static const Data::const_iterator resultH = data.upper_bound('H'); - static const Data::const_iterator resultI = data.upper_bound('I'); - static const Data::const_iterator resultJ = data.upper_bound('J'); - static const Data::const_iterator resultK = data.upper_bound('K'); + static const const_iterator resultA = data.upper_bound('A'); + static const const_iterator resultB = data.upper_bound('B'); + static const const_iterator resultC = data.upper_bound('C'); + static const const_iterator resultD = data.upper_bound('D'); + static const const_iterator resultE = data.upper_bound('E'); + static const const_iterator resultF = data.upper_bound('F'); + static const const_iterator resultG = data.upper_bound('G'); + static const const_iterator resultH = data.upper_bound('H'); + static const const_iterator resultI = data.upper_bound('I'); + static const const_iterator resultJ = data.upper_bound('J'); + static const const_iterator resultK = data.upper_bound('K'); #ifdef TEST_GREATER_THAN CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); @@ -768,10 +760,10 @@ namespace { #ifdef TEST_GREATER_THAN static const Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif static const size_t countA = data.count(Key('A')); @@ -804,10 +796,10 @@ namespace { #ifdef TEST_GREATER_THAN static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif static const size_t countA = data.count('A'); @@ -840,13 +832,13 @@ namespace { #ifdef TEST_GREATER_THAN static const Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - Data::const_iterator itr = data.begin(); + const_iterator itr = data.begin(); #ifdef TEST_GREATER_THAN CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); @@ -880,22 +872,22 @@ namespace { #ifdef TEST_GREATER_THAN static const Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static const Data::const_iterator resultA = data.find(Key('A')); - static const Data::const_iterator resultB = data.find(Key('B')); - static const Data::const_iterator resultC = data.find(Key('C')); - static const Data::const_iterator resultD = data.find(Key('D')); - static const Data::const_iterator resultE = data.find(Key('E')); - static const Data::const_iterator resultF = data.find(Key('F')); - static const Data::const_iterator resultG = data.find(Key('G')); - static const Data::const_iterator resultH = data.find(Key('H')); - static const Data::const_iterator resultI = data.find(Key('I')); - static const Data::const_iterator resultJ = data.find(Key('J')); + static const const_iterator resultA = data.find(Key('A')); + static const const_iterator resultB = data.find(Key('B')); + static const const_iterator resultC = data.find(Key('C')); + static const const_iterator resultD = data.find(Key('D')); + static const const_iterator resultE = data.find(Key('E')); + static const const_iterator resultF = data.find(Key('F')); + static const const_iterator resultG = data.find(Key('G')); + static const const_iterator resultH = data.find(Key('H')); + static const const_iterator resultI = data.find(Key('I')); + static const const_iterator resultJ = data.find(Key('J')); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); @@ -927,22 +919,22 @@ namespace { #ifdef TEST_GREATER_THAN static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static const Data::const_iterator resultA = data.find('A'); - static const Data::const_iterator resultB = data.find('B'); - static const Data::const_iterator resultC = data.find('C'); - static const Data::const_iterator resultD = data.find('D'); - static const Data::const_iterator resultE = data.find('E'); - static const Data::const_iterator resultF = data.find('F'); - static const Data::const_iterator resultG = data.find('G'); - static const Data::const_iterator resultH = data.find('H'); - static const Data::const_iterator resultI = data.find('I'); - static const Data::const_iterator resultJ = data.find('J'); + static const const_iterator resultA = data.find('A'); + static const const_iterator resultB = data.find('B'); + static const const_iterator resultC = data.find('C'); + static const const_iterator resultD = data.find('D'); + static const const_iterator resultE = data.find('E'); + static const const_iterator resultF = data.find('F'); + static const const_iterator resultG = data.find('G'); + static const const_iterator resultH = data.find('H'); + static const const_iterator resultI = data.find('I'); + static const const_iterator resultJ = data.find('J'); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); @@ -1031,10 +1023,10 @@ namespace { #ifdef TEST_GREATER_THAN static const Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif static const bool containsA = data.contains(Key('A')); @@ -1067,10 +1059,10 @@ namespace { #ifdef TEST_GREATER_THAN static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif static const bool containsA = data.contains('A'); diff --git a/test/test_const_map_constexpr.cpp b/test/test_const_map_constexpr.cpp index 6296cf6c..43336dfa 100644 --- a/test/test_const_map_constexpr.cpp +++ b/test/test_const_map_constexpr.cpp @@ -35,6 +35,7 @@ SOFTWARE. #include #include #include +#include #include "etl/const_map.h" #include "etl/map.h" @@ -105,8 +106,10 @@ namespace using IDataTransparentComparator = etl::iconst_map>; #endif - using value_type = Data::value_type; - using Data_const_iterator = Data::const_iterator; + using value_type = Data::value_type; + using key_type = Data::key_type; + using mapped_type = Data::mapped_type; + using const_iterator = Data::const_iterator; SUITE(test_const_map) { @@ -115,14 +118,14 @@ namespace { static constexpr Data data; - static constexpr bool is_valid = data.is_valid(); - static constexpr size_t size = data.size(); - static constexpr bool empty = data.empty(); - static constexpr bool full = data.full(); - static constexpr size_t capacity = data.capacity(); - static constexpr size_t max_size = data.max_size(); - static constexpr Data::const_iterator begin = data.begin(); - static constexpr Data::const_iterator end = data.end(); + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr const_iterator begin = data.begin(); + static constexpr const_iterator end = data.end(); CHECK_TRUE(is_valid); CHECK_TRUE(size == 0UL); @@ -138,14 +141,14 @@ namespace { static constexpr Data data{ value_type{Key('A'), 0 } }; - static constexpr bool is_valid = data.is_valid(); - static constexpr size_t size = data.size(); - static constexpr bool empty = data.empty(); - static constexpr bool full = data.full(); - static constexpr size_t capacity = data.capacity(); - static constexpr size_t max_size = data.max_size(); - static constexpr Data::const_iterator begin = data.begin(); - static constexpr Data::const_iterator end = data.end(); + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr const_iterator begin = data.begin(); + static constexpr const_iterator end = data.end(); CHECK_TRUE(is_valid); CHECK_TRUE(size == 1U); @@ -167,14 +170,14 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr bool is_valid = data.is_valid(); - static constexpr size_t size = data.size(); - static constexpr bool empty = data.empty(); - static constexpr bool full = data.full(); - static constexpr size_t capacity = data.capacity(); - static constexpr size_t max_size = data.max_size(); - static constexpr Data::const_iterator begin = data.begin(); - static constexpr Data::const_iterator end = data.end(); + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr const_iterator begin = data.begin(); + static constexpr const_iterator end = data.end(); CHECK_TRUE(is_valid); CHECK_TRUE(size == Max_Size); @@ -198,14 +201,14 @@ namespace static constexpr const IData& idata = data; - static constexpr bool is_valid = idata.is_valid(); - static constexpr size_t size = idata.size(); - static constexpr bool empty = idata.empty(); - static constexpr bool full = idata.full(); - static constexpr size_t capacity = idata.capacity(); - static constexpr size_t max_size = idata.max_size(); - static constexpr Data::const_iterator begin = idata.begin(); - static constexpr Data::const_iterator end = idata.end(); + static constexpr bool is_valid = idata.is_valid(); + static constexpr size_t size = idata.size(); + static constexpr bool empty = idata.empty(); + static constexpr bool full = idata.full(); + static constexpr size_t capacity = idata.capacity(); + static constexpr size_t max_size = idata.max_size(); + static constexpr const_iterator begin = idata.begin(); + static constexpr const_iterator end = idata.end(); CHECK_TRUE(is_valid); CHECK_TRUE(size == Max_Size); @@ -230,21 +233,11 @@ namespace //************************************************************************* TEST(test_cpp17_deduced_constructor) { -#ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; -#endif - -#ifdef TEST_GREATER_THAN - etl::const_map check{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else + static constexpr etl::const_map data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; etl::const_map check{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; -#endif + CHECK_TRUE(data.is_valid()); CHECK_TRUE(data.size() == Max_Size); CHECK_FALSE(data.empty()); @@ -282,7 +275,7 @@ namespace static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; - static constexpr Data::const_iterator end_itr = data.end(); + static constexpr const_iterator end_itr = data.end(); CHECK_TRUE(end_itr == (data.begin() + data.size())); } @@ -298,16 +291,16 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr Data::mapped_type atA = data[Key('A')]; - static constexpr Data::mapped_type atB = data[Key('B')]; - static constexpr Data::mapped_type atC = data[Key('C')]; - static constexpr Data::mapped_type atD = data[Key('D')]; - static constexpr Data::mapped_type atE = data[Key('E')]; - static constexpr Data::mapped_type atF = data[Key('F')]; - static constexpr Data::mapped_type atG = data[Key('G')]; - static constexpr Data::mapped_type atH = data[Key('H')]; - static constexpr Data::mapped_type atI = data[Key('I')]; - static constexpr Data::mapped_type atJ = data[Key('J')]; + static constexpr mapped_type atA = data[Key('A')]; + static constexpr mapped_type atB = data[Key('B')]; + static constexpr mapped_type atC = data[Key('C')]; + static constexpr mapped_type atD = data[Key('D')]; + static constexpr mapped_type atE = data[Key('E')]; + static constexpr mapped_type atF = data[Key('F')]; + static constexpr mapped_type atG = data[Key('G')]; + static constexpr mapped_type atH = data[Key('H')]; + static constexpr mapped_type atI = data[Key('I')]; + static constexpr mapped_type atJ = data[Key('J')]; CHECK_TRUE(data.is_valid()); CHECK(atA == 0); @@ -333,16 +326,16 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr Data::mapped_type atA = data['A']; - static constexpr Data::mapped_type atB = data['B']; - static constexpr Data::mapped_type atC = data['C']; - static constexpr Data::mapped_type atD = data['D']; - static constexpr Data::mapped_type atE = data['E']; - static constexpr Data::mapped_type atF = data['F']; - static constexpr Data::mapped_type atG = data['G']; - static constexpr Data::mapped_type atH = data['H']; - static constexpr Data::mapped_type atI = data['I']; - static constexpr Data::mapped_type atJ = data['J']; + static constexpr mapped_type atA = data['A']; + static constexpr mapped_type atB = data['B']; + static constexpr mapped_type atC = data['C']; + static constexpr mapped_type atD = data['D']; + static constexpr mapped_type atE = data['E']; + static constexpr mapped_type atF = data['F']; + static constexpr mapped_type atG = data['G']; + static constexpr mapped_type atH = data['H']; + static constexpr mapped_type atI = data['I']; + static constexpr mapped_type atJ = data['J']; CHECK_TRUE(data.is_valid()); CHECK(atA == 0); @@ -368,16 +361,16 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr Data::mapped_type atA = data.at(Key('A')); - static constexpr Data::mapped_type atB = data.at(Key('B')); - static constexpr Data::mapped_type atC = data.at(Key('C')); - static constexpr Data::mapped_type atD = data.at(Key('D')); - static constexpr Data::mapped_type atE = data.at(Key('E')); - static constexpr Data::mapped_type atF = data.at(Key('F')); - static constexpr Data::mapped_type atG = data.at(Key('G')); - static constexpr Data::mapped_type atH = data.at(Key('H')); - static constexpr Data::mapped_type atI = data.at(Key('I')); - static constexpr Data::mapped_type atJ = data.at(Key('J')); + static constexpr mapped_type atA = data.at(Key('A')); + static constexpr mapped_type atB = data.at(Key('B')); + static constexpr mapped_type atC = data.at(Key('C')); + static constexpr mapped_type atD = data.at(Key('D')); + static constexpr mapped_type atE = data.at(Key('E')); + static constexpr mapped_type atF = data.at(Key('F')); + static constexpr mapped_type atG = data.at(Key('G')); + static constexpr mapped_type atH = data.at(Key('H')); + static constexpr mapped_type atI = data.at(Key('I')); + static constexpr mapped_type atJ = data.at(Key('J')); CHECK_TRUE(data.is_valid()); CHECK(atA == 0); @@ -403,16 +396,16 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr Data::mapped_type atA = data.at('A'); - static constexpr Data::mapped_type atB = data.at('B'); - static constexpr Data::mapped_type atC = data.at('C'); - static constexpr Data::mapped_type atD = data.at('D'); - static constexpr Data::mapped_type atE = data.at('E'); - static constexpr Data::mapped_type atF = data.at('F'); - static constexpr Data::mapped_type atG = data.at('G'); - static constexpr Data::mapped_type atH = data.at('H'); - static constexpr Data::mapped_type atI = data.at('I'); - static constexpr Data::mapped_type atJ = data.at('J'); + static constexpr mapped_type atA = data.at('A'); + static constexpr mapped_type atB = data.at('B'); + static constexpr mapped_type atC = data.at('C'); + static constexpr mapped_type atD = data.at('D'); + static constexpr mapped_type atE = data.at('E'); + static constexpr mapped_type atF = data.at('F'); + static constexpr mapped_type atG = data.at('G'); + static constexpr mapped_type atH = data.at('H'); + static constexpr mapped_type atI = data.at('I'); + static constexpr mapped_type atJ = data.at('J'); CHECK_TRUE(data.is_valid()); CHECK(atA == 0); @@ -438,16 +431,16 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr ETL_OR_STD::pair resultA = data.equal_range(Key('A')); - static constexpr ETL_OR_STD::pair resultB = data.equal_range(Key('B')); - static constexpr ETL_OR_STD::pair resultC = data.equal_range(Key('C')); - static constexpr ETL_OR_STD::pair resultD = data.equal_range(Key('D')); - static constexpr ETL_OR_STD::pair resultE = data.equal_range(Key('E')); - static constexpr ETL_OR_STD::pair resultF = data.equal_range(Key('F')); - static constexpr ETL_OR_STD::pair resultG = data.equal_range(Key('G')); - static constexpr ETL_OR_STD::pair resultH = data.equal_range(Key('H')); - static constexpr ETL_OR_STD::pair resultI = data.equal_range(Key('I')); - static constexpr ETL_OR_STD::pair resultJ = data.equal_range(Key('J')); + static constexpr ETL_OR_STD::pair resultA = data.equal_range(Key('A')); + static constexpr ETL_OR_STD::pair resultB = data.equal_range(Key('B')); + static constexpr ETL_OR_STD::pair resultC = data.equal_range(Key('C')); + static constexpr ETL_OR_STD::pair resultD = data.equal_range(Key('D')); + static constexpr ETL_OR_STD::pair resultE = data.equal_range(Key('E')); + static constexpr ETL_OR_STD::pair resultF = data.equal_range(Key('F')); + static constexpr ETL_OR_STD::pair resultG = data.equal_range(Key('G')); + static constexpr ETL_OR_STD::pair resultH = data.equal_range(Key('H')); + static constexpr ETL_OR_STD::pair resultI = data.equal_range(Key('I')); + static constexpr ETL_OR_STD::pair resultJ = data.equal_range(Key('J')); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); @@ -507,16 +500,16 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr ETL_OR_STD::pair resultA = data.equal_range('A'); - static constexpr ETL_OR_STD::pair resultB = data.equal_range('B'); - static constexpr ETL_OR_STD::pair resultC = data.equal_range('C'); - static constexpr ETL_OR_STD::pair resultD = data.equal_range('D'); - static constexpr ETL_OR_STD::pair resultE = data.equal_range('E'); - static constexpr ETL_OR_STD::pair resultF = data.equal_range('F'); - static constexpr ETL_OR_STD::pair resultG = data.equal_range('G'); - static constexpr ETL_OR_STD::pair resultH = data.equal_range('H'); - static constexpr ETL_OR_STD::pair resultI = data.equal_range('I'); - static constexpr ETL_OR_STD::pair resultJ = data.equal_range('J'); + static constexpr ETL_OR_STD::pair resultA = data.equal_range('A'); + static constexpr ETL_OR_STD::pair resultB = data.equal_range('B'); + static constexpr ETL_OR_STD::pair resultC = data.equal_range('C'); + static constexpr ETL_OR_STD::pair resultD = data.equal_range('D'); + static constexpr ETL_OR_STD::pair resultE = data.equal_range('E'); + static constexpr ETL_OR_STD::pair resultF = data.equal_range('F'); + static constexpr ETL_OR_STD::pair resultG = data.equal_range('G'); + static constexpr ETL_OR_STD::pair resultH = data.equal_range('H'); + static constexpr ETL_OR_STD::pair resultI = data.equal_range('I'); + static constexpr ETL_OR_STD::pair resultJ = data.equal_range('J'); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); @@ -576,17 +569,17 @@ namespace value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; #endif - static constexpr Data::const_iterator resultA = data.lower_bound(Key('A')); - static constexpr Data::const_iterator resultB = data.lower_bound(Key('B')); - static constexpr Data::const_iterator resultC = data.lower_bound(Key('C')); - static constexpr Data::const_iterator resultD = data.lower_bound(Key('D')); - static constexpr Data::const_iterator resultE = data.lower_bound(Key('E')); - static constexpr Data::const_iterator resultF = data.lower_bound(Key('F')); - static constexpr Data::const_iterator resultG = data.lower_bound(Key('G')); - static constexpr Data::const_iterator resultH = data.lower_bound(Key('H')); - static constexpr Data::const_iterator resultI = data.lower_bound(Key('I')); - static constexpr Data::const_iterator resultJ = data.lower_bound(Key('J')); - static constexpr Data::const_iterator resultK = data.lower_bound(Key('K')); + static constexpr const_iterator resultA = data.lower_bound(Key('A')); + static constexpr const_iterator resultB = data.lower_bound(Key('B')); + static constexpr const_iterator resultC = data.lower_bound(Key('C')); + static constexpr const_iterator resultD = data.lower_bound(Key('D')); + static constexpr const_iterator resultE = data.lower_bound(Key('E')); + static constexpr const_iterator resultF = data.lower_bound(Key('F')); + static constexpr const_iterator resultG = data.lower_bound(Key('G')); + static constexpr const_iterator resultH = data.lower_bound(Key('H')); + static constexpr const_iterator resultI = data.lower_bound(Key('I')); + static constexpr const_iterator resultJ = data.lower_bound(Key('J')); + static constexpr const_iterator resultK = data.lower_bound(Key('K')); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); @@ -626,17 +619,17 @@ namespace value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; #endif - static constexpr Data::const_iterator resultA = data.lower_bound('A'); - static constexpr Data::const_iterator resultB = data.lower_bound('B'); - static constexpr Data::const_iterator resultC = data.lower_bound('C'); - static constexpr Data::const_iterator resultD = data.lower_bound('D'); - static constexpr Data::const_iterator resultE = data.lower_bound('E'); - static constexpr Data::const_iterator resultF = data.lower_bound('F'); - static constexpr Data::const_iterator resultG = data.lower_bound('G'); - static constexpr Data::const_iterator resultH = data.lower_bound('H'); - static constexpr Data::const_iterator resultI = data.lower_bound('I'); - static constexpr Data::const_iterator resultJ = data.lower_bound('J'); - static constexpr Data::const_iterator resultK = data.lower_bound('K'); + static constexpr const_iterator resultA = data.lower_bound('A'); + static constexpr const_iterator resultB = data.lower_bound('B'); + static constexpr const_iterator resultC = data.lower_bound('C'); + static constexpr const_iterator resultD = data.lower_bound('D'); + static constexpr const_iterator resultE = data.lower_bound('E'); + static constexpr const_iterator resultF = data.lower_bound('F'); + static constexpr const_iterator resultG = data.lower_bound('G'); + static constexpr const_iterator resultH = data.lower_bound('H'); + static constexpr const_iterator resultI = data.lower_bound('I'); + static constexpr const_iterator resultJ = data.lower_bound('J'); + static constexpr const_iterator resultK = data.lower_bound('K'); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); @@ -676,17 +669,17 @@ namespace value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; #endif - static constexpr Data::const_iterator resultA = data.upper_bound(Key('A')); - static constexpr Data::const_iterator resultB = data.upper_bound(Key('B')); - static constexpr Data::const_iterator resultC = data.upper_bound(Key('C')); - static constexpr Data::const_iterator resultD = data.upper_bound(Key('D')); - static constexpr Data::const_iterator resultE = data.upper_bound(Key('E')); - static constexpr Data::const_iterator resultF = data.upper_bound(Key('F')); - static constexpr Data::const_iterator resultG = data.upper_bound(Key('G')); - static constexpr Data::const_iterator resultH = data.upper_bound(Key('H')); - static constexpr Data::const_iterator resultI = data.upper_bound(Key('I')); - static constexpr Data::const_iterator resultJ = data.upper_bound(Key('J')); - static constexpr Data::const_iterator resultK = data.upper_bound(Key('K')); + static constexpr const_iterator resultA = data.upper_bound(Key('A')); + static constexpr const_iterator resultB = data.upper_bound(Key('B')); + static constexpr const_iterator resultC = data.upper_bound(Key('C')); + static constexpr const_iterator resultD = data.upper_bound(Key('D')); + static constexpr const_iterator resultE = data.upper_bound(Key('E')); + static constexpr const_iterator resultF = data.upper_bound(Key('F')); + static constexpr const_iterator resultG = data.upper_bound(Key('G')); + static constexpr const_iterator resultH = data.upper_bound(Key('H')); + static constexpr const_iterator resultI = data.upper_bound(Key('I')); + static constexpr const_iterator resultJ = data.upper_bound(Key('J')); + static constexpr const_iterator resultK = data.upper_bound(Key('K')); #ifdef TEST_GREATER_THAN CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); @@ -726,17 +719,17 @@ namespace value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; #endif - static constexpr Data::const_iterator resultA = data.upper_bound('A'); - static constexpr Data::const_iterator resultB = data.upper_bound('B'); - static constexpr Data::const_iterator resultC = data.upper_bound('C'); - static constexpr Data::const_iterator resultD = data.upper_bound('D'); - static constexpr Data::const_iterator resultE = data.upper_bound('E'); - static constexpr Data::const_iterator resultF = data.upper_bound('F'); - static constexpr Data::const_iterator resultG = data.upper_bound('G'); - static constexpr Data::const_iterator resultH = data.upper_bound('H'); - static constexpr Data::const_iterator resultI = data.upper_bound('I'); - static constexpr Data::const_iterator resultJ = data.upper_bound('J'); - static constexpr Data::const_iterator resultK = data.upper_bound('K'); + static constexpr const_iterator resultA = data.upper_bound('A'); + static constexpr const_iterator resultB = data.upper_bound('B'); + static constexpr const_iterator resultC = data.upper_bound('C'); + static constexpr const_iterator resultD = data.upper_bound('D'); + static constexpr const_iterator resultE = data.upper_bound('E'); + static constexpr const_iterator resultF = data.upper_bound('F'); + static constexpr const_iterator resultG = data.upper_bound('G'); + static constexpr const_iterator resultH = data.upper_bound('H'); + static constexpr const_iterator resultI = data.upper_bound('I'); + static constexpr const_iterator resultJ = data.upper_bound('J'); + static constexpr const_iterator resultK = data.upper_bound('K'); #ifdef TEST_GREATER_THAN CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); @@ -848,7 +841,7 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - Data::const_iterator itr = data.begin(); + const_iterator itr = data.begin(); #ifdef TEST_GREATER_THAN CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); @@ -888,16 +881,16 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr Data::const_iterator resultA = data.find(Key('A')); - static constexpr Data::const_iterator resultB = data.find(Key('B')); - static constexpr Data::const_iterator resultC = data.find(Key('C')); - static constexpr Data::const_iterator resultD = data.find(Key('D')); - static constexpr Data::const_iterator resultE = data.find(Key('E')); - static constexpr Data::const_iterator resultF = data.find(Key('F')); - static constexpr Data::const_iterator resultG = data.find(Key('G')); - static constexpr Data::const_iterator resultH = data.find(Key('H')); - static constexpr Data::const_iterator resultI = data.find(Key('I')); - static constexpr Data::const_iterator resultJ = data.find(Key('J')); + static constexpr const_iterator resultA = data.find(Key('A')); + static constexpr const_iterator resultB = data.find(Key('B')); + static constexpr const_iterator resultC = data.find(Key('C')); + static constexpr const_iterator resultD = data.find(Key('D')); + static constexpr const_iterator resultE = data.find(Key('E')); + static constexpr const_iterator resultF = data.find(Key('F')); + static constexpr const_iterator resultG = data.find(Key('G')); + static constexpr const_iterator resultH = data.find(Key('H')); + static constexpr const_iterator resultI = data.find(Key('I')); + static constexpr const_iterator resultJ = data.find(Key('J')); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); @@ -935,16 +928,16 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr Data::const_iterator resultA = data.find('A'); - static constexpr Data::const_iterator resultB = data.find('B'); - static constexpr Data::const_iterator resultC = data.find('C'); - static constexpr Data::const_iterator resultD = data.find('D'); - static constexpr Data::const_iterator resultE = data.find('E'); - static constexpr Data::const_iterator resultF = data.find('F'); - static constexpr Data::const_iterator resultG = data.find('G'); - static constexpr Data::const_iterator resultH = data.find('H'); - static constexpr Data::const_iterator resultI = data.find('I'); - static constexpr Data::const_iterator resultJ = data.find('J'); + static constexpr const_iterator resultA = data.find('A'); + static constexpr const_iterator resultB = data.find('B'); + static constexpr const_iterator resultC = data.find('C'); + static constexpr const_iterator resultD = data.find('D'); + static constexpr const_iterator resultE = data.find('E'); + static constexpr const_iterator resultF = data.find('F'); + static constexpr const_iterator resultG = data.find('G'); + static constexpr const_iterator resultH = data.find('H'); + static constexpr const_iterator resultI = data.find('I'); + static constexpr const_iterator resultJ = data.find('J'); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); diff --git a/test/test_const_map_ext.cpp b/test/test_const_map_ext.cpp new file mode 100644 index 00000000..7bded872 --- /dev/null +++ b/test/test_const_map_ext.cpp @@ -0,0 +1,1689 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove, rlindeman + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the 'Software'), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "etl/const_map.h" +#include "etl/span.h" + +#include "data.h" + +namespace +{ + static const size_t Max_Size = 10UL; + + //************************************************************************* + // The key type + //************************************************************************* + struct Key + { + // Default constructor + constexpr Key() + : k(0) + { + } + + // Construct from char key + constexpr explicit Key(char k_) + : k(k_) + { + } + + char k; + }; + + // Less-than operator for Key < Key + constexpr bool operator <(const Key& lhs, const Key& rhs) noexcept + { + return (lhs.k < rhs.k); + } + + // Less-than operator for Key < char + constexpr bool operator <(const Key& lhs, char rhs) noexcept + { + return (lhs.k < rhs); + } + + // Less-than operator for char < Key + constexpr bool operator <(char lhs, const Key& rhs) noexcept + { + return (lhs < rhs.k); + } + + // Greater-than operator for char > Key + constexpr bool operator ==(const Key& lhs, const Key& rhs) noexcept + { + return (lhs.k == rhs.k); + } + + #define TEST_GREATER_THAN + #ifdef TEST_GREATER_THAN + using Data = etl::const_map_ext>; + using IData = etl::iconst_map>; + using DataTransparentComparator = etl::const_map_ext>; + using IDataTransparentComparator = etl::iconst_map>; + #else + using Data = etl::const_map>; + using IData = etl::iconst_map>; + using DataTransparentComparator = etl::const_map>; + using IDataTransparentComparator = etl::iconst_map>; + #endif + + using value_type = Data::value_type; + using key_type = Data::key_type; + using mapped_type = Data::mapped_type; + using const_iterator = Data::const_iterator; + using span_type = etl::span; + + SUITE(test_const_map) + { + //************************************************************************* + TEST(test_default_constructor) + { + static const Data data; + + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const const_iterator begin = data.begin(); + static const const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == 0UL); + CHECK_TRUE(empty); + CHECK_FALSE(full); + CHECK_TRUE(capacity == 0); + CHECK_TRUE(max_size == 0); + CHECK_TRUE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_min_size_from_span) + { + static const value_type values[]{value_type{Key('A'), 0}}; + static const etl::span span(values); + static const Data data{ span }; + + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const const_iterator begin = data.begin(); + static const const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == 1U); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == span.size()); + CHECK_TRUE(max_size == span.size()); + CHECK_FALSE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_max_size_from_span) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const span_type span(values); + static const Data data{ span }; + + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const const_iterator begin = data.begin(); + static const const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == Max_Size); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_FALSE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_max_size_from_array) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data data{ values }; + + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const const_iterator begin = data.begin(); + static const const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == Max_Size); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_FALSE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_max_size_status_from_iconst_map) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data data{ values }; + + static const IData& idata = data; + + static const bool is_valid = idata.is_valid(); + static const size_t size = idata.size(); + static const bool empty = idata.empty(); + static const bool full = idata.full(); + static const size_t capacity = idata.capacity(); + static const size_t max_size = idata.max_size(); + static const const_iterator begin = idata.begin(); + static const const_iterator end = idata.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == Max_Size); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_FALSE(begin == end); + } + +#if ETL_USING_CPP17 + //************************************************************************* + TEST(test_cpp17_deduced_constructor_from_span) + { + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const span_type span(values); + static const etl::const_map_ext data{span}; + + etl::const_map check{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + CHECK_TRUE(data.is_valid()); + CHECK_TRUE(data.size() == Max_Size); + CHECK_FALSE(data.empty()); + CHECK_TRUE(data.full()); + CHECK_TRUE(data.capacity() == Max_Size); + CHECK_TRUE(data.max_size() == Max_Size); + CHECK_FALSE(data.begin() == data.end()); + } + + //************************************************************************* + TEST(test_cpp17_deduced_constructor_from_array) + { + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const etl::const_map_ext data{values}; + + etl::const_map check{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + CHECK_TRUE(data.is_valid()); + CHECK_TRUE(data.size() == Max_Size); + CHECK_FALSE(data.empty()); + CHECK_TRUE(data.full()); + CHECK_TRUE(data.capacity() == Max_Size); + CHECK_TRUE(data.max_size() == Max_Size); + CHECK_FALSE(data.begin() == data.end()); + } +#endif + + //************************************************************************* + TEST(test_begin) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data data{ values }; + + CHECK_TRUE(data.is_valid()); + static const auto value = *data.begin(); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE((value_type{ Key('J'), 9 }) == value); +#else + CHECK_TRUE((value_type{ Key('A'), 0 }) == value); +#endif + } + + //************************************************************************* + TEST(test_end) + { + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + + static const Data data{ values }; + + static const const_iterator end_itr = data.end(); + + CHECK_TRUE(end_itr == (data.begin() + data.size())); + } + + //************************************************************************* + TEST(test_index) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data data{ values }; + + static const mapped_type atA = data[Key('A')]; + static const mapped_type atB = data[Key('B')]; + static const mapped_type atC = data[Key('C')]; + static const mapped_type atD = data[Key('D')]; + static const mapped_type atE = data[Key('E')]; + static const mapped_type atF = data[Key('F')]; + static const mapped_type atG = data[Key('G')]; + static const mapped_type atH = data[Key('H')]; + static const mapped_type atI = data[Key('I')]; + static const mapped_type atJ = data[Key('J')]; + + CHECK_TRUE(data.is_valid()); + CHECK(atA == 0); + CHECK(atB == 1); + CHECK(atC == 2); + CHECK(atD == 3); + CHECK(atE == 4); + CHECK(atF == 5); + CHECK(atG == 6); + CHECK(atH == 7); + CHECK(atI == 8); + CHECK(atJ == 9); + } + + //************************************************************************* + TEST(test_index_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const DataTransparentComparator data{ values }; + + static const mapped_type atA = data['A']; + static const mapped_type atB = data['B']; + static const mapped_type atC = data['C']; + static const mapped_type atD = data['D']; + static const mapped_type atE = data['E']; + static const mapped_type atF = data['F']; + static const mapped_type atG = data['G']; + static const mapped_type atH = data['H']; + static const mapped_type atI = data['I']; + static const mapped_type atJ = data['J']; + + CHECK_TRUE(data.is_valid()); + CHECK(atA == 0); + CHECK(atB == 1); + CHECK(atC == 2); + CHECK(atD == 3); + CHECK(atE == 4); + CHECK(atF == 5); + CHECK(atG == 6); + CHECK(atH == 7); + CHECK(atI == 8); + CHECK(atJ == 9); + } + + //************************************************************************* + TEST(test_at) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data data{ values }; + + static const mapped_type atA = data.at(Key('A')); + static const mapped_type atB = data.at(Key('B')); + static const mapped_type atC = data.at(Key('C')); + static const mapped_type atD = data.at(Key('D')); + static const mapped_type atE = data.at(Key('E')); + static const mapped_type atF = data.at(Key('F')); + static const mapped_type atG = data.at(Key('G')); + static const mapped_type atH = data.at(Key('H')); + static const mapped_type atI = data.at(Key('I')); + static const mapped_type atJ = data.at(Key('J')); + + CHECK_TRUE(data.is_valid()); + CHECK(atA == 0); + CHECK(atB == 1); + CHECK(atC == 2); + CHECK(atD == 3); + CHECK(atE == 4); + CHECK(atF == 5); + CHECK(atG == 6); + CHECK(atH == 7); + CHECK(atI == 8); + CHECK(atJ == 9); + } + + //************************************************************************* + TEST(test_at_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const DataTransparentComparator data{ values }; + + static const mapped_type atA = data.at('A'); + static const mapped_type atB = data.at('B'); + static const mapped_type atC = data.at('C'); + static const mapped_type atD = data.at('D'); + static const mapped_type atE = data.at('E'); + static const mapped_type atF = data.at('F'); + static const mapped_type atG = data.at('G'); + static const mapped_type atH = data.at('H'); + static const mapped_type atI = data.at('I'); + static const mapped_type atJ = data.at('J'); + + CHECK_TRUE(data.is_valid()); + CHECK(atA == 0); + CHECK(atB == 1); + CHECK(atC == 2); + CHECK(atD == 3); + CHECK(atE == 4); + CHECK(atF == 5); + CHECK(atG == 6); + CHECK(atH == 7); + CHECK(atI == 8); + CHECK(atJ == 9); + } + + //************************************************************************* + TEST(test_equal_range) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data data{ values }; + + static const ETL_OR_STD::pair resultA = data.equal_range(Key('A')); + static const ETL_OR_STD::pair resultB = data.equal_range(Key('B')); + static const ETL_OR_STD::pair resultC = data.equal_range(Key('C')); + static const ETL_OR_STD::pair resultD = data.equal_range(Key('D')); + static const ETL_OR_STD::pair resultE = data.equal_range(Key('E')); + static const ETL_OR_STD::pair resultF = data.equal_range(Key('F')); + static const ETL_OR_STD::pair resultG = data.equal_range(Key('G')); + static const ETL_OR_STD::pair resultH = data.equal_range(Key('H')); + static const ETL_OR_STD::pair resultI = data.equal_range(Key('I')); + static const ETL_OR_STD::pair resultJ = data.equal_range(Key('J')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(10, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ.second))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(1, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ.second))); +#endif + } + + //************************************************************************* + TEST(test_equal_range_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const DataTransparentComparator data{ values }; + + static const ETL_OR_STD::pair resultA = data.equal_range('A'); + static const ETL_OR_STD::pair resultB = data.equal_range('B'); + static const ETL_OR_STD::pair resultC = data.equal_range('C'); + static const ETL_OR_STD::pair resultD = data.equal_range('D'); + static const ETL_OR_STD::pair resultE = data.equal_range('E'); + static const ETL_OR_STD::pair resultF = data.equal_range('F'); + static const ETL_OR_STD::pair resultG = data.equal_range('G'); + static const ETL_OR_STD::pair resultH = data.equal_range('H'); + static const ETL_OR_STD::pair resultI = data.equal_range('I'); + static const ETL_OR_STD::pair resultJ = data.equal_range('J'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(10, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ.second))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(1, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ.second))); +#endif + } + + //************************************************************************* + TEST(test_lower_bound) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; +#endif + + static const Data data{ values }; + + static const const_iterator resultA = data.lower_bound(Key('A')); + static const const_iterator resultB = data.lower_bound(Key('B')); + static const const_iterator resultC = data.lower_bound(Key('C')); + static const const_iterator resultD = data.lower_bound(Key('D')); + static const const_iterator resultE = data.lower_bound(Key('E')); + static const const_iterator resultF = data.lower_bound(Key('F')); + static const const_iterator resultG = data.lower_bound(Key('G')); + static const const_iterator resultH = data.lower_bound(Key('H')); + static const const_iterator resultI = data.lower_bound(Key('I')); + static const const_iterator resultJ = data.lower_bound(Key('J')); + static const const_iterator resultK = data.lower_bound(Key('K')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_lower_bound_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; +#endif + + static const DataTransparentComparator data{ values }; + + static const const_iterator resultA = data.lower_bound('A'); + static const const_iterator resultB = data.lower_bound('B'); + static const const_iterator resultC = data.lower_bound('C'); + static const const_iterator resultD = data.lower_bound('D'); + static const const_iterator resultE = data.lower_bound('E'); + static const const_iterator resultF = data.lower_bound('F'); + static const const_iterator resultG = data.lower_bound('G'); + static const const_iterator resultH = data.lower_bound('H'); + static const const_iterator resultI = data.lower_bound('I'); + static const const_iterator resultJ = data.lower_bound('J'); + static const const_iterator resultK = data.lower_bound('K'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_upper_bound) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; +#endif + + static const Data data{ values }; + + static const const_iterator resultA = data.upper_bound(Key('A')); + static const const_iterator resultB = data.upper_bound(Key('B')); + static const const_iterator resultC = data.upper_bound(Key('C')); + static const const_iterator resultD = data.upper_bound(Key('D')); + static const const_iterator resultE = data.upper_bound(Key('E')); + static const const_iterator resultF = data.upper_bound(Key('F')); + static const const_iterator resultG = data.upper_bound(Key('G')); + static const const_iterator resultH = data.upper_bound(Key('H')); + static const const_iterator resultI = data.upper_bound(Key('I')); + static const const_iterator resultJ = data.upper_bound(Key('J')); + static const const_iterator resultK = data.upper_bound(Key('K')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(1, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_upper_bound_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; +#endif + + static const DataTransparentComparator data{ values }; + + static const const_iterator resultA = data.upper_bound('A'); + static const const_iterator resultB = data.upper_bound('B'); + static const const_iterator resultC = data.upper_bound('C'); + static const const_iterator resultD = data.upper_bound('D'); + static const const_iterator resultE = data.upper_bound('E'); + static const const_iterator resultF = data.upper_bound('F'); + static const const_iterator resultG = data.upper_bound('G'); + static const const_iterator resultH = data.upper_bound('H'); + static const const_iterator resultI = data.upper_bound('I'); + static const const_iterator resultJ = data.upper_bound('J'); + static const const_iterator resultK = data.upper_bound('K'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(1, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_count) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data data{ values }; + + static const size_t countA = data.count(Key('A')); + static const size_t countB = data.count(Key('B')); + static const size_t countC = data.count(Key('C')); + static const size_t countD = data.count(Key('D')); + static const size_t countE = data.count(Key('E')); + static const size_t countF = data.count(Key('F')); + static const size_t countG = data.count(Key('G')); + static const size_t countH = data.count(Key('H')); + static const size_t countI = data.count(Key('I')); + static const size_t countJ = data.count(Key('J')); + static const size_t countK = data.count(Key('K')); + + CHECK_EQUAL(1, countA); + CHECK_EQUAL(1, countB); + CHECK_EQUAL(1, countC); + CHECK_EQUAL(1, countD); + CHECK_EQUAL(1, countE); + CHECK_EQUAL(1, countF); + CHECK_EQUAL(1, countG); + CHECK_EQUAL(1, countH); + CHECK_EQUAL(1, countI); + CHECK_EQUAL(1, countJ); + CHECK_EQUAL(0, countK); + } + + //************************************************************************* + TEST(test_count_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const DataTransparentComparator data{ values }; + + static const size_t countA = data.count('A'); + static const size_t countB = data.count('B'); + static const size_t countC = data.count('C'); + static const size_t countD = data.count('D'); + static const size_t countE = data.count('E'); + static const size_t countF = data.count('F'); + static const size_t countG = data.count('G'); + static const size_t countH = data.count('H'); + static const size_t countI = data.count('I'); + static const size_t countJ = data.count('J'); + static const size_t countK = data.count('K'); + + CHECK_EQUAL(1, countA); + CHECK_EQUAL(1, countB); + CHECK_EQUAL(1, countC); + CHECK_EQUAL(1, countD); + CHECK_EQUAL(1, countE); + CHECK_EQUAL(1, countF); + CHECK_EQUAL(1, countG); + CHECK_EQUAL(1, countH); + CHECK_EQUAL(1, countI); + CHECK_EQUAL(1, countJ); + CHECK_EQUAL(0, countK); + } + + //************************************************************************* + TEST(test_const_iterator) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data data{ values }; + + const_iterator itr = data.begin(); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); + CHECK_TRUE((value_type{Key('I'), 8 }) == *itr++); + CHECK_TRUE((value_type{Key('H'), 7 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 6 }) == *itr++); + CHECK_TRUE((value_type{Key('F'), 5 }) == *itr++); + CHECK_TRUE((value_type{Key('E'), 4 }) == *itr++); + CHECK_TRUE((value_type{Key('D'), 3 }) == *itr++); + CHECK_TRUE((value_type{Key('C'), 2 }) == *itr++); + CHECK_TRUE((value_type{Key('B'), 1 }) == *itr++); + CHECK_TRUE((value_type{Key('A'), 0 }) == *itr++); + CHECK_TRUE(itr == data.end()); +#else + CHECK_TRUE((value_type{Key('A'), 0 }) == *itr++); + CHECK_TRUE((value_type{Key('B'), 1 }) == *itr++); + CHECK_TRUE((value_type{Key('C'), 2 }) == *itr++); + CHECK_TRUE((value_type{Key('D'), 3 }) == *itr++); + CHECK_TRUE((value_type{Key('E'), 4 }) == *itr++); + CHECK_TRUE((value_type{Key('F'), 5 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 6 }) == *itr++); + CHECK_TRUE((value_type{Key('H'), 7 }) == *itr++); + CHECK_TRUE((value_type{Key('I'), 8 }) == *itr++); + CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); + CHECK_TRUE(itr == data.end()); +#endif + } + + //************************************************************************* + TEST(test_find) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data data{ values }; + + static const const_iterator resultA = data.find(Key('A')); + static const const_iterator resultB = data.find(Key('B')); + static const const_iterator resultC = data.find(Key('C')); + static const const_iterator resultD = data.find(Key('D')); + static const const_iterator resultE = data.find(Key('E')); + static const const_iterator resultF = data.find(Key('F')); + static const const_iterator resultG = data.find(Key('G')); + static const const_iterator resultH = data.find(Key('H')); + static const const_iterator resultI = data.find(Key('I')); + static const const_iterator resultJ = data.find(Key('J')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); +#endif + } + + //************************************************************************* + TEST(test_find_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const DataTransparentComparator data{ values }; + + static const const_iterator resultA = data.find('A'); + static const const_iterator resultB = data.find('B'); + static const const_iterator resultC = data.find('C'); + static const const_iterator resultD = data.find('D'); + static const const_iterator resultE = data.find('E'); + static const const_iterator resultF = data.find('F'); + static const const_iterator resultG = data.find('G'); + static const const_iterator resultH = data.find('H'); + static const const_iterator resultI = data.find('I'); + static const const_iterator resultJ = data.find('J'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); +#endif + } + + //************************************************************************* + TEST(test_key_compare) + { + static const Data data; + + static const Data::key_compare compare = data.key_comp(); + + static const Data::key_type a(Key('A')); + static const Data::key_type b(Key('B')); + +#ifdef TEST_GREATER_THAN + CHECK(!compare(a, b)); + CHECK(compare(b, a)); +#else + CHECK(compare(a, b)); + CHECK(!compare(b, a)); +#endif + } + + //************************************************************************* + TEST(test_key_compare_using_transparent_comparator) + { + static const DataTransparentComparator data; + static const DataTransparentComparator::key_compare compare = data.key_comp(); + + static const DataTransparentComparator::key_type a(Key('A')); + static const DataTransparentComparator::key_type b(Key('B')); + +#ifdef TEST_GREATER_THAN + CHECK(!compare(a, b)); + CHECK(compare(b, a)); +#else + CHECK(compare(a, b)); + CHECK(!compare(b, a)); +#endif + } + + //************************************************************************* + TEST(test_value_compare) + { + static const Data data; + static const Data::value_compare compare = data.value_comp(); + + static const Data::value_type a(Key('A'), 0); + static const Data::value_type b(Key('B'), 1); + +#ifdef TEST_GREATER_THAN + CHECK(!compare(a, b)); + CHECK(compare(b, a)); +#else + CHECK(compare(a, b)); + CHECK(!compare(b, a)); +#endif + } + + //************************************************************************* + TEST(test_contains) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data data{ values }; + + static const bool containsA = data.contains(Key('A')); + static const bool containsB = data.contains(Key('B')); + static const bool containsC = data.contains(Key('C')); + static const bool containsD = data.contains(Key('D')); + static const bool containsE = data.contains(Key('E')); + static const bool containsF = data.contains(Key('F')); + static const bool containsG = data.contains(Key('G')); + static const bool containsH = data.contains(Key('H')); + static const bool containsI = data.contains(Key('I')); + static const bool containsJ = data.contains(Key('J')); + static const bool containsK = data.contains(Key('K')); + + CHECK_TRUE(containsA); + CHECK_TRUE(containsB); + CHECK_TRUE(containsC); + CHECK_TRUE(containsD); + CHECK_TRUE(containsE); + CHECK_TRUE(containsF); + CHECK_TRUE(containsG); + CHECK_TRUE(containsH); + CHECK_TRUE(containsI); + CHECK_TRUE(containsJ); + CHECK_FALSE(containsK); + } + + //************************************************************************* + TEST(test_contains_with_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const DataTransparentComparator data{ values }; + + static const bool containsA = data.contains('A'); + static const bool containsB = data.contains('B'); + static const bool containsC = data.contains('C'); + static const bool containsD = data.contains('D'); + static const bool containsE = data.contains('E'); + static const bool containsF = data.contains('F'); + static const bool containsG = data.contains('G'); + static const bool containsH = data.contains('H'); + static const bool containsI = data.contains('I'); + static const bool containsJ = data.contains('J'); + static const bool containsK = data.contains('K'); + + CHECK_TRUE(containsA); + CHECK_TRUE(containsB); + CHECK_TRUE(containsC); + CHECK_TRUE(containsD); + CHECK_TRUE(containsE); + CHECK_TRUE(containsF); + CHECK_TRUE(containsG); + CHECK_TRUE(containsH); + CHECK_TRUE(containsI); + CHECK_TRUE(containsJ); + CHECK_FALSE(containsK); + } + + //************************************************************************* + TEST(test_key_comp) + { + static const Data data; + static const Data::key_compare compare = data.key_comp(); + + static const bool compareAA = compare(Key{ 'A' }, Key{ 'A' }); + static const bool compareBA = compare(Key{ 'B' }, Key{ 'A' }); + static const bool compareAB = compare(Key{ 'A' }, Key{ 'B' }); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA); + CHECK_TRUE(compareBA); + CHECK_FALSE(compareAB); +#else + CHECK_FALSE(compareAA); + CHECK_FALSE(compareBA); + CHECK_TRUE(compareAB); +#endif + } + + //************************************************************************* + TEST(test_key_comp_transparent_comparator) + { + static const DataTransparentComparator data; + static const DataTransparentComparator::key_compare compare = data.key_comp(); + + static const bool compareAA = compare('A', 'A'); + static const bool compareBA = compare('B', 'A'); + static const bool compareAB = compare('A', 'B'); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA); + CHECK_TRUE(compareBA); + CHECK_FALSE(compareAB); +#else + CHECK_FALSE(compareAA); + CHECK_FALSE(compareBA); + CHECK_TRUE(compareAB); +#endif + } + + //************************************************************************* + TEST(test_value_comp) + { + static const Data data; + static const Data::value_compare compare = data.value_comp(); + + static const bool compareAA1 = compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'A' }, 0 }); + static const bool compareAA2 = compare(value_type{ Key{ 'A' }, 0 }, Key{ 'A' }); + static const bool compareAA3 = compare(Key{ 'A' }, value_type{ Key{ 'A' }, 0 }); + + static const bool compareBA1 = compare(value_type{ Key{ 'B' }, 0 }, value_type{ Key{ 'A' }, 0 }); + static const bool compareBA2 = compare(value_type{ Key{ 'B' }, 0 }, Key{ 'A' }); + static const bool compareBA3 = compare(Key{ 'B' }, value_type{ Key{ 'A' }, 0 }); + + static const bool compareAB1 = compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'B' }, 0 }); + static const bool compareAB2 = compare(value_type{ Key{ 'A' }, 0 }, Key{ 'B' }); + static const bool compareAB3 = compare(Key{ 'A' }, value_type{ Key{ 'B' }, 0 });; + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_TRUE(compareBA1); + CHECK_TRUE(compareBA2); + CHECK_TRUE(compareBA3); + + CHECK_FALSE(compareAB1); + CHECK_FALSE(compareAB2); + CHECK_FALSE(compareAB3); +#else + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_FALSE(compareBA1); + CHECK_FALSE(compareBA2); + CHECK_FALSE(compareBA3); + + CHECK_TRUE(compareAB1); + CHECK_TRUE(compareAB2); + CHECK_TRUE(compareAB3); +#endif + } + + //************************************************************************* + TEST(test_value_comp_transparent_comparator) + { + static const DataTransparentComparator data; + static const DataTransparentComparator::value_compare compare = data.value_comp(); + + static const bool compareAA1 = compare(value_type{ 'A', 0 }, value_type{ 'A', 0 }); + static const bool compareAA2 = compare(value_type{ 'A', 0 }, 'A'); + static const bool compareAA3 = compare('A', value_type{ 'A', 0 }); + + static const bool compareBA1 = compare(value_type{ 'B', 0 }, value_type{ 'A', 0 }); + static const bool compareBA2 = compare(value_type{ 'B', 0 }, 'A'); + static const bool compareBA3 = compare('B', value_type{ 'A', 0 }); + + static const bool compareAB1 = compare(value_type{ 'A', 0 }, value_type{ 'B', 0 }); + static const bool compareAB2 = compare(value_type{ 'A', 0 }, 'B'); + static const bool compareAB3 = compare('A', value_type{ 'B', 0 });; + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_TRUE(compareBA1); + CHECK_TRUE(compareBA2); + CHECK_TRUE(compareBA3); + + CHECK_FALSE(compareAB1); + CHECK_FALSE(compareAB2); + CHECK_FALSE(compareAB3); +#else + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_FALSE(compareBA1); + CHECK_FALSE(compareBA2); + CHECK_FALSE(compareBA3); + + CHECK_TRUE(compareAB1); + CHECK_TRUE(compareAB2); + CHECK_TRUE(compareAB3); +#endif + } + + //************************************************************************* + TEST(test_equal) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data1{values1}; + static const Data data2{values2}; + static const Data data3{values3}; + + static const bool equal12 = (data1 == data2); + static const bool equal13 = (data1 == data3); + + CHECK_TRUE(equal12); + CHECK_FALSE(equal13); + } + + //************************************************************************* + TEST(test_equal_with_transparent_comparator) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data1{values1}; + static const DataTransparentComparator data2{values2}; + static const DataTransparentComparator data3{values3}; + + static const bool equal12 = (data1 == data2); + static const bool equal13 = (data1 == data3); + + CHECK_TRUE(equal12); + CHECK_FALSE(equal13); + } + + //************************************************************************* + TEST(test_not_equal) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data1{values1}; + static const Data data2{values2}; + static const Data data3{values3}; + + static const bool not_equal12 = (data1 != data2); + static const bool not_equal13 = (data1 != data3); + + CHECK_FALSE(not_equal12); + CHECK_TRUE(not_equal13); + } + + //************************************************************************* + TEST(test_not_equal_with_transparent_comparator) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data1{values1}; + static const DataTransparentComparator data2{values2}; + static const DataTransparentComparator data3{values3}; + + static const bool not_equal12 = (data1 != data2); + static const bool not_equal13 = (data1 != data3); + + CHECK_FALSE(not_equal12); + CHECK_TRUE(not_equal13); + } + + //************************************************************************* + TEST(test_less_than) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data1{values1}; + static const Data data2{values2}; + static const Data data3{values3}; + + static const bool less_than12 = (data1 < data2); + static const bool less_than23 = (data2 < data3); + static const bool less_than21 = (data2 < data1); + static const bool less_than32 = (data3 < data2); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than12); + CHECK_FALSE(less_than23); + CHECK_TRUE(less_than21); + CHECK_TRUE(less_than32); +#else + CHECK_TRUE(less_than12); + CHECK_TRUE(less_than23); + CHECK_FALSE(less_than21); + CHECK_FALSE(less_than32); +#endif + } + + //************************************************************************* + TEST(test_less_than_with_transparent_comparator) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data1{values1}; + static const DataTransparentComparator data2{values2}; + static const DataTransparentComparator data3{values3}; + + static const bool less_than12 = (data1 < data2); + static const bool less_than23 = (data2 < data3); + static const bool less_than21 = (data2 < data1); + static const bool less_than32 = (data3 < data2); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than12); + CHECK_FALSE(less_than23); + CHECK_TRUE(less_than21); + CHECK_TRUE(less_than32); +#else + CHECK_TRUE(less_than12); + CHECK_TRUE(less_than23); + CHECK_FALSE(less_than21); + CHECK_FALSE(less_than32); +#endif + } + + //************************************************************************* + TEST(test_less_than_equal) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data1{values1}; + static const Data data2{values2}; + static const Data data3{values3}; + + static const bool less_than_equal12 = (data1 <= data2); + static const bool less_than_equal23 = (data2 <= data3); + static const bool less_than_equal21 = (data2 <= data1); + static const bool less_than_equal32 = (data3 <= data2); + static const bool less_than_equal11 = (data1 <= data1); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than_equal12); + CHECK_FALSE(less_than_equal23); + CHECK_TRUE(less_than_equal21); + CHECK_TRUE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#else + CHECK_TRUE(less_than_equal12); + CHECK_TRUE(less_than_equal23); + CHECK_FALSE(less_than_equal21); + CHECK_FALSE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_less_than_equal_with_transparent_comparator) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data1{values1}; + static const DataTransparentComparator data2{values2}; + static const DataTransparentComparator data3{values3}; + + static const bool less_than_equal12 = (data1 <= data2); + static const bool less_than_equal23 = (data2 <= data3); + static const bool less_than_equal21 = (data2 <= data1); + static const bool less_than_equal32 = (data3 <= data2); + static const bool less_than_equal11 = (data1 <= data1); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than_equal12); + CHECK_FALSE(less_than_equal23); + CHECK_TRUE(less_than_equal21); + CHECK_TRUE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#else + CHECK_TRUE(less_than_equal12); + CHECK_TRUE(less_than_equal23); + CHECK_FALSE(less_than_equal21); + CHECK_FALSE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_greater_than) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data1{values1}; + static const Data data2{values2}; + static const Data data3{values3}; + + static const bool greater_than12 = (data1 > data2); + static const bool greater_than23 = (data2 > data3); + static const bool greater_than21 = (data2 > data1); + static const bool greater_than32 = (data3 > data2); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than12); + CHECK_TRUE(greater_than23); + CHECK_FALSE(greater_than21); + CHECK_FALSE(greater_than32); +#else + CHECK_FALSE(greater_than12); + CHECK_FALSE(greater_than23); + CHECK_TRUE(greater_than21); + CHECK_TRUE(greater_than32); +#endif + } + + //************************************************************************* + TEST(test_greater_than_with_transparent_comparator) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data1{values1}; + static const DataTransparentComparator data2{values2}; + static const DataTransparentComparator data3{values3}; + + static const bool greater_than12 = (data1 > data2); + static const bool greater_than23 = (data2 > data3); + static const bool greater_than21 = (data2 > data1); + static const bool greater_than32 = (data3 > data2); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than12); + CHECK_TRUE(greater_than23); + CHECK_FALSE(greater_than21); + CHECK_FALSE(greater_than32); +#else + CHECK_FALSE(greater_than12); + CHECK_FALSE(greater_than23); + CHECK_TRUE(greater_than21); + CHECK_TRUE(greater_than32); +#endif + } + + //************************************************************************* + TEST(test_greater_than_equal) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data1{values1}; + static const Data data2{values2}; + static const Data data3{values3}; + + static const bool greater_than_equal12 = (data1 >= data2); + static const bool greater_than_equal23 = (data2 >= data3); + static const bool greater_than_equal21 = (data2 >= data1); + static const bool greater_than_equal32 = (data3 >= data2); + static const bool greater_than_equal11 = (data1 >= data1); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than_equal12); + CHECK_TRUE(greater_than_equal23); + CHECK_FALSE(greater_than_equal21); + CHECK_FALSE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#else + CHECK_FALSE(greater_than_equal12); + CHECK_FALSE(greater_than_equal23); + CHECK_TRUE(greater_than_equal21); + CHECK_TRUE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_greater_than_equal_with_transparent_comparator) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data1{values1}; + static const DataTransparentComparator data2{values2}; + static const DataTransparentComparator data3{values3}; + + static const bool greater_than_equal12 = (data1 >= data2); + static const bool greater_than_equal23 = (data2 >= data3); + static const bool greater_than_equal21 = (data2 >= data1); + static const bool greater_than_equal32 = (data3 >= data2); + static const bool greater_than_equal11 = (data1 >= data1); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than_equal12); + CHECK_TRUE(greater_than_equal23); + CHECK_FALSE(greater_than_equal21); + CHECK_FALSE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#else + CHECK_FALSE(greater_than_equal12); + CHECK_FALSE(greater_than_equal23); + CHECK_TRUE(greater_than_equal21); + CHECK_TRUE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#endif + } + }; +} diff --git a/test/test_const_map_ext_constexpr.cpp b/test/test_const_map_ext_constexpr.cpp new file mode 100644 index 00000000..61816dd0 --- /dev/null +++ b/test/test_const_map_ext_constexpr.cpp @@ -0,0 +1,1689 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove, rlindeman + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the 'Software'), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "etl/const_map.h" +#include "etl/span.h" + +#include "data.h" + +namespace +{ + static constexpr size_t Max_Size = 10UL; + + //************************************************************************* + // The key type + //************************************************************************* + struct Key + { + // Default constructor + constexpr Key() + : k(0) + { + } + + // Construct from char key + constexpr explicit Key(char k_) + : k(k_) + { + } + + char k; + }; + + // Less-than operator for Key < Key + constexpr bool operator <(const Key& lhs, const Key& rhs) noexcept + { + return (lhs.k < rhs.k); + } + + // Less-than operator for Key < char + constexpr bool operator <(const Key& lhs, char rhs) noexcept + { + return (lhs.k < rhs); + } + + // Less-than operator for char < Key + constexpr bool operator <(char lhs, const Key& rhs) noexcept + { + return (lhs < rhs.k); + } + + // Greater-than operator for char > Key + constexpr bool operator ==(const Key& lhs, const Key& rhs) noexcept + { + return (lhs.k == rhs.k); + } + + #define TEST_GREATER_THAN + #ifdef TEST_GREATER_THAN + using Data = etl::const_map_ext>; + using IData = etl::iconst_map>; + using DataTransparentComparator = etl::const_map_ext>; + using IDataTransparentComparator = etl::iconst_map>; + #else + using Data = etl::const_map>; + using IData = etl::iconst_map>; + using DataTransparentComparator = etl::const_map>; + using IDataTransparentComparator = etl::iconst_map>; + #endif + + using value_type = Data::value_type; + using key_type = Data::key_type; + using mapped_type = Data::mapped_type; + using const_iterator = Data::const_iterator; + using span_type = etl::span; + + SUITE(test_const_map) + { + //************************************************************************* + TEST(test_default_constructor) + { + static constexpr Data data; + + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr const_iterator begin = data.begin(); + static constexpr const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == 0UL); + CHECK_TRUE(empty); + CHECK_FALSE(full); + CHECK_TRUE(capacity == 0); + CHECK_TRUE(max_size == 0); + CHECK_TRUE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_min_size_from_span) + { + static constexpr value_type values[]{value_type{Key('A'), 0}}; + static constexpr etl::span span(values); + static constexpr Data data{ span }; + + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr const_iterator begin = data.begin(); + static constexpr const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == 1U); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == span.size()); + CHECK_TRUE(max_size == span.size()); + CHECK_FALSE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_max_size_from_span) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr span_type span(values); + static constexpr Data data{ span }; + + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr const_iterator begin = data.begin(); + static constexpr const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == Max_Size); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_FALSE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_max_size_from_array) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data data{ values }; + + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr const_iterator begin = data.begin(); + static constexpr const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == Max_Size); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_FALSE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_max_size_status_from_iconst_map) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data data{ values }; + + static const constexpr IData& idata = data; + + static constexpr bool is_valid = idata.is_valid(); + static constexpr size_t size = idata.size(); + static constexpr bool empty = idata.empty(); + static constexpr bool full = idata.full(); + static constexpr size_t capacity = idata.capacity(); + static constexpr size_t max_size = idata.max_size(); + static constexpr const_iterator begin = idata.begin(); + static constexpr const_iterator end = idata.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == Max_Size); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_FALSE(begin == end); + } + +#if ETL_USING_CPP17 + //************************************************************************* + TEST(test_cpp17_deduced_constructor_from_span) + { + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr span_type span(values); + static constexpr etl::const_map_ext data{span}; + + etl::const_map check{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + CHECK_TRUE(data.is_valid()); + CHECK_TRUE(data.size() == Max_Size); + CHECK_FALSE(data.empty()); + CHECK_TRUE(data.full()); + CHECK_TRUE(data.capacity() == Max_Size); + CHECK_TRUE(data.max_size() == Max_Size); + CHECK_FALSE(data.begin() == data.end()); + } + + //************************************************************************* + TEST(test_cpp17_deduced_constructor_from_array) + { + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr etl::const_map_ext data{values}; + + etl::const_map check{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + CHECK_TRUE(data.is_valid()); + CHECK_TRUE(data.size() == Max_Size); + CHECK_FALSE(data.empty()); + CHECK_TRUE(data.full()); + CHECK_TRUE(data.capacity() == Max_Size); + CHECK_TRUE(data.max_size() == Max_Size); + CHECK_FALSE(data.begin() == data.end()); + } +#endif + + //************************************************************************* + TEST(test_begin) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data data{ values }; + + CHECK_TRUE(data.is_valid()); + static constexpr auto value = *data.begin(); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE((value_type{ Key('J'), 9 }) == value); +#else + CHECK_TRUE((value_type{ Key('A'), 0 }) == value); +#endif + } + + //************************************************************************* + TEST(test_end) + { + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + + static constexpr Data data{ values }; + + static constexpr const_iterator end_itr = data.end(); + + CHECK_TRUE(end_itr == (data.begin() + data.size())); + } + + //************************************************************************* + TEST(test_index) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data data{ values }; + + static constexpr mapped_type atA = data[Key('A')]; + static constexpr mapped_type atB = data[Key('B')]; + static constexpr mapped_type atC = data[Key('C')]; + static constexpr mapped_type atD = data[Key('D')]; + static constexpr mapped_type atE = data[Key('E')]; + static constexpr mapped_type atF = data[Key('F')]; + static constexpr mapped_type atG = data[Key('G')]; + static constexpr mapped_type atH = data[Key('H')]; + static constexpr mapped_type atI = data[Key('I')]; + static constexpr mapped_type atJ = data[Key('J')]; + + CHECK_TRUE(data.is_valid()); + CHECK(atA == 0); + CHECK(atB == 1); + CHECK(atC == 2); + CHECK(atD == 3); + CHECK(atE == 4); + CHECK(atF == 5); + CHECK(atG == 6); + CHECK(atH == 7); + CHECK(atI == 8); + CHECK(atJ == 9); + } + + //************************************************************************* + TEST(test_index_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr DataTransparentComparator data{ values }; + + static constexpr mapped_type atA = data['A']; + static constexpr mapped_type atB = data['B']; + static constexpr mapped_type atC = data['C']; + static constexpr mapped_type atD = data['D']; + static constexpr mapped_type atE = data['E']; + static constexpr mapped_type atF = data['F']; + static constexpr mapped_type atG = data['G']; + static constexpr mapped_type atH = data['H']; + static constexpr mapped_type atI = data['I']; + static constexpr mapped_type atJ = data['J']; + + CHECK_TRUE(data.is_valid()); + CHECK(atA == 0); + CHECK(atB == 1); + CHECK(atC == 2); + CHECK(atD == 3); + CHECK(atE == 4); + CHECK(atF == 5); + CHECK(atG == 6); + CHECK(atH == 7); + CHECK(atI == 8); + CHECK(atJ == 9); + } + + //************************************************************************* + TEST(test_at) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data data{ values }; + + static constexpr mapped_type atA = data.at(Key('A')); + static constexpr mapped_type atB = data.at(Key('B')); + static constexpr mapped_type atC = data.at(Key('C')); + static constexpr mapped_type atD = data.at(Key('D')); + static constexpr mapped_type atE = data.at(Key('E')); + static constexpr mapped_type atF = data.at(Key('F')); + static constexpr mapped_type atG = data.at(Key('G')); + static constexpr mapped_type atH = data.at(Key('H')); + static constexpr mapped_type atI = data.at(Key('I')); + static constexpr mapped_type atJ = data.at(Key('J')); + + CHECK_TRUE(data.is_valid()); + CHECK(atA == 0); + CHECK(atB == 1); + CHECK(atC == 2); + CHECK(atD == 3); + CHECK(atE == 4); + CHECK(atF == 5); + CHECK(atG == 6); + CHECK(atH == 7); + CHECK(atI == 8); + CHECK(atJ == 9); + } + + //************************************************************************* + TEST(test_at_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr DataTransparentComparator data{ values }; + + static constexpr mapped_type atA = data.at('A'); + static constexpr mapped_type atB = data.at('B'); + static constexpr mapped_type atC = data.at('C'); + static constexpr mapped_type atD = data.at('D'); + static constexpr mapped_type atE = data.at('E'); + static constexpr mapped_type atF = data.at('F'); + static constexpr mapped_type atG = data.at('G'); + static constexpr mapped_type atH = data.at('H'); + static constexpr mapped_type atI = data.at('I'); + static constexpr mapped_type atJ = data.at('J'); + + CHECK_TRUE(data.is_valid()); + CHECK(atA == 0); + CHECK(atB == 1); + CHECK(atC == 2); + CHECK(atD == 3); + CHECK(atE == 4); + CHECK(atF == 5); + CHECK(atG == 6); + CHECK(atH == 7); + CHECK(atI == 8); + CHECK(atJ == 9); + } + + //************************************************************************* + TEST(test_equal_range) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data data{ values }; + + static constexpr ETL_OR_STD::pair resultA = data.equal_range(Key('A')); + static constexpr ETL_OR_STD::pair resultB = data.equal_range(Key('B')); + static constexpr ETL_OR_STD::pair resultC = data.equal_range(Key('C')); + static constexpr ETL_OR_STD::pair resultD = data.equal_range(Key('D')); + static constexpr ETL_OR_STD::pair resultE = data.equal_range(Key('E')); + static constexpr ETL_OR_STD::pair resultF = data.equal_range(Key('F')); + static constexpr ETL_OR_STD::pair resultG = data.equal_range(Key('G')); + static constexpr ETL_OR_STD::pair resultH = data.equal_range(Key('H')); + static constexpr ETL_OR_STD::pair resultI = data.equal_range(Key('I')); + static constexpr ETL_OR_STD::pair resultJ = data.equal_range(Key('J')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(10, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ.second))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(1, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ.second))); +#endif + } + + //************************************************************************* + TEST(test_equal_range_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr DataTransparentComparator data{ values }; + + static constexpr ETL_OR_STD::pair resultA = data.equal_range('A'); + static constexpr ETL_OR_STD::pair resultB = data.equal_range('B'); + static constexpr ETL_OR_STD::pair resultC = data.equal_range('C'); + static constexpr ETL_OR_STD::pair resultD = data.equal_range('D'); + static constexpr ETL_OR_STD::pair resultE = data.equal_range('E'); + static constexpr ETL_OR_STD::pair resultF = data.equal_range('F'); + static constexpr ETL_OR_STD::pair resultG = data.equal_range('G'); + static constexpr ETL_OR_STD::pair resultH = data.equal_range('H'); + static constexpr ETL_OR_STD::pair resultI = data.equal_range('I'); + static constexpr ETL_OR_STD::pair resultJ = data.equal_range('J'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(10, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ.second))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(1, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ.second))); +#endif + } + + //************************************************************************* + TEST(test_lower_bound) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; +#endif + + static constexpr Data data{ values }; + + static constexpr const_iterator resultA = data.lower_bound(Key('A')); + static constexpr const_iterator resultB = data.lower_bound(Key('B')); + static constexpr const_iterator resultC = data.lower_bound(Key('C')); + static constexpr const_iterator resultD = data.lower_bound(Key('D')); + static constexpr const_iterator resultE = data.lower_bound(Key('E')); + static constexpr const_iterator resultF = data.lower_bound(Key('F')); + static constexpr const_iterator resultG = data.lower_bound(Key('G')); + static constexpr const_iterator resultH = data.lower_bound(Key('H')); + static constexpr const_iterator resultI = data.lower_bound(Key('I')); + static constexpr const_iterator resultJ = data.lower_bound(Key('J')); + static constexpr const_iterator resultK = data.lower_bound(Key('K')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_lower_bound_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; +#endif + + static constexpr DataTransparentComparator data{ values }; + + static constexpr const_iterator resultA = data.lower_bound('A'); + static constexpr const_iterator resultB = data.lower_bound('B'); + static constexpr const_iterator resultC = data.lower_bound('C'); + static constexpr const_iterator resultD = data.lower_bound('D'); + static constexpr const_iterator resultE = data.lower_bound('E'); + static constexpr const_iterator resultF = data.lower_bound('F'); + static constexpr const_iterator resultG = data.lower_bound('G'); + static constexpr const_iterator resultH = data.lower_bound('H'); + static constexpr const_iterator resultI = data.lower_bound('I'); + static constexpr const_iterator resultJ = data.lower_bound('J'); + static constexpr const_iterator resultK = data.lower_bound('K'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_upper_bound) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; +#endif + + static constexpr Data data{ values }; + + static constexpr const_iterator resultA = data.upper_bound(Key('A')); + static constexpr const_iterator resultB = data.upper_bound(Key('B')); + static constexpr const_iterator resultC = data.upper_bound(Key('C')); + static constexpr const_iterator resultD = data.upper_bound(Key('D')); + static constexpr const_iterator resultE = data.upper_bound(Key('E')); + static constexpr const_iterator resultF = data.upper_bound(Key('F')); + static constexpr const_iterator resultG = data.upper_bound(Key('G')); + static constexpr const_iterator resultH = data.upper_bound(Key('H')); + static constexpr const_iterator resultI = data.upper_bound(Key('I')); + static constexpr const_iterator resultJ = data.upper_bound(Key('J')); + static constexpr const_iterator resultK = data.upper_bound(Key('K')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(1, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_upper_bound_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('K'), 10 }, value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, + value_type{Key('F'), 5 }, value_type{Key('E'), 4 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, + value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 }, value_type{Key('K'), 10 } }; +#endif + + static constexpr DataTransparentComparator data{ values }; + + static constexpr const_iterator resultA = data.upper_bound('A'); + static constexpr const_iterator resultB = data.upper_bound('B'); + static constexpr const_iterator resultC = data.upper_bound('C'); + static constexpr const_iterator resultD = data.upper_bound('D'); + static constexpr const_iterator resultE = data.upper_bound('E'); + static constexpr const_iterator resultF = data.upper_bound('F'); + static constexpr const_iterator resultG = data.upper_bound('G'); + static constexpr const_iterator resultH = data.upper_bound('H'); + static constexpr const_iterator resultI = data.upper_bound('I'); + static constexpr const_iterator resultJ = data.upper_bound('J'); + static constexpr const_iterator resultK = data.upper_bound('K'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(1, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_count) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data data{ values }; + + static constexpr size_t countA = data.count(Key('A')); + static constexpr size_t countB = data.count(Key('B')); + static constexpr size_t countC = data.count(Key('C')); + static constexpr size_t countD = data.count(Key('D')); + static constexpr size_t countE = data.count(Key('E')); + static constexpr size_t countF = data.count(Key('F')); + static constexpr size_t countG = data.count(Key('G')); + static constexpr size_t countH = data.count(Key('H')); + static constexpr size_t countI = data.count(Key('I')); + static constexpr size_t countJ = data.count(Key('J')); + static constexpr size_t countK = data.count(Key('K')); + + CHECK_EQUAL(1, countA); + CHECK_EQUAL(1, countB); + CHECK_EQUAL(1, countC); + CHECK_EQUAL(1, countD); + CHECK_EQUAL(1, countE); + CHECK_EQUAL(1, countF); + CHECK_EQUAL(1, countG); + CHECK_EQUAL(1, countH); + CHECK_EQUAL(1, countI); + CHECK_EQUAL(1, countJ); + CHECK_EQUAL(0, countK); + } + + //************************************************************************* + TEST(test_count_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr DataTransparentComparator data{ values }; + + static constexpr size_t countA = data.count('A'); + static constexpr size_t countB = data.count('B'); + static constexpr size_t countC = data.count('C'); + static constexpr size_t countD = data.count('D'); + static constexpr size_t countE = data.count('E'); + static constexpr size_t countF = data.count('F'); + static constexpr size_t countG = data.count('G'); + static constexpr size_t countH = data.count('H'); + static constexpr size_t countI = data.count('I'); + static constexpr size_t countJ = data.count('J'); + static constexpr size_t countK = data.count('K'); + + CHECK_EQUAL(1, countA); + CHECK_EQUAL(1, countB); + CHECK_EQUAL(1, countC); + CHECK_EQUAL(1, countD); + CHECK_EQUAL(1, countE); + CHECK_EQUAL(1, countF); + CHECK_EQUAL(1, countG); + CHECK_EQUAL(1, countH); + CHECK_EQUAL(1, countI); + CHECK_EQUAL(1, countJ); + CHECK_EQUAL(0, countK); + } + + //************************************************************************* + TEST(test_const_iterator) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data data{ values }; + + const_iterator itr = data.begin(); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); + CHECK_TRUE((value_type{Key('I'), 8 }) == *itr++); + CHECK_TRUE((value_type{Key('H'), 7 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 6 }) == *itr++); + CHECK_TRUE((value_type{Key('F'), 5 }) == *itr++); + CHECK_TRUE((value_type{Key('E'), 4 }) == *itr++); + CHECK_TRUE((value_type{Key('D'), 3 }) == *itr++); + CHECK_TRUE((value_type{Key('C'), 2 }) == *itr++); + CHECK_TRUE((value_type{Key('B'), 1 }) == *itr++); + CHECK_TRUE((value_type{Key('A'), 0 }) == *itr++); + CHECK_TRUE(itr == data.end()); +#else + CHECK_TRUE((value_type{Key('A'), 0 }) == *itr++); + CHECK_TRUE((value_type{Key('B'), 1 }) == *itr++); + CHECK_TRUE((value_type{Key('C'), 2 }) == *itr++); + CHECK_TRUE((value_type{Key('D'), 3 }) == *itr++); + CHECK_TRUE((value_type{Key('E'), 4 }) == *itr++); + CHECK_TRUE((value_type{Key('F'), 5 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 6 }) == *itr++); + CHECK_TRUE((value_type{Key('H'), 7 }) == *itr++); + CHECK_TRUE((value_type{Key('I'), 8 }) == *itr++); + CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); + CHECK_TRUE(itr == data.end()); +#endif + } + + //************************************************************************* + TEST(test_find) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data data{ values }; + + static constexpr const_iterator resultA = data.find(Key('A')); + static constexpr const_iterator resultB = data.find(Key('B')); + static constexpr const_iterator resultC = data.find(Key('C')); + static constexpr const_iterator resultD = data.find(Key('D')); + static constexpr const_iterator resultE = data.find(Key('E')); + static constexpr const_iterator resultF = data.find(Key('F')); + static constexpr const_iterator resultG = data.find(Key('G')); + static constexpr const_iterator resultH = data.find(Key('H')); + static constexpr const_iterator resultI = data.find(Key('I')); + static constexpr const_iterator resultJ = data.find(Key('J')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); +#endif + } + + //************************************************************************* + TEST(test_find_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr DataTransparentComparator data{ values }; + + static constexpr const_iterator resultA = data.find('A'); + static constexpr const_iterator resultB = data.find('B'); + static constexpr const_iterator resultC = data.find('C'); + static constexpr const_iterator resultD = data.find('D'); + static constexpr const_iterator resultE = data.find('E'); + static constexpr const_iterator resultF = data.find('F'); + static constexpr const_iterator resultG = data.find('G'); + static constexpr const_iterator resultH = data.find('H'); + static constexpr const_iterator resultI = data.find('I'); + static constexpr const_iterator resultJ = data.find('J'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); +#endif + } + + //************************************************************************* + TEST(test_key_compare) + { + static constexpr Data data; + + static constexpr Data::key_compare compare = data.key_comp(); + + static constexpr Data::key_type a(Key('A')); + static constexpr Data::key_type b(Key('B')); + +#ifdef TEST_GREATER_THAN + CHECK(!compare(a, b)); + CHECK(compare(b, a)); +#else + CHECK(compare(a, b)); + CHECK(!compare(b, a)); +#endif + } + + //************************************************************************* + TEST(test_key_compare_using_transparent_comparator) + { + static constexpr DataTransparentComparator data; + static constexpr DataTransparentComparator::key_compare compare = data.key_comp(); + + static constexpr DataTransparentComparator::key_type a(Key('A')); + static constexpr DataTransparentComparator::key_type b(Key('B')); + +#ifdef TEST_GREATER_THAN + CHECK(!compare(a, b)); + CHECK(compare(b, a)); +#else + CHECK(compare(a, b)); + CHECK(!compare(b, a)); +#endif + } + + //************************************************************************* + TEST(test_value_compare) + { + static constexpr Data data; + static constexpr Data::value_compare compare = data.value_comp(); + + static constexpr Data::value_type a(Key('A'), 0); + static constexpr Data::value_type b(Key('B'), 1); + +#ifdef TEST_GREATER_THAN + CHECK(!compare(a, b)); + CHECK(compare(b, a)); +#else + CHECK(compare(a, b)); + CHECK(!compare(b, a)); +#endif + } + + //************************************************************************* + TEST(test_contains) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data data{ values }; + + static constexpr bool containsA = data.contains(Key('A')); + static constexpr bool containsB = data.contains(Key('B')); + static constexpr bool containsC = data.contains(Key('C')); + static constexpr bool containsD = data.contains(Key('D')); + static constexpr bool containsE = data.contains(Key('E')); + static constexpr bool containsF = data.contains(Key('F')); + static constexpr bool containsG = data.contains(Key('G')); + static constexpr bool containsH = data.contains(Key('H')); + static constexpr bool containsI = data.contains(Key('I')); + static constexpr bool containsJ = data.contains(Key('J')); + static constexpr bool containsK = data.contains(Key('K')); + + CHECK_TRUE(containsA); + CHECK_TRUE(containsB); + CHECK_TRUE(containsC); + CHECK_TRUE(containsD); + CHECK_TRUE(containsE); + CHECK_TRUE(containsF); + CHECK_TRUE(containsG); + CHECK_TRUE(containsH); + CHECK_TRUE(containsI); + CHECK_TRUE(containsJ); + CHECK_FALSE(containsK); + } + + //************************************************************************* + TEST(test_contains_with_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr DataTransparentComparator data{ values }; + + static constexpr bool containsA = data.contains('A'); + static constexpr bool containsB = data.contains('B'); + static constexpr bool containsC = data.contains('C'); + static constexpr bool containsD = data.contains('D'); + static constexpr bool containsE = data.contains('E'); + static constexpr bool containsF = data.contains('F'); + static constexpr bool containsG = data.contains('G'); + static constexpr bool containsH = data.contains('H'); + static constexpr bool containsI = data.contains('I'); + static constexpr bool containsJ = data.contains('J'); + static constexpr bool containsK = data.contains('K'); + + CHECK_TRUE(containsA); + CHECK_TRUE(containsB); + CHECK_TRUE(containsC); + CHECK_TRUE(containsD); + CHECK_TRUE(containsE); + CHECK_TRUE(containsF); + CHECK_TRUE(containsG); + CHECK_TRUE(containsH); + CHECK_TRUE(containsI); + CHECK_TRUE(containsJ); + CHECK_FALSE(containsK); + } + + //************************************************************************* + TEST(test_key_comp) + { + static constexpr Data data; + static constexpr Data::key_compare compare = data.key_comp(); + + static constexpr bool compareAA = compare(Key{ 'A' }, Key{ 'A' }); + static constexpr bool compareBA = compare(Key{ 'B' }, Key{ 'A' }); + static constexpr bool compareAB = compare(Key{ 'A' }, Key{ 'B' }); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA); + CHECK_TRUE(compareBA); + CHECK_FALSE(compareAB); +#else + CHECK_FALSE(compareAA); + CHECK_FALSE(compareBA); + CHECK_TRUE(compareAB); +#endif + } + + //************************************************************************* + TEST(test_key_comp_transparent_comparator) + { + static constexpr DataTransparentComparator data; + static constexpr DataTransparentComparator::key_compare compare = data.key_comp(); + + static constexpr bool compareAA = compare('A', 'A'); + static constexpr bool compareBA = compare('B', 'A'); + static constexpr bool compareAB = compare('A', 'B'); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA); + CHECK_TRUE(compareBA); + CHECK_FALSE(compareAB); +#else + CHECK_FALSE(compareAA); + CHECK_FALSE(compareBA); + CHECK_TRUE(compareAB); +#endif + } + + //************************************************************************* + TEST(test_value_comp) + { + static constexpr Data data; + static constexpr Data::value_compare compare = data.value_comp(); + + static constexpr bool compareAA1 = compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'A' }, 0 }); + static constexpr bool compareAA2 = compare(value_type{ Key{ 'A' }, 0 }, Key{ 'A' }); + static constexpr bool compareAA3 = compare(Key{ 'A' }, value_type{ Key{ 'A' }, 0 }); + + static constexpr bool compareBA1 = compare(value_type{ Key{ 'B' }, 0 }, value_type{ Key{ 'A' }, 0 }); + static constexpr bool compareBA2 = compare(value_type{ Key{ 'B' }, 0 }, Key{ 'A' }); + static constexpr bool compareBA3 = compare(Key{ 'B' }, value_type{ Key{ 'A' }, 0 }); + + static constexpr bool compareAB1 = compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'B' }, 0 }); + static constexpr bool compareAB2 = compare(value_type{ Key{ 'A' }, 0 }, Key{ 'B' }); + static constexpr bool compareAB3 = compare(Key{ 'A' }, value_type{ Key{ 'B' }, 0 });; + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_TRUE(compareBA1); + CHECK_TRUE(compareBA2); + CHECK_TRUE(compareBA3); + + CHECK_FALSE(compareAB1); + CHECK_FALSE(compareAB2); + CHECK_FALSE(compareAB3); +#else + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_FALSE(compareBA1); + CHECK_FALSE(compareBA2); + CHECK_FALSE(compareBA3); + + CHECK_TRUE(compareAB1); + CHECK_TRUE(compareAB2); + CHECK_TRUE(compareAB3); +#endif + } + + //************************************************************************* + TEST(test_value_comp_transparent_comparator) + { + static constexpr DataTransparentComparator data; + static constexpr DataTransparentComparator::value_compare compare = data.value_comp(); + + static constexpr bool compareAA1 = compare(value_type{ 'A', 0 }, value_type{ 'A', 0 }); + static constexpr bool compareAA2 = compare(value_type{ 'A', 0 }, 'A'); + static constexpr bool compareAA3 = compare('A', value_type{ 'A', 0 }); + + static constexpr bool compareBA1 = compare(value_type{ 'B', 0 }, value_type{ 'A', 0 }); + static constexpr bool compareBA2 = compare(value_type{ 'B', 0 }, 'A'); + static constexpr bool compareBA3 = compare('B', value_type{ 'A', 0 }); + + static constexpr bool compareAB1 = compare(value_type{ 'A', 0 }, value_type{ 'B', 0 }); + static constexpr bool compareAB2 = compare(value_type{ 'A', 0 }, 'B'); + static constexpr bool compareAB3 = compare('A', value_type{ 'B', 0 });; + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_TRUE(compareBA1); + CHECK_TRUE(compareBA2); + CHECK_TRUE(compareBA3); + + CHECK_FALSE(compareAB1); + CHECK_FALSE(compareAB2); + CHECK_FALSE(compareAB3); +#else + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_FALSE(compareBA1); + CHECK_FALSE(compareBA2); + CHECK_FALSE(compareBA3); + + CHECK_TRUE(compareAB1); + CHECK_TRUE(compareAB2); + CHECK_TRUE(compareAB3); +#endif + } + + //************************************************************************* + TEST(test_equal) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data1{values1}; + static constexpr Data data2{values2}; + static constexpr Data data3{values3}; + + static constexpr bool equal12 = (data1 == data2); + static constexpr bool equal13 = (data1 == data3); + + CHECK_TRUE(equal12); + CHECK_FALSE(equal13); + } + + //************************************************************************* + TEST(test_equal_with_transparent_comparator) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data1{values1}; + static constexpr DataTransparentComparator data2{values2}; + static constexpr DataTransparentComparator data3{values3}; + + static constexpr bool equal12 = (data1 == data2); + static constexpr bool equal13 = (data1 == data3); + + CHECK_TRUE(equal12); + CHECK_FALSE(equal13); + } + + //************************************************************************* + TEST(test_not_equal) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data1{values1}; + static constexpr Data data2{values2}; + static constexpr Data data3{values3}; + + static constexpr bool not_equal12 = (data1 != data2); + static constexpr bool not_equal13 = (data1 != data3); + + CHECK_FALSE(not_equal12); + CHECK_TRUE(not_equal13); + } + + //************************************************************************* + TEST(test_not_equal_with_transparent_comparator) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data1{values1}; + static constexpr DataTransparentComparator data2{values2}; + static constexpr DataTransparentComparator data3{values3}; + + static constexpr bool not_equal12 = (data1 != data2); + static constexpr bool not_equal13 = (data1 != data3); + + CHECK_FALSE(not_equal12); + CHECK_TRUE(not_equal13); + } + + //************************************************************************* + TEST(test_less_than) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data1{values1}; + static constexpr Data data2{values2}; + static constexpr Data data3{values3}; + + static constexpr bool less_than12 = (data1 < data2); + static constexpr bool less_than23 = (data2 < data3); + static constexpr bool less_than21 = (data2 < data1); + static constexpr bool less_than32 = (data3 < data2); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than12); + CHECK_FALSE(less_than23); + CHECK_TRUE(less_than21); + CHECK_TRUE(less_than32); +#else + CHECK_TRUE(less_than12); + CHECK_TRUE(less_than23); + CHECK_FALSE(less_than21); + CHECK_FALSE(less_than32); +#endif + } + + //************************************************************************* + TEST(test_less_than_with_transparent_comparator) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data1{values1}; + static constexpr DataTransparentComparator data2{values2}; + static constexpr DataTransparentComparator data3{values3}; + + static constexpr bool less_than12 = (data1 < data2); + static constexpr bool less_than23 = (data2 < data3); + static constexpr bool less_than21 = (data2 < data1); + static constexpr bool less_than32 = (data3 < data2); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than12); + CHECK_FALSE(less_than23); + CHECK_TRUE(less_than21); + CHECK_TRUE(less_than32); +#else + CHECK_TRUE(less_than12); + CHECK_TRUE(less_than23); + CHECK_FALSE(less_than21); + CHECK_FALSE(less_than32); +#endif + } + + //************************************************************************* + TEST(test_less_than_equal) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data1{values1}; + static constexpr Data data2{values2}; + static constexpr Data data3{values3}; + + static constexpr bool less_than_equal12 = (data1 <= data2); + static constexpr bool less_than_equal23 = (data2 <= data3); + static constexpr bool less_than_equal21 = (data2 <= data1); + static constexpr bool less_than_equal32 = (data3 <= data2); + static constexpr bool less_than_equal11 = (data1 <= data1); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than_equal12); + CHECK_FALSE(less_than_equal23); + CHECK_TRUE(less_than_equal21); + CHECK_TRUE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#else + CHECK_TRUE(less_than_equal12); + CHECK_TRUE(less_than_equal23); + CHECK_FALSE(less_than_equal21); + CHECK_FALSE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_less_than_equal_with_transparent_comparator) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data1{values1}; + static constexpr DataTransparentComparator data2{values2}; + static constexpr DataTransparentComparator data3{values3}; + + static constexpr bool less_than_equal12 = (data1 <= data2); + static constexpr bool less_than_equal23 = (data2 <= data3); + static constexpr bool less_than_equal21 = (data2 <= data1); + static constexpr bool less_than_equal32 = (data3 <= data2); + static constexpr bool less_than_equal11 = (data1 <= data1); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than_equal12); + CHECK_FALSE(less_than_equal23); + CHECK_TRUE(less_than_equal21); + CHECK_TRUE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#else + CHECK_TRUE(less_than_equal12); + CHECK_TRUE(less_than_equal23); + CHECK_FALSE(less_than_equal21); + CHECK_FALSE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_greater_than) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data1{values1}; + static constexpr Data data2{values2}; + static constexpr Data data3{values3}; + + static constexpr bool greater_than12 = (data1 > data2); + static constexpr bool greater_than23 = (data2 > data3); + static constexpr bool greater_than21 = (data2 > data1); + static constexpr bool greater_than32 = (data3 > data2); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than12); + CHECK_TRUE(greater_than23); + CHECK_FALSE(greater_than21); + CHECK_FALSE(greater_than32); +#else + CHECK_FALSE(greater_than12); + CHECK_FALSE(greater_than23); + CHECK_TRUE(greater_than21); + CHECK_TRUE(greater_than32); +#endif + } + + //************************************************************************* + TEST(test_greater_than_with_transparent_comparator) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data1{values1}; + static constexpr DataTransparentComparator data2{values2}; + static constexpr DataTransparentComparator data3{values3}; + + static constexpr bool greater_than12 = (data1 > data2); + static constexpr bool greater_than23 = (data2 > data3); + static constexpr bool greater_than21 = (data2 > data1); + static constexpr bool greater_than32 = (data3 > data2); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than12); + CHECK_TRUE(greater_than23); + CHECK_FALSE(greater_than21); + CHECK_FALSE(greater_than32); +#else + CHECK_FALSE(greater_than12); + CHECK_FALSE(greater_than23); + CHECK_TRUE(greater_than21); + CHECK_TRUE(greater_than32); +#endif + } + + //************************************************************************* + TEST(test_greater_than_equal) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data1{values1}; + static constexpr Data data2{values2}; + static constexpr Data data3{values3}; + + static constexpr bool greater_than_equal12 = (data1 >= data2); + static constexpr bool greater_than_equal23 = (data2 >= data3); + static constexpr bool greater_than_equal21 = (data2 >= data1); + static constexpr bool greater_than_equal32 = (data3 >= data2); + static constexpr bool greater_than_equal11 = (data1 >= data1); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than_equal12); + CHECK_TRUE(greater_than_equal23); + CHECK_FALSE(greater_than_equal21); + CHECK_FALSE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#else + CHECK_FALSE(greater_than_equal12); + CHECK_FALSE(greater_than_equal23); + CHECK_TRUE(greater_than_equal21); + CHECK_TRUE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_greater_than_equal_with_transparent_comparator) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data1{values1}; + static constexpr DataTransparentComparator data2{values2}; + static constexpr DataTransparentComparator data3{values3}; + + static constexpr bool greater_than_equal12 = (data1 >= data2); + static constexpr bool greater_than_equal23 = (data2 >= data3); + static constexpr bool greater_than_equal21 = (data2 >= data1); + static constexpr bool greater_than_equal32 = (data3 >= data2); + static constexpr bool greater_than_equal11 = (data1 >= data1); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than_equal12); + CHECK_TRUE(greater_than_equal23); + CHECK_FALSE(greater_than_equal21); + CHECK_FALSE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#else + CHECK_FALSE(greater_than_equal12); + CHECK_FALSE(greater_than_equal23); + CHECK_TRUE(greater_than_equal21); + CHECK_TRUE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#endif + } + }; +} diff --git a/test/test_const_multimap.cpp b/test/test_const_multimap.cpp index d3c8bd7b..de9a1089 100644 --- a/test/test_const_multimap.cpp +++ b/test/test_const_multimap.cpp @@ -102,8 +102,10 @@ namespace using IDataTransparentComparator = etl::iconst_multimap>; #endif - using value_type = Data::value_type; - using Data_const_iterator = Data::const_iterator; + using value_type = Data::value_type; + using key_type = Data::key_type; + using mapped_type = Data::mapped_type; + using const_iterator = Data::const_iterator; SUITE(test_const_multimap) { @@ -112,14 +114,14 @@ namespace { static const Data data; - static const bool is_valid = data.is_valid(); - static const size_t size = data.size(); - static const bool empty = data.empty(); - static const bool full = data.full(); - static const size_t capacity = data.capacity(); - static const size_t max_size = data.max_size(); - static const Data::const_iterator begin = data.begin(); - static const Data::const_iterator end = data.end(); + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const const_iterator begin = data.begin(); + static const const_iterator end = data.end(); CHECK_TRUE(is_valid); CHECK_TRUE(size == 0UL); @@ -135,14 +137,14 @@ namespace { static const Data data{ value_type{Key('A'), 0 } }; - static const bool is_valid = data.is_valid(); - static const size_t size = data.size(); - static const bool empty = data.empty(); - static const bool full = data.full(); - static const size_t capacity = data.capacity(); - static const size_t max_size = data.max_size(); - static const Data::const_iterator begin = data.begin(); - static const Data::const_iterator end = data.end(); + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const const_iterator begin = data.begin(); + static const const_iterator end = data.end(); CHECK_TRUE(is_valid); CHECK_TRUE(size == 1U); @@ -158,20 +160,20 @@ namespace { #ifdef TEST_GREATER_THAN static const Data data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; #endif - static const bool is_valid = data.is_valid(); - static const size_t size = data.size(); - static const bool empty = data.empty(); - static const bool full = data.full(); - static const size_t capacity = data.capacity(); - static const size_t max_size = data.max_size(); - static const Data::const_iterator begin = data.begin(); - static const Data::const_iterator end = data.end(); + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const const_iterator begin = data.begin(); + static const const_iterator end = data.end(); CHECK_TRUE(is_valid); CHECK_TRUE(size == Max_Size); @@ -196,21 +198,12 @@ namespace //************************************************************************* TEST(test_cpp17_deduced_constructor) { -#ifdef TEST_GREATER_THAN - static const Data data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else - static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; -#endif + static const etl::const_multimap data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; -#ifdef TEST_GREATER_THAN - etl::const_multimap check{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else etl::const_multimap check{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; -#endif + CHECK_TRUE(data.is_valid()); CHECK_TRUE(data.size() == Max_Size); CHECK_FALSE(data.empty()); @@ -248,7 +241,7 @@ namespace static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; - static const Data::const_iterator end_itr = data.end(); + static const const_iterator end_itr = data.end(); CHECK_TRUE(end_itr == (data.begin() + data.size())); } @@ -264,16 +257,16 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; #endif - static const ETL_OR_STD::pair resultA = data.equal_range(Key('A')); - static const ETL_OR_STD::pair resultB = data.equal_range(Key('B')); - static const ETL_OR_STD::pair resultC = data.equal_range(Key('C')); - static const ETL_OR_STD::pair resultD = data.equal_range(Key('D')); - static const ETL_OR_STD::pair resultE = data.equal_range(Key('E')); - static const ETL_OR_STD::pair resultF = data.equal_range(Key('F')); - static const ETL_OR_STD::pair resultG = data.equal_range(Key('G')); - static const ETL_OR_STD::pair resultH = data.equal_range(Key('H')); - static const ETL_OR_STD::pair resultI = data.equal_range(Key('I')); - static const ETL_OR_STD::pair resultJ = data.equal_range(Key('J')); + static const ETL_OR_STD::pair resultA = data.equal_range(Key('A')); + static const ETL_OR_STD::pair resultB = data.equal_range(Key('B')); + static const ETL_OR_STD::pair resultC = data.equal_range(Key('C')); + static const ETL_OR_STD::pair resultD = data.equal_range(Key('D')); + static const ETL_OR_STD::pair resultE = data.equal_range(Key('E')); + static const ETL_OR_STD::pair resultF = data.equal_range(Key('F')); + static const ETL_OR_STD::pair resultG = data.equal_range(Key('G')); + static const ETL_OR_STD::pair resultH = data.equal_range(Key('H')); + static const ETL_OR_STD::pair resultI = data.equal_range(Key('I')); + static const ETL_OR_STD::pair resultJ = data.equal_range(Key('J')); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); @@ -333,16 +326,16 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; #endif - static const ETL_OR_STD::pair resultA = data.equal_range('A'); - static const ETL_OR_STD::pair resultB = data.equal_range('B'); - static const ETL_OR_STD::pair resultC = data.equal_range('C'); - static const ETL_OR_STD::pair resultD = data.equal_range('D'); - static const ETL_OR_STD::pair resultE = data.equal_range('E'); - static const ETL_OR_STD::pair resultF = data.equal_range('F'); - static const ETL_OR_STD::pair resultG = data.equal_range('G'); - static const ETL_OR_STD::pair resultH = data.equal_range('H'); - static const ETL_OR_STD::pair resultI = data.equal_range('I'); - static const ETL_OR_STD::pair resultJ = data.equal_range('J'); + static const ETL_OR_STD::pair resultA = data.equal_range('A'); + static const ETL_OR_STD::pair resultB = data.equal_range('B'); + static const ETL_OR_STD::pair resultC = data.equal_range('C'); + static const ETL_OR_STD::pair resultD = data.equal_range('D'); + static const ETL_OR_STD::pair resultE = data.equal_range('E'); + static const ETL_OR_STD::pair resultF = data.equal_range('F'); + static const ETL_OR_STD::pair resultG = data.equal_range('G'); + static const ETL_OR_STD::pair resultH = data.equal_range('H'); + static const ETL_OR_STD::pair resultI = data.equal_range('I'); + static const ETL_OR_STD::pair resultJ = data.equal_range('J'); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); @@ -395,24 +388,24 @@ namespace TEST(test_lower_bound_const) { #ifdef TEST_GREATER_THAN - static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + static const Data data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; #endif - static const Data::const_iterator resultA = data.lower_bound(Key('A')); - static const Data::const_iterator resultB = data.lower_bound(Key('B')); - static const Data::const_iterator resultC = data.lower_bound(Key('C')); - static const Data::const_iterator resultD = data.lower_bound(Key('D')); - static const Data::const_iterator resultE = data.lower_bound(Key('E')); - static const Data::const_iterator resultF = data.lower_bound(Key('F')); - static const Data::const_iterator resultG = data.lower_bound(Key('G')); - static const Data::const_iterator resultH = data.lower_bound(Key('H')); - static const Data::const_iterator resultI = data.lower_bound(Key('I')); - static const Data::const_iterator resultJ = data.lower_bound(Key('J')); - static const Data::const_iterator resultK = data.lower_bound(Key('K')); + static const const_iterator resultA = data.lower_bound(Key('A')); + static const const_iterator resultB = data.lower_bound(Key('B')); + static const const_iterator resultC = data.lower_bound(Key('C')); + static const const_iterator resultD = data.lower_bound(Key('D')); + static const const_iterator resultE = data.lower_bound(Key('E')); + static const const_iterator resultF = data.lower_bound(Key('F')); + static const const_iterator resultG = data.lower_bound(Key('G')); + static const const_iterator resultH = data.lower_bound(Key('H')); + static const const_iterator resultI = data.lower_bound(Key('I')); + static const const_iterator resultJ = data.lower_bound(Key('J')); + static const const_iterator resultK = data.lower_bound(Key('K')); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); @@ -452,17 +445,17 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; #endif - static const Data::const_iterator resultA = data.lower_bound('A'); - static const Data::const_iterator resultB = data.lower_bound('B'); - static const Data::const_iterator resultC = data.lower_bound('C'); - static const Data::const_iterator resultD = data.lower_bound('D'); - static const Data::const_iterator resultE = data.lower_bound('E'); - static const Data::const_iterator resultF = data.lower_bound('F'); - static const Data::const_iterator resultG = data.lower_bound('G'); - static const Data::const_iterator resultH = data.lower_bound('H'); - static const Data::const_iterator resultI = data.lower_bound('I'); - static const Data::const_iterator resultJ = data.lower_bound('J'); - static const Data::const_iterator resultK = data.lower_bound('K'); + static const const_iterator resultA = data.lower_bound('A'); + static const const_iterator resultB = data.lower_bound('B'); + static const const_iterator resultC = data.lower_bound('C'); + static const const_iterator resultD = data.lower_bound('D'); + static const const_iterator resultE = data.lower_bound('E'); + static const const_iterator resultF = data.lower_bound('F'); + static const const_iterator resultG = data.lower_bound('G'); + static const const_iterator resultH = data.lower_bound('H'); + static const const_iterator resultI = data.lower_bound('I'); + static const const_iterator resultJ = data.lower_bound('J'); + static const const_iterator resultK = data.lower_bound('K'); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); @@ -495,24 +488,24 @@ namespace TEST(test_upper_bound_const) { #ifdef TEST_GREATER_THAN - static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + static const Data data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; #endif - static const Data::const_iterator resultA = data.upper_bound(Key('A')); - static const Data::const_iterator resultB = data.upper_bound(Key('B')); - static const Data::const_iterator resultC = data.upper_bound(Key('C')); - static const Data::const_iterator resultD = data.upper_bound(Key('D')); - static const Data::const_iterator resultE = data.upper_bound(Key('E')); - static const Data::const_iterator resultF = data.upper_bound(Key('F')); - static const Data::const_iterator resultG = data.upper_bound(Key('G')); - static const Data::const_iterator resultH = data.upper_bound(Key('H')); - static const Data::const_iterator resultI = data.upper_bound(Key('I')); - static const Data::const_iterator resultJ = data.upper_bound(Key('J')); - static const Data::const_iterator resultK = data.upper_bound(Key('K')); + static const const_iterator resultA = data.upper_bound(Key('A')); + static const const_iterator resultB = data.upper_bound(Key('B')); + static const const_iterator resultC = data.upper_bound(Key('C')); + static const const_iterator resultD = data.upper_bound(Key('D')); + static const const_iterator resultE = data.upper_bound(Key('E')); + static const const_iterator resultF = data.upper_bound(Key('F')); + static const const_iterator resultG = data.upper_bound(Key('G')); + static const const_iterator resultH = data.upper_bound(Key('H')); + static const const_iterator resultI = data.upper_bound(Key('I')); + static const const_iterator resultJ = data.upper_bound(Key('J')); + static const const_iterator resultK = data.upper_bound(Key('K')); #ifdef TEST_GREATER_THAN CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); @@ -552,17 +545,17 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; #endif - static const Data::const_iterator resultA = data.upper_bound('A'); - static const Data::const_iterator resultB = data.upper_bound('B'); - static const Data::const_iterator resultC = data.upper_bound('C'); - static const Data::const_iterator resultD = data.upper_bound('D'); - static const Data::const_iterator resultE = data.upper_bound('E'); - static const Data::const_iterator resultF = data.upper_bound('F'); - static const Data::const_iterator resultG = data.upper_bound('G'); - static const Data::const_iterator resultH = data.upper_bound('H'); - static const Data::const_iterator resultI = data.upper_bound('I'); - static const Data::const_iterator resultJ = data.upper_bound('J'); - static const Data::const_iterator resultK = data.upper_bound('K'); + static const const_iterator resultA = data.upper_bound('A'); + static const const_iterator resultB = data.upper_bound('B'); + static const const_iterator resultC = data.upper_bound('C'); + static const const_iterator resultD = data.upper_bound('D'); + static const const_iterator resultE = data.upper_bound('E'); + static const const_iterator resultF = data.upper_bound('F'); + static const const_iterator resultG = data.upper_bound('G'); + static const const_iterator resultH = data.upper_bound('H'); + static const const_iterator resultI = data.upper_bound('I'); + static const const_iterator resultJ = data.upper_bound('J'); + static const const_iterator resultK = data.upper_bound('K'); #ifdef TEST_GREATER_THAN CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); @@ -595,11 +588,11 @@ namespace TEST(test_count_const) { #ifdef TEST_GREATER_THAN - static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + static const Data data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; #endif CHECK_EQUAL(1, data.count(Key('A'))); @@ -643,14 +636,14 @@ namespace TEST(test_const_iterator) { #ifdef TEST_GREATER_THAN - static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + static const Data data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; #endif - Data::const_iterator itr = data.begin(); + const_iterator itr = data.begin(); #ifdef TEST_GREATER_THAN CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); @@ -683,23 +676,23 @@ namespace TEST(test_find_const) { #ifdef TEST_GREATER_THAN - static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + static const Data data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; #endif - static const Data::const_iterator resultA = data.find(Key('A')); - static const Data::const_iterator resultB = data.find(Key('B')); - static const Data::const_iterator resultC = data.find(Key('C')); - static const Data::const_iterator resultD = data.find(Key('D')); - static const Data::const_iterator resultE = data.find(Key('E')); - static const Data::const_iterator resultF = data.find(Key('F')); - static const Data::const_iterator resultG = data.find(Key('G')); - static const Data::const_iterator resultH = data.find(Key('H')); - static const Data::const_iterator resultI = data.find(Key('I')); - static const Data::const_iterator resultJ = data.find(Key('J')); + static const const_iterator resultA = data.find(Key('A')); + static const const_iterator resultB = data.find(Key('B')); + static const const_iterator resultC = data.find(Key('C')); + static const const_iterator resultD = data.find(Key('D')); + static const const_iterator resultE = data.find(Key('E')); + static const const_iterator resultF = data.find(Key('F')); + static const const_iterator resultG = data.find(Key('G')); + static const const_iterator resultH = data.find(Key('H')); + static const const_iterator resultI = data.find(Key('I')); + static const const_iterator resultJ = data.find(Key('J')); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); @@ -737,16 +730,16 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; #endif - static const Data::const_iterator resultA = data.find('A'); - static const Data::const_iterator resultB = data.find('B'); - static const Data::const_iterator resultC = data.find('C'); - static const Data::const_iterator resultD = data.find('D'); - static const Data::const_iterator resultE = data.find('E'); - static const Data::const_iterator resultF = data.find('F'); - static const Data::const_iterator resultG = data.find('G'); - static const Data::const_iterator resultH = data.find('H'); - static const Data::const_iterator resultI = data.find('I'); - static const Data::const_iterator resultJ = data.find('J'); + static const const_iterator resultA = data.find('A'); + static const const_iterator resultB = data.find('B'); + static const const_iterator resultC = data.find('C'); + static const const_iterator resultD = data.find('D'); + static const const_iterator resultE = data.find('E'); + static const const_iterator resultF = data.find('F'); + static const const_iterator resultG = data.find('G'); + static const const_iterator resultH = data.find('H'); + static const const_iterator resultI = data.find('I'); + static const const_iterator resultJ = data.find('J'); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); @@ -777,11 +770,11 @@ namespace TEST(test_contains_const) { #ifdef TEST_GREATER_THAN - static const DataTransparentComparator data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; + static const Data data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; #else - static const DataTransparentComparator data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; + static const Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; #endif static const bool containsA = data.contains(Key('A')); diff --git a/test/test_const_multimap_constexpr.cpp b/test/test_const_multimap_constexpr.cpp index dd7d4036..68720992 100644 --- a/test/test_const_multimap_constexpr.cpp +++ b/test/test_const_multimap_constexpr.cpp @@ -104,8 +104,10 @@ namespace using IDataTransparentComparator = etl::iconst_multimap>; #endif - using value_type = Data::value_type; - using Data_const_iterator = Data::const_iterator; + using value_type = Data::value_type; + using key_type = Data::key_type; + using mapped_type = Data::mapped_type; + using const_iterator = Data::const_iterator; SUITE(test_const_multimap) { @@ -114,14 +116,14 @@ namespace { static constexpr Data data; - static constexpr bool is_valid = data.is_valid(); - static constexpr size_t size = data.size(); - static constexpr bool empty = data.empty(); - static constexpr bool full = data.full(); - static constexpr size_t capacity = data.capacity(); - static constexpr size_t max_size = data.max_size(); - static constexpr Data::const_iterator begin = data.begin(); - static constexpr Data::const_iterator end = data.end(); + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr const_iterator begin = data.begin(); + static constexpr const_iterator end = data.end(); CHECK_TRUE(is_valid); CHECK_TRUE(size == 0UL); @@ -137,14 +139,14 @@ namespace { static constexpr Data data{ value_type{Key('A'), 0 } }; - static constexpr bool is_valid = data.is_valid(); - static constexpr size_t size = data.size(); - static constexpr bool empty = data.empty(); - static constexpr bool full = data.full(); - static constexpr size_t capacity = data.capacity(); - static constexpr size_t max_size = data.max_size(); - static constexpr Data::const_iterator begin = data.begin(); - static constexpr Data::const_iterator end = data.end(); + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr const_iterator begin = data.begin(); + static constexpr const_iterator end = data.end(); CHECK_TRUE(is_valid); CHECK_TRUE(size == 1U); @@ -166,14 +168,14 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr bool is_valid = data.is_valid(); - static constexpr size_t size = data.size(); - static constexpr bool empty = data.empty(); - static constexpr bool full = data.full(); - static constexpr size_t capacity = data.capacity(); - static constexpr size_t max_size = data.max_size(); - static constexpr Data::const_iterator begin = data.begin(); - static constexpr Data::const_iterator end = data.end(); + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr const_iterator begin = data.begin(); + static constexpr const_iterator end = data.end(); CHECK_TRUE(is_valid); CHECK_TRUE(size == Max_Size); @@ -198,21 +200,12 @@ namespace //************************************************************************* TEST(test_cpp17_deduced_constructor) { -#ifdef TEST_GREATER_THAN - static constexpr Data data{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else - static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, - value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; -#endif + static constexpr etl::const_multimap data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; -#ifdef TEST_GREATER_THAN - etl::const_multimap check{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, - value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; -#else etl::const_multimap check{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; -#endif + CHECK_TRUE(data.is_valid()); CHECK_TRUE(data.size() == Max_Size); CHECK_FALSE(data.empty()); @@ -250,7 +243,7 @@ namespace static constexpr Data data{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; - static constexpr Data::const_iterator end_itr = data.end(); + static constexpr const_iterator end_itr = data.end(); CHECK_TRUE(end_itr == (data.begin() + data.size())); } @@ -266,16 +259,16 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr ETL_OR_STD::pair resultA = data.equal_range(Key('A')); - static constexpr ETL_OR_STD::pair resultB = data.equal_range(Key('B')); - static constexpr ETL_OR_STD::pair resultC = data.equal_range(Key('C')); - static constexpr ETL_OR_STD::pair resultD = data.equal_range(Key('D')); - static constexpr ETL_OR_STD::pair resultE = data.equal_range(Key('E')); - static constexpr ETL_OR_STD::pair resultF = data.equal_range(Key('F')); - static constexpr ETL_OR_STD::pair resultG = data.equal_range(Key('G')); - static constexpr ETL_OR_STD::pair resultH = data.equal_range(Key('H')); - static constexpr ETL_OR_STD::pair resultI = data.equal_range(Key('I')); - static constexpr ETL_OR_STD::pair resultJ = data.equal_range(Key('J')); + static constexpr ETL_OR_STD::pair resultA = data.equal_range(Key('A')); + static constexpr ETL_OR_STD::pair resultB = data.equal_range(Key('B')); + static constexpr ETL_OR_STD::pair resultC = data.equal_range(Key('C')); + static constexpr ETL_OR_STD::pair resultD = data.equal_range(Key('D')); + static constexpr ETL_OR_STD::pair resultE = data.equal_range(Key('E')); + static constexpr ETL_OR_STD::pair resultF = data.equal_range(Key('F')); + static constexpr ETL_OR_STD::pair resultG = data.equal_range(Key('G')); + static constexpr ETL_OR_STD::pair resultH = data.equal_range(Key('H')); + static constexpr ETL_OR_STD::pair resultI = data.equal_range(Key('I')); + static constexpr ETL_OR_STD::pair resultJ = data.equal_range(Key('J')); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); @@ -335,17 +328,17 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr Data::const_iterator resultA = data.lower_bound(Key('A')); - static constexpr Data::const_iterator resultB = data.lower_bound(Key('B')); - static constexpr Data::const_iterator resultC = data.lower_bound(Key('C')); - static constexpr Data::const_iterator resultD = data.lower_bound(Key('D')); - static constexpr Data::const_iterator resultE = data.lower_bound(Key('E')); - static constexpr Data::const_iterator resultF = data.lower_bound(Key('F')); - static constexpr Data::const_iterator resultG = data.lower_bound(Key('G')); - static constexpr Data::const_iterator resultH = data.lower_bound(Key('H')); - static constexpr Data::const_iterator resultI = data.lower_bound(Key('I')); - static constexpr Data::const_iterator resultJ = data.lower_bound(Key('J')); - static constexpr Data::const_iterator resultK = data.lower_bound(Key('K')); + static constexpr const_iterator resultA = data.lower_bound(Key('A')); + static constexpr const_iterator resultB = data.lower_bound(Key('B')); + static constexpr const_iterator resultC = data.lower_bound(Key('C')); + static constexpr const_iterator resultD = data.lower_bound(Key('D')); + static constexpr const_iterator resultE = data.lower_bound(Key('E')); + static constexpr const_iterator resultF = data.lower_bound(Key('F')); + static constexpr const_iterator resultG = data.lower_bound(Key('G')); + static constexpr const_iterator resultH = data.lower_bound(Key('H')); + static constexpr const_iterator resultI = data.lower_bound(Key('I')); + static constexpr const_iterator resultJ = data.lower_bound(Key('J')); + static constexpr const_iterator resultK = data.lower_bound(Key('K')); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); @@ -385,17 +378,17 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr Data::const_iterator resultA = data.lower_bound('A'); - static constexpr Data::const_iterator resultB = data.lower_bound('B'); - static constexpr Data::const_iterator resultC = data.lower_bound('C'); - static constexpr Data::const_iterator resultD = data.lower_bound('D'); - static constexpr Data::const_iterator resultE = data.lower_bound('E'); - static constexpr Data::const_iterator resultF = data.lower_bound('F'); - static constexpr Data::const_iterator resultG = data.lower_bound('G'); - static constexpr Data::const_iterator resultH = data.lower_bound('H'); - static constexpr Data::const_iterator resultI = data.lower_bound('I'); - static constexpr Data::const_iterator resultJ = data.lower_bound('J'); - static constexpr Data::const_iterator resultK = data.lower_bound('K'); + static constexpr const_iterator resultA = data.lower_bound('A'); + static constexpr const_iterator resultB = data.lower_bound('B'); + static constexpr const_iterator resultC = data.lower_bound('C'); + static constexpr const_iterator resultD = data.lower_bound('D'); + static constexpr const_iterator resultE = data.lower_bound('E'); + static constexpr const_iterator resultF = data.lower_bound('F'); + static constexpr const_iterator resultG = data.lower_bound('G'); + static constexpr const_iterator resultH = data.lower_bound('H'); + static constexpr const_iterator resultI = data.lower_bound('I'); + static constexpr const_iterator resultJ = data.lower_bound('J'); + static constexpr const_iterator resultK = data.lower_bound('K'); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); @@ -435,17 +428,17 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr Data::const_iterator resultA = data.upper_bound(Key('A')); - static constexpr Data::const_iterator resultB = data.upper_bound(Key('B')); - static constexpr Data::const_iterator resultC = data.upper_bound(Key('C')); - static constexpr Data::const_iterator resultD = data.upper_bound(Key('D')); - static constexpr Data::const_iterator resultE = data.upper_bound(Key('E')); - static constexpr Data::const_iterator resultF = data.upper_bound(Key('F')); - static constexpr Data::const_iterator resultG = data.upper_bound(Key('G')); - static constexpr Data::const_iterator resultH = data.upper_bound(Key('H')); - static constexpr Data::const_iterator resultI = data.upper_bound(Key('I')); - static constexpr Data::const_iterator resultJ = data.upper_bound(Key('J')); - static constexpr Data::const_iterator resultK = data.upper_bound(Key('K')); + static constexpr const_iterator resultA = data.upper_bound(Key('A')); + static constexpr const_iterator resultB = data.upper_bound(Key('B')); + static constexpr const_iterator resultC = data.upper_bound(Key('C')); + static constexpr const_iterator resultD = data.upper_bound(Key('D')); + static constexpr const_iterator resultE = data.upper_bound(Key('E')); + static constexpr const_iterator resultF = data.upper_bound(Key('F')); + static constexpr const_iterator resultG = data.upper_bound(Key('G')); + static constexpr const_iterator resultH = data.upper_bound(Key('H')); + static constexpr const_iterator resultI = data.upper_bound(Key('I')); + static constexpr const_iterator resultJ = data.upper_bound(Key('J')); + static constexpr const_iterator resultK = data.upper_bound(Key('K')); #ifdef TEST_GREATER_THAN CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); @@ -485,17 +478,17 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr Data::const_iterator resultA = data.upper_bound('A'); - static constexpr Data::const_iterator resultB = data.upper_bound('B'); - static constexpr Data::const_iterator resultC = data.upper_bound('C'); - static constexpr Data::const_iterator resultD = data.upper_bound('D'); - static constexpr Data::const_iterator resultE = data.upper_bound('E'); - static constexpr Data::const_iterator resultF = data.upper_bound('F'); - static constexpr Data::const_iterator resultG = data.upper_bound('G'); - static constexpr Data::const_iterator resultH = data.upper_bound('H'); - static constexpr Data::const_iterator resultI = data.upper_bound('I'); - static constexpr Data::const_iterator resultJ = data.upper_bound('J'); - static constexpr Data::const_iterator resultK = data.upper_bound('K'); + static constexpr const_iterator resultA = data.upper_bound('A'); + static constexpr const_iterator resultB = data.upper_bound('B'); + static constexpr const_iterator resultC = data.upper_bound('C'); + static constexpr const_iterator resultD = data.upper_bound('D'); + static constexpr const_iterator resultE = data.upper_bound('E'); + static constexpr const_iterator resultF = data.upper_bound('F'); + static constexpr const_iterator resultG = data.upper_bound('G'); + static constexpr const_iterator resultH = data.upper_bound('H'); + static constexpr const_iterator resultI = data.upper_bound('I'); + static constexpr const_iterator resultJ = data.upper_bound('J'); + static constexpr const_iterator resultK = data.upper_bound('K'); #ifdef TEST_GREATER_THAN CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); @@ -583,7 +576,7 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; #endif - Data::const_iterator itr = data.begin(); + const_iterator itr = data.begin(); #ifdef TEST_GREATER_THAN CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); @@ -623,16 +616,16 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr Data::const_iterator resultA = data.find(Key('A')); - static constexpr Data::const_iterator resultB = data.find(Key('B')); - static constexpr Data::const_iterator resultC = data.find(Key('C')); - static constexpr Data::const_iterator resultD = data.find(Key('D')); - static constexpr Data::const_iterator resultE = data.find(Key('E')); - static constexpr Data::const_iterator resultF = data.find(Key('F')); - static constexpr Data::const_iterator resultG = data.find(Key('G')); - static constexpr Data::const_iterator resultH = data.find(Key('H')); - static constexpr Data::const_iterator resultI = data.find(Key('I')); - static constexpr Data::const_iterator resultJ = data.find(Key('J')); + static constexpr const_iterator resultA = data.find(Key('A')); + static constexpr const_iterator resultB = data.find(Key('B')); + static constexpr const_iterator resultC = data.find(Key('C')); + static constexpr const_iterator resultD = data.find(Key('D')); + static constexpr const_iterator resultE = data.find(Key('E')); + static constexpr const_iterator resultF = data.find(Key('F')); + static constexpr const_iterator resultG = data.find(Key('G')); + static constexpr const_iterator resultH = data.find(Key('H')); + static constexpr const_iterator resultI = data.find(Key('I')); + static constexpr const_iterator resultJ = data.find(Key('J')); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); @@ -670,16 +663,16 @@ namespace value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; #endif - static constexpr Data::const_iterator resultA = data.find('A'); - static constexpr Data::const_iterator resultB = data.find('B'); - static constexpr Data::const_iterator resultC = data.find('C'); - static constexpr Data::const_iterator resultD = data.find('D'); - static constexpr Data::const_iterator resultE = data.find('E'); - static constexpr Data::const_iterator resultF = data.find('F'); - static constexpr Data::const_iterator resultG = data.find('G'); - static constexpr Data::const_iterator resultH = data.find('H'); - static constexpr Data::const_iterator resultI = data.find('I'); - static constexpr Data::const_iterator resultJ = data.find('J'); + static constexpr const_iterator resultA = data.find('A'); + static constexpr const_iterator resultB = data.find('B'); + static constexpr const_iterator resultC = data.find('C'); + static constexpr const_iterator resultD = data.find('D'); + static constexpr const_iterator resultE = data.find('E'); + static constexpr const_iterator resultF = data.find('F'); + static constexpr const_iterator resultG = data.find('G'); + static constexpr const_iterator resultH = data.find('H'); + static constexpr const_iterator resultI = data.find('I'); + static constexpr const_iterator resultJ = data.find('J'); #ifdef TEST_GREATER_THAN CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); diff --git a/test/test_const_multimap_ext.cpp b/test/test_const_multimap_ext.cpp new file mode 100644 index 00000000..b01e475c --- /dev/null +++ b/test/test_const_multimap_ext.cpp @@ -0,0 +1,1495 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove, rlindeman + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the 'Software'), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "etl/const_multimap.h" +#include "etl/string.h" + +#include "data.h" + +namespace +{ + static const size_t Max_Size = 10UL; + + //************************************************************************* + // The key type + //************************************************************************* + struct Key + { + // Default constructor + constexpr Key() + : k(0) + { + } + + // Construct from char key + constexpr explicit Key(char k_) + : k(k_) + { + } + + char k; + }; + + // Less-than operator for Key < Key + constexpr bool operator <(const Key& lhs, const Key& rhs) noexcept + { + return (lhs.k < rhs.k); + } + + // Less-than operator for Key < char + constexpr bool operator <(const Key& lhs, char rhs) noexcept + { + return (lhs.k < rhs); + } + + // Less-than operator for char < Key + constexpr bool operator <(char lhs, const Key& rhs) noexcept + { + return (lhs < rhs.k); + } + + // Greater-than operator for char > Key + constexpr bool operator ==(const Key& lhs, const Key& rhs) noexcept + { + return (lhs.k == rhs.k); + } + +#define TEST_GREATER_THAN +#ifdef TEST_GREATER_THAN + using Data = etl::const_multimap_ext>; + using IData = etl::iconst_multimap>; + using DataTransparentComparator = etl::const_multimap_ext>; + using IDataTransparentComparator = etl::iconst_multimap>; +#else + using Data = etl::const_multimap_ext>; + using IData = etl::iconst_multimap>; + using DataTransparentComparator = etl::const_multimap_ext>; + using IDataTransparentComparator = etl::iconst_multimap>; +#endif + + using value_type = Data::value_type; + using key_type = Data::key_type; + using mapped_type = Data::mapped_type; + using const_iterator = Data::const_iterator; + using span_type = etl::span; + + SUITE(test_const_multimap) + { + //************************************************************************* + TEST(test_default_constructor) + { + static const Data data; + + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const const_iterator begin = data.begin(); + static const const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == 0UL); + CHECK_TRUE(empty); + CHECK_FALSE(full); + CHECK_TRUE(capacity == 0); + CHECK_TRUE(max_size == 0); + CHECK_TRUE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_min_size_from_span) + { + static const value_type values[]{value_type{Key('A'), 0}}; + static const etl::span span(values); + static const Data data{ span }; + + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const const_iterator begin = data.begin(); + static const const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == 1U); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == span.size()); + CHECK_TRUE(max_size == span.size()); + CHECK_FALSE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_max_size_from_span) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const span_type span(values); + static const Data data{ span }; + + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const const_iterator begin = data.begin(); + static const const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == Max_Size); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_FALSE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_max_size_from_array) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data data{ values }; + + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const const_iterator begin = data.begin(); + static const const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == Max_Size); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_FALSE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_min_size) + { + static const value_type values[]{value_type{Key('A'), 0}}; + static const Data data{ values }; + + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const const_iterator begin = data.begin(); + static const const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == 1U); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == 1); + CHECK_TRUE(max_size == 1); + CHECK_FALSE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_max_size) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data data{ values }; + + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const const_iterator begin = data.begin(); + static const const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == Max_Size); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_FALSE(begin == end); + } + + //************************************************************************* + // Enable to check static_assert "Number of elements exceeds capacity" + //************************************************************************* + //TEST(test_constructor_excess_size) + //{ + // static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + // value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G')), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 }, + // value_type{Key('K'), 10 } }; + // + // static const Data data{ values }; + //} + +#if ETL_USING_CPP17 + //************************************************************************* + TEST(test_cpp17_deduced_constructor_from_span) + { + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; + static const etl::span span(values); + static const etl::const_multimap_ext data{ span }; + + etl::const_multimap check{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + CHECK_TRUE(data.is_valid()); + CHECK_TRUE(data.size() == Max_Size); + CHECK_FALSE(data.empty()); + CHECK_TRUE(data.full()); + CHECK_TRUE(data.capacity() == Max_Size); + CHECK_TRUE(data.max_size() == Max_Size); + CHECK_FALSE(data.begin() == data.end()); + } + + //************************************************************************* + TEST(test_cpp17_deduced_constructor_from_array) + { + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; + + static const etl::const_multimap_ext data{ values }; + + etl::const_multimap check{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + CHECK_TRUE(data.is_valid()); + CHECK_TRUE(data.size() == Max_Size); + CHECK_FALSE(data.empty()); + CHECK_TRUE(data.full()); + CHECK_TRUE(data.capacity() == Max_Size); + CHECK_TRUE(data.max_size() == Max_Size); + CHECK_FALSE(data.begin() == data.end()); + } +#endif + + //************************************************************************* + TEST(test_begin_const) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data data{ values }; + + CHECK_TRUE(data.is_valid()); + static const auto value = *data.begin(); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE((value_type{ Key('J'), 9 }) == value); +#else + CHECK_TRUE((value_type{ Key('A'), 0 }) == value); +#endif + } + + //************************************************************************* + TEST(test_end_const) + { + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data{ values }; + + static const const_iterator end_itr = data.end(); + + CHECK_TRUE(end_itr == (data.begin() + data.size())); + } + + //************************************************************************* + TEST(test_equal_range_const) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data data{ values }; + + static const ETL_OR_STD::pair resultA = data.equal_range(Key('A')); + static const ETL_OR_STD::pair resultB = data.equal_range(Key('B')); + static const ETL_OR_STD::pair resultC = data.equal_range(Key('C')); + static const ETL_OR_STD::pair resultD = data.equal_range(Key('D')); + static const ETL_OR_STD::pair resultE = data.equal_range(Key('E')); + static const ETL_OR_STD::pair resultF = data.equal_range(Key('F')); + static const ETL_OR_STD::pair resultG = data.equal_range(Key('G')); + static const ETL_OR_STD::pair resultH = data.equal_range(Key('H')); + static const ETL_OR_STD::pair resultI = data.equal_range(Key('I')); + static const ETL_OR_STD::pair resultJ = data.equal_range(Key('J')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(10, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ.second))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(1, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ.second))); +#endif + } + + //************************************************************************* + TEST(test_equal_range_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const DataTransparentComparator data{ values }; + + static const ETL_OR_STD::pair resultA = data.equal_range('A'); + static const ETL_OR_STD::pair resultB = data.equal_range('B'); + static const ETL_OR_STD::pair resultC = data.equal_range('C'); + static const ETL_OR_STD::pair resultD = data.equal_range('D'); + static const ETL_OR_STD::pair resultE = data.equal_range('E'); + static const ETL_OR_STD::pair resultF = data.equal_range('F'); + static const ETL_OR_STD::pair resultG = data.equal_range('G'); + static const ETL_OR_STD::pair resultH = data.equal_range('H'); + static const ETL_OR_STD::pair resultI = data.equal_range('I'); + static const ETL_OR_STD::pair resultJ = data.equal_range('J'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(10, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ.second))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(1, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ.second))); +#endif + } + + //************************************************************************* + TEST(test_lower_bound_const) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data data{ values }; + + static const const_iterator resultA = data.lower_bound(Key('A')); + static const const_iterator resultB = data.lower_bound(Key('B')); + static const const_iterator resultC = data.lower_bound(Key('C')); + static const const_iterator resultD = data.lower_bound(Key('D')); + static const const_iterator resultE = data.lower_bound(Key('E')); + static const const_iterator resultF = data.lower_bound(Key('F')); + static const const_iterator resultG = data.lower_bound(Key('G')); + static const const_iterator resultH = data.lower_bound(Key('H')); + static const const_iterator resultI = data.lower_bound(Key('I')); + static const const_iterator resultJ = data.lower_bound(Key('J')); + static const const_iterator resultK = data.lower_bound(Key('K')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_lower_bound_const_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const DataTransparentComparator data{ values }; + + static const const_iterator resultA = data.lower_bound('A'); + static const const_iterator resultB = data.lower_bound('B'); + static const const_iterator resultC = data.lower_bound('C'); + static const const_iterator resultD = data.lower_bound('D'); + static const const_iterator resultE = data.lower_bound('E'); + static const const_iterator resultF = data.lower_bound('F'); + static const const_iterator resultG = data.lower_bound('G'); + static const const_iterator resultH = data.lower_bound('H'); + static const const_iterator resultI = data.lower_bound('I'); + static const const_iterator resultJ = data.lower_bound('J'); + static const const_iterator resultK = data.lower_bound('K'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_upper_bound_const) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data data{ values }; + + static const const_iterator resultA = data.upper_bound(Key('A')); + static const const_iterator resultB = data.upper_bound(Key('B')); + static const const_iterator resultC = data.upper_bound(Key('C')); + static const const_iterator resultD = data.upper_bound(Key('D')); + static const const_iterator resultE = data.upper_bound(Key('E')); + static const const_iterator resultF = data.upper_bound(Key('F')); + static const const_iterator resultG = data.upper_bound(Key('G')); + static const const_iterator resultH = data.upper_bound(Key('H')); + static const const_iterator resultI = data.upper_bound(Key('I')); + static const const_iterator resultJ = data.upper_bound(Key('J')); + static const const_iterator resultK = data.upper_bound(Key('K')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(1, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_upper_bound_const_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const DataTransparentComparator data{ values }; + + static const const_iterator resultA = data.upper_bound('A'); + static const const_iterator resultB = data.upper_bound('B'); + static const const_iterator resultC = data.upper_bound('C'); + static const const_iterator resultD = data.upper_bound('D'); + static const const_iterator resultE = data.upper_bound('E'); + static const const_iterator resultF = data.upper_bound('F'); + static const const_iterator resultG = data.upper_bound('G'); + static const const_iterator resultH = data.upper_bound('H'); + static const const_iterator resultI = data.upper_bound('I'); + static const const_iterator resultJ = data.upper_bound('J'); + static const const_iterator resultK = data.upper_bound('K'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(1, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_count_const) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data data{ values }; + + CHECK_EQUAL(1, data.count(Key('A'))); + CHECK_EQUAL(1, data.count(Key('B'))); + CHECK_EQUAL(1, data.count(Key('C'))); + CHECK_EQUAL(1, data.count(Key('D'))); + CHECK_EQUAL(1, data.count(Key('E'))); + CHECK_EQUAL(1, data.count(Key('F'))); + CHECK_EQUAL(3, data.count(Key('G'))); + CHECK_EQUAL(0, data.count(Key('H'))); + CHECK_EQUAL(0, data.count(Key('I'))); + CHECK_EQUAL(1, data.count(Key('J'))); + CHECK_EQUAL(0, data.count(Key('K'))); + } + + //************************************************************************* + TEST(test_count_const_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const DataTransparentComparator data{ values }; + + CHECK_EQUAL(1, data.count('A')); + CHECK_EQUAL(1, data.count('B')); + CHECK_EQUAL(1, data.count('C')); + CHECK_EQUAL(1, data.count('D')); + CHECK_EQUAL(1, data.count('E')); + CHECK_EQUAL(1, data.count('F')); + CHECK_EQUAL(3, data.count('G')); + CHECK_EQUAL(0, data.count('H')); + CHECK_EQUAL(0, data.count('I')); + CHECK_EQUAL(1, data.count('J')); + CHECK_EQUAL(0, data.count('K')); + } + + //************************************************************************* + TEST(test_const_iterator) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data data{ values }; + + const_iterator itr = data.begin(); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 8 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 7 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 6 }) == *itr++); + CHECK_TRUE((value_type{Key('F'), 5 }) == *itr++); + CHECK_TRUE((value_type{Key('E'), 4 }) == *itr++); + CHECK_TRUE((value_type{Key('D'), 3 }) == *itr++); + CHECK_TRUE((value_type{Key('C'), 2 }) == *itr++); + CHECK_TRUE((value_type{Key('B'), 1 }) == *itr++); + CHECK_TRUE((value_type{Key('A'), 0 }) == *itr++); + CHECK_TRUE(itr == data.end()); +#else + CHECK_TRUE((value_type{Key('A'), 0 }) == *itr++); + CHECK_TRUE((value_type{Key('B'), 1 }) == *itr++); + CHECK_TRUE((value_type{Key('C'), 2 }) == *itr++); + CHECK_TRUE((value_type{Key('D'), 3 }) == *itr++); + CHECK_TRUE((value_type{Key('E'), 4 }) == *itr++); + CHECK_TRUE((value_type{Key('F'), 5 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 6 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 7 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 8 }) == *itr++); + CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); + CHECK_TRUE(itr == data.end()); +#endif + } + + //************************************************************************* + TEST(test_find_const) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data data{ values }; + + static const const_iterator resultA = data.find(Key('A')); + static const const_iterator resultB = data.find(Key('B')); + static const const_iterator resultC = data.find(Key('C')); + static const const_iterator resultD = data.find(Key('D')); + static const const_iterator resultE = data.find(Key('E')); + static const const_iterator resultF = data.find(Key('F')); + static const const_iterator resultG = data.find(Key('G')); + static const const_iterator resultH = data.find(Key('H')); + static const const_iterator resultI = data.find(Key('I')); + static const const_iterator resultJ = data.find(Key('J')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); +#endif + } + + //************************************************************************* + TEST(test_find_const_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const DataTransparentComparator data{ values }; + + static const const_iterator resultA = data.find('A'); + static const const_iterator resultB = data.find('B'); + static const const_iterator resultC = data.find('C'); + static const const_iterator resultD = data.find('D'); + static const const_iterator resultE = data.find('E'); + static const const_iterator resultF = data.find('F'); + static const const_iterator resultG = data.find('G'); + static const const_iterator resultH = data.find('H'); + static const const_iterator resultI = data.find('I'); + static const const_iterator resultJ = data.find('J'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); +#endif + } + + //************************************************************************* + TEST(test_contains_const) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const Data data{ values }; + + static const bool containsA = data.contains(Key('A')); + static const bool containsB = data.contains(Key('B')); + static const bool containsC = data.contains(Key('C')); + static const bool containsD = data.contains(Key('D')); + static const bool containsE = data.contains(Key('E')); + static const bool containsF = data.contains(Key('F')); + static const bool containsG = data.contains(Key('G')); + static const bool containsH = data.contains(Key('H')); + static const bool containsI = data.contains(Key('I')); + static const bool containsJ = data.contains(Key('J')); + static const bool containsK = data.contains(Key('K')); + + CHECK_TRUE(containsA); + CHECK_TRUE(containsB); + CHECK_TRUE(containsC); + CHECK_TRUE(containsD); + CHECK_TRUE(containsE); + CHECK_TRUE(containsF); + CHECK_TRUE(containsG); + CHECK_FALSE(containsH); + CHECK_FALSE(containsI); + CHECK_TRUE(containsJ); + CHECK_FALSE(containsK); + } + + //************************************************************************* + TEST(test_contains_with_transparent_comparator_const) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const DataTransparentComparator data{ values }; + + static const bool containsA = data.contains('A'); + static const bool containsB = data.contains('B'); + static const bool containsC = data.contains('C'); + static const bool containsD = data.contains('D'); + static const bool containsE = data.contains('E'); + static const bool containsF = data.contains('F'); + static const bool containsG = data.contains('G'); + static const bool containsH = data.contains('H'); + static const bool containsI = data.contains('I'); + static const bool containsJ = data.contains('J'); + static const bool containsK = data.contains('K'); + + CHECK_TRUE(containsA); + CHECK_TRUE(containsB); + CHECK_TRUE(containsC); + CHECK_TRUE(containsD); + CHECK_TRUE(containsE); + CHECK_TRUE(containsF); + CHECK_TRUE(containsG); + CHECK_FALSE(containsH); + CHECK_FALSE(containsI); + CHECK_TRUE(containsJ); + CHECK_FALSE(containsK); + } + + //************************************************************************* + TEST(test_key_comp_const) + { + static const Data data; + static const Data::key_compare compare = data.key_comp(); + + static const bool compareAA = compare(Key{ 'A' }, Key{ 'A' }); + static const bool compareBA = compare(Key{ 'B' }, Key{ 'A' }); + static const bool compareAB = compare(Key{ 'A' }, Key{ 'B' }); + + #ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA); + CHECK_TRUE(compareBA); + CHECK_FALSE(compareAB); + #else + CHECK_FALSE(compareAA); + CHECK_FALSE(compareBA); + CHECK_TRUE(compareAB); + #endif + } + + //************************************************************************* + TEST(test_key_comp_const_transparent_comparator) + { + static const DataTransparentComparator data; + static const DataTransparentComparator::key_compare compare = data.key_comp(); + + static const bool compareAA = compare('A', 'A'); + static const bool compareBA = compare('B', 'A'); + static const bool compareAB = compare('A', 'B'); + + #ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA); + CHECK_TRUE(compareBA); + CHECK_FALSE(compareAB); + #else + CHECK_FALSE(compareAA); + CHECK_FALSE(compareBA); + CHECK_TRUE(compareAB); + #endif + } + + //************************************************************************* + TEST(test_value_comp_const) + { + static const Data data; + static const Data::value_compare compare = data.value_comp(); + + static const bool compareAA1 = compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'A' }, 0 }); + static const bool compareAA2 = compare(value_type{ Key{ 'A' }, 0 }, Key{ 'A' }); + static const bool compareAA3 = compare(Key{ 'A' }, value_type{ Key{ 'A' }, 0 }); + + static const bool compareBA1 = compare(value_type{ Key{ 'B' }, 0 }, value_type{ Key{ 'A' }, 0 }); + static const bool compareBA2 = compare(value_type{ Key{ 'B' }, 0 }, Key{ 'A' }); + static const bool compareBA3 = compare(Key{ 'B' }, value_type{ Key{ 'A' }, 0 }); + + static const bool compareAB1 = compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'B' }, 0 }); + static const bool compareAB2 = compare(value_type{ Key{ 'A' }, 0 }, Key{ 'B' }); + static const bool compareAB3 = compare(Key{ 'A' }, value_type{ Key{ 'B' }, 0 });; + + #ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_TRUE(compareBA1); + CHECK_TRUE(compareBA2); + CHECK_TRUE(compareBA3); + + CHECK_FALSE(compareAB1); + CHECK_FALSE(compareAB2); + CHECK_FALSE(compareAB3); + #else + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_FALSE(compareBA1); + CHECK_FALSE(compareBA2); + CHECK_FALSE(compareBA3); + + CHECK_TRUE(compareAB1); + CHECK_TRUE(compareAB2); + CHECK_TRUE(compareAB3); + #endif + } + + //************************************************************************* + TEST(test_value_comp_const_transparent_comparator) + { + static const DataTransparentComparator data; + static const DataTransparentComparator::value_compare compare = data.value_comp(); + + static const bool compareAA1 = compare(value_type{ 'A', 0 }, value_type{ 'A', 0 }); + static const bool compareAA2 = compare(value_type{ 'A', 0 }, 'A'); + static const bool compareAA3 = compare('A', value_type{ 'A', 0 }); + + static const bool compareBA1 = compare(value_type{ 'B', 0 }, value_type{ 'A', 0 }); + static const bool compareBA2 = compare(value_type{ 'B', 0 }, 'A'); + static const bool compareBA3 = compare('B', value_type{ 'A', 0 }); + + static const bool compareAB1 = compare(value_type{ 'A', 0 }, value_type{ 'B', 0 }); + static const bool compareAB2 = compare(value_type{ 'A', 0 }, 'B'); + static const bool compareAB3 = compare('A', value_type{ 'B', 0 });; + + #ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_TRUE(compareBA1); + CHECK_TRUE(compareBA2); + CHECK_TRUE(compareBA3); + + CHECK_FALSE(compareAB1); + CHECK_FALSE(compareAB2); + CHECK_FALSE(compareAB3); + #else + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_FALSE(compareBA1); + CHECK_FALSE(compareBA2); + CHECK_FALSE(compareBA3); + + CHECK_TRUE(compareAB1); + CHECK_TRUE(compareAB2); + CHECK_TRUE(compareAB3); + #endif + } + + //************************************************************************* + TEST(test_equal) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data1{values1}; + static const Data data2{values2}; + static const Data data3{values3}; + + static const bool equal12 = (data1 == data2); + static const bool equal13 = (data1 == data3); + + CHECK_TRUE(equal12); + CHECK_FALSE(equal13); + } + + //************************************************************************* + TEST(test_equal_with_transparent_comparator) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data1{values1}; + static const DataTransparentComparator data2{values2}; + static const DataTransparentComparator data3{values3}; + + static const bool equal12 = (data1 == data2); + static const bool equal13 = (data1 == data3); + + CHECK_TRUE(equal12); + CHECK_FALSE(equal13); + } + + //************************************************************************* + TEST(test_not_equal) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data1{values1}; + static const Data data2{values2}; + static const Data data3{values3}; + + static const bool not_equal12 = (data1 != data2); + static const bool not_equal13 = (data1 != data3); + + CHECK_FALSE(not_equal12); + CHECK_TRUE(not_equal13); + } + + //************************************************************************* + TEST(test_not_equal_with_transparent_comparator) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data1{values1}; + static const DataTransparentComparator data2{values2}; + static const DataTransparentComparator data3{values3}; + + static const bool not_equal12 = (data1 != data2); + static const bool not_equal13 = (data1 != data3); + + CHECK_FALSE(not_equal12); + CHECK_TRUE(not_equal13); + } + + //************************************************************************* + TEST(test_less_than) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data1{values1}; + static const Data data2{values2}; + static const Data data3{values3}; + + static const bool less_than12 = (data1 < data2); + static const bool less_than23 = (data2 < data3); + static const bool less_than21 = (data2 < data1); + static const bool less_than32 = (data3 < data2); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than12); + CHECK_FALSE(less_than23); + CHECK_TRUE(less_than21); + CHECK_TRUE(less_than32); +#else + CHECK_TRUE(less_than12); + CHECK_TRUE(less_than23); + CHECK_FALSE(less_than21); + CHECK_FALSE(less_than32); +#endif + } + + //************************************************************************* + TEST(test_less_than_with_transparent_comparator) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data1{values1}; + static const DataTransparentComparator data2{values2}; + static const DataTransparentComparator data3{values3}; + + static const bool less_than12 = (data1 < data2); + static const bool less_than23 = (data2 < data3); + static const bool less_than21 = (data2 < data1); + static const bool less_than32 = (data3 < data2); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than12); + CHECK_FALSE(less_than23); + CHECK_TRUE(less_than21); + CHECK_TRUE(less_than32); +#else + CHECK_TRUE(less_than12); + CHECK_TRUE(less_than23); + CHECK_FALSE(less_than21); + CHECK_FALSE(less_than32); +#endif + } + + //************************************************************************* + TEST(test_less_than_equal) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data1{values1}; + static const Data data2{values2}; + static const Data data3{values3}; + + static const bool less_than_equal12 = (data1 <= data2); + static const bool less_than_equal23 = (data2 <= data3); + static const bool less_than_equal21 = (data2 <= data1); + static const bool less_than_equal32 = (data3 <= data2); + static const bool less_than_equal11 = (data1 <= data1); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than_equal12); + CHECK_FALSE(less_than_equal23); + CHECK_TRUE(less_than_equal21); + CHECK_TRUE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#else + CHECK_TRUE(less_than_equal12); + CHECK_TRUE(less_than_equal23); + CHECK_FALSE(less_than_equal21); + CHECK_FALSE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_less_than_equal_with_transparent_comparator) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data1{values1}; + static const DataTransparentComparator data2{values2}; + static const DataTransparentComparator data3{values3}; + + static const bool less_than_equal12 = (data1 <= data2); + static const bool less_than_equal23 = (data2 <= data3); + static const bool less_than_equal21 = (data2 <= data1); + static const bool less_than_equal32 = (data3 <= data2); + static const bool less_than_equal11 = (data1 <= data1); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than_equal12); + CHECK_FALSE(less_than_equal23); + CHECK_TRUE(less_than_equal21); + CHECK_TRUE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#else + CHECK_TRUE(less_than_equal12); + CHECK_TRUE(less_than_equal23); + CHECK_FALSE(less_than_equal21); + CHECK_FALSE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_greater_than) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data1{values1}; + static const Data data2{values2}; + static const Data data3{values3}; + + static const bool greater_than12 = (data1 > data2); + static const bool greater_than23 = (data2 > data3); + static const bool greater_than21 = (data2 > data1); + static const bool greater_than32 = (data3 > data2); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than12); + CHECK_TRUE(greater_than23); + CHECK_FALSE(greater_than21); + CHECK_FALSE(greater_than32); +#else + CHECK_FALSE(greater_than12); + CHECK_FALSE(greater_than23); + CHECK_TRUE(greater_than21); + CHECK_TRUE(greater_than32); +#endif + } + + //************************************************************************* + TEST(test_greater_than_with_transparent_comparator) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data1{values1}; + static const DataTransparentComparator data2{values2}; + static const DataTransparentComparator data3{values3}; + + static const bool greater_than12 = (data1 > data2); + static const bool greater_than23 = (data2 > data3); + static const bool greater_than21 = (data2 > data1); + static const bool greater_than32 = (data3 > data2); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than12); + CHECK_TRUE(greater_than23); + CHECK_FALSE(greater_than21); + CHECK_FALSE(greater_than32); +#else + CHECK_FALSE(greater_than12); + CHECK_FALSE(greater_than23); + CHECK_TRUE(greater_than21); + CHECK_TRUE(greater_than32); +#endif + } + + //************************************************************************* + TEST(test_greater_than_equal) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const Data data1{values1}; + static const Data data2{values2}; + static const Data data3{values3}; + + static const bool greater_than_equal12 = (data1 >= data2); + static const bool greater_than_equal23 = (data2 >= data3); + static const bool greater_than_equal21 = (data2 >= data1); + static const bool greater_than_equal32 = (data3 >= data2); + static const bool greater_than_equal11 = (data1 >= data1); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than_equal12); + CHECK_TRUE(greater_than_equal23); + CHECK_FALSE(greater_than_equal21); + CHECK_FALSE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#else + CHECK_FALSE(greater_than_equal12); + CHECK_FALSE(greater_than_equal23); + CHECK_TRUE(greater_than_equal21); + CHECK_TRUE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_greater_than_equal_with_transparent_comparator) + { + static const value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static const DataTransparentComparator data1{values1}; + static const DataTransparentComparator data2{values2}; + static const DataTransparentComparator data3{values3}; + + static const bool greater_than_equal12 = (data1 >= data2); + static const bool greater_than_equal23 = (data2 >= data3); + static const bool greater_than_equal21 = (data2 >= data1); + static const bool greater_than_equal32 = (data3 >= data2); + static const bool greater_than_equal11 = (data1 >= data1); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than_equal12); + CHECK_TRUE(greater_than_equal23); + CHECK_FALSE(greater_than_equal21); + CHECK_FALSE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#else + CHECK_FALSE(greater_than_equal12); + CHECK_FALSE(greater_than_equal23); + CHECK_TRUE(greater_than_equal21); + CHECK_TRUE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#endif + } + }; +} diff --git a/test/test_const_multimap_ext_constexpr.cpp b/test/test_const_multimap_ext_constexpr.cpp new file mode 100644 index 00000000..3f84174a --- /dev/null +++ b/test/test_const_multimap_ext_constexpr.cpp @@ -0,0 +1,1484 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove, rlindeman + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the 'Software'), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "etl/const_multimap.h" +#include "etl/string.h" + +#include "data.h" + +namespace +{ + static constexpr size_t Max_Size = 10UL; + + //************************************************************************* + // The key type + //************************************************************************* + struct Key + { + // Default constructor + constexpr Key() + : k(0) + { + } + + // Construct from char key + constexpr explicit Key(char k_) + : k(k_) + { + } + + char k; + }; + + // Less-than operator for Key < Key + constexpr bool operator <(const Key& lhs, const Key& rhs) noexcept + { + return (lhs.k < rhs.k); + } + + // Less-than operator for Key < char + constexpr bool operator <(const Key& lhs, char rhs) noexcept + { + return (lhs.k < rhs); + } + + // Less-than operator for char < Key + constexpr bool operator <(char lhs, const Key& rhs) noexcept + { + return (lhs < rhs.k); + } + + // Greater-than operator for char > Key + constexpr bool operator ==(const Key& lhs, const Key& rhs) noexcept + { + return (lhs.k == rhs.k); + } + +#define TEST_GREATER_THAN +#ifdef TEST_GREATER_THAN + using Data = etl::const_multimap_ext>; + using IData = etl::iconst_multimap>; + using DataTransparentComparator = etl::const_multimap_ext>; + using IDataTransparentComparator = etl::iconst_multimap>; +#else + using Data = etl::const_multimap_ext>; + using IData = etl::iconst_multimap>; + using DataTransparentComparator = etl::const_multimap_ext>; + using IDataTransparentComparator = etl::iconst_multimap>; +#endif + + using value_type = Data::value_type; + using key_type = Data::key_type; + using mapped_type = Data::mapped_type; + using const_iterator = Data::const_iterator; + using span_type = etl::span; + + SUITE(test_const_multimap) + { + //************************************************************************* + TEST(test_default_constructor) + { + static constexpr Data data; + + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr const_iterator begin = data.begin(); + static constexpr const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == 0UL); + CHECK_TRUE(empty); + CHECK_FALSE(full); + CHECK_TRUE(capacity == 0); + CHECK_TRUE(max_size == 0); + CHECK_TRUE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_min_size_from_span) + { + static constexpr value_type values[]{value_type{Key('A'), 0}}; + static constexpr etl::span span(values); + static constexpr Data data{ span }; + + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr const_iterator begin = data.begin(); + static constexpr const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == 1U); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == span.size()); + CHECK_TRUE(max_size == span.size()); + CHECK_FALSE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_max_size_from_span) + { +#ifdef TEST_GREATER_THAN + static const value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('I'), 8 }, value_type{Key('H'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static const value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static const span_type span(values); + static const Data data{ span }; + + static const bool is_valid = data.is_valid(); + static const size_t size = data.size(); + static const bool empty = data.empty(); + static const bool full = data.full(); + static const size_t capacity = data.capacity(); + static const size_t max_size = data.max_size(); + static const const_iterator begin = data.begin(); + static const const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == Max_Size); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_FALSE(begin == end); + } + + //************************************************************************* + TEST(test_cpp17_deduced_constructor_from_span) + { + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; + static constexpr etl::span span(values); + static constexpr etl::const_multimap_ext data{ span }; + + etl::const_multimap check{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + CHECK_TRUE(data.is_valid()); + CHECK_TRUE(data.size() == Max_Size); + CHECK_FALSE(data.empty()); + CHECK_TRUE(data.full()); + CHECK_TRUE(data.capacity() == Max_Size); + CHECK_TRUE(data.max_size() == Max_Size); + CHECK_FALSE(data.begin() == data.end()); + } + + //************************************************************************* + TEST(test_cpp17_deduced_constructor_from_array) + { + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr etl::const_multimap_ext data{ values }; + + etl::const_multimap check{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + CHECK_TRUE(data.is_valid()); + CHECK_TRUE(data.size() == Max_Size); + CHECK_FALSE(data.empty()); + CHECK_TRUE(data.full()); + CHECK_TRUE(data.capacity() == Max_Size); + CHECK_TRUE(data.max_size() == Max_Size); + CHECK_FALSE(data.begin() == data.end()); + } + + //************************************************************************* + TEST(test_constructor_min_size) + { + static constexpr value_type values[]{value_type{Key('A'), 0}}; + static constexpr Data data{ values }; + + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr const_iterator begin = data.begin(); + static constexpr const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == 1U); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == 1); + CHECK_TRUE(max_size == 1); + CHECK_FALSE(begin == end); + } + + //************************************************************************* + TEST(test_constructor_max_size) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data data{ values }; + + static constexpr bool is_valid = data.is_valid(); + static constexpr size_t size = data.size(); + static constexpr bool empty = data.empty(); + static constexpr bool full = data.full(); + static constexpr size_t capacity = data.capacity(); + static constexpr size_t max_size = data.max_size(); + static constexpr const_iterator begin = data.begin(); + static constexpr const_iterator end = data.end(); + + CHECK_TRUE(is_valid); + CHECK_TRUE(size == Max_Size); + CHECK_FALSE(empty); + CHECK_TRUE(full); + CHECK_TRUE(capacity == Max_Size); + CHECK_TRUE(max_size == Max_Size); + CHECK_FALSE(begin == end); + } + + //************************************************************************* + // Enable to check static_assert "Number of elements exceeds capacity" + //************************************************************************* + //TEST(test_constructor_excess_size) + //{ + // static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + // value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G')), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 }, + // value_type{Key('K'), 10 } }; + // + // static constexpr Data data{ values }; + //} + +#if ETL_USING_CPP17 + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr etl::const_multimap_ext data{ values }; + + etl::const_multimap check{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + CHECK_TRUE(data.is_valid()); + CHECK_TRUE(data.size() == Max_Size); + CHECK_FALSE(data.empty()); + CHECK_TRUE(data.full()); + CHECK_TRUE(data.capacity() == Max_Size); + CHECK_TRUE(data.max_size() == Max_Size); + CHECK_FALSE(data.begin() == data.end()); + } +#endif + + //************************************************************************* + TEST(test_begin_const) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data data{ values }; + + CHECK_TRUE(data.is_valid()); + static constexpr auto value = *data.begin(); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE((value_type{ Key('J'), 9 }) == value); +#else + CHECK_TRUE((value_type{ Key('A'), 0 }) == value); +#endif + } + + //************************************************************************* + TEST(test_end_const) + { + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data{ values }; + + static constexpr const_iterator end_itr = data.end(); + + CHECK_TRUE(end_itr == (data.begin() + data.size())); + } + + //************************************************************************* + TEST(test_equal_range_const) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data data{ values }; + + static constexpr ETL_OR_STD::pair resultA = data.equal_range(Key('A')); + static constexpr ETL_OR_STD::pair resultB = data.equal_range(Key('B')); + static constexpr ETL_OR_STD::pair resultC = data.equal_range(Key('C')); + static constexpr ETL_OR_STD::pair resultD = data.equal_range(Key('D')); + static constexpr ETL_OR_STD::pair resultE = data.equal_range(Key('E')); + static constexpr ETL_OR_STD::pair resultF = data.equal_range(Key('F')); + static constexpr ETL_OR_STD::pair resultG = data.equal_range(Key('G')); + static constexpr ETL_OR_STD::pair resultH = data.equal_range(Key('H')); + static constexpr ETL_OR_STD::pair resultI = data.equal_range(Key('I')); + static constexpr ETL_OR_STD::pair resultJ = data.equal_range(Key('J')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(10, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ.second))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(1, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ.second))); +#endif + } + + //************************************************************************* + TEST(test_equal_range_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr DataTransparentComparator data{ values }; + + static constexpr ETL_OR_STD::pair resultA = data.equal_range('A'); + static constexpr ETL_OR_STD::pair resultB = data.equal_range('B'); + static constexpr ETL_OR_STD::pair resultC = data.equal_range('C'); + static constexpr ETL_OR_STD::pair resultD = data.equal_range('D'); + static constexpr ETL_OR_STD::pair resultE = data.equal_range('E'); + static constexpr ETL_OR_STD::pair resultF = data.equal_range('F'); + static constexpr ETL_OR_STD::pair resultG = data.equal_range('G'); + static constexpr ETL_OR_STD::pair resultH = data.equal_range('H'); + static constexpr ETL_OR_STD::pair resultI = data.equal_range('I'); + static constexpr ETL_OR_STD::pair resultJ = data.equal_range('J'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(10, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ.second))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA.first))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB.first))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC.first))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD.first))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE.first))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF.first))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.first))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ.first))); + + CHECK_EQUAL(1, (std::distance(data.begin(), resultA.second))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB.second))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC.second))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD.second))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE.second))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultG.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH.second))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI.second))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ.second))); +#endif + } + + //************************************************************************* + TEST(test_lower_bound_const) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data data{ values }; + + static constexpr const_iterator resultA = data.lower_bound(Key('A')); + static constexpr const_iterator resultB = data.lower_bound(Key('B')); + static constexpr const_iterator resultC = data.lower_bound(Key('C')); + static constexpr const_iterator resultD = data.lower_bound(Key('D')); + static constexpr const_iterator resultE = data.lower_bound(Key('E')); + static constexpr const_iterator resultF = data.lower_bound(Key('F')); + static constexpr const_iterator resultG = data.lower_bound(Key('G')); + static constexpr const_iterator resultH = data.lower_bound(Key('H')); + static constexpr const_iterator resultI = data.lower_bound(Key('I')); + static constexpr const_iterator resultJ = data.lower_bound(Key('J')); + static constexpr const_iterator resultK = data.lower_bound(Key('K')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_lower_bound_const_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr DataTransparentComparator data{ values }; + + static constexpr const_iterator resultA = data.lower_bound('A'); + static constexpr const_iterator resultB = data.lower_bound('B'); + static constexpr const_iterator resultC = data.lower_bound('C'); + static constexpr const_iterator resultD = data.lower_bound('D'); + static constexpr const_iterator resultE = data.lower_bound('E'); + static constexpr const_iterator resultF = data.lower_bound('F'); + static constexpr const_iterator resultG = data.lower_bound('G'); + static constexpr const_iterator resultH = data.lower_bound('H'); + static constexpr const_iterator resultI = data.lower_bound('I'); + static constexpr const_iterator resultJ = data.lower_bound('J'); + static constexpr const_iterator resultK = data.lower_bound('K'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_upper_bound_const) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data data{ values }; + + static constexpr const_iterator resultA = data.upper_bound(Key('A')); + static constexpr const_iterator resultB = data.upper_bound(Key('B')); + static constexpr const_iterator resultC = data.upper_bound(Key('C')); + static constexpr const_iterator resultD = data.upper_bound(Key('D')); + static constexpr const_iterator resultE = data.upper_bound(Key('E')); + static constexpr const_iterator resultF = data.upper_bound(Key('F')); + static constexpr const_iterator resultG = data.upper_bound(Key('G')); + static constexpr const_iterator resultH = data.upper_bound(Key('H')); + static constexpr const_iterator resultI = data.upper_bound(Key('I')); + static constexpr const_iterator resultJ = data.upper_bound(Key('J')); + static constexpr const_iterator resultK = data.upper_bound(Key('K')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(1, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_upper_bound_const_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr DataTransparentComparator data{ values }; + + static constexpr const_iterator resultA = data.upper_bound('A'); + static constexpr const_iterator resultB = data.upper_bound('B'); + static constexpr const_iterator resultC = data.upper_bound('C'); + static constexpr const_iterator resultD = data.upper_bound('D'); + static constexpr const_iterator resultE = data.upper_bound('E'); + static constexpr const_iterator resultF = data.upper_bound('F'); + static constexpr const_iterator resultG = data.upper_bound('G'); + static constexpr const_iterator resultH = data.upper_bound('H'); + static constexpr const_iterator resultI = data.upper_bound('I'); + static constexpr const_iterator resultJ = data.upper_bound('J'); + static constexpr const_iterator resultK = data.upper_bound('K'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(10, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultK))); +#else + CHECK_EQUAL(1, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultJ))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultK))); +#endif + } + + //************************************************************************* + TEST(test_count_const) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data data{ values }; + + CHECK_EQUAL(1, data.count(Key('A'))); + CHECK_EQUAL(1, data.count(Key('B'))); + CHECK_EQUAL(1, data.count(Key('C'))); + CHECK_EQUAL(1, data.count(Key('D'))); + CHECK_EQUAL(1, data.count(Key('E'))); + CHECK_EQUAL(1, data.count(Key('F'))); + CHECK_EQUAL(3, data.count(Key('G'))); + CHECK_EQUAL(0, data.count(Key('H'))); + CHECK_EQUAL(0, data.count(Key('I'))); + CHECK_EQUAL(1, data.count(Key('J'))); + CHECK_EQUAL(0, data.count(Key('K'))); + } + + //************************************************************************* + TEST(test_count_const_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr DataTransparentComparator data{ values }; + + CHECK_EQUAL(1, data.count('A')); + CHECK_EQUAL(1, data.count('B')); + CHECK_EQUAL(1, data.count('C')); + CHECK_EQUAL(1, data.count('D')); + CHECK_EQUAL(1, data.count('E')); + CHECK_EQUAL(1, data.count('F')); + CHECK_EQUAL(3, data.count('G')); + CHECK_EQUAL(0, data.count('H')); + CHECK_EQUAL(0, data.count('I')); + CHECK_EQUAL(1, data.count('J')); + CHECK_EQUAL(0, data.count('K')); + } + + //************************************************************************* + TEST(test_const_iterator) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data data{ values }; + + const_iterator itr = data.begin(); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 8 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 7 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 6 }) == *itr++); + CHECK_TRUE((value_type{Key('F'), 5 }) == *itr++); + CHECK_TRUE((value_type{Key('E'), 4 }) == *itr++); + CHECK_TRUE((value_type{Key('D'), 3 }) == *itr++); + CHECK_TRUE((value_type{Key('C'), 2 }) == *itr++); + CHECK_TRUE((value_type{Key('B'), 1 }) == *itr++); + CHECK_TRUE((value_type{Key('A'), 0 }) == *itr++); + CHECK_TRUE(itr == data.end()); +#else + CHECK_TRUE((value_type{Key('A'), 0 }) == *itr++); + CHECK_TRUE((value_type{Key('B'), 1 }) == *itr++); + CHECK_TRUE((value_type{Key('C'), 2 }) == *itr++); + CHECK_TRUE((value_type{Key('D'), 3 }) == *itr++); + CHECK_TRUE((value_type{Key('E'), 4 }) == *itr++); + CHECK_TRUE((value_type{Key('F'), 5 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 6 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 7 }) == *itr++); + CHECK_TRUE((value_type{Key('G'), 8 }) == *itr++); + CHECK_TRUE((value_type{Key('J'), 9 }) == *itr++); + CHECK_TRUE(itr == data.end()); +#endif + } + + //************************************************************************* + TEST(test_find_const) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data data{ values }; + + static constexpr const_iterator resultA = data.find(Key('A')); + static constexpr const_iterator resultB = data.find(Key('B')); + static constexpr const_iterator resultC = data.find(Key('C')); + static constexpr const_iterator resultD = data.find(Key('D')); + static constexpr const_iterator resultE = data.find(Key('E')); + static constexpr const_iterator resultF = data.find(Key('F')); + static constexpr const_iterator resultG = data.find(Key('G')); + static constexpr const_iterator resultH = data.find(Key('H')); + static constexpr const_iterator resultI = data.find(Key('I')); + static constexpr const_iterator resultJ = data.find(Key('J')); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); +#endif + } + + //************************************************************************* + TEST(test_find_const_using_transparent_comparator) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr DataTransparentComparator data{ values }; + + static constexpr const_iterator resultA = data.find('A'); + static constexpr const_iterator resultB = data.find('B'); + static constexpr const_iterator resultC = data.find('C'); + static constexpr const_iterator resultD = data.find('D'); + static constexpr const_iterator resultE = data.find('E'); + static constexpr const_iterator resultF = data.find('F'); + static constexpr const_iterator resultG = data.find('G'); + static constexpr const_iterator resultH = data.find('H'); + static constexpr const_iterator resultI = data.find('I'); + static constexpr const_iterator resultJ = data.find('J'); + +#ifdef TEST_GREATER_THAN + CHECK_EQUAL(9, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(8, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(7, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(0, (std::distance(data.begin(), resultJ))); +#else + CHECK_EQUAL(0, (std::distance(data.begin(), resultA))); + CHECK_EQUAL(1, (std::distance(data.begin(), resultB))); + CHECK_EQUAL(2, (std::distance(data.begin(), resultC))); + CHECK_EQUAL(3, (std::distance(data.begin(), resultD))); + CHECK_EQUAL(4, (std::distance(data.begin(), resultE))); + CHECK_EQUAL(5, (std::distance(data.begin(), resultF))); + CHECK_EQUAL(6, (std::distance(data.begin(), resultG))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultH))); + CHECK_EQUAL(10, (std::distance(data.begin(), resultI))); + CHECK_EQUAL(9, (std::distance(data.begin(), resultJ))); +#endif + } + + //************************************************************************* + TEST(test_contains_const) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr Data data{ values }; + + static constexpr bool containsA = data.contains(Key('A')); + static constexpr bool containsB = data.contains(Key('B')); + static constexpr bool containsC = data.contains(Key('C')); + static constexpr bool containsD = data.contains(Key('D')); + static constexpr bool containsE = data.contains(Key('E')); + static constexpr bool containsF = data.contains(Key('F')); + static constexpr bool containsG = data.contains(Key('G')); + static constexpr bool containsH = data.contains(Key('H')); + static constexpr bool containsI = data.contains(Key('I')); + static constexpr bool containsJ = data.contains(Key('J')); + static constexpr bool containsK = data.contains(Key('K')); + + CHECK_TRUE(containsA); + CHECK_TRUE(containsB); + CHECK_TRUE(containsC); + CHECK_TRUE(containsD); + CHECK_TRUE(containsE); + CHECK_TRUE(containsF); + CHECK_TRUE(containsG); + CHECK_FALSE(containsH); + CHECK_FALSE(containsI); + CHECK_TRUE(containsJ); + CHECK_FALSE(containsK); + } + + //************************************************************************* + TEST(test_contains_with_transparent_comparator_const) + { +#ifdef TEST_GREATER_THAN + static constexpr value_type values[]{ value_type{Key('J'), 9 }, value_type{Key('G'), 8 }, value_type{Key('G'), 7 }, value_type{Key('G'), 6 }, value_type{Key('F'), 5 }, + value_type{Key('E'), 4 }, value_type{Key('D'), 3 }, value_type{Key('C'), 2 }, value_type{Key('B'), 1 }, value_type{Key('A'), 0 } }; +#else + static constexpr value_type values[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('G'), 7 }, value_type{Key('G'), 8 }, value_type{Key('J'), 9 } }; +#endif + + static constexpr DataTransparentComparator data{ values }; + + static constexpr bool containsA = data.contains('A'); + static constexpr bool containsB = data.contains('B'); + static constexpr bool containsC = data.contains('C'); + static constexpr bool containsD = data.contains('D'); + static constexpr bool containsE = data.contains('E'); + static constexpr bool containsF = data.contains('F'); + static constexpr bool containsG = data.contains('G'); + static constexpr bool containsH = data.contains('H'); + static constexpr bool containsI = data.contains('I'); + static constexpr bool containsJ = data.contains('J'); + static constexpr bool containsK = data.contains('K'); + + CHECK_TRUE(containsA); + CHECK_TRUE(containsB); + CHECK_TRUE(containsC); + CHECK_TRUE(containsD); + CHECK_TRUE(containsE); + CHECK_TRUE(containsF); + CHECK_TRUE(containsG); + CHECK_FALSE(containsH); + CHECK_FALSE(containsI); + CHECK_TRUE(containsJ); + CHECK_FALSE(containsK); + } + + //************************************************************************* + TEST(test_key_comp_const) + { + static constexpr Data data; + static constexpr Data::key_compare compare = data.key_comp(); + + static constexpr bool compareAA = compare(Key{ 'A' }, Key{ 'A' }); + static constexpr bool compareBA = compare(Key{ 'B' }, Key{ 'A' }); + static constexpr bool compareAB = compare(Key{ 'A' }, Key{ 'B' }); + + #ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA); + CHECK_TRUE(compareBA); + CHECK_FALSE(compareAB); + #else + CHECK_FALSE(compareAA); + CHECK_FALSE(compareBA); + CHECK_TRUE(compareAB); + #endif + } + + //************************************************************************* + TEST(test_key_comp_const_transparent_comparator) + { + static constexpr DataTransparentComparator data; + static constexpr DataTransparentComparator::key_compare compare = data.key_comp(); + + static constexpr bool compareAA = compare('A', 'A'); + static constexpr bool compareBA = compare('B', 'A'); + static constexpr bool compareAB = compare('A', 'B'); + + #ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA); + CHECK_TRUE(compareBA); + CHECK_FALSE(compareAB); + #else + CHECK_FALSE(compareAA); + CHECK_FALSE(compareBA); + CHECK_TRUE(compareAB); + #endif + } + + //************************************************************************* + TEST(test_value_comp_const) + { + static constexpr Data data; + static constexpr Data::value_compare compare = data.value_comp(); + + static constexpr bool compareAA1 = compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'A' }, 0 }); + static constexpr bool compareAA2 = compare(value_type{ Key{ 'A' }, 0 }, Key{ 'A' }); + static constexpr bool compareAA3 = compare(Key{ 'A' }, value_type{ Key{ 'A' }, 0 }); + + static constexpr bool compareBA1 = compare(value_type{ Key{ 'B' }, 0 }, value_type{ Key{ 'A' }, 0 }); + static constexpr bool compareBA2 = compare(value_type{ Key{ 'B' }, 0 }, Key{ 'A' }); + static constexpr bool compareBA3 = compare(Key{ 'B' }, value_type{ Key{ 'A' }, 0 }); + + static constexpr bool compareAB1 = compare(value_type{ Key{ 'A' }, 0 }, value_type{ Key{ 'B' }, 0 }); + static constexpr bool compareAB2 = compare(value_type{ Key{ 'A' }, 0 }, Key{ 'B' }); + static constexpr bool compareAB3 = compare(Key{ 'A' }, value_type{ Key{ 'B' }, 0 });; + + #ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_TRUE(compareBA1); + CHECK_TRUE(compareBA2); + CHECK_TRUE(compareBA3); + + CHECK_FALSE(compareAB1); + CHECK_FALSE(compareAB2); + CHECK_FALSE(compareAB3); + #else + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_FALSE(compareBA1); + CHECK_FALSE(compareBA2); + CHECK_FALSE(compareBA3); + + CHECK_TRUE(compareAB1); + CHECK_TRUE(compareAB2); + CHECK_TRUE(compareAB3); + #endif + } + + //************************************************************************* + TEST(test_value_comp_const_transparent_comparator) + { + static constexpr DataTransparentComparator data; + static constexpr DataTransparentComparator::value_compare compare = data.value_comp(); + + static constexpr bool compareAA1 = compare(value_type{ 'A', 0 }, value_type{ 'A', 0 }); + static constexpr bool compareAA2 = compare(value_type{ 'A', 0 }, 'A'); + static constexpr bool compareAA3 = compare('A', value_type{ 'A', 0 }); + + static constexpr bool compareBA1 = compare(value_type{ 'B', 0 }, value_type{ 'A', 0 }); + static constexpr bool compareBA2 = compare(value_type{ 'B', 0 }, 'A'); + static constexpr bool compareBA3 = compare('B', value_type{ 'A', 0 }); + + static constexpr bool compareAB1 = compare(value_type{ 'A', 0 }, value_type{ 'B', 0 }); + static constexpr bool compareAB2 = compare(value_type{ 'A', 0 }, 'B'); + static constexpr bool compareAB3 = compare('A', value_type{ 'B', 0 });; + + #ifdef TEST_GREATER_THAN + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_TRUE(compareBA1); + CHECK_TRUE(compareBA2); + CHECK_TRUE(compareBA3); + + CHECK_FALSE(compareAB1); + CHECK_FALSE(compareAB2); + CHECK_FALSE(compareAB3); + #else + CHECK_FALSE(compareAA1); + CHECK_FALSE(compareAA2); + CHECK_FALSE(compareAA3); + + CHECK_FALSE(compareBA1); + CHECK_FALSE(compareBA2); + CHECK_FALSE(compareBA3); + + CHECK_TRUE(compareAB1); + CHECK_TRUE(compareAB2); + CHECK_TRUE(compareAB3); + #endif + } + + //************************************************************************* + TEST(test_equal) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data1{values1}; + static constexpr Data data2{values2}; + static constexpr Data data3{values3}; + + static constexpr bool equal12 = (data1 == data2); + static constexpr bool equal13 = (data1 == data3); + + CHECK_TRUE(equal12); + CHECK_FALSE(equal13); + } + + //************************************************************************* + TEST(test_equal_with_transparent_comparator) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data1{values1}; + static constexpr DataTransparentComparator data2{values2}; + static constexpr DataTransparentComparator data3{values3}; + + static constexpr bool equal12 = (data1 == data2); + static constexpr bool equal13 = (data1 == data3); + + CHECK_TRUE(equal12); + CHECK_FALSE(equal13); + } + + //************************************************************************* + TEST(test_not_equal) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data1{values1}; + static constexpr Data data2{values2}; + static constexpr Data data3{values3}; + + static constexpr bool not_equal12 = (data1 != data2); + static constexpr bool not_equal13 = (data1 != data3); + + CHECK_FALSE(not_equal12); + CHECK_TRUE(not_equal13); + } + + //************************************************************************* + TEST(test_not_equal_with_transparent_comparator) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 6 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data1{values1}; + static constexpr DataTransparentComparator data2{values2}; + static constexpr DataTransparentComparator data3{values3}; + + static constexpr bool not_equal12 = (data1 != data2); + static constexpr bool not_equal13 = (data1 != data3); + + CHECK_FALSE(not_equal12); + CHECK_TRUE(not_equal13); + } + + //************************************************************************* + TEST(test_less_than) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data1{values1}; + static constexpr Data data2{values2}; + static constexpr Data data3{values3}; + + static constexpr bool less_than12 = (data1 < data2); + static constexpr bool less_than23 = (data2 < data3); + static constexpr bool less_than21 = (data2 < data1); + static constexpr bool less_than32 = (data3 < data2); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than12); + CHECK_FALSE(less_than23); + CHECK_TRUE(less_than21); + CHECK_TRUE(less_than32); +#else + CHECK_TRUE(less_than12); + CHECK_TRUE(less_than23); + CHECK_FALSE(less_than21); + CHECK_FALSE(less_than32); +#endif + } + + //************************************************************************* + TEST(test_less_than_with_transparent_comparator) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data1{values1}; + static constexpr DataTransparentComparator data2{values2}; + static constexpr DataTransparentComparator data3{values3}; + + static constexpr bool less_than12 = (data1 < data2); + static constexpr bool less_than23 = (data2 < data3); + static constexpr bool less_than21 = (data2 < data1); + static constexpr bool less_than32 = (data3 < data2); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than12); + CHECK_FALSE(less_than23); + CHECK_TRUE(less_than21); + CHECK_TRUE(less_than32); +#else + CHECK_TRUE(less_than12); + CHECK_TRUE(less_than23); + CHECK_FALSE(less_than21); + CHECK_FALSE(less_than32); +#endif + } + + //************************************************************************* + TEST(test_less_than_equal) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data1{values1}; + static constexpr Data data2{values2}; + static constexpr Data data3{values3}; + + static constexpr bool less_than_equal12 = (data1 <= data2); + static constexpr bool less_than_equal23 = (data2 <= data3); + static constexpr bool less_than_equal21 = (data2 <= data1); + static constexpr bool less_than_equal32 = (data3 <= data2); + static constexpr bool less_than_equal11 = (data1 <= data1); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than_equal12); + CHECK_FALSE(less_than_equal23); + CHECK_TRUE(less_than_equal21); + CHECK_TRUE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#else + CHECK_TRUE(less_than_equal12); + CHECK_TRUE(less_than_equal23); + CHECK_FALSE(less_than_equal21); + CHECK_FALSE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_less_than_equal_with_transparent_comparator) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data1{values1}; + static constexpr DataTransparentComparator data2{values2}; + static constexpr DataTransparentComparator data3{values3}; + + static constexpr bool less_than_equal12 = (data1 <= data2); + static constexpr bool less_than_equal23 = (data2 <= data3); + static constexpr bool less_than_equal21 = (data2 <= data1); + static constexpr bool less_than_equal32 = (data3 <= data2); + static constexpr bool less_than_equal11 = (data1 <= data1); + +#ifdef TEST_GREATER_THAN + CHECK_FALSE(less_than_equal12); + CHECK_FALSE(less_than_equal23); + CHECK_TRUE(less_than_equal21); + CHECK_TRUE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#else + CHECK_TRUE(less_than_equal12); + CHECK_TRUE(less_than_equal23); + CHECK_FALSE(less_than_equal21); + CHECK_FALSE(less_than_equal32); + CHECK_TRUE(less_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_greater_than) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data1{values1}; + static constexpr Data data2{values2}; + static constexpr Data data3{values3}; + + static constexpr bool greater_than12 = (data1 > data2); + static constexpr bool greater_than23 = (data2 > data3); + static constexpr bool greater_than21 = (data2 > data1); + static constexpr bool greater_than32 = (data3 > data2); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than12); + CHECK_TRUE(greater_than23); + CHECK_FALSE(greater_than21); + CHECK_FALSE(greater_than32); +#else + CHECK_FALSE(greater_than12); + CHECK_FALSE(greater_than23); + CHECK_TRUE(greater_than21); + CHECK_TRUE(greater_than32); +#endif + } + + //************************************************************************* + TEST(test_greater_than_with_transparent_comparator) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data1{values1}; + static constexpr DataTransparentComparator data2{values2}; + static constexpr DataTransparentComparator data3{values3}; + + static constexpr bool greater_than12 = (data1 > data2); + static constexpr bool greater_than23 = (data2 > data3); + static constexpr bool greater_than21 = (data2 > data1); + static constexpr bool greater_than32 = (data3 > data2); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than12); + CHECK_TRUE(greater_than23); + CHECK_FALSE(greater_than21); + CHECK_FALSE(greater_than32); +#else + CHECK_FALSE(greater_than12); + CHECK_FALSE(greater_than23); + CHECK_TRUE(greater_than21); + CHECK_TRUE(greater_than32); +#endif + } + + //************************************************************************* + TEST(test_greater_than_equal) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr Data data1{values1}; + static constexpr Data data2{values2}; + static constexpr Data data3{values3}; + + static constexpr bool greater_than_equal12 = (data1 >= data2); + static constexpr bool greater_than_equal23 = (data2 >= data3); + static constexpr bool greater_than_equal21 = (data2 >= data1); + static constexpr bool greater_than_equal32 = (data3 >= data2); + static constexpr bool greater_than_equal11 = (data1 >= data1); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than_equal12); + CHECK_TRUE(greater_than_equal23); + CHECK_FALSE(greater_than_equal21); + CHECK_FALSE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#else + CHECK_FALSE(greater_than_equal12); + CHECK_FALSE(greater_than_equal23); + CHECK_TRUE(greater_than_equal21); + CHECK_TRUE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#endif + } + + //************************************************************************* + TEST(test_greater_than_equal_with_transparent_comparator) + { + static constexpr value_type values1[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('B'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values2[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('C'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr value_type values3[]{ value_type{Key('A'), 0 }, value_type{Key('B'), 1 }, value_type{Key('D'), 2 }, value_type{Key('D'), 3 }, value_type{Key('E'), 4 }, + value_type{Key('F'), 5 }, value_type{Key('G'), 6 }, value_type{Key('H'), 7 }, value_type{Key('I'), 8 }, value_type{Key('J'), 9 } }; + + static constexpr DataTransparentComparator data1{values1}; + static constexpr DataTransparentComparator data2{values2}; + static constexpr DataTransparentComparator data3{values3}; + + static constexpr bool greater_than_equal12 = (data1 >= data2); + static constexpr bool greater_than_equal23 = (data2 >= data3); + static constexpr bool greater_than_equal21 = (data2 >= data1); + static constexpr bool greater_than_equal32 = (data3 >= data2); + static constexpr bool greater_than_equal11 = (data1 >= data1); + +#ifdef TEST_GREATER_THAN + CHECK_TRUE(greater_than_equal12); + CHECK_TRUE(greater_than_equal23); + CHECK_FALSE(greater_than_equal21); + CHECK_FALSE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#else + CHECK_FALSE(greater_than_equal12); + CHECK_FALSE(greater_than_equal23); + CHECK_TRUE(greater_than_equal21); + CHECK_TRUE(greater_than_equal32); + CHECK_TRUE(greater_than_equal11); +#endif + } + }; +} diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 41cfa582..fbb10c95 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -9274,8 +9274,12 @@ + + + + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 9874dd7e..4f9af8a2 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1516,7 +1516,7 @@ ETL\Containers - UnitTest++\Header Files + ETL\Containers @@ -3611,6 +3611,18 @@ Tests\Containers + + Tests\Containers + + + Tests\Containers + + + Tests\Containers + + + Tests\Containers + From 51040d1a2847352f03cd54040071c20c28049623 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Wed, 25 Jun 2025 19:38:25 +0200 Subject: [PATCH 11/12] Fix error on running clang test only (#1135) * Fix error on running clang test only Consolidate tests by factoring out redundant test function * Make run-tests.sh executable --- test/run-tests.sh | 558 ++++++---------------------------------------- 1 file changed, 71 insertions(+), 487 deletions(-) mode change 100644 => 100755 test/run-tests.sh diff --git a/test/run-tests.sh b/test/run-tests.sh old mode 100644 new mode 100755 index 9910a4e0..37cf9945 --- a/test/run-tests.sh +++ b/test/run-tests.sh @@ -1,16 +1,12 @@ -#!/bin/sh +#!/bin/bash + +shopt -s xpg_echo + clear -mkdir -p build-make || exit 1 -cd build-make || exit 1 - -echo "ETL Tests" > log.txt - export ASAN_OPTIONS=symbol_line=1 export ASAN_SYMBOLIZER_PATH=/usr/lib/llvm-14/bin//llvm-symbolizer -echo -e - configuration_name="Configuration Name Not Set" FailColour='\033[38;2;255;128;128m' @@ -55,14 +51,14 @@ PrintHeader() PrintHelp() { echo "$HelpColour" - echo "-------------------------------------------------------------------------------------" - echo " Syntax : ./runtests.sh " - echo " C++ Standard : 11, 14, 17, 20 or 23 " - echo " Optimisation : 0, 1, 2 or 3. Default = 0 " - echo " Threads : Number of threads to use. Default = 4 " - echo " Sanitizer : s enables sanitizer checks, n disables. Default disabled " - echo " Compiler select : gcc or clang. Default All compilers " - echo "-------------------------------------------------------------------------------------" + echo "------------------------------------------------------------------------------------------------" + echo " Syntax : ./run-tests.sh " + echo " C++ Standard : 11, 14, 17, 20 or 23 " + echo " Optimisation : 0, 1, 2 or 3. Default = 0 " + echo " Threads : Number of threads to use. Default = 4 " + echo " Sanitizer : s enables sanitizer checks, n disables. Default disabled " + echo " Compiler select : gcc or clang. Default All compilers " + echo "------------------------------------------------------------------------------------------------" echo "$NoColour" } @@ -180,483 +176,71 @@ fi #****************************************************************************** # Get the ETL version #****************************************************************************** -etl_version_raw=$(cat ../../version.txt) +etl_version_raw=$(cat ../version.txt) etl_version=$(echo $etl_version_raw | sed -e 's/\r//g') # Remove trailing \r #****************************************************************************** # Get the compiler versions #****************************************************************************** -gcc_compiler=$(g++ --version | grep g++) -clang_compiler=$(clang++ --version | grep clang) -#****************************************************************************** -# GCC -#****************************************************************************** -if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then -compiler=$gcc_compiler -SetConfigurationName "STL" -PrintHeader -rm * -rf -cmake -DCMAKE_C_COMPILER="gcc" -DCMAKE_CXX_COMPILER="g++" -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize -DETL_MESSAGES_ARE_NOT_VIRTUAL=OFF .. -cmake --build . -if [ $? -eq 0 ]; then - PassedCompilation -else - FailedCompilation - exit $? -fi -./etl_tests -if [ $? -eq 0 ]; then - PassedTests -else - FailedTests - exit $? -fi -fi +while read i ; do + CC=`echo $i | cut -d, -f1 | sed -e 's/ *$//'` + MSG=`echo $i | cut -d, -f2 | sed -e 's/ *$//'` + DIR=`echo $i | cut -d, -f3 | sed -e 's/ *$//'` + CMD=`echo $i | cut -d, -f4 | sed -e 's/ *$//'` -#****************************************************************************** -if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then -compiler=$gcc_compiler -SetConfigurationName "STL - Non-virtual messages" -PrintHeader -rm * -rf -cmake -DCMAKE_C_COMPILER="gcc" -DCMAKE_CXX_COMPILER="g++" -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize -DETL_MESSAGES_ARE_NOT_VIRTUAL=ON .. -cmake --build . -if [ $? -eq 0 ]; then - PassedCompilation -else - FailedCompilation - exit $? -fi -./etl_tests -if [ $? -eq 0 ]; then - PassedTests -else - FailedTests - exit $? -fi -fi - -#****************************************************************************** -if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then -compiler=$gcc_compiler -SetConfigurationName "STL - Force C++03" -PrintHeader -rm * -rf -cmake -DCMAKE_C_COMPILER="gcc" -DCMAKE_CXX_COMPILER="g++" -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize -DETL_MESSAGES_ARE_NOT_VIRTUAL=OFF .. -cmake --build . -if [ $? -eq 0 ]; then - PassedCompilation -else - FailedCompilation - exit $? -fi -./etl_tests -if [ $? -eq 0 ]; then - PassedTests -else - FailedTests - exit $? -fi -fi - -#****************************************************************************** -if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then -compiler=$gcc_compiler -SetConfigurationName "No STL" -PrintHeader -rm * -rf -cmake -DCMAKE_C_COMPILER="gcc" -DCMAKE_CXX_COMPILER="g++" -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize -DETL_MESSAGES_ARE_NOT_VIRTUAL=OFF .. -cmake --build . -if [ $? -eq 0 ]; then - PassedCompilation -else - FailedCompilation - exit $? -fi -./etl_tests -if [ $? -eq 0 ]; then - PassedTests -else - FailedTests - exit $? -fi -fi - -#****************************************************************************** -if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then -compiler=$gcc_compiler -SetConfigurationName "No STL - Force C++03" -PrintHeader -rm * -rf -cmake -DCMAKE_C_COMPILER="gcc" -DCMAKE_CXX_COMPILER="g++" -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize -DETL_MESSAGES_ARE_NOT_VIRTUAL=OFF .. -cmake --build . -if [ $? -eq 0 ]; then - PassedCompilation -else - FailedCompilation - exit $? -fi -./etl_tests -if [ $? -eq 0 ]; then - PassedTests -else - FailedTests - exit $? -fi -fi - -#****************************************************************************** -# CLANG -#****************************************************************************** -if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then -compiler=$clang_compiler -SetConfigurationName "STL" -PrintHeader -rm * -rf -cmake -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize -DETL_MESSAGES_ARE_NOT_VIRTUAL=OFF .. -cmake --build . -if [ $? -eq 0 ]; then - PassedCompilation -else - FailedCompilation - exit $? -fi -./etl_tests -if [ $? -eq 0 ]; then - PassedTests -else - FailedTests - exit $? -fi -fi - -#****************************************************************************** -if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then -compiler=$clang_compiler -SetConfigurationName "STL - Force C++03" -PrintHeader -rm * -rf -cmake -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize -DETL_MESSAGES_ARE_NOT_VIRTUAL=OFF .. -cmake --build . -if [ $? -eq 0 ]; then - PassedCompilation -else - FailedCompilation - exit $? -fi -./etl_tests -if [ $? -eq 0 ]; then - PassedTests -else - FailedTests - exit $? -fi -fi - -#****************************************************************************** -if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then -compiler=$clang_compiler -SetConfigurationName "No STL" -PrintHeader -rm * -rf -cmake -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize -DETL_MESSAGES_ARE_NOT_VIRTUAL=OFF .. -cmake --build . -if [ $? -eq 0 ]; then - PassedCompilation -else - FailedCompilation - exit $? -fi -./etl_tests -if [ $? -eq 0 ]; then - PassedTests -else - FailedTests - exit $? -fi -fi - -#****************************************************************************** -if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then -compiler=$clang_compiler -SetConfigurationName "No STL - Force C++03" -PrintHeader -rm * -rf -cmake -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize -DETL_MESSAGES_ARE_NOT_VIRTUAL=OFF .. -cmake --build . -if [ $? -eq 0 ]; then - PassedCompilation -else - FailedCompilation - exit $? -fi -./etl_tests -if [ $? -eq 0 ]; then - PassedTests -else - FailedTests - exit $? -fi -fi - -#****************************************************************************** -if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then -compiler=$gcc_compiler -SetConfigurationName "Initializer list test" -PrintHeader -cd ../etl_initializer_list/ -mkdir -p build-make || exit 1 -cd build-make || exit 1 -rm * -rf -cmake -DCMAKE_C_COMPILER="gcc" -DCMAKE_C_COMPILER="gcc" -DCMAKE_CXX_COMPILER="g++" -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize .. -cmake --build . -if [ $? -eq 0 ]; then - PassedCompilation -else - FailedCompilation - exit $? -fi -./etl_tests -if [ $? -eq 0 ]; then - PassedTests -else - FailedTests - exit $? -fi -fi - -#****************************************************************************** -if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then -compiler=$clang_compiler -SetConfigurationName "Initializer list test" -PrintHeader -rm * -rf -cmake -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize .. -cmake --build . -if [ $? -eq 0 ]; then - PassedCompilation -else - FailedCompilation - exit $? -fi -./etl_tests -if [ $? -eq 0 ]; then - PassedTests -else - FailedTests - exit $? -fi -fi - -#****************************************************************************** -if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then -compiler=$gcc_compiler -SetConfigurationName "Error macros 'log_errors' test" -PrintHeader -cd ../../etl_error_handler/log_errors -mkdir -p build-make || exit 1 -cd build-make || exit 1 -rm * -rf -cmake -DCMAKE_C_COMPILER="gcc" -DCMAKE_CXX_COMPILER="g++" -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize .. -cmake --build . -if [ $? -eq 0 ]; then - PassedCompilation -else - FailedCompilation - exit $? -fi -./etl_tests -if [ $? -eq 0 ]; then - PassedTests -else - FailedTests - exit $? -fi -fi - -#****************************************************************************** -if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then -compiler=$gcc_compiler -SetConfigurationName "Error macros 'exceptions' test" -PrintHeader -cd ../../../etl_error_handler/exceptions -mkdir -p build-make || exit 1 -cd build-make || exit 1 -rm * -rf -cmake -DCMAKE_C_COMPILER="gcc" -DCMAKE_CXX_COMPILER="g++" -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize .. -cmake --build . -if [ $? -eq 0 ]; then - PassedCompilation -else - FailedCompilation - exit $? -fi -./etl_tests -if [ $? -eq 0 ]; then - PassedTests -else - FailedTests - exit $? -fi -fi - -#****************************************************************************** -if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then -compiler=$gcc_compiler -SetConfigurationName "Error macros 'log_errors and exceptions' test" -PrintHeader -cd ../../../etl_error_handler/log_errors_and_exceptions -mkdir -p build-make || exit 1 -cd build-make || exit 1 -rm * -rf -cmake -DCMAKE_C_COMPILER="gcc" -DCMAKE_CXX_COMPILER="g++" -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize .. -cmake --build . -if [ $? -eq 0 ]; then - PassedCompilation -else - FailedCompilation - exit $? -fi -./etl_tests -if [ $? -eq 0 ]; then - PassedTests -else - FailedTests - exit $? -fi -fi - -#****************************************************************************** -if [ "$compiler_enabled" = "gcc" ] || [ "$compiler_enabled" = "All compilers" ]; then -compiler=$gcc_compiler -SetConfigurationName "Error macros 'assert function' test" -PrintHeader -cd ../../../etl_error_handler/assert_function -mkdir -p build-make || exit 1 -cd build-make || exit 1 -rm * -rf -cmake -DCMAKE_C_COMPILER="gcc" -DCMAKE_CXX_COMPILER="g++" -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize .. -cmake --build . -if [ $? -eq 0 ]; then - PassedCompilation -else - FailedCompilation - exit $? -fi -./etl_tests -if [ $? -eq 0 ]; then - PassedTests -else - FailedTests - exit $? -fi -fi - -#****************************************************************************** -if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then -compiler=$clang_compiler -SetConfigurationName "Error macros 'log_errors' test" -PrintHeader -cd ../../../etl_error_handler/log_errors -mkdir -p build-make || exit 1 -cd build-make || exit 1 -rm * -rf -cmake -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize .. -cmake --build . -if [ $? -eq 0 ]; then - PassedCompilation -else - FailedCompilation - exit $? -fi -./etl_tests -if [ $? -eq 0 ]; then - PassedTests -else - FailedTests - exit $? -fi -fi - -#****************************************************************************** -if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then -compiler=$clang_compiler -SetConfigurationName "Error macros 'exceptions' test" -PrintHeader -cd ../../../etl_error_handler/exceptions -mkdir -p build-make || exit 1 -cd build-make || exit 1 -rm * -rf -cmake -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize .. -cmake --build . -if [ $? -eq 0 ]; then - PassedCompilation -else - FailedCompilation - exit $? -fi -./etl_tests -if [ $? -eq 0 ]; then - PassedTests -else - FailedTests - exit $? -fi -fi - -#****************************************************************************** -if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then -compiler=$clang_compiler -SetConfigurationName "Error macros 'log_errors and exceptions' test" -PrintHeader -cd ../../../etl_error_handler/log_errors_and_exceptions -mkdir -p build-make || exit 1 -cd build-make || exit 1 -rm * -rf -cmake -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize .. -cmake --build . -if [ $? -eq 0 ]; then - PassedCompilation -else - FailedCompilation - exit $? -fi -./etl_tests -if [ $? -eq 0 ]; then - PassedTests -else - FailedTests - exit $? -fi -fi - -#****************************************************************************** -if [ "$compiler_enabled" = "clang" ] || [ "$compiler_enabled" = "All compilers" ]; then -compiler=$clang_compiler -SetConfigurationName "Error macros 'assert function' test" -PrintHeader -cd ../../../etl_error_handler/assert_function -mkdir -p build-make || exit 1 -cd build-make || exit 1 -rm * -rf -cmake -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize .. -cmake --build . -if [ $? -eq 0 ]; then - PassedCompilation -else - FailedCompilation - exit $? -fi -./etl_tests -if [ $? -eq 0 ]; then - PassedTests -else - FailedTests - exit $? -fi -fi - -cd ../.. + if [ "$compiler_enabled" = "$CC" ] || [ "$compiler_enabled" = "All compilers" ]; then + if [ "$CC" = "gcc" ] ; then + compiler=$(g++ --version | grep g++) + else + compiler=$(clang++ --version | grep clang) + fi + OLD_DIR=`pwd` + cd $DIR + mkdir -p build-make || exit 1 + cd build-make || exit 1 + echo "ETL Tests" > log.txt + SetConfigurationName "$MSG" + PrintHeader + $CMD + cmake --build . + if [ $? -eq 0 ]; then + PassedCompilation + else + FailedCompilation + exit $? + fi + ./etl_tests + if [ $? -eq 0 ]; then + PassedTests + else + FailedTests + exit $? + fi + cd .. + rm -rf build-make + cd $OLD_DIR + fi +done <<-EOF +gcc ,STL ,.,cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize -DETL_MESSAGES_ARE_NOT_VIRTUAL=OFF .. +gcc ,STL - Non-virtual messages,.,cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize -DETL_MESSAGES_ARE_NOT_VIRTUAL=ON .. +gcc ,STL - Force C++03 ,.,cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize -DETL_MESSAGES_ARE_NOT_VIRTUAL=OFF .. +gcc ,No STL ,.,cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize -DETL_MESSAGES_ARE_NOT_VIRTUAL=OFF .. +gcc ,No STL - Force C++03 ,.,cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize -DETL_MESSAGES_ARE_NOT_VIRTUAL=OFF .. +clang,STL ,.,cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize -DETL_MESSAGES_ARE_NOT_VIRTUAL=OFF .. +clang,STL - Force C++03 ,.,cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize -DETL_MESSAGES_ARE_NOT_VIRTUAL=OFF .. +clang,No STL ,.,cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize -DETL_MESSAGES_ARE_NOT_VIRTUAL=OFF .. +clang,No STL - Force C++03 ,.,cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize -DETL_MESSAGES_ARE_NOT_VIRTUAL=OFF .. +gcc ,Initializer list test ,etl_initializer_list,cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize .. +clang,Initializer list test ,etl_initializer_list,cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize .. +gcc ,Error macros 'log_errors' test,etl_error_handler/log_errors ,cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize .. +gcc ,Error macros 'exceptions' test,etl_error_handler/exceptions ,cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize .. +gcc ,Error macros 'log_errors and exceptions' test,etl_error_handler/log_errors_and_exceptions,cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize .. +gcc ,Error macros 'assert function' test,etl_error_handler/assert_function ,cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize .. +clang,Error macros 'log_errors' test,etl_error_handler/log_errors ,cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize .. +clang,Error macros 'exceptions' test,etl_error_handler/exceptions ,cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize .. +clang,Error macros 'log_errors and exceptions' test,etl_error_handler/log_errors_and_exceptions,cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize .. +clang,Error macros 'assert function' test,etl_error_handler/assert_function ,cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DETL_OPTIMISATION=$opt -DETL_CXX_STANDARD=$cxx_standard -DETL_ENABLE_SANITIZER=$sanitize .. +EOF TestsCompleted From 9fdc1e1326543f248bc934886676f234e3d0e0c0 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 26 Jun 2025 20:22:41 +0100 Subject: [PATCH 12/12] Minor format change --- test/run-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/run-tests.sh b/test/run-tests.sh index 37cf9945..9644bde4 100755 --- a/test/run-tests.sh +++ b/test/run-tests.sh @@ -38,7 +38,7 @@ PrintHeader() echo " Configuration : $configuration_name" | tee -a log.txt echo " Compiler : $compiler " | tee -a log.txt echo " Language : C++$cxx_standard " | tee -a log.txt - echo " Optimisation : $opt " | tee -a log.txt + echo " Optimisation : $opt " | tee -a log.txt echo " Sanitizer : $sanitize " | tee -a log.txt echo " Compiler select : $compiler_enabled " | tee -a log.txt echo " ETL version : $etl_version " | tee -a log.txt