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_HPP
0011 #define BOOST_HANA_FUNCTIONAL_OVERLOAD_HPP
0012
0013 #include <boost/hana/config.hpp>
0014 #include <boost/hana/detail/decay.hpp>
0015
0016
0017 namespace boost { namespace hana {
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0035 constexpr auto overload = [](auto&& f1, auto&& f2, ..., auto&& fn) {
0036 return [perfect-capture](auto&& ...x) -> decltype(auto) {
0037 return forwarded(fk)(forwarded(x)...);
0038 };
0039 };
0040 #else
0041 template <typename F, typename ...G>
0042 struct overload_t
0043 : overload_t<F>::type
0044 , overload_t<G...>::type
0045 {
0046 using type = overload_t;
0047 using overload_t<F>::type::operator();
0048 using overload_t<G...>::type::operator();
0049
0050 template <typename F_, typename ...G_>
0051 constexpr explicit overload_t(F_&& f, G_&& ...g)
0052 : overload_t<F>::type(static_cast<F_&&>(f))
0053 , overload_t<G...>::type(static_cast<G_&&>(g)...)
0054 { }
0055 };
0056
0057 template <typename F>
0058 struct overload_t<F> { using type = F; };
0059
0060 template <typename R, typename ...Args>
0061 struct overload_t<R(*)(Args...)> {
0062 using type = overload_t;
0063 R (*fptr_)(Args...);
0064
0065 explicit constexpr overload_t(R (*fp)(Args...))
0066 : fptr_(fp)
0067 { }
0068
0069 constexpr R operator()(Args ...args) const
0070 { return fptr_(static_cast<Args&&>(args)...); }
0071 };
0072
0073 struct make_overload_t {
0074 template <typename ...F,
0075 typename Overload = typename overload_t<
0076 typename detail::decay<F>::type...
0077 >::type
0078 >
0079 constexpr Overload operator()(F&& ...f) const {
0080 return Overload(static_cast<F&&>(f)...);
0081 }
0082 };
0083
0084 BOOST_HANA_INLINE_VARIABLE constexpr make_overload_t overload{};
0085 #endif
0086 }}
0087
0088 #endif