Function visit

Summary

#include <include/type_safe/visitor.hpp>

(1) template <typename Visitor, class... Optionals, typename std::enable_if< detail::all_of< detail::is_optional< Optionals >::value... >::value, int >::type = 0>
    auto visit(Visitor &&visitor, Optionals &&... optionals) -> decltype(detail::visit_optional_impl(std::forward< Visitor >(visitor), std::forward< Optionals >(optionals)...))

(2) template <class Visitor, class... Variants, typename = typename std::enable_if<              detail::all_of<detail::is_variant<Variants>::value...>::value>::type>
    auto visit(Visitor &&visitor, Variants &&... variants) -> decltype(detail::visit_variant(std::forward< Visitor >(visitor), std::forward< Variants >(variants)...))

Function overload

Synopsis

#include <include/type_safe/visitor.hpp>

template <typename Visitor, class... Optionals, typename std::enable_if< detail::all_of< detail::is_optional< Optionals >::value... >::value, int >::type = 0>
auto visit(Visitor &&visitor, Optionals &&... optionals) -> decltype(detail::visit_optional_impl(std::forward< Visitor >(visitor), std::forward< Optionals >(optionals)...))

Description

Visits a [ts::basic_optional](). \effects Effectively calls visitor((optionals.has_value() ? optionals.value() : nullopt)...), i.e. the operator() of visitor passing it sizeof...(Optionals) arguments, where the ith argument is the value() of the ith optional or nullopt, if it has none. If the particular combination of types is not overloaded, the program is ill-formed, unless the Visitor provides a member named incomplete_visitor, then visit() does not do anything instead of the error.

Returns
The result of the chosen operator(), its the type is the common type of all possible combinations. \module optional \exclude return
Parameters

2 - \exclude

Mentioned in

Source

Lines 155-165 in include/type_safe/visitor.hpp.

template <typename Visitor, class... Optionals,
          typename std::enable_if<detail::all_of<detail::is_optional<Optionals>::value...>::value,
                                  int>::type
          = 0>
auto visit(Visitor&& visitor, Optionals&&... optionals)
    -> decltype(detail::visit_optional_impl(std::forward<Visitor>(visitor),
                                            std::forward<Optionals>(optionals)...))
{
    return detail::visit_optional_impl(std::forward<Visitor>(visitor),
                                       std::forward<Optionals>(optionals)...);
}

Synopsis

#include <include/type_safe/visitor.hpp>

template <class Visitor, class... Variants, typename = typename std::enable_if<              detail::all_of<detail::is_variant<Variants>::value...>::value>::type>
auto visit(Visitor &&visitor, Variants &&... variants) -> decltype(detail::visit_variant(std::forward< Visitor >(visitor), std::forward< Variants >(variants)...))

Description

Visits a [ts::basic_variant](). \effects Effectively calls visitor(variants.value(variant_type<Ts>{})...), where Ts... are the types of the currently active element in the variant, i.e. it calls the operator() of the visitor where the ith argument is the currently stored value in the ith variant, perfectly forwarded. If the ith variant is empty and it allows the empty state, it passes nullvar as parameter, otherwise the behavior is undefined. If the particular combination of types is not overloaded, the program is ill-formed, unless the Visitor provides a member named incomplete_visitor, then visit() does not do anything instead of the error.

Returns
The result of the chosen operator(), its the type is the common type of all possible combinations. \exclude return \module variant

Mentioned in

Source

Lines 392-401 in include/type_safe/visitor.hpp.

template <class Visitor, class... Variants,
          typename = typename std::enable_if<
              detail::all_of<detail::is_variant<Variants>::value...>::value>::type>
auto visit(Visitor&& visitor, Variants&&... variants)
    -> decltype(detail::visit_variant(std::forward<Visitor>(visitor),
                                      std::forward<Variants>(variants)...))
{
    return detail::visit_variant(std::forward<Visitor>(visitor),
                                 std::forward<Variants>(variants)...);
}





Add Discussion as Guest

Log in