From 693661fe8777d6eb5bcf612a5103d1704ec97eff Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 13 Jul 2020 19:54:51 +0100 Subject: feat(3p/nix/libutil): Add util::overloaded class for std::visitor Implements the fairly common lambda overload class used for std::visit over variants and other things that require groups of callables. Change-Id: Ia7448b7e1bd349b4909974758e6e6303a80d86d7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1137 Tested-by: BuildkiteCI Reviewed-by: glittershark Reviewed-by: edef --- third_party/nix/src/libutil/visitor.hh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 third_party/nix/src/libutil/visitor.hh (limited to 'third_party/nix/src/libutil/visitor.hh') diff --git a/third_party/nix/src/libutil/visitor.hh b/third_party/nix/src/libutil/visitor.hh new file mode 100644 index 000000000000..bf1d665af77f --- /dev/null +++ b/third_party/nix/src/libutil/visitor.hh @@ -0,0 +1,19 @@ +#pragma once + +namespace nix::util { + +// Helper class used for visiting std::variants by creating a variadic +// list of lambda expressions that delegates calls to each of the +// callables. +// +// See e.g. +// https://dev.to/tmr232/that-overloaded-trick-overloading-lambdas-in-c17 +template +struct overloaded : Ts... { + using Ts::operator()...; +}; + +template +overloaded(Ts...) -> overloaded; + +} // namespace nix::util -- cgit 1.4.1