LLVM API Documentation

Public Member Functions
llvm::VariadicFunction< ResultT, ArgT, Func > Struct Template Reference

Class which can simulate a type-safe variadic function. More...

#include <VariadicFunction.h>

List of all members.

Public Member Functions

ResultT operator() () const

Detailed Description

template<typename ResultT, typename ArgT, ResultT(*)(ArrayRef< const ArgT * >) Func>
struct llvm::VariadicFunction< ResultT, ArgT, Func >

Class which can simulate a type-safe variadic function.

The VariadicFunction class template makes it easy to define type-safe variadic functions where all arguments have the same type.

Suppose we need a variadic function like this:

ResultT Foo(const ArgT &A_0, const ArgT &A_1, ..., const ArgT &A_N);

Instead of many overloads of Foo(), we only need to define a helper function that takes an array of arguments:

ResultT FooImpl(ArrayRef<const ArgT *> Args) { 'Args[i]' is a pointer to the i-th argument passed to Foo(). ... }

and then define Foo() like this:

const VariadicFunction<ResultT, ArgT, FooImpl> Foo;

VariadicFunction takes care of defining the overloads of Foo().

Actually, Foo is a function object (i.e. functor) instead of a plain function. This object is stateless and its constructor/destructor does nothing, so it's safe to create global objects and call Foo(...) at any time.

Sometimes we need a variadic function to have some fixed leading arguments whose types may be different from that of the optional arguments. For example:

bool FullMatch(const StringRef &S, const RE &Regex, const ArgT &A_0, ..., const ArgT &A_N);

VariadicFunctionN is for such cases, where N is the number of fixed arguments. It is like VariadicFunction, except that it takes N more template arguments for the types of the fixed arguments:

bool FullMatchImpl(const StringRef &S, const RE &Regex, ArrayRef<const ArgT *> Args) { ... } const VariadicFunction2<bool, const StringRef&, const RE&, ArgT, FullMatchImpl> FullMatch;

Currently VariadicFunction and friends support up-to 3 fixed leading arguments and up-to 32 optional arguments.

Definition at line 106 of file VariadicFunction.h.


Member Function Documentation

template<typename ResultT , typename ArgT , ResultT(*)(ArrayRef< const ArgT * >) Func>
ResultT llvm::VariadicFunction< ResultT, ArgT, Func >::operator() ( ) const [inline]

Definition at line 107 of file VariadicFunction.h.

References llvm::None.


The documentation for this struct was generated from the following file: