Skip to content

Commit 4b2dc92

Browse files
committed
refactor
1 parent 5dd2bb1 commit 4b2dc92

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
55
set(CMAKE_CXX_STANDARD 26)
66

77
project(rsltest CXX)
8-
add_library(rsltest )
8+
add_library(rsltest SHARED)
99

1010
set_target_properties(rsltest PROPERTIES OUTPUT_NAME rsltest)
1111
target_compile_options(rsltest PUBLIC
@@ -20,7 +20,7 @@ target_include_directories(rsltest PUBLIC
2020
find_package(libassert REQUIRED)
2121
target_link_libraries(rsltest PUBLIC libassert::assert)
2222

23-
add_library(rsltest_main )
23+
add_library(rsltest_main SHARED)
2424

2525
target_link_libraries(rsltest_main PUBLIC rsltest)
2626

example/tparams.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ consteval std::vector<rsl::testing::ParamSet> make_tparams() {
1212
[[=rsl::tparams({{^^int, 10}, {^^float, 21}})]]
1313
[[=rsl::params({{42, 'c'}, {12, 'b'}})]]
1414
constexpr inline auto tparam_gt_5 = []<typename T, unsigned I>(int a, char b) static {
15-
ASSERT(I > 5);
15+
ASSERT(I < 5);
1616
};
1717

1818
struct TestAggregate{ unsigned value; };

include/rsl/testing/_testing_impl/paramset.hpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,32 @@ struct ParamSet {
1010

1111
template <typename T>
1212
requires(!std::same_as<std::remove_cvref_t<T>, ParamSet>)
13-
consteval explicit(std::invocable<T>) ParamSet(T&& v) {
13+
consteval explicit(std::invocable<T>) ParamSet(T&& v) : value(make(std::forward<T>(v))) {
1414
// this constructor is only explicit if the argument is a nullary function
1515
// this is done so `initializer_list<ParamSet>` does not win over Params' templated generator
1616
// function ctor
1717
// TODO only do this if the return type is an iterable with element_type ParamSet or tuple-like
18-
value = std::define_static_array(std::vector{std::meta::reflect_constant(v)});
1918
}
2019

2120
template <typename... Ts>
2221
requires(sizeof...(Ts) > 1 && !(std::same_as<std::remove_cvref_t<Ts>, ParamSet> || ...))
23-
consteval ParamSet(Ts&&... ts) {
22+
consteval ParamSet(Ts&&... ts) : value(make(std::forward<Ts>(ts)...)) {}
23+
24+
private:
25+
template <typename... Ts>
26+
static consteval rsl::span<std::meta::info const> make(Ts&&... ts) {
2427
std::vector<std::meta::info> elts;
2528
template for (auto&& elt : {std::forward<Ts>(ts)...}) {
26-
if constexpr (std::same_as<std::remove_cvref_t<decltype(elt)>, std::meta::info>)
29+
using type = std::remove_cvref_t<decltype(elt)>;
30+
if constexpr (std::convertible_to<type, std::string_view>) {
31+
elts.push_back(std::meta::reflect_constant_string(elt));
32+
} else if constexpr (std::same_as<type, std::meta::info>) {
2733
elts.push_back(elt);
28-
else
34+
} else {
2935
elts.push_back(std::meta::reflect_constant(elt));
36+
}
3037
}
31-
value = std::define_static_array(elts);
38+
return std::define_static_array(elts);
3239
}
3340
};
34-
} // namespace rsl::testing
41+
} // namespace rsl::testing::_testing_impl

0 commit comments

Comments
 (0)