2011-11-12 11:24:42 +00:00
|
|
|
#ifndef SPROUT_VARIANT_APPLY_VISITOR_HPP
|
|
|
|
#define SPROUT_VARIANT_APPLY_VISITOR_HPP
|
|
|
|
|
2012-12-19 14:06:08 +00:00
|
|
|
#include <type_traits>
|
2011-11-12 11:24:42 +00:00
|
|
|
#include <sprout/config.hpp>
|
|
|
|
#include <sprout/utility/forward.hpp>
|
2012-12-19 14:06:08 +00:00
|
|
|
#include <sprout/type_traits/has_xxx.hpp>
|
2011-11-12 11:24:42 +00:00
|
|
|
|
|
|
|
namespace sprout {
|
2012-12-19 14:06:08 +00:00
|
|
|
//
|
|
|
|
// has_visitor_result
|
|
|
|
//
|
|
|
|
SPROUT_HAS_XXX_TEMPLATE_DEF_LAZY(visitor_result);
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
template<typename Visitor, typename Visitable, typename = void>
|
|
|
|
struct visitor_result_impl;
|
|
|
|
template<typename Visitor, typename Visitable>
|
|
|
|
struct visitor_result_impl<
|
|
|
|
Visitor, Visitable,
|
|
|
|
typename std::enable_if<sprout::has_visitor_result<Visitable>::value>::type
|
|
|
|
>
|
|
|
|
: public Visitable::template visitor_result<Visitor, Visitable>
|
|
|
|
{};
|
|
|
|
template<typename Visitor, typename Visitable>
|
|
|
|
struct visitor_result_impl<
|
|
|
|
Visitor, Visitable,
|
|
|
|
typename std::enable_if<!sprout::has_visitor_result<Visitable>::value>::type
|
|
|
|
> {
|
|
|
|
public:
|
|
|
|
typedef typename Visitor::result_type type;
|
|
|
|
};
|
|
|
|
} // namespace detail
|
|
|
|
//
|
|
|
|
// visitor_result
|
|
|
|
//
|
|
|
|
template<typename Visitor, typename Visitable>
|
|
|
|
struct visitor_result
|
|
|
|
: public sprout::detail::visitor_result_impl<Visitor, Visitable>
|
|
|
|
{};
|
|
|
|
|
|
|
|
//
|
|
|
|
// apply_visitor
|
|
|
|
//
|
2011-11-12 11:24:42 +00:00
|
|
|
template<typename Visitor, typename Visitable>
|
2012-12-19 14:06:08 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename sprout::visitor_result<
|
|
|
|
typename std::remove_reference<Visitor>::type,
|
|
|
|
typename std::remove_reference<Visitable>::type
|
|
|
|
>::type
|
2012-10-05 15:58:56 +00:00
|
|
|
apply_visitor(Visitor&& visitor, Visitable&& visitable) {
|
2011-11-12 11:24:42 +00:00
|
|
|
return sprout::forward<Visitable>(visitable).apply_visitor(sprout::forward<Visitor>(visitor));
|
|
|
|
}
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_VARIANT_APPLY_VISITOR_HPP
|