mirror of
https://github.com/ETLCPP/etl.git
synced 2026-10-28 18:07:10 +08:00
Allow easier construction of const_(multi_)map (#1561)
When forcing to feed into value_types it has to be an ETL_OR_STD::pair<const K, V>, but when you want to use CTAD on the pairs the const is missing and the assert triggers.
This commit is contained in:
parent
266b0f99c6
commit
ed6c46bf7d
@ -508,7 +508,8 @@ namespace etl
|
|||||||
|
|
||||||
//*************************************************************************
|
//*************************************************************************
|
||||||
///\brief Construct a const_map from a variadic list of elements.
|
///\brief Construct a const_map from a variadic list of elements.
|
||||||
/// Static asserts if the elements are not of type <code>value_type</code>.
|
/// Static asserts if the elements are not constructible into
|
||||||
|
/// <code>value_type</code>.
|
||||||
/// Static asserts if the number of elements is greater than the capacity of
|
/// Static asserts if the number of elements is greater than the capacity of
|
||||||
/// the const_map.
|
/// the const_map.
|
||||||
//*************************************************************************
|
//*************************************************************************
|
||||||
@ -517,7 +518,8 @@ namespace etl
|
|||||||
: iconst_map<TKey, TMapped, TKeyCompare>(element_list, sizeof...(elements), Size)
|
: iconst_map<TKey, TMapped, TKeyCompare>(element_list, sizeof...(elements), Size)
|
||||||
, element_list{etl::forward<TElements>(elements)...}
|
, element_list{etl::forward<TElements>(elements)...}
|
||||||
{
|
{
|
||||||
static_assert((etl::are_all_same<value_type, etl::decay_t<TElements>...>::value), "All elements must be value_type");
|
static_assert((etl::conjunction<etl::is_constructible<value_type, etl::decay_t<TElements>>...>::value),
|
||||||
|
"All elements must be constructible into value_type");
|
||||||
static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity");
|
static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -458,7 +458,8 @@ namespace etl
|
|||||||
//*************************************************************************
|
//*************************************************************************
|
||||||
///\brief Construct a const_map from a variadic list of elements.
|
///\brief Construct a const_map from a variadic list of elements.
|
||||||
/// Static asserts if the element type is not constructible.
|
/// Static asserts if the element type is not constructible.
|
||||||
/// Static asserts if the elements are not of type <code>value_type</code>.
|
/// Static asserts if the elements are not constructible into
|
||||||
|
/// <code>value_type</code>.
|
||||||
/// Static asserts if the number of elements is greater than the capacity of
|
/// Static asserts if the number of elements is greater than the capacity of
|
||||||
/// the const_map.
|
/// the const_map.
|
||||||
//*************************************************************************
|
//*************************************************************************
|
||||||
@ -467,7 +468,8 @@ namespace etl
|
|||||||
: iconst_multimap<TKey, TMapped, TKeyCompare>(element_list, sizeof...(elements), Size)
|
: iconst_multimap<TKey, TMapped, TKeyCompare>(element_list, sizeof...(elements), Size)
|
||||||
, element_list{etl::forward<TElements>(elements)...}
|
, element_list{etl::forward<TElements>(elements)...}
|
||||||
{
|
{
|
||||||
static_assert((etl::are_all_same<value_type, etl::decay_t<TElements>...>::value), "All elements must be value_type");
|
static_assert((etl::conjunction<etl::is_constructible<value_type, etl::decay_t<TElements>>...>::value),
|
||||||
|
"All elements must be constructible into value_type");
|
||||||
static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity");
|
static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -257,6 +257,27 @@ namespace
|
|||||||
CHECK_TRUE(data.max_size() == Max_Size);
|
CHECK_TRUE(data.max_size() == Max_Size);
|
||||||
CHECK_FALSE(data.begin() == data.end());
|
CHECK_FALSE(data.begin() == data.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
TEST(test_cpp17_deduced_constructor_of_plain_pair)
|
||||||
|
{
|
||||||
|
static const etl::const_map data{ETL_OR_STD::pair{Key('A'), 0}, ETL_OR_STD::pair{Key('B'), 1}, ETL_OR_STD::pair{Key('C'), 2},
|
||||||
|
ETL_OR_STD::pair{Key('D'), 3}, ETL_OR_STD::pair{Key('E'), 4}, ETL_OR_STD::pair{Key('F'), 5},
|
||||||
|
ETL_OR_STD::pair{Key('G'), 6}, ETL_OR_STD::pair{Key('H'), 7}, ETL_OR_STD::pair{Key('I'), 8},
|
||||||
|
ETL_OR_STD::pair{Key('J'), 9}};
|
||||||
|
etl::const_map<Key, int, 10U> check{ETL_OR_STD::pair{Key('A'), 0}, ETL_OR_STD::pair{Key('B'), 1}, ETL_OR_STD::pair{Key('C'), 2},
|
||||||
|
ETL_OR_STD::pair{Key('D'), 3}, ETL_OR_STD::pair{Key('E'), 4}, ETL_OR_STD::pair{Key('F'), 5},
|
||||||
|
ETL_OR_STD::pair{Key('G'), 6}, ETL_OR_STD::pair{Key('H'), 7}, ETL_OR_STD::pair{Key('I'), 8},
|
||||||
|
ETL_OR_STD::pair{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
|
#endif
|
||||||
|
|
||||||
//*************************************************************************
|
//*************************************************************************
|
||||||
|
|||||||
@ -226,6 +226,28 @@ namespace
|
|||||||
CHECK_TRUE(data.max_size() == Max_Size);
|
CHECK_TRUE(data.max_size() == Max_Size);
|
||||||
CHECK_FALSE(data.begin() == data.end());
|
CHECK_FALSE(data.begin() == data.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
TEST(test_cpp17_deduced_constructor_of_plain_pair)
|
||||||
|
{
|
||||||
|
static const etl::const_multimap data{ETL_OR_STD::pair{Key('A'), 0}, ETL_OR_STD::pair{Key('B'), 1}, ETL_OR_STD::pair{Key('C'), 2},
|
||||||
|
ETL_OR_STD::pair{Key('D'), 3}, ETL_OR_STD::pair{Key('E'), 4}, ETL_OR_STD::pair{Key('F'), 5},
|
||||||
|
ETL_OR_STD::pair{Key('G'), 6}, ETL_OR_STD::pair{Key('G'), 7}, ETL_OR_STD::pair{Key('G'), 8},
|
||||||
|
ETL_OR_STD::pair{Key('J'), 9}};
|
||||||
|
|
||||||
|
etl::const_multimap<Key, int, 10U> check{ETL_OR_STD::pair{Key('A'), 0}, ETL_OR_STD::pair{Key('B'), 1}, ETL_OR_STD::pair{Key('C'), 2},
|
||||||
|
ETL_OR_STD::pair{Key('D'), 3}, ETL_OR_STD::pair{Key('E'), 4}, ETL_OR_STD::pair{Key('F'), 5},
|
||||||
|
ETL_OR_STD::pair{Key('G'), 6}, ETL_OR_STD::pair{Key('H'), 7}, ETL_OR_STD::pair{Key('I'), 8},
|
||||||
|
ETL_OR_STD::pair{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
|
#endif
|
||||||
|
|
||||||
//*************************************************************************
|
//*************************************************************************
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user