Saturday, October 19, 2013

c++11 std::array

Here's a quickie on the std::array. its a nice wrapper on the old c-style lookup table approach that gives it a std container like feel to it with very little fuss.

#include <iostream>
#include <array>

int main()
{
    std::array<float,3> a = {1,2,3};

    for(auto& b: a)
        std::cout << b << ' ';
    std::cout << "\n";

    std::cout << a[1] << "\n";

    std::array<std::array<float,3>, 3> b
        = {{ {1,2,3},
             {2,4,5},
             {3,6,9} }};

    for(auto& c: b)
        for(auto& d: c)
            std::cout << d << ' ';
    std::cout << "\n";

    std::cout << b[1][2] << "\n";
}

No comments:

Post a Comment