diff --git a/include/etl/const_map.h b/include/etl/const_map.h index f96f616b..051e6303 100644 --- a/include/etl/const_map.h +++ b/include/etl/const_map.h @@ -508,7 +508,8 @@ namespace etl //************************************************************************* ///\brief Construct a const_map from a variadic list of elements. - /// Static asserts if the elements are not of type value_type. + /// Static asserts if the elements are not constructible into + /// value_type. /// Static asserts if the number of elements is greater than the capacity of /// the const_map. //************************************************************************* @@ -517,7 +518,8 @@ namespace etl : iconst_map(element_list, sizeof...(elements), Size) , element_list{etl::forward(elements)...} { - static_assert((etl::are_all_same...>::value), "All elements must be value_type"); + static_assert((etl::conjunction>...>::value), + "All elements must be constructible into value_type"); static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity"); } diff --git a/include/etl/const_multimap.h b/include/etl/const_multimap.h index dea60ee1..589fe331 100644 --- a/include/etl/const_multimap.h +++ b/include/etl/const_multimap.h @@ -458,7 +458,8 @@ namespace etl //************************************************************************* ///\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 elements are not constructible into + /// value_type. /// Static asserts if the number of elements is greater than the capacity of /// the const_map. //************************************************************************* @@ -467,7 +468,8 @@ namespace etl : iconst_multimap(element_list, sizeof...(elements), Size) , element_list{etl::forward(elements)...} { - static_assert((etl::are_all_same...>::value), "All elements must be value_type"); + static_assert((etl::conjunction>...>::value), + "All elements must be constructible into value_type"); static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity"); } diff --git a/test/test_const_map.cpp b/test/test_const_map.cpp index fe998a7d..a3dc8f14 100644 --- a/test/test_const_map.cpp +++ b/test/test_const_map.cpp @@ -257,6 +257,27 @@ namespace CHECK_TRUE(data.max_size() == Max_Size); 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 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 //************************************************************************* diff --git a/test/test_const_multimap.cpp b/test/test_const_multimap.cpp index 8c134899..3e181311 100644 --- a/test/test_const_multimap.cpp +++ b/test/test_const_multimap.cpp @@ -226,6 +226,28 @@ namespace CHECK_TRUE(data.max_size() == Max_Size); 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 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 //*************************************************************************