// -*-C++-*- array.hpp // // // // // // // // // // // // Author: Dietmar Kuehl dietmar.kuehl@claas-solutions.de // Title: STL container support, including support for built-in arrays // Version: $Id$ // -------------------------------------------------------------------------- #if !defined(BOOST_ARRAY_HPP) #define BOOST_ARRAY_HPP 1 // -------------------------------------------------------------------------- #include // -------------------------------------------------------------------------- namespace boost { // --- a general version of container traits ------------------------------ template struct array_traits { typedef typename Cont::iterator iter_type; typedef typename Cont::size_type size_type; static iter_type begin(Cont &cont) { return cont.begin(); } static iter_type end(Cont &cont) { return cont.end(); } static size_type size(Cont &cont) { return cont.size(); } }; // --- a version of container traits for constant constainer -------------- template struct array_traits { typedef typename Cont::const_iterator iter_type; typedef typename Cont::size_type size_type; static iter_type begin(Cont const &cont) { return cont.begin(); } static iter_type end(Cont const &cont) { return cont.end(); } static size_type size(Cont const &cont) { return cont.size(); } }; // --- a special version for non-const built-in arrays -------------------- template struct array_traits { typedef T* iter_type; typedef size_t size_type; static iter_type begin(T (&array)[sz]) { return array; } static iter_type end(T (&array)[sz]) { return array + sz; } static size_type size(T (&)[sz]) { return sz; } }; // --- a special version for const built-in arrays ------------------------ template struct array_traits { typedef T const* iter_type; typedef size_t size_type; static iter_type begin(T const (&array)[sz]) { return array; } static iter_type end(T const (&array)[sz]) { return array + sz; } static size_type size(T const (&array)[sz]) { return sz; } }; template inline char (&sizer(T (&)[sz]))[sz]; // --- general version of the global accessor functions --------------------- template inline typename array_traits::iter_type begin(Cont &cont) { return array_traits::begin(cont); } template inline typename array_traits::iter_type end(Cont &cont) { return array_traits::end(cont); } template inline typename array_traits::size_type size(Cont &cont) { return array_traits::size(cont); } // --- Actually the above should be sufficient but compilers seem ----------- // --- to welcome some help. So here we go: template inline typename array_traits::iter_type begin(T (&a)[sz]) { return array_traits::begin(a); } template inline typename array_traits::iter_type end(T (&a)[sz]) { return array_traits::end(a); } template inline typename array_traits::size_type size(T (&a)[sz]) { return array_traits::size(a); } // --- Apparently the compilers also need some specific help, --------------- // --- EDG-2.39 wants to pass around pointers in some contexts -------------- #ifdef __EDG__ template struct array_traits { typedef T* iter_type; typedef size_t size_type; }; #endif // --- egcs-1998-11-22 apparently likes an extra const version: ------------- #ifdef __GNUG__ template inline typename array_traits::iter_type begin(T const(&a)[sz]) { return array_traits::begin(a); } template inline typename array_traits::iter_type end(T const(&a)[sz]) { return array_traits::end(a); } template inline typename array_traits::size_type size(T const (&a)[sz]) { return array_traits::size(a); } #endif } // ----------------------------------------------------------------------------- #endif /* BOOST_ARRAY_HPP */