The std::end
function in C ++ 11 has an overload for array types that demonstrate this well. It can be executed here:
template< class T, std::size_t N > T* end(T(&array)[N]) { return array + N; }
If you need an object that wraps an array, the templated factory function will help you create it:
template< class T, std::size_t N > struct fifo { T(&array)[N]; }; template< class T, std::size_t N > fifo<T,N> make_fifo(T(&array)[N]) { return Fifo<T,N>{ array }; } int main() { int arr[] = { 1,2,3,4,5 };
source share