Provide utilities for operating on bdlat
"array" types.
More...
Namespaces |
namespace | bdlat |
Detailed Description
- Outline
-
-
- Purpose:
- Provide utilities for operating on
bdlat
"array" types.
-
- Classes:
-
- See also:
- Component bdlat_arrayfunctions, Component bdlat_typecategory
-
- Description:
- This component provides a utility
struct
, bdlat::ArrayUtil
, which serves as a namespace for a collection of function templates providing derived operations for "array" types. See bdlat_arrayfunctions
for the set of requirements of "array" types in the bdlat
framework. See bdlat_typecategory
for more general information about this framework.
-
- Primitive and Derived Functions of Arrays:
- In order to be "plugged in" to the
bdlat
framework as an "array", a type must meet a set of requirements including providing certain function overloads (customization points) and specifying certain type traits, as specified by the bdlat_arrayfunctions
component. We call the required function overloads the "primitive" operations of "array" types. This component provides "derived" operations, which are operations that are exclusively defined in terms of primitive operations, and as such can be used with any "array" type.
-
- Usage:
- In this section we show intended usage of this component.
-
- Example 1: Accessing an Array Element And Its Category:
- Suppose we would like to define a function that detects whether an element of an array is itself an array, in order to more generally detect nested arrays.
- First, we need to define an accessor functor per
bdlat_typecategory'|'ACCESSOR
Functors that will be used to detect whether an array element is itself an array: class MyArrayDetector {
bool d_didVisitArray;
public:
MyArrayDetector()
: d_didVisitArray(false)
{
}
template <class TYPE>
int operator()(const TYPE& object, bdlat_TypeCategory::Array)
{
d_didVisitArray = true;
return 0;
}
template <class TYPE, class OTHER_CATEGORY>
int operator()(const TYPE&, OTHER_CATEGORY)
{
d_didVisitArray = false;
return 0;
}
bool didVisitArray()
{
return d_didVisitArray;
}
};
Then, we can define a utility struct
, MyArrayUtil
, that provides a function for detecting whether or not an array has an element that is itself an array: Finally, we can use this utility to detect whether elements of array types are themselves arrays: