//========================================================================
/**@file libs/luc_lib/array_help.hpp
* @author Luc Hermitte <EMAIL:hermitte {at} free {dot} fr>
* @version «version»
* @date
* Created: 14th May 2004 \n
* Last Update: 14th May 2004
*/
/*------------------------------------------------------------------------
* Description: «description»
*
*------------------------------------------------------------------------
* History: «history»
* TODO: «missing features»
*========================================================================
*/
#ifndef __LIBS_LUC_LIB_ARRAY_HELP_HPP__
#define __LIBS_LUC_LIB_ARRAY_HELP_HPP__
#include <cstddef>
namespace luc_lib {
template <typename T, int N>
inline const T* begin(const T (&array)[N])
{ return array; }
template <typename T, int N>
inline const T* end(const T (&array)[N])
{ return array + N; }
template <typename T, std::size_t N>
inline std::size_t size(const T (&)[N])
{ return N; }
template <typename T, std::size_t N, std::size_t M>
inline std::size_t size2(const T (&)[N][M])
{ return M; }
// Parfois on a besoin d'une constante de compilation ;
// dans ce cas la solution suivante est applicable :
// Falk Tannhäuser, fclc++,
// Message-ID: <3FCB378C.1A1C6066@crf.canon.fr>
template <std::size_t N>
struct array { char value[N]; };
template<typename T, std::size_t N>
array<N> array_size_helper(T (&)[N]);
#define array_size(array) (sizeof luc_lib::array_size_helper(array).value)
// Gabriel Dos Reis, fclc++,
// Message-ID: <m3u14kya16.fsf@uniton.integrable-solutions.net>
// C'est, entre autres, pour couper court à ces « abus » de macros
// et de templates que j'ai proposé les « constant-valued functions
// »
// http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1521.pdf
// Voir également
// « literals for user-defined types »
// http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1511.pdf
}
#endif // __LIBS_LUC_LIB_ARRAY_HELP_HPP__