diff options
author | Vincent Ambo <mail@tazj.in> | 2020-07-13T18·54+0100 |
---|---|---|
committer | tazjin <mail@tazj.in> | 2020-07-13T20·14+0000 |
commit | 693661fe8777d6eb5bcf612a5103d1704ec97eff (patch) | |
tree | a18d91b7dbca0c728731d789509618c94772d9bf /third_party | |
parent | 2832ea43ead9d47ced32338d269184c08ec91469 (diff) |
feat(3p/nix/libutil): Add util::overloaded class for std::visitor r/1277
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>
Diffstat (limited to 'third_party')
-rw-r--r-- | third_party/nix/src/libutil/CMakeLists.txt | 1 | ||||
-rw-r--r-- | third_party/nix/src/libutil/visitor.hh | 19 |
2 files changed, 20 insertions, 0 deletions
diff --git a/third_party/nix/src/libutil/CMakeLists.txt b/third_party/nix/src/libutil/CMakeLists.txt index 43b9e8525f78..a9736b37bc05 100644 --- a/third_party/nix/src/libutil/CMakeLists.txt +++ b/third_party/nix/src/libutil/CMakeLists.txt @@ -25,6 +25,7 @@ set(HEADER_FILES thread-pool.hh types.hh util.hh + visitor.hh xml-writer.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 <class... Ts> +struct overloaded : Ts... { + using Ts::operator()...; +}; + +template <class... Ts> +overloaded(Ts...) -> overloaded<Ts...>; + +} // namespace nix::util |