fork(1) download
  1. #include <iostream>
  2. #include <string>
  3.  
  4.  
  5. template <std::size_t N>
  6. void showcolumns_num(std::string (&columns)[N])
  7. {
  8. int columns_num=std::extent<typename std::remove_reference<decltype(columns)>::type>::value;
  9. std::cout<<"function array length: "<<columns_num<<std::endl;
  10. }
  11.  
  12. int main()
  13. {
  14. std::string column_list[]={"col1","col2","col3","col4","col5"};
  15.  
  16. // local calculation of column number
  17. int columns_num=std::extent<decltype(column_list)>::value;
  18. std::cout<<"local array length: "<<columns_num<<std::endl;
  19.  
  20. // function calculation of column number
  21. showcolumns_num(column_list);
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
local array length: 5
function array length: 5