Audacity 3.2.0
Namespaces | Functions | Variables
TypeSwitch Namespace Reference

Namespaces

namespace  detail
 

Functions

template<typename R = void, typename Types , class TupleLike , typename... Args>
auto Dispatch (Head_t< Types > &object, const TupleLike &functions, Args &&... args) -> std::enable_if_t< TypeListCheck_v< Types >, R >
 
template<typename R = void, typename Types , typename ... Functions>
auto VDispatch (Head_t< Types > &object, const Functions &...functions)
 

Variables

template<typename TypeList >
constexpr bool TypeListCheck_v
 

Function Documentation

◆ Dispatch()

template<typename R = void, typename Types , class TupleLike , typename... Args>
auto TypeSwitch::Dispatch ( Head_t< Types > &  object,
const TupleLike &  functions,
Args &&...  args 
) -> std::enable_if_t<TypeListCheck_v<Types>, R>

A variadic function taking any number of function objects, each taking

  • a reference to the first of Types or a subclass of it, plus extra aruments, or
  • a first, callable next-function argument, and returning a function, which takes a reference to the first of Types or a subclass, plus extra arguments. (Typically, a generic lambda returning a lambda. That is, it's curried.)

In the first case, the function object returns R or a type convertible to R.

In the second case, the next-function takes no arguments and returns likewise; the partial application of the curried function is then like the first case.

Calls the first in the sequence that accepts the actual type of the object (after any needed partial application).

If none accepts, do nothing and return R{} (or void when R is void).

If one of the curried functions invokes the no-argument function passed into it, the inner call invokes the next applicable function.

There is a compile-time check that all of the given functions are reachable (that is, all have correct signatures, and no function earlier in the list shadows a later function, by accepting a less derived class, without partial application).

A single Callable::OverloadSet might be used instead of this dispatch, when the next-functions are not used, but that would lose the advantage of the compile time checks.

Template Parameters
Rreturned by this function; each given function must return a type convertible to R
Typesa non-empty TypeList; the first is polymorphic and a proper base of all other types; no type is a subclass of any type left of it; and either all are const-qualified, or none are
TupleLikededuced from argument
Args...extra arguments, passed to the functions
Parameters
objectdetermines the function to call by its run-time type
functionstypically lambdas; see above

Definition at line 313 of file TypeSwitch.h.

316{
317 // Generate a function that dispatches dynamically on track type
319 object, functions, std::forward<Args>(args)...);
320}

Referenced by anonymous_namespace{ProjectStatus.cpp}::Dispatcher::NewFieldRegistered(), and AudacityApp::OnExit().

Here is the caller graph for this function:

◆ VDispatch()

template<typename R = void, typename Types , typename ... Functions>
auto TypeSwitch::VDispatch ( Head_t< Types > &  object,
const Functions &...  functions 
)

A variadic function taking any number of function objects, each taking

  • a reference to the first of Types or a subclass of it, plus extra aruments, or
  • a first, callable next-function argument, and returning a function, which takes a reference to the first of Types or a subclass, plus extra arguments. (Typically, a generic lambda returning a lambda. That is, it's curried.)

In the first case, the function object returns R or a type convertible to R.

In the second case, the next-function takes no arguments and returns likewise; the partial application of the curried function is then like the first case.

Calls the first in the sequence that accepts the actual type of the object (after any needed partial application).

If none accepts, do nothing and return R{} (or void when R is void).

If one of the curried functions invokes the no-argument function passed into it, the inner call invokes the next applicable function.

There is a compile-time check that all of the given functions are reachable (that is, all have correct signatures, and no function earlier in the list shadows a later function, by accepting a less derived class, without partial application).

A single Callable::OverloadSet might be used instead of this dispatch, when the next-functions are not used, but that would lose the advantage of the compile time checks.

Template Parameters
Rreturned by this function; each given function must return a type convertible to R
Typesa non-empty TypeList; the first is polymorphic and a proper base of all other types; no type is a subclass of any type left of it; and either all are const-qualified, or none are
TupleLikededuced from argument
Args...extra arguments, passed to the functions
Parameters
objectdetermines the function to call by its run-time type
functionstypically lambdas; see above

Variadic overload of Dispatch; doesn't accept extra arguments

Definition at line 331 of file TypeSwitch.h.

332{
333 return Dispatch<R, Types>(object, std::forward_as_tuple(functions...));
334}

Variable Documentation

◆ TypeListCheck_v

template<typename TypeList >
constexpr bool TypeSwitch::TypeListCheck_v
constexpr
Initial value:
=
std::is_polymorphic_v<Head_t<TypeList>> &&
detail::RootTypeCheck_v<TypeList> &&
Every_v<Fn<detail::InheritanceCheck>, NonEmptyTails_t<TypeList>> &&
(Every_v<Fn<std::is_const>, TypeList> ||
NotAny_v<Fn<std::is_const>, TypeList>)
Utilities for compile-time type manipulation. Some terminology as in Lisp.
Definition: TypeList.h:22
typename NonEmptyTails< TypeList >::type NonEmptyTails_t
Definition: TypeList.h:173

Definition at line 259 of file TypeSwitch.h.