6#include <bond/core/config.h>
10#include <boost/optional.hpp>
20#if !defined(BOND_NO_CXX14_RETURN_TYPE_DEDUCTION) && !defined(BOND_NO_CXX14_GENERIC_LAMBDAS)
22#if defined(BOND_CXX_17)
23 template<
typename Visitor,
typename T>
24 using invoke_result_of_t = std::invoke_result_t<Visitor, T&>;
26 template<
typename Visitor,
typename T>
27 using invoke_result_of_t = std::result_of_t<Visitor(T&)>;
30template <
typename T,
typename Visitor,
typename Any>
31inline typename boost::disable_if<std::is_void<invoke_result_of_t<Visitor, T> >, boost::optional<invoke_result_of_t<Visitor, T> > >::type
32try_visit_any(Visitor&& visitor, Any& x)
34 if (
auto value = any_cast<T>(&x))
36 return std::forward<Visitor>(visitor)(*value);
42template <
typename T,
typename Visitor,
typename Any>
43inline typename boost::enable_if<std::is_void<invoke_result_of_t<Visitor, T> >,
bool>::type
44try_visit_any(Visitor&& visitor, Any& x)
46 if (
auto value = any_cast<T>(&x))
48 std::forward<Visitor>(visitor)(*value);
55template <
typename List,
typename Visitor,
typename Any>
56inline auto visit_any(Visitor&& visitor, Any& x)
58 return mpl::try_apply<List>(
62 return try_visit_any<typename decltype(identity)::type>(std::forward<Visitor>(visitor), x);
68template <
typename Result,
typename Visitor,
typename Any>
71 try_visit_any(Visitor& visitor, Any& x)
76 try_visit_any& operator=(
const try_visit_any& other) =
delete;
78 template <
typename T,
typename R = Result>
79 typename boost::disable_if<std::is_void<R>, boost::optional<Result> >::type
80 operator()(
const mpl::identity<T>&)
const
82 if (
auto value = any_cast<T>(&_x))
84 return _visitor(*value);
90 template <
typename T,
typename R = Result>
91 typename boost::enable_if<std::is_void<R>,
bool>::type
92 operator()(
const mpl::identity<T>&)
const
94 if (
auto value = any_cast<T>(&_x))
107template <
typename T>
struct
110 using type = boost::optional<T>;
119template <
typename Result,
typename Visitor,
typename Any,
typename T,
typename... U>
120inline typename visitor_result<Result>::type visit_any(Visitor&& visitor, Any& x,
const mpl::list<T, U...>&)
122 return mpl::try_apply<mpl::list<T, U...> >(try_visit_any<Result, Visitor, Any>(visitor, x));
125template <
typename List,
typename Result,
typename Visitor,
typename Any>
126inline typename visitor_result<Result>::type visit_any(Visitor&& visitor, Any& x)
128 return visit_any<Result>(std::forward<Visitor>(visitor), x, List{});
namespace bond
Definition: apply.h:17