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 <grfn@gws.fyi> Reviewed-by: edef <edef@edef.eu>
This commit is contained in:
parent
2832ea43ea
commit
693661fe87
2 changed files with 20 additions and 0 deletions
1
third_party/nix/src/libutil/CMakeLists.txt
vendored
1
third_party/nix/src/libutil/CMakeLists.txt
vendored
|
@ -25,6 +25,7 @@ set(HEADER_FILES
|
|||
thread-pool.hh
|
||||
types.hh
|
||||
util.hh
|
||||
visitor.hh
|
||||
xml-writer.hh
|
||||
)
|
||||
|
||||
|
|
19
third_party/nix/src/libutil/visitor.hh
vendored
Normal file
19
third_party/nix/src/libutil/visitor.hh
vendored
Normal file
|
@ -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 <class... Ts>
|
||||
struct overloaded : Ts... {
|
||||
using Ts::operator()...;
|
||||
};
|
||||
|
||||
template <class... Ts>
|
||||
overloaded(Ts...) -> overloaded<Ts...>;
|
||||
|
||||
} // namespace nix::util
|
Loading…
Reference in a new issue