Set default compare for iconst_map (#1560)

This is consistent with (i)flat_map, and allows to just write iconst_map<K, V>.

Add tests, also fix iconst_set.
This commit is contained in:
Björn Schäpers 2026-09-03 13:27:56 +02:00 committed by GitHub
parent e25a44195c
commit a547336322
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 21 additions and 2 deletions

View File

@ -48,7 +48,7 @@ SOFTWARE.
namespace etl namespace etl
{ {
template <typename TKey, typename TMapped, typename TKeyCompare> template <typename TKey, typename TMapped, typename TKeyCompare = etl::less<TKey>>
class iconst_map class iconst_map
{ {
public: public:

View File

@ -48,7 +48,7 @@ SOFTWARE.
namespace etl namespace etl
{ {
template <typename TKey, typename TKeyCompare> template <typename TKey, typename TKeyCompare = etl::less<TKey>>
class iconst_set class iconst_set
{ {
public: public:

View File

@ -112,6 +112,9 @@ namespace
using mapped_type = Data::mapped_type; using mapped_type = Data::mapped_type;
using const_iterator = Data::const_iterator; using const_iterator = Data::const_iterator;
static_assert(etl::is_same<etl::iconst_map<key_type, mapped_type>, etl::iconst_map<key_type, mapped_type, etl::less<key_type>>>::value,
"default compare is not less");
SUITE(test_const_map) SUITE(test_const_map)
{ {
//************************************************************************* //*************************************************************************

View File

@ -111,6 +111,9 @@ namespace
using mapped_type = Data::mapped_type; using mapped_type = Data::mapped_type;
using const_iterator = Data::const_iterator; using const_iterator = Data::const_iterator;
static_assert(etl::is_same<etl::iconst_multimap<key_type, mapped_type>, etl::iconst_multimap<key_type, mapped_type, etl::less<key_type>>>::value,
"default compare is not less");
SUITE(test_const_multimap) SUITE(test_const_multimap)
{ {
//************************************************************************* //*************************************************************************

View File

@ -114,6 +114,9 @@ namespace
using key_type = Data::key_type; using key_type = Data::key_type;
using const_iterator = Data::const_iterator; using const_iterator = Data::const_iterator;
static_assert(etl::is_same<etl::iconst_multiset<key_type>, etl::iconst_multiset<key_type, etl::less<key_type>>>::value,
"default compare is not less");
SUITE(test_const_multiset) SUITE(test_const_multiset)
{ {
//************************************************************************* //*************************************************************************

View File

@ -112,6 +112,8 @@ namespace
using key_type = Data::key_type; using key_type = Data::key_type;
using const_iterator = Data::const_iterator; using const_iterator = Data::const_iterator;
static_assert(etl::is_same<etl::iconst_set<key_type>, etl::iconst_set<key_type, etl::less<key_type>>>::value, "default compare is not less");
SUITE(test_const_set) SUITE(test_const_set)
{ {
//************************************************************************* //*************************************************************************

View File

@ -211,6 +211,8 @@ namespace
// return os; // return os;
//} //}
static_assert(etl::is_same<etl::iflat_map<int, D1>, etl::iflat_map<int, D1, etl::less<int>>>::value, "default compare is not less");
SUITE(test_flat_map) SUITE(test_flat_map)
{ {
NDC N0 = NDC("A"); NDC N0 = NDC("A");

View File

@ -239,6 +239,8 @@ namespace
return true; return true;
} }
static_assert(etl::is_same<etl::iflat_multimap<int, D1>, etl::iflat_multimap<int, D1, etl::less<int>>>::value, "default compare is not less");
SUITE(test_flat_multimap) SUITE(test_flat_multimap)
{ {
//************************************************************************* //*************************************************************************

View File

@ -241,6 +241,8 @@ namespace
std::vector<int> int_data; std::vector<int> int_data;
static_assert(etl::is_same<etl::iflat_multiset<int>, etl::iflat_multiset<int, etl::less<int>>>::value, "default compare is not less");
//************************************************************************* //*************************************************************************
struct SetupFixture struct SetupFixture
{ {

View File

@ -261,6 +261,8 @@ namespace
return (lhs.value < rhs.k.value); return (lhs.value < rhs.k.value);
} }
static_assert(etl::is_same<etl::iflat_set<int>, etl::iflat_set<int, etl::less<int>>>::value, "default compare is not less");
//************************************************************************* //*************************************************************************
struct SetupFixture struct SetupFixture
{ {