// begin() and end() functions for arrays (C++03)
//
// Written in 2012 by Martinho Fernandes
//
// To the extent possible under law, the author(s) have dedicated all copyright and related
// and neighboring rights to this software to the public domain worldwide. This software is
// distributed without any warranty.
//
// You should have received a copy of the CC0 Public Domain Dedication along with this software.
// If not, see <http://c...content-available-to-author-only...s.org/publicdomain/zero/1.0/>.
 
// Installation:
//   Place this into a header file and #include it in your code. Done.
//
// Usage:
//   int array[10];                  // create an array of ten ints
//   int* first = so::begin(array);  // get a pointer to the beginning
//   int* last = so::end(array);     // get a pointer to one past the end
//   size_t n = so::size(array);     // get the size of the array (10)
 
#ifndef SO_BEGIN_END_HPP_INCLUDED
#define SO_BEGIN_END_HPP_INCLUDED

#include <cstddef> // size_t

namespace so {
    template <typename T, std::size_t N>
    T* begin(T(&arr)[N]) { return &arr[0]; }

    template <typename T, std::size_t N>
    T* end(T(&arr)[N]) { return &arr[0] + N; }

    template <typename T, std::size_t N>
    std::size_t size(T(&)[N]) { return N; }
}

#endif
