What to use for typedef struct array in c++
I have been implementing a visual debugger in my application using another bit of source code. I ran into an issue when I stumbled across them using this..
struct DebugVertex
{
gkVector3 v;
unsigned int color;
};
typedef utArray<DebugVertex> Buffer;
I found the free library 开发者_运维百科that they are using for utArray, however I like to stick with the included libraries when possible (it seems like they used external libs just cause). This is what the definition of utArray looks like...
template <typename T>
class utArray
{
public:
typedef T *Pointer;
typedef const T *ConstPointer;
typedef T ValueType;
typedef const T ConstValueType;
typedef T &ReferenceType;
typedef const T &ConstReferenceType;
typedef utArrayIterator<utArray<T> > Iterator;
typedef const utArrayIterator<utArray<T> > ConstIterator;
public:
utArray() : m_size(0), m_capacity(0), m_data(0), m_cache(0) {}
utArray(const utArray<T>& o)
: m_size(o.size()), m_capacity(0), m_data(0), m_cache(0)
{
reserve(m_size);
copy(m_data, o.m_data, m_size);
}
Is there anything similar I can use? I am not experienced defining a type based on a struct array so any help would be appreciated.
It looks a lot like a std::vector to me ... (#include <vector>
)
From all standard sequence STL containers probably vector
& deque
are closest to an array (at least to me, I associate random access with arrays...).
The only problem you would have is that STL containers have different naming conventions for the internal typedefs like: iterator, pointer, value type & so on. If you really like typing Buffer::Iterator
instead of Buffer::iterator
then you'll need to have a proxy type over the STL type of your choosing. Something like:
#include <vector>
template <typename T>
class utArray
{
private:
typedef std::vector<T> InnerContainer;
InnerContainer m_innerContainer;
public:
typedef typename InnerContainer::pointer Pointer;
typedef typename const InnerContainer::pointer ConstPointer;
typedef typename InnerContainer::value_type ValueType;
typedef const typename InnerContainer::value_type ConstValueType;
typedef typename InnerContainer::reference ReferenceType;
typedef typename InnerContainer::const_reference ConstReferenceType;
typedef typename InnerContainer::iterator Iterator;
typedef typename InnerContainer::const_iterator ConstIterator;
public:
utArray() {}
utArray(const utArray<T>& o)
: m_innerContainer(o.m_innerContainer)
{
}
};
精彩评论