Modify

Opened 16 years ago

Closed 9 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);
}

Attachments (0)

Change History (2)

comment:1 Changed 15 years ago by nobody

Logged In: NO 

-----------------
what's wrong with boost::array<>?

Thorsten Ottosen, nesotto@cs.auc.dk

comment:2 Changed 9 years ago by Steven Watanabe

Resolution: Nonefixed
Severity: Showstopper
Status: assignedclosed

The Range library provides boost::size.

http://www.boost.org/libs/range/doc/boost_range.html#size

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain mark_rodgers.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.