Opened 20 years ago
Closed 14 years ago
#87 closed Feature Requests (fixed)
function to get the size of a array
| Reported by: | flier | Owned by: | mark_rodgers |
|---|---|---|---|
| Milestone: | Component: | functional | |
| Version: | None | Severity: | Showstopper |
| Keywords: | Cc: |
Description
why not add a function which can get the size of a
array? just like this
#include <boost/type_traits.hpp>
template <bool IS_CLASS>
struct SizeOfArrayHelper;
template <>
struct SizeOfArrayHelper<false>
{
template<typename T>
static inline int SizeOfArray(const T& array)
{
BOOST_STATIC_ASSERT(boost::is_array<T>::value);
return sizeof(array) / sizeof(array[0]);
}
static inline int SizeOfArray(char *str)
{
return strlen(str);
}
static inline int SizeOfArray(const char *str)
{
return strlen(str);
}
};
template <>
struct SizeOfArrayHelper<true>
{
template<typename T>
static inline int SizeOfArray(const T& array)
{
BOOST_STATIC_ASSERT(boost::is_class<T>::value);
return array.size();
}
};
template <typename T>
inline int SizeOfArray(const T& array)
{
return
SizeOfArrayHelper<boost::is_class<T>::value>::SizeOfArr
ay(array);
}
Change History (2)
comment:2 by , 14 years ago
| Resolution: | None → fixed |
|---|---|
| Severity: | → Showstopper |
| Status: | assigned → closed |
The Range library provides boost::size.
Note:
See TracTickets
for help on using tickets.
