lokinet/llarp/util/variant.hpp

46 lines
874 B
C++
Raw Normal View History

2019-06-11 20:46:51 +00:00
#ifndef LLARP_VARIANT_HPP
#define LLARP_VARIANT_HPP
#include <absl/types/variant.h>
namespace llarp
{
namespace util
{
template < typename... Ts >
struct _overloaded;
template < typename T, typename... Ts >
2019-06-12 13:15:02 +00:00
struct _overloaded< T, Ts... > : T, _overloaded< Ts... >
2019-06-11 20:46:51 +00:00
{
2019-06-12 13:15:02 +00:00
_overloaded(T&& t, Ts&&... ts)
: T(t), _overloaded< Ts... >(std::forward< Ts >(ts)...)
{
}
2019-06-11 20:46:51 +00:00
using T::operator();
using _overloaded< Ts... >::operator();
};
2019-06-12 13:15:02 +00:00
template < typename T >
struct _overloaded< T > : T
2019-06-11 20:46:51 +00:00
{
2019-06-12 13:15:02 +00:00
_overloaded(T&& t) : T(t)
{
}
2019-06-11 20:46:51 +00:00
using T::operator();
};
template < typename... Ts >
2019-06-12 13:15:02 +00:00
constexpr auto
overloaded(Ts&&... ts) -> _overloaded< Ts... >
2019-06-11 20:46:51 +00:00
{
2019-06-12 13:15:02 +00:00
return _overloaded< Ts... >(std::forward< Ts >(ts)...);
2019-06-11 20:46:51 +00:00
}
} // namespace util
} // namespace llarp
#endif