1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <iostream>
#include <array>
using namespace std::literals;
int main()
{
//Explicitely mentioning size
int foo[5] {1, 2, 3, 4, 5};
std::array<int, 5> bar {1, 2, 3, 4, 5};
//Deducing size from init list
int c_array[] = {0, 1, 0}; //arr has type int[3]
auto cpp_array = std::make_array(0, 1, 0); //C++17
//String literals converted to constant character pointers
auto cp_array = std::make_array("Hello", "World"); //cp_array value_type is const char*
//Explicitely mentioning type:
auto str_array = std::make_array<std::string>("Hello", "World") //str_array value_type is std::string
//Using type deduction and string literals:
auto s_array = std::make_array("Hello"s, "World"s); //s_array value_type is std::string
}
|