diff --git a/include/etl/const_set.h b/include/etl/const_set.h index 92bbad2c..50dfe20f 100644 --- a/include/etl/const_set.h +++ b/include/etl/const_set.h @@ -401,8 +401,6 @@ namespace etl /// Defines the parameter types using const_key_reference = const key_type&; - static_assert((etl::is_default_constructible::value), "key_type must be default constructible"); - #include "private/diagnostic_uninitialized_push.h" //************************************************************************* ///\brief Construct a const_set from a variadic list of elements. @@ -420,6 +418,9 @@ namespace etl { static_assert((etl::are_all_same...>::value), "All elements must be key_type"); static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity"); + + static_assert(sizeof...(elements) == Size || etl::is_default_constructible::value, + "key_type must be default constructible, if providing less than Size elements"); } #include "private/diagnostic_pop.h" @@ -454,8 +455,6 @@ namespace etl using const_iterator = typename base_t::const_iterator; using size_type = typename base_t::size_type; - static_assert((etl::is_default_constructible::value), "key_type must be default constructible"); - //************************************************************************* ///\brief Default construct a const_set. //************************************************************************* diff --git a/test/test_const_set.cpp b/test/test_const_set.cpp index 0383e852..18ff6b82 100644 --- a/test/test_const_set.cpp +++ b/test/test_const_set.cpp @@ -1381,5 +1381,22 @@ namespace CHECK_TRUE(greater_than_equal11); #endif } + + //************************************************************************* + TEST(test_construct_from_not_default_constuctible) + { + struct F : Key + { + constexpr explicit F(char c) + : Key(c) + { + } + }; + + using Set = etl::const_set; + + static const Set set{F('1'), F('2'), F('3')}; + CHECK_TRUE(set.is_valid()); + } } } // namespace