/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_FUNCTIONAL_OVERLOAD_HPP #define RANGES_V3_FUNCTIONAL_OVERLOAD_HPP #include #include #include #include namespace ranges { /// \addtogroup group-functional /// @{ template struct overloaded; template<> struct overloaded<> {}; template struct overloaded { private: RANGES_NO_UNIQUE_ADDRESS First first_; RANGES_NO_UNIQUE_ADDRESS overloaded second_; public: overloaded() = default; constexpr overloaded(First first, Rest... rest) : first_(static_cast(first)) , second_{static_cast(rest)...} {} // clang-format off template auto CPP_auto_fun(operator())(Args &&...args) ( return invoke(first_, static_cast(args)...) ) template auto CPP_auto_fun(operator())(Args &&...args) (const) ( return invoke((First const &) first_, static_cast(args)...) ) template auto CPP_auto_fun(operator())(Args &&...args) ( return second_(static_cast(args)...) ) template auto CPP_auto_fun(operator())(Args &&...args) (const) ( return ((overloaded const &) second_)(static_cast(args)...) ) // clang-format on }; struct overload_fn { template constexpr Fn operator()(Fn fn) const { return fn; } template constexpr overloaded operator()(Fns... fns) const { return overloaded{static_cast(fns)...}; } }; /// \ingroup group-functional /// \sa `overload_fn` RANGES_INLINE_VARIABLE(overload_fn, overload) /// @} } // namespace ranges #endif