Skip to content

Instantly share code, notes, and snippets.

@eklitzke
Created August 28, 2012 19:57
Show Gist options
  • Select an option

  • Save eklitzke/3503475 to your computer and use it in GitHub Desktop.

Select an option

Save eklitzke/3503475 to your computer and use it in GitHub Desktop.
#include <string>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <array>
int main()
{
// construction uses aggregate initialization
std::array<int, 3> a1{ {1,2,3} }; // double-braces required
std::array<int, 3> a2 = {1, 2, 3}; // except after =
std::array<std::string, 2> a3 = { {std::string("a"), "b"} };
// container operations are supported
std::sort(a1.begin(), a1.end());
std::reverse_copy(a2.begin(), a2.end(), std::ostream_iterator<int>(std::cout, " "));
// ranged for loop is supported
for(auto& s: a3)
std::cout << s << ' ';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment