Which C++ type trait is used to determine the size of a particular array dimension?

Options

  • A. std::rank
  • B. std::extent
  • C. std::is_array
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. std::extent

Detailed Explanation

Answer: (B) std::extent

std::extent is a type trait from the <type_traits> header. It is used to obtain the number of elements in a specified dimension of an array type.

For example, for int arr[3][4], std::extent<decltype(arr), 0>::value gives 3, while std::extent<decltype(arr), 1>::value gives 4.

Remember the difference: std::rank gives the number of dimensions, whereas std::extent gives the size of a particular dimension.