Quick Links:

bal | bbl | bdl | bsl

Classes

Component bslmf_removeextent
[Package bslmf]

Provide a metafunction to return an array type's element type. More...

Classes

struct  bsl::remove_extent< t_TYPE >
struct  bsl::remove_extent< t_TYPE[]>
struct  bsl::remove_extent< t_TYPE[t_SZ]>

Detailed Description

Outline
Purpose:
Provide a metafunction to return an array type's element type.
Classes:
bsl::remove_extent type trait that returns the element type of an array
bsl::remove_extent_t alias to the return type of the bsl::remove_extent
See also:
Component bslmf_decay
Description:
This component provides a metafunction bsl::remove_extent that returns the element type of an array. The functionality is intended to be identical to the C++11 metafunction std::remove_extent. From the C++14 standard:
If T names a type "array of <code>U</code>", the member typedef type shall be U, otherwise T. [ Note: For multidimensional arrays, only the first array dimension is removed. For a type "array of <code>const U</code>", the resulting type is const U. -- end note ]
Usage:
The class template Traverser is used to traverse an array and perform some operation. In order to do its job in the case of two-dimensional arrays, Traverser must hold on to an entire row of the array at a time in order to process it correctly. The row type is determined from the array type using remove_extent:
  template <class ARRAY_TYPE>
  class Traverser {
  public:

#ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
Note that if the current compiler supports alias templates C++11 feature, we can use bsl::remove_extent_t alias to the "result" type of the bsl::remove_extent meta-function, that avoids the ::type suffix and typename prefix in the declaration of the function return type:
      using RowType = bsl::remove_extent_t<ARRAY_TYPE>;
#else
      typedef typename bsl::remove_extent<ARRAY_TYPE>::type RowType;
#endif

  private:
      RowType d_row;  // Might be scalar
      // ...
  };
Now we can see that the row type is the type of the array after having striped off the high-order dimension:
  int main()
  {
      assert((bsl::is_same<int, Traverser<int>::RowType>::value));
      assert((bsl::is_same<int, Traverser<int[]>::RowType>::value));
      assert((bsl::is_same<int, Traverser<int[5]>::RowType>::value));
      typedef const int MyRow[6];
      assert((bsl::is_same<MyRow, Traverser<MyRow[]>::RowType>::value));
      assert((bsl::is_same<int[6], Traverser<int[7][6]>::RowType>::value));

      return 0;
  }