Tools for better usability of boost::variant
, eggs::variant
and potentially other implementations of sum types.
More...
Classes | |
struct | otherwise_t |
Wraps a functor such that it has a fixed return value. More... | |
struct | variant_types |
Metafunction that for a given type T , returns a meta::pack containing the list of types that can be held in the variant. More... | |
struct | variant_types_impl |
Given an unqualified variant type T , returns a meta::pack with the alternatives in the variant. More... | |
struct | variant_types_impl< boost::variant< T, Ts... > > |
struct | variant_types_impl< eggs::variants::variant< Ts... > > |
struct | variant_types_impl< meta::pack< Ts... > > |
struct | visitor_result_of |
struct | visitor_result_of< FnT, meta::pack< VariantTs... > > |
class | visitor_t |
General visitor based on a set of function objects. More... | |
struct | when_t |
Wraps a functor such that it has a fixed argument list. More... | |
Typedefs | |
using | eggs_t = meta::copy_decay_t< VariantT, meta::unpack< eggs::variant, variant_types_t< estd::decay_t< VariantT > > > > |
template<typename FnT , typename... VariantTs> | |
using | visitor_result_of_t = typename visitor_result_of< FnT, VariantTs... >::type |
Functions | |
template<typename VariantT , typename... FnTs> | |
auto | match (VariantT &variant, FnTs &&...fns) -> estd::enable_if_t< detail::is_boost_variant< estd::decay_t< VariantT > > |
Destructure a boost::variant with a given set of functions. More... | |
template<typename VariantT , typename... FnTs> | |
auto | match (const VariantT &variant, FnTs &&...fns) -> estd::enable_if_t< detail::is_boost_variant< estd::decay_t< VariantT > > |
template<typename VariantT , typename... FnTs> | |
auto | match (VariantT &&variant, FnTs &&...fns) -> estd::enable_if_t< detail::is_eggs_variant< estd::decay_t< VariantT > > |
Destructure a eggs::variant with a given set of functions. More... | |
ABL_METAFUNCTION_T (variant_types) | |
template<typename ReturnType = void, typename Fn = detail::default_construct<ReturnType>> | |
otherwise_t< Fn, ReturnType > | otherwise (Fn &&fn=Fn()) |
template<typename... Args, typename Fn > | |
when_t< Fn, typename boost::mpl::if_< std::is_reference< Args >, Args, const Args & >::type... > | when (Fn &&fn) |
Factory for when functors. More... | |
template<typename... FnTs> | |
auto | visitor (FnTs &&...fns) -> visitor_t< meta::common_type_t< typename std::result_of< FnTs(meta::bottom)>::type... >, FnTs... > |
Returns a visitor object that can be used to deconstruct various variant types, created by composing the functions fns... . More... | |
template<typename FnT > | |
auto | visitor (FnT &&fn) -> FnT && |
template<typename VariantT , typename... FnTs> | |
auto | visitor_for (FnTs &&...fns) -> visitor_t< visitor_result_of_t< detail::visitor_impl< FnTs... >, variant_types_t< VariantT > >, FnTs... > |
Like visitor, but it uses the variant_types in VariantT to deduce what the return type of the visitor should be. More... | |
template<typename VarianT , typename FnT > | |
auto | visitor_for (FnT &&fn) -> FnT && |
Detailed Description
Tools for better usability of boost::variant
, eggs::variant
and potentially other implementations of sum types.
Function Documentation
auto atria::variant::match | ( | VariantT && | variant, |
FnTs &&... | fns | ||
) | -> estd::enable_if_t< detail::is_eggs_variant<estd::decay_t<VariantT> > |
Destructure a eggs::variant
with a given set of functions.
This uses C++ function overload rules to pick the right function. If the passed in variant is a non-const l-value, alternatives can destructure by reference and mutate the variant in place.
- Note
- This method can destructure either instances of
eggs::variant<...>
or for subclasses ofeggs::variant<Ts...>
for whichmeta::variant_types
is defined to returnmeta::pack<Ts...>
.
- Returns
- The return type is deduced as the
meta::common_type<>
of the result of destructuring all alternatives in the variant.
Definition at line 66 of file match_eggs.hpp.
auto atria::variant::match | ( | VariantT & | variant, |
FnTs &&... | fns | ||
) | -> estd::enable_if_t< detail::is_boost_variant<estd::decay_t<VariantT> > |
Destructure a boost::variant
with a given set of functions.
This uses C++ function overload rules to pick the right function. If the passed in variant is a non-const l-value, alternatives can destructure by reference and mutate the variant in place.
- Note
- This method can destructure either instances of
boost::variant<...>
or for subclasses ofboost::variant<Ts...>
for whichmeta::variant_types
is defined to returnmeta::pack<Ts...>
. -
boost::variant
does not support destructuring by r-value reference, and so doesn't this.
- Returns
- The return type is deduced as the
meta::common_type<>
of the result of destructuring all alternatives in the variant.
Definition at line 69 of file match_boost.hpp.
auto atria::variant::visitor | ( | FnTs &&... | fns | ) | -> visitor_t< meta::common_type_t< typename std::result_of<FnTs(meta::bottom)>::type...>, FnTs...> |
Returns a visitor object that can be used to deconstruct various variant types, created by composing the functions fns...
.
It attempts to deduce the return type of the function, but this might fail when generic functions are passed in.
Definition at line 253 of file visitor.hpp.
auto atria::variant::visitor_for | ( | FnTs &&... | fns | ) | -> visitor_t< visitor_result_of_t< detail::visitor_impl<FnTs...>, variant_types_t<VariantT> >, FnTs...> |
Like visitor, but it uses the variant_types
in VariantT
to deduce what the return type of the visitor should be.
This allows it to deduce it even if generic functions are passed in.
Definition at line 274 of file visitor.hpp.
when_t<Fn, typename boost::mpl::if_<std::is_reference<Args>, Args, const Args&>::type...> atria::variant::when | ( | Fn && | fn | ) |
Factory for when functors.
Returns a wrapper for functor F with signature fixed to Args
. Copy arguments are converted to const&
, which eases use with std::bind
and std::mem_fn
.
Definition at line 191 of file visitor.hpp.