pytorch/c10/util/overloaded.h
Scott Wolchok 44cc873fba [PyTorch] Autoformat c10 (#56830)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/56830

Opt into formatting on GitHub and format everything. This is a trial run before turning on formatting for more and eventually all of the codebase.

Test Plan: CI

Reviewed By: zertosh

Differential Revision: D27979080

fbshipit-source-id: a80f0c48691c08ae8ca0af06377b87e6a2351151
2021-04-30 21:23:28 -07:00

31 lines
709 B
C++

#pragma once
namespace c10 {
namespace detail {
template <class... Ts>
struct overloaded_t {};
template <class T0>
struct overloaded_t<T0> : T0 {
using T0::operator();
overloaded_t(T0 t0) : T0(std::move(t0)) {}
};
template <class T0, class... Ts>
struct overloaded_t<T0, Ts...> : T0, overloaded_t<Ts...> {
using T0::operator();
using overloaded_t<Ts...>::operator();
overloaded_t(T0 t0, Ts... ts)
: T0(std::move(t0)), overloaded_t<Ts...>(std::move(ts)...) {}
};
} // namespace detail
// Construct an overloaded callable combining multiple callables, e.g. lambdas
template <class... Ts>
detail::overloaded_t<Ts...> overloaded(Ts... ts) {
return {std::move(ts)...};
}
} // namespace c10