computer science goes bonk / all posts / rss / about

std::is_array and std::extent in C++11

Rats.

#include <iostream>
#include <type_traits>

void foo(int arr[]);

int main() {
  int arr[10] = {0};

  std::cout 
    << std::boolalpha                      // output:
    << std::is_array<decltype(arr)>::value //  true
    << ' '
    << std::extent<decltype(arr)>::value   //  10
    << '\n';

  foo(arr);
}

void foo(int arr[]) {
  std::cout 
    << std::boolalpha                      // output:
    << std::is_array<decltype(arr)>::value //  false
    << ' '
    << std::extent<decltype(arr)>::value   //  0
    << '\n';
}

(A little background reading)