Skip to content

Commit 4e0d697

Browse files
authored
Rework decltype(lambda) appearances (#150)
1 parent 4ce09cf commit 4e0d697

File tree

4 files changed

+72
-53
lines changed

4 files changed

+72
-53
lines changed

include/mimic++/matchers/Common.hpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,21 @@ namespace mimicpp::detail::describe_hook
102102

103103
inline constexpr util::priority_tag<1> maxTag{};
104104

105-
template <typename Matcher>
106-
[[nodiscard]]
107-
constexpr auto describe(Matcher const& matcher)
108-
-> decltype(describe_impl(maxTag, matcher))
109-
requires requires {
110-
{ describe_impl(maxTag, matcher) } -> util::explicitly_convertible_to<std::optional<StringT>>;
111-
}
105+
struct describe_fn
112106
{
113-
return describe_impl(maxTag, matcher);
114-
}
107+
template <typename Matcher>
108+
[[nodiscard]]
109+
constexpr auto operator()(Matcher const& matcher) const
110+
-> decltype(describe_impl(maxTag, matcher))
111+
requires requires {
112+
{ describe_impl(maxTag, matcher) } -> util::explicitly_convertible_to<std::optional<StringT>>;
113+
}
114+
{
115+
return describe_impl(maxTag, matcher);
116+
}
117+
};
118+
119+
inline constexpr describe_fn describe{};
115120
}
116121

117122
namespace mimicpp

include/mimic++/matchers/RangeMatchers.hpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -179,21 +179,23 @@ MIMICPP_DETAIL_MODULE_EXPORT namespace mimicpp::matches::range
179179
[[nodiscard]]
180180
constexpr auto each_element(Matcher&& matcher)
181181
{
182-
using MatcherT = std::remove_cvref_t<Matcher>;
182+
using MatcherType = std::remove_cvref_t<Matcher>;
183+
using arg_storage = mimicpp::detail::arg_storage<
184+
MatcherType,
185+
std::identity,
186+
mimicpp::detail::describe_hook::describe_fn>;
187+
183188
return PredicateMatcher{
184-
[](std::ranges::range auto&& target, const MatcherT& m) {
189+
[]<std::ranges::range Range>(Range&& target, MatcherType const& m) {
185190
return std::ranges::all_of(
186-
target,
187-
[&](const auto& element) { return m.matches(element); });
191+
std::forward<Range>(target),
192+
[&](auto&& element) {
193+
return mimicpp::detail::matches_hook::matches(m, element);
194+
});
188195
},
189196
"each el in range: el {}",
190197
"not each el in range: el {}",
191-
std::make_tuple(
192-
mimicpp::detail::arg_storage<
193-
MatcherT,
194-
std::identity,
195-
decltype([](const auto& m) { return mimicpp::detail::describe_hook::describe(m); })>{
196-
std::forward<MatcherT>(matcher)})};
198+
std::tuple<arg_storage>{std::forward<Matcher>(matcher)}};
197199
}
198200

199201
/**
@@ -204,21 +206,23 @@ MIMICPP_DETAIL_MODULE_EXPORT namespace mimicpp::matches::range
204206
[[nodiscard]]
205207
constexpr auto any_element(Matcher&& matcher)
206208
{
207-
using MatcherT = std::remove_cvref_t<Matcher>;
209+
using MatcherType = std::remove_cvref_t<Matcher>;
210+
using arg_storage = mimicpp::detail::arg_storage<
211+
MatcherType,
212+
std::identity,
213+
mimicpp::detail::describe_hook::describe_fn>;
214+
208215
return PredicateMatcher{
209-
[](std::ranges::range auto&& target, const MatcherT& m) {
216+
[]<std::ranges::range Range>(Range&& target, MatcherType const& m) {
210217
return std::ranges::any_of(
211-
target,
212-
[&](const auto& element) { return m.matches(element); });
218+
std::forward<Range>(target),
219+
[&](auto&& element) {
220+
return mimicpp::detail::matches_hook::matches(m, element);
221+
});
213222
},
214223
"any el in range: el {}",
215224
"none el in range: el {}",
216-
std::make_tuple(
217-
mimicpp::detail::arg_storage<
218-
MatcherT,
219-
std::identity,
220-
decltype([](const auto& m) { return mimicpp::detail::describe_hook::describe(m); })>{
221-
std::forward<MatcherT>(matcher)})};
225+
std::tuple<arg_storage>{std::forward<Matcher>(matcher)}};
222226
}
223227

224228
/**

include/mimic++/printing/type/PrintType.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,25 @@ MIMICPP_DETAIL_MODULE_EXPORT namespace mimicpp::printing::type
9696

9797
namespace mimicpp::printing::type
9898
{
99+
namespace detail
100+
{
101+
struct free_deleter
102+
{
103+
void operator()(char* const c) const noexcept
104+
{
105+
std::free(c);
106+
}
107+
};
108+
}
109+
99110
template <typename T>
100111
StringT type_name()
101112
{
102113
auto* const rawName = typeid(T).name();
103114

104115
// see: https://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_demangling.html
105116
int status{};
106-
using free_deleter_t = decltype([](char* c) noexcept { std::free(c); });
107-
std::unique_ptr<char, free_deleter_t> const demangledName{
117+
std::unique_ptr<char, detail::free_deleter> const demangledName{
108118
abi::__cxa_demangle(rawName, nullptr, nullptr, &status)};
109119
if (0 == status)
110120
{

include/mimic++/printing/type/Templated.hpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -199,35 +199,35 @@ namespace mimicpp::printing::type::detail
199199
{
200200
};
201201

202-
// used for array, span and the like
203-
// should also handle c++26s inplace_vector
204-
// see: https://en.cppreference.com/w/cpp/container/inplace_vector
205202
template <template <typename, auto...> typename Template, typename T, auto n>
206-
struct template_type_printer<Template<T, n>>
207-
: public basic_template_type_printer<
208-
decltype([]<print_iterator OutIter>(OutIter out) {
209-
out = pretty_template_name<Template<T, n>>(std::move(out));
210-
out = format::format_to(std::move(out), "<");
211-
out = mimicpp::print_type<T>(std::move(out));
212-
out = format::format_to(std::move(out), ", {}>", n);
213-
214-
return out;
215-
})>
203+
struct array_like_name_generator
216204
{
205+
template <print_iterator OutIter>
206+
constexpr OutIter operator()(OutIter out) const
207+
{
208+
out = pretty_template_name<Template<T, n>>(std::move(out));
209+
out = format::format_to(std::move(out), "<");
210+
out = mimicpp::print_type<T>(std::move(out));
211+
212+
if constexpr (constexpr bool isDefaultSize = requires { requires std::same_as<Template<T>, Template<T, n>>; };
213+
!isDefaultSize)
214+
{
215+
out = format::format_to(std::move(out), ", {}", n);
216+
}
217+
218+
out = format::format_to(std::move(out), ">");
219+
220+
return out;
221+
}
217222
};
218223

224+
// used for array, span and the like
225+
// should also handle c++26s inplace_vector
226+
// see: https://en.cppreference.com/w/cpp/container/inplace_vector
219227
template <template <typename, auto...> typename Template, typename T, auto n>
220-
requires std::same_as<Template<T>, Template<T, n>>
221228
struct template_type_printer<Template<T, n>>
222229
: public basic_template_type_printer<
223-
decltype([]<print_iterator OutIter>(OutIter out) {
224-
out = pretty_template_name<Template<T, n>>(std::move(out));
225-
out = format::format_to(std::move(out), "<");
226-
out = mimicpp::print_type<T>(std::move(out));
227-
out = format::format_to(std::move(out), ">");
228-
229-
return out;
230-
})>
230+
array_like_name_generator<Template, T, n>>
231231
{
232232
};
233233

0 commit comments

Comments
 (0)