variant
A type safe generalized union type
Classes | Functions
visitor.hpp File Reference

Implements the function apply_visitor. More...

#include <utility>
#include <type_traits>
#include "variant_storage.hpp"

Go to the source code of this file.

Classes

class  variant< Types >
 A type safe generalized union. More...
 
struct  result_of_visit< Callable, Args >
 Compute the result type of a visit. More...
 
struct  is_nothrow_visitable< Callable, Args >
 Determine if a visit operation might throw. More...
 

Functions

template<class Callable , class... Args>
result_of_visit_t< Callable &&, Args &&...> apply_visitor (Callable &&c, Args &&...args) noexcept(is_nothrow_visitable< Callable &&, Args &&...>::value)
 Calls the provided Callable with the given Args, replacing the variant args with the actual type. More...
 

Detailed Description

Implements the function apply_visitor.

Author
Ennio Barbaro
Date
18 Jan 2015

Function Documentation

template<class Callable , class... Args>
result_of_visit_t<Callable&&, Args&& ...> apply_visitor ( Callable &&  c,
Args &&...  args 
)
noexcept

Calls the provided Callable with the given Args, replacing the variant args with the actual type.

Template Parameters
CallableMust be a function object that can accept all the possible combination of the variant types provided in Args

Example:

apply_visitor(f, variant<int,string>(32) ); //Calls f(32);
apply_visitor(f, variant<int,string>("h"), 5); // Calls f("h", 5);
apply_visitor(f, 12, variant<int,string>("g"), variant<double,string>(32.4)); //Calls f(12, "g", 32.4 );