Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
|
The purpose of this utility is to make passing arrays into argument lists easier [Deprecated]. More...
Classes | |
class | Teuchos::ArrayArg< N, T > |
Utility class that allows arrays to be passed into argument list. More... | |
Functions | |
template<class T > | |
TEUCHOS_DEPRECATED ArrayArg< 1, T > | Teuchos::arrayArg (T t1) |
Return an array with 1 member. More... | |
template<class T > | |
TEUCHOS_DEPRECATED ArrayArg< 2, T > | Teuchos::arrayArg (T t1, T t2) |
Return an array with 2 members. More... | |
template<class T > | |
TEUCHOS_DEPRECATED ArrayArg< 3, T > | Teuchos::arrayArg (T t1, T t2, T t3) |
Return an array with 3 members. More... | |
template<class T > | |
TEUCHOS_DEPRECATED ArrayArg< 4, T > | Teuchos::arrayArg (T t1, T t2, T t3, T t4) |
Return an array with 4 members. More... | |
template<class T > | |
TEUCHOS_DEPRECATED ArrayArg< 5, T > | Teuchos::arrayArg (T t1, T t2, T t3, T t4, T t5) |
Return an array with 5 members. More... | |
template<class T > | |
TEUCHOS_DEPRECATED ArrayArg< 6, T > | Teuchos::arrayArg (T t1, T t2, T t3, T t4, T t5, T t6) |
Return an array with 6 members. More... | |
The purpose of this utility is to make passing arrays into argument lists easier [Deprecated].
Declaring arrays outside of a function just to pass a (small) list of values into a function can be tiresome. The templated function arrayArg()
simplifies this process. With this function you can construct (using stack memory not dynamically allocated memory) an array of data to be passed into a function.
For example, consider the following function prototype:
which takes an array of double
s of length x_size
. Generally, to call this function one would have to first declare an array and then call the function as:
Now, however, one can create the array in the call to f()
as:
In the above situation, one may be able to write the call as:
but the former, slightly more verbose, version is to be preferred since it makes explicit what type of array is being created and insures that the compiler will not get confused about the final (implicit) conversion to a raw const double*
pointer.
Note that a copy is made of the array arguments before they are passed into the function so care must be taken when using arrayArg()
to pass a non-const
input-output or output-only array of objects. For example, consider the following function:
The above function f2()
modifies the objects in the array y[]
. If this function is attempted to be called as:
then the objects a
, b
and c
will not be modified as might be expected. Instead, this function must be called as:
However, the arrayArg()
function can be used to pass an array of pointers to non-const
objects. For example, consider the function:
which modifies an array of double
objects through pointers. We could then call this function as:
which will result in objects a
, b
and c
being modified correctly.
Warning! Never try to pass an array of references (which should almost never be used anyway) using arrayArg()
. This will result in the copy constructor being called which is almost never a desirable situation.
The arrayArg()
function is overloaded to accept 1, 2, 3, 4, 5 and 6 arguments. If more elements are needed, then more overrides are easy to add.
|
inline |
Return an array with 1 member.
Definition at line 198 of file Teuchos_arrayArg.hpp.
|
inline |
Return an array with 2 members.
Definition at line 209 of file Teuchos_arrayArg.hpp.
|
inline |
Return an array with 3 members.
Definition at line 220 of file Teuchos_arrayArg.hpp.
|
inline |
Return an array with 4 members.
Definition at line 231 of file Teuchos_arrayArg.hpp.
|
inline |
Return an array with 5 members.
Definition at line 242 of file Teuchos_arrayArg.hpp.
|
inline |
Return an array with 6 members.
Definition at line 253 of file Teuchos_arrayArg.hpp.