File indexing completed on 2025-01-18 09:37:58
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_FUNCTIONAL_OVERLOAD_LINEARLY_HPP
0011 #define BOOST_HANA_FUNCTIONAL_OVERLOAD_LINEARLY_HPP
0012
0013 #include <boost/hana/config.hpp>
0014 #include <boost/hana/detail/decay.hpp>
0015
0016 #include <utility>
0017
0018
0019 namespace boost { namespace hana {
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0038 constexpr auto overload_linearly = [](auto&& f1, auto&& f2, ..., auto&& fn) {
0039 return [perfect-capture](auto&& ...x) -> decltype(auto) {
0040 return forwarded(fk)(forwarded(x)...);
0041 };
0042 };
0043 #else
0044 template <typename F, typename G>
0045 struct overload_linearly_t {
0046 F f;
0047 G g;
0048
0049 private:
0050 template <typename ...Args, typename =
0051 decltype(std::declval<F const&>()(std::declval<Args>()...))>
0052 constexpr F const& which(int) const& { return f; }
0053
0054 template <typename ...Args, typename =
0055 decltype(std::declval<F&>()(std::declval<Args>()...))>
0056 constexpr F& which(int) & { return f; }
0057
0058 template <typename ...Args, typename =
0059 decltype(std::declval<F&&>()(std::declval<Args>()...))>
0060 constexpr F which(int) && { return static_cast<F&&>(f); }
0061
0062 template <typename ...Args>
0063 constexpr G const& which(long) const& { return g; }
0064
0065 template <typename ...Args>
0066 constexpr G& which(long) & { return g; }
0067
0068 template <typename ...Args>
0069 constexpr G which(long) && { return static_cast<G&&>(g); }
0070
0071 public:
0072 template <typename ...Args>
0073 constexpr decltype(auto) operator()(Args&& ...args) const&
0074 { return which<Args...>(int{})(static_cast<Args&&>(args)...); }
0075
0076 template <typename ...Args>
0077 constexpr decltype(auto) operator()(Args&& ...args) &
0078 { return which<Args...>(int{})(static_cast<Args&&>(args)...); }
0079
0080 template <typename ...Args>
0081 constexpr decltype(auto) operator()(Args&& ...args) &&
0082 { return which<Args...>(int{})(static_cast<Args&&>(args)...); }
0083 };
0084
0085 struct make_overload_linearly_t {
0086 template <typename F, typename G>
0087 constexpr overload_linearly_t<
0088 typename detail::decay<F>::type,
0089 typename detail::decay<G>::type
0090 > operator()(F&& f, G&& g) const {
0091 return {static_cast<F&&>(f), static_cast<G&&>(g)};
0092 }
0093
0094 template <typename F, typename G, typename ...H>
0095 constexpr decltype(auto) operator()(F&& f, G&& g, H&& ...h) const {
0096 return (*this)(static_cast<F&&>(f),
0097 (*this)(static_cast<G&&>(g), static_cast<H&&>(h)...));
0098 }
0099
0100 template <typename F>
0101 constexpr typename detail::decay<F>::type operator()(F&& f) const {
0102 return static_cast<F&&>(f);
0103 }
0104 };
0105
0106 BOOST_HANA_INLINE_VARIABLE constexpr make_overload_linearly_t overload_linearly{};
0107 #endif
0108 }}
0109
0110 #endif