i spent a good 25 minutes making a zero-copy use function for a custom shared data object only to have it rejected for being weird and complicated
template<typename L>
concept Lockable = requires(L l)
{
{l.lock() } -> std::same_as<void>;
{l.unlock() } -> std::same_as<void>;
};
template<typename T, Lockable... Lockables>
requires (sizeof...(Lockables) > 0)
class thing
{
T data;
mutable std::tuple<Lockables...> lockables;
static constexpr auto lock_fn = [](auto&... l) { return std::scoped_lock(l...); };
public:
/*
* other stuff
*/
template<typename F>
requires std::invocable<F, const T&>
auto use_with(F&& f) const noexcept(noexcept(f(std::declval<T const&>())))
-> decltype(f(std::declval<T const&>()))
{
auto lock = std::apply(lock_fn, lockables);
return f(data);
}
};
am i in the wrong?