added array constructor for different length
This commit is contained in:
parent
ddaed337cf
commit
1b96fd982e
|
|
@ -46,7 +46,7 @@ namespace cc {
|
||||||
|
|
||||||
constexpr explicit const_vector(const value_type (&array)[N]) noexcept;
|
constexpr explicit const_vector(const value_type (&array)[N]) noexcept;
|
||||||
template <std::size_t N2>
|
template <std::size_t N2>
|
||||||
constexpr explicit const_vector(const value_type (&array)[N2]) noexcept;
|
constexpr explicit const_vector(const value_type (&array)[N2]);
|
||||||
|
|
||||||
constexpr const_vector(std::initializer_list<value_type> values);
|
constexpr const_vector(std::initializer_list<value_type> values);
|
||||||
|
|
||||||
|
|
@ -213,7 +213,16 @@ namespace cc {
|
||||||
constexpr const_vector<T, N>::const_vector(const value_type (&array)[N]) noexcept
|
constexpr const_vector<T, N>::const_vector(const value_type (&array)[N]) noexcept
|
||||||
: _size(N)
|
: _size(N)
|
||||||
{
|
{
|
||||||
std::move(std::begin(array), std::end(array), _arr);
|
std::copy(std::begin(array), std::end(array), _arr);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, std::size_t N>
|
||||||
|
template<std::size_t N2>
|
||||||
|
constexpr const_vector<T, N>::const_vector(const value_type (&array)[N2])
|
||||||
|
: _size(N2)
|
||||||
|
{
|
||||||
|
if (N < N2) throw std::invalid_argument("Size of array has to be smaller or equal to the capacity: " + std::to_string(N2) + ">=" + std::to_string(N));
|
||||||
|
std::copy(std::begin(array), std::end(array), _arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, std::size_t N>
|
template<typename T, std::size_t N>
|
||||||
|
|
|
||||||
|
|
@ -265,6 +265,23 @@ constexpr test_suite tests = define_tests("Tests")
|
||||||
|
|
||||||
return TEST_PASS();
|
return TEST_PASS();
|
||||||
|
|
||||||
|
}, EvalFlag::RUNTIME_CONSTEVAL)
|
||||||
|
("const_vector(const value_type (&array)[N2])", []() constexpr {
|
||||||
|
|
||||||
|
REPEAT_FOR_TYPES_N(([]<typename T, std::size_t N, typename Ctx>() constexpr {
|
||||||
|
|
||||||
|
cc::const_vector<T, test_params<"arr", Ctx>::get_arr_len() + 1> v(test_context_params<T, N>::template value<"arr">);
|
||||||
|
|
||||||
|
ASSERT_TYPE_NUM((v.size() == test_params<"arr", Ctx>::get_arr_len()), T, N);
|
||||||
|
ASSERT_TYPE_NUM_RANGE_VEC_ARR_EQ(v, 0, (test_params<"arr", Ctx>::get_arr_len()), (test_context_params<T, N>::template value<"arr">), T, N);
|
||||||
|
|
||||||
|
ASSERT_TYPE_NUM_THROWS((cc::const_vector<T, test_params<"arr", Ctx>::get_arr_len() - 1>(test_context_params<T, N>::template value<"arr">)), std::invalid_argument, T, N);
|
||||||
|
|
||||||
|
return TEST_PASS();
|
||||||
|
}), 2, int, char, const char *, TestObj);
|
||||||
|
|
||||||
|
return TEST_PASS();
|
||||||
|
|
||||||
}, EvalFlag::RUNTIME_CONSTEVAL)
|
}, EvalFlag::RUNTIME_CONSTEVAL)
|
||||||
("const_vector(std::initializer_list<value_type> list)", []() constexpr {
|
("const_vector(std::initializer_list<value_type> list)", []() constexpr {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue