General Utility Library for C++14  2.11
Classes | Functions
gul14/variant.h

Detailed Description

Backport of std::variant from C++17.

Classes

class  gul14::bad_variant_access
 The exception thrown if the wrong type is accessed on a gul14::variant. More...
 
class  gul14::variant< Ts >
 A "type-safe union". More...
 
struct  gul14::OverloadSet< Fct1, Fcts >
 A function object that works like an overload set of functions. More...
 
struct  gul14::OverloadSet< Fct1 >
 OverloadSet for a single function object. More...
 

Functions

virtual const char * gul14::bad_variant_access::what () const noexcept override
 
template<typename Visitor , typename... Variants>
constexpr decltype(auto) gul14::visit (Visitor &&visitor_fct, Variants &&... variants)
 Call a visitor function with the actual objects stored in the given variants. More...
 
 gul14::OverloadSet< Fct1, Fcts >::OverloadSet (Fct1 f1, Fcts... fs)
 
 gul14::OverloadSet< Fct1 >::OverloadSet (Fct1 f1)
 
template<typename... Fct>
auto gul14::make_overload_set (Fct... f)
 Create an OverloadSet from an arbitrary number of function objects. More...
 

Function Documentation

◆ make_overload_set()

template<typename... Fct>
auto gul14::make_overload_set ( Fct...  f)

Create an OverloadSet from an arbitrary number of function objects.

This function creates an OverloadSet from the function objects given to it. This is particularly helpful for using multiple lambdas with visit():

[](int) { std::cout << "int\n"; },
[](double) { std::cout << "double\n"; }
), v);
A "type-safe union".
Definition: variant.h:72
constexpr decltype(auto) visit(Visitor &&visitor_fct, Variants &&... variants)
Call a visitor function with the actual objects stored in the given variants.
auto make_overload_set(Fct... f)
Create an OverloadSet from an arbitrary number of function objects.
Definition: variant.h:139
Since
GUL version 2.9.2

◆ visit()

template<typename Visitor , typename... Variants>
constexpr decltype(auto) gul14::visit ( Visitor &&  visitor_fct,
Variants &&...  variants 
)
inlineconstexpr

Call a visitor function with the actual objects stored in the given variants.

This function works like std::visit from the C++17 standard library. It is often convenient to use it with make_overload_set():

[](int) { std::cout << "int\n"; },
[](double) { std::cout << "double\n"; }
), v);
Since
GUL version 2.9.0