Provide a non-allocating class to test variadic function arguments.
More...
Namespaces |
namespace | bsltf |
Detailed Description
- Outline
-
-
- Purpose:
- Provide a non-allocating class to test variadic function arguments.
-
- Classes:
bsltf::ArgumentType<N> | simple wrapper around an in-place int |
- See also:
- Component bsltf_allocargumenttype, Component bsltf_templatetestfacility
-
- Description:
- This component provides a class,
bsltf::ArgumentType<N>
, used for testing functions that take a variable number of template arguments. The integer template parameter enables specification of a number of types without requiring a separate component for each. bsltf::ArgumentType
does not allocate memory, and defines both copy and move constructors.
-
- Attributes:
Name Type Default
------------------ ----------- -------
data int -1
-
data
: representation of the class value
-
- Usage:
- This section illustrates intended use of this component.
-
- Example 1: Passing Arguments of the Correct Type and Order:
- Suppose we wanted to test a function,
forwardData
, that takes a variable number of arguments and forwards them to another function (called delegateFunction
, in this example). Note, that the example below provides separate implementations for compilers that support C++11 standard and those that do not. For clarity, we define forwardData
in line, and limit our expansion of the variadic template to 2 arguments on platforms that don't support variadic templates.
- First, we show the signature to the variadic function
delegateFunction
, that forwardData
(which we wish to test) will forward to (note that the implementation has been elided for simplicity): void delegateFunction();
void delegateFunction(ArgumentType<1> arg01);
void delegateFunction(ArgumentType<1> arg01, ArgumentType<2> arg02);
Then, we define the forwarding function we intend to test: Finally, we define a test case for forwardData
passing ArgumentType
as variadic arguments to the forwardData
function and verifying that compilation succeeds: void usageExample()
{
forwardData();
ArgumentType<1> A01(1);
forwardData(A01);
ArgumentType<1> A11(13);
ArgumentType<2> A12(28);
forwardData(A11, A12);
}