From e6ddca402b822489a3c855ad386499efbf5c555a Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Wed, 1 Jul 2026 13:43:40 +0200 Subject: [PATCH] libutil: make blanket rpc converters more useful having from() work on primitive types lets us specialize less elsewhere. Change-Id: Ia6eb72ab03c264c6ba3149cb8fe21fa5b3ab4b4d --- lix/libutil/rpc.hh | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/lix/libutil/rpc.hh b/lix/libutil/rpc.hh index f200efd45..d63be5a8b 100644 --- a/lix/libutil/rpc.hh +++ b/lix/libutil/rpc.hh @@ -28,6 +28,27 @@ To to(const From & from, auto &&... args) return Convert::convert(from, args...); } +template + requires std::integral || std::floating_point || std::same_as +T from(T t, auto &&...) +{ + return t; +} + +// blanket converter that turns a `from` into a `to` +template +struct Convert +{ + template + requires requires(typename Rpc::Reader r, Args... args) { + { from(r, args...) } -> std::same_as; + } + static To convert(const typename Rpc::Reader & r, Args &&... args) + { + return from(r, args...); + } +}; + // conversions for capnp Text template<> struct Convert @@ -126,21 +147,6 @@ struct Fill, From> } }; -// blanket converter that turns a `from` into a `to` -template - requires requires(typename Rpc::Reader r) { - { - from(r) - } -> std::same_as; - } -struct Convert -{ - static To convert(const typename Rpc::Reader & r, auto &&... args) - { - return from(r, args...); - } -}; - namespace detail { // strings to Data and Text template From>