updated access to test_params
This commit is contained in:
parent
221eac7cd4
commit
ddaed337cf
|
|
@ -155,7 +155,7 @@ struct ret_val {
|
|||
|
||||
struct empty_param {};
|
||||
|
||||
struct test_params {
|
||||
struct test_common_params {
|
||||
template<tstring var_name>
|
||||
constexpr static auto value = empty_param{};
|
||||
};
|
||||
|
|
@ -169,6 +169,21 @@ struct test_context_params {
|
|||
constexpr static auto value = empty_param{};
|
||||
};
|
||||
|
||||
template<tstring Name, typename Ctx = void>
|
||||
struct test_params {
|
||||
constexpr static auto get() {
|
||||
if constexpr (requires { typename Ctx::type; }) {
|
||||
if constexpr (requires { { Ctx::nr } -> std::convertible_to<std::size_t>; }) {
|
||||
return test_context_params<typename Ctx::type, Ctx::nr>::template value<Name>;
|
||||
} else {
|
||||
return test_context_params<typename Ctx::type>::template value<Name>;
|
||||
}
|
||||
} else {
|
||||
return test_common_params::template value<Name>;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#define CONTEXT_PARAM(type, name, ...) template<> template<> constexpr type test_context_params<__VA_ARGS__>::value< #name >
|
||||
#define CONTEXT_PARAM_ARR(type, name, ...) template<> template<> constexpr type test_context_params<__VA_ARGS__>::value< #name >[]
|
||||
|
||||
|
|
@ -396,7 +411,9 @@ template <std::size_t _N, typename ...Ts, std::size_t N = _N - 1>
|
|||
constexpr auto _repeat_for_types_n(auto f) {
|
||||
std::array rets = {
|
||||
[&]<typename T, std::size_t ...Ns>(std::index_sequence<Ns...>) constexpr {
|
||||
return std::array { f.template operator()<T, Ns, test_context_params<T, Ns>>()... };
|
||||
return std::array {
|
||||
(f.template operator()<T, Ns, test_context_params<T, Ns>>())...
|
||||
};
|
||||
}.template operator()<Ts>(std::make_index_sequence<N>())...
|
||||
};
|
||||
// Clion does not accept this as a constant expression
|
||||
|
|
|
|||
|
|
@ -1188,17 +1188,17 @@ constexpr test_suite tests = define_tests("Tests")
|
|||
}, EvalFlag::RUNTIME_CONSTEVAL)
|
||||
("const_vector::assign(std::initializer_list<value_type> values)", []() constexpr {
|
||||
|
||||
REPEAT_FOR_TYPES_N(([]<typename T, std::size_t N, typename params>() constexpr {
|
||||
REPEAT_FOR_TYPES_N(([]<typename T, std::size_t N, typename Ctx>() constexpr {
|
||||
|
||||
cc::const_vector<T, (params::template value<"ilist">).size()> v1;
|
||||
cc::const_vector<T, (params::template value<"ilist">).size() - 1> v2;
|
||||
cc::const_vector<T, (test_params<"ilist", Ctx>::get()).size()> v1;
|
||||
cc::const_vector<T, (test_params<"ilist", Ctx>::get()).size() - 1> v2;
|
||||
|
||||
v1.assign(params::template value<"ilist">);
|
||||
v1.assign(test_params<"ilist", Ctx>::get());
|
||||
|
||||
ASSERT_TYPE_NUM_VEC_ARR_EQ(v1, params::template value<"ilist">, T, N);
|
||||
ASSERT_TYPE_NUM(v1.size() == params::template value<"ilist">.size(), T, N);
|
||||
ASSERT_TYPE_NUM_VEC_ARR_EQ(v1, (test_params<"ilist", Ctx>::get()), T, N);
|
||||
ASSERT_TYPE_NUM((v1.size() == test_params<"ilist", Ctx>::get().size()), T, N);
|
||||
|
||||
ASSERT_TYPE_NUM_THROWS(v2.assign(params::template value<"ilist">), std::invalid_argument, T, N);
|
||||
ASSERT_TYPE_NUM_THROWS(v2.assign(test_params<"ilist", Ctx>::get()), std::invalid_argument, T, N);
|
||||
|
||||
return TEST_PASS();
|
||||
}), 2, int, char, const char *, TestObj);
|
||||
|
|
|
|||
Loading…
Reference in New Issue