libutil: make blanket rpc converters more useful
having from() work on primitive types lets us specialize less elsewhere. Change-Id: Ia6eb72ab03c264c6ba3149cb8fe21fa5b3ab4b4d
This commit is contained in:
+21
-15
@@ -28,6 +28,27 @@ To to(const From & from, auto &&... args)
|
||||
return Convert<typename From::Reads, To>::convert(from, args...);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
requires std::integral<T> || std::floating_point<T> || std::same_as<T, bool>
|
||||
T from(T t, auto &&...)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
// blanket converter that turns a `from` into a `to`
|
||||
template<typename Rpc, typename To>
|
||||
struct Convert
|
||||
{
|
||||
template<typename... Args>
|
||||
requires requires(typename Rpc::Reader r, Args... args) {
|
||||
{ from(r, args...) } -> std::same_as<To>;
|
||||
}
|
||||
static To convert(const typename Rpc::Reader & r, Args &&... args)
|
||||
{
|
||||
return from(r, args...);
|
||||
}
|
||||
};
|
||||
|
||||
// conversions for capnp Text
|
||||
template<>
|
||||
struct Convert<capnp::Text, std::string_view>
|
||||
@@ -126,21 +147,6 @@ struct Fill<capnp::List<Elem>, From>
|
||||
}
|
||||
};
|
||||
|
||||
// blanket converter that turns a `from` into a `to`
|
||||
template<typename Rpc, typename To>
|
||||
requires requires(typename Rpc::Reader r) {
|
||||
{
|
||||
from(r)
|
||||
} -> std::same_as<To>;
|
||||
}
|
||||
struct Convert<Rpc, To>
|
||||
{
|
||||
static To convert(const typename Rpc::Reader & r, auto &&... args)
|
||||
{
|
||||
return from(r, args...);
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
// strings to Data and Text
|
||||
template<typename Builder, std::convertible_to<std::string_view> From>
|
||||
|
||||
Reference in New Issue
Block a user