BDE 4.14.0 Production release
|
Provide a template parameter pack of integers.
This component defines a factory function bslmf::MakeIntegerSequence
that generate a compile-time sequence of increasing integer values starting with 0.
bslmf::MakeIntegerSequence
meets the requirements of the make_integer_sequence
template introduced in the C++14 standard [intseq.intseq] and can be used in a client's code if the compiler supports the C++11 standard.
Note, that this component has no (emulated) support for pre-standard C++11 compilers, as its only purpose is to be used in deduction with template parameter packs. There is no language support to emulate in earlier compilers.
In this section we show intended use of this component.
Suppose we want to initialize a C-Array of known size t_N
with data read from a data source using a library class that provides a variadic template interface that loads a data of variable length into the supplied parameter pack.
First, define a class template DataReader
,
Then, implement a method that loads the specified parameter pack args
with data read from a data source.
Next, for the test purpose provide simple implementation of the recursive variadic read_impl function that streams the index of the C-Array's element to stdout
.
Then, implement the recursion break condition.
Next, define a helper function template readData
that expands the parameter pack of indices I
and invokes the variadic template read
method of the specified reader
object.
Now, define function template readData
that invokes the helper function Note, that the bslmf::MakeIntegerSequence<std::size_t, t_N>
function generates an object of an integer sequence class instantiated with a template parameter pack of integers that will be expanded and used as an array's indices in the helper function when calling the Reader::read(t_T*...)
variadic template function.
Finally, define a data
C-Array and reader
variables and pass them to the readData
function as parameters.
The streaming operator produces output in the following format on stdout
: