Skip to content

Commit 0d8012f

Browse files
committed
Merge #165: clang-tidy: fix warnings introduced in version 19
aa19285 use ranges transform (Daniel Pfeifer) a78137c make member function const (Daniel Pfeifer) ca3226e replace custom tuple unpacking code with `std::apply` (Daniel Pfeifer) 949fe85 replace SFINAE trick with `if constexpr` (Daniel Pfeifer) Pull request description: Should fix #153. ACKs for top commit: ryanofsky: Code review ACK aa19285 Tree-SHA512: 21e87f82c02a6e59569f2da61e8c8716719af29fa94d43549eae86b7b41ce1f37c5782a9f42f38ef58bdc1a5adbb0bc2c5b5a41a07dc8c8e06c573e92f7d1155
2 parents 35944ff + aa19285 commit 0d8012f

File tree

4 files changed

+66
-68
lines changed

4 files changed

+66
-68
lines changed

include/mp/proxy-io.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class EventLoop
172172
void addClient(std::unique_lock<std::mutex>& lock);
173173
bool removeClient(std::unique_lock<std::mutex>& lock);
174174
//! Check if loop should exit.
175-
bool done(std::unique_lock<std::mutex>& lock);
175+
bool done(std::unique_lock<std::mutex>& lock) const;
176176

177177
Logger log()
178178
{

include/mp/proxy-types.h

Lines changed: 63 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,45 @@ struct StructField
3737
}
3838
Struct& m_struct;
3939

40-
// clang-format off
41-
template<typename A = Accessor> auto get() const -> decltype(A::get(this->m_struct)) { return A::get(this->m_struct); }
42-
template<typename A = Accessor> auto has() const -> std::enable_if_t<A::optional, bool> { return A::getHas(m_struct); }
43-
template<typename A = Accessor> auto has() const -> std::enable_if_t<!A::optional && A::boxed, bool> { return A::has(m_struct); }
44-
template<typename A = Accessor> auto has() const -> std::enable_if_t<!A::optional && !A::boxed, bool> { return true; }
45-
template<typename A = Accessor> auto want() const -> std::enable_if_t<A::requested, bool> { return A::getWant(m_struct); }
46-
template<typename A = Accessor> auto want() const -> std::enable_if_t<!A::requested, bool> { return true; }
47-
template<typename A = Accessor, typename... Args> decltype(auto) set(Args&&... args) const { return A::set(this->m_struct, std::forward<Args>(args)...); }
48-
template<typename A = Accessor, typename... Args> decltype(auto) init(Args&&... args) const { return A::init(this->m_struct, std::forward<Args>(args)...); }
49-
template<typename A = Accessor> auto setHas() const -> std::enable_if_t<A::optional> { return A::setHas(m_struct); }
50-
template<typename A = Accessor> auto setHas() const -> std::enable_if_t<!A::optional> { }
51-
template<typename A = Accessor> auto setWant() const -> std::enable_if_t<A::requested> { return A::setWant(m_struct); }
52-
template<typename A = Accessor> auto setWant() const -> std::enable_if_t<!A::requested> { }
53-
// clang-format on
40+
decltype(auto) get() const { return Accessor::get(this->m_struct); }
41+
42+
bool has() const {
43+
if constexpr (Accessor::optional) {
44+
return Accessor::getHas(m_struct);
45+
} else if constexpr (Accessor::boxed) {
46+
return Accessor::has(m_struct);
47+
} else {
48+
return true;
49+
}
50+
}
51+
52+
bool want() const {
53+
if constexpr (Accessor::requested) {
54+
return Accessor::getWant(m_struct);
55+
} else {
56+
return true;
57+
}
58+
}
59+
60+
template <typename... Args> decltype(auto) set(Args &&...args) const {
61+
return Accessor::set(this->m_struct, std::forward<Args>(args)...);
62+
}
63+
64+
template <typename... Args> decltype(auto) init(Args &&...args) const {
65+
return Accessor::init(this->m_struct, std::forward<Args>(args)...);
66+
}
67+
68+
void setHas() const {
69+
if constexpr (Accessor::optional) {
70+
Accessor::setHas(m_struct);
71+
}
72+
}
73+
74+
void setWant() const {
75+
if constexpr (Accessor::requested) {
76+
Accessor::setWant(m_struct);
77+
}
78+
}
5479
};
5580

5681

@@ -364,30 +389,17 @@ struct ClientParam
364389

365390
struct BuildParams : IterateFieldsHelper<BuildParams, sizeof...(Types)>
366391
{
367-
template <typename... Args>
368-
void handleField(Args&&... args)
369-
{
370-
callBuild<0>(std::forward<Args>(args)...);
371-
}
372-
373-
// TODO Possible optimization to speed up compile time:
374-
// https://stackoverflow.com/a/7858971 Using enable_if below to check
375-
// position when unpacking tuple might be slower than pattern matching
376-
// approach in the stack overflow solution
377-
template <size_t I, typename... Args>
378-
auto callBuild(Args&&... args) -> std::enable_if_t<(I < sizeof...(Types))>
379-
{
380-
callBuild<I + 1>(std::forward<Args>(args)..., std::get<I>(m_client_param->m_values));
381-
}
382-
383-
template <size_t I, typename Params, typename ParamList, typename... Values>
384-
auto callBuild(ClientInvokeContext& invoke_context, Params& params, ParamList, Values&&... values) ->
385-
std::enable_if_t<(I == sizeof...(Types))>
392+
template <typename Params, typename ParamList>
393+
void handleField(ClientInvokeContext& invoke_context, Params& params, ParamList)
386394
{
387-
MaybeBuildField(std::integral_constant<bool, Accessor::in>(), ParamList(), invoke_context,
388-
Make<StructField, Accessor>(params), std::forward<Values>(values)...);
389-
MaybeSetWant(
390-
ParamList(), Priority<1>(), std::forward<Values>(values)..., Make<StructField, Accessor>(params));
395+
auto const fun = [&]<typename... Values>(Values&&... values) {
396+
MaybeBuildField(std::integral_constant<bool, Accessor::in>(), ParamList(), invoke_context,
397+
Make<StructField, Accessor>(params), std::forward<Values>(values)...);
398+
MaybeSetWant(
399+
ParamList(), Priority<1>(), std::forward<Values>(values)..., Make<StructField, Accessor>(params));
400+
};
401+
402+
std::apply(fun, m_client_param->m_values);
391403
}
392404

393405
BuildParams(ClientParam* client_param) : m_client_param(client_param) {}
@@ -396,24 +408,15 @@ struct ClientParam
396408

397409
struct ReadResults : IterateFieldsHelper<ReadResults, sizeof...(Types)>
398410
{
399-
template <typename... Args>
400-
void handleField(Args&&... args)
411+
template <typename Results, typename... Params>
412+
void handleField(ClientInvokeContext& invoke_context, Results& results, TypeList<Params...>)
401413
{
402-
callRead<0>(std::forward<Args>(args)...);
403-
}
414+
auto const fun = [&]<typename... Values>(Values&&... values) {
415+
MaybeReadField(std::integral_constant<bool, Accessor::out>(), TypeList<Decay<Params>...>(), invoke_context,
416+
Make<StructField, Accessor>(results), ReadDestUpdate(values)...);
417+
};
404418

405-
template <int I, typename... Args>
406-
auto callRead(Args&&... args) -> std::enable_if_t<(I < sizeof...(Types))>
407-
{
408-
callRead<I + 1>(std::forward<Args>(args)..., std::get<I>(m_client_param->m_values));
409-
}
410-
411-
template <int I, typename Results, typename... Params, typename... Values>
412-
auto callRead(ClientInvokeContext& invoke_context, Results& results, TypeList<Params...>, Values&&... values)
413-
-> std::enable_if_t<I == sizeof...(Types)>
414-
{
415-
MaybeReadField(std::integral_constant<bool, Accessor::out>(), TypeList<Decay<Params>...>(), invoke_context,
416-
Make<StructField, Accessor>(results), ReadDestUpdate(values)...);
419+
std::apply(fun, m_client_param->m_values);
417420
}
418421

419422
ReadResults(ClientParam* client_param) : m_client_param(client_param) {}
@@ -650,19 +653,14 @@ void clientInvoke(ProxyClient& proxy_client, const GetRequest& get_request, Fiel
650653
//! return value with value of `ret()`. This is useful for avoiding code
651654
//! duplication and branching in generic code that forwards calls to functions.
652655
template <typename Fn, typename Ret>
653-
auto ReplaceVoid(Fn&& fn, Ret&& ret) ->
654-
std::enable_if_t<std::is_same_v<void, decltype(fn())>, decltype(ret())>
656+
auto ReplaceVoid(Fn&& fn, Ret&& ret)
655657
{
656-
fn();
657-
return ret();
658-
}
659-
660-
//! Overload of above for non-void `fn()` case.
661-
template <typename Fn, typename Ret>
662-
auto ReplaceVoid(Fn&& fn, Ret&& ret) ->
663-
std::enable_if_t<!std::is_same_v<void, decltype(fn())>, decltype(fn())>
664-
{
665-
return fn();
658+
if constexpr (std::is_same_v<decltype(fn()), void>) {
659+
fn();
660+
return ret();
661+
} else {
662+
return fn();
663+
}
666664
}
667665

668666
extern std::atomic<int> server_reqs;

src/mp/gen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ static void Generate(kj::StringPtr src_prefix,
215215
cpp_types << "namespace mp {\n";
216216

217217
std::string guard = output_path;
218-
std::transform(guard.begin(), guard.end(), guard.begin(), [](unsigned char c) -> unsigned char {
218+
std::ranges::transform(guard, guard.begin(), [](unsigned char c) -> unsigned char {
219219
if ('0' <= c && c <= '9') return c;
220220
if ('A' <= c && c <= 'Z') return c;
221221
if ('a' <= c && c <= 'z') return c - 'a' + 'A';

src/mp/proxy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ void EventLoop::startAsyncThread(std::unique_lock<std::mutex>& lock)
277277
}
278278
}
279279

280-
bool EventLoop::done(std::unique_lock<std::mutex>& lock)
280+
bool EventLoop::done(std::unique_lock<std::mutex>& lock) const
281281
{
282282
assert(m_num_clients >= 0);
283283
assert(lock.owns_lock());

0 commit comments

Comments
 (0)