You.i Engine
YiSmallVector.h
Go to the documentation of this file.
1 // © You i Labs Inc. All rights reserved.
2 #ifndef _YI_SMALL_VECTOR_H_
3 #define _YI_SMALL_VECTOR_H_
4 
5 #include <framework/YiPredef.h>
6 
7 #include <vector>
8 
9 template<typename T, size_t StackCapacity>
11 
33 template<typename T, size_t StackCapacity>
35 {
36 public:
37  using ContainerType = std::vector<T, CYIStackAllocator<T, StackCapacity>>;
38  using ValueType = typename ContainerType::value_type;
39  using Allocator = decltype(std::declval<ContainerType>().get_allocator());
40 
46 
56 
60  const ContainerType &GetContainer() const;
61 
71  const ContainerType *operator->() const;
72 
76  T &operator[](size_t index);
77  const T &operator[](size_t index) const;
78 
82  size_t size() const;
83 
87  bool empty() const;
88 
92  bool IsStackStorageUsed() const;
93 
100 
104  template<typename NewAllocator = std::allocator<T>>
105  std::vector<T, NewAllocator> CopyContainer() const;
106 
110  template<typename NewAllocator = std::allocator<T>>
111  std::vector<T, NewAllocator> MoveContainer();
112 
113  auto begin() -> decltype(std::declval<ContainerType>().begin());
114  auto begin() const -> decltype(std::declval<const ContainerType>().begin());
115  auto cbegin() const -> decltype(std::declval<const ContainerType>().cbegin());
116  auto end() -> decltype(std::declval<ContainerType>().end());
117  auto end() const -> decltype(std::declval<const ContainerType>().end());
118  auto cend() const -> decltype(std::declval<const ContainerType>().cend());
119 
120  auto rbegin() -> decltype(std::declval<ContainerType>().rbegin());
121  auto rbegin() const -> decltype(std::declval<const ContainerType>().rbegin());
122  auto crbegin() const -> decltype(std::declval<const ContainerType>().crbegin());
123  auto rend() -> decltype(std::declval<ContainerType>().rend());
124  auto rend() const -> decltype(std::declval<const ContainerType>().rend());
125  auto crend() const -> decltype(std::declval<const ContainerType>().crend());
126 
127  bool operator==(const CYISmallVector<T, StackCapacity> &other) const;
128  bool operator!=(const CYISmallVector<T, StackCapacity> &other) const;
129  bool operator<(const CYISmallVector<T, StackCapacity> &other) const;
130  bool operator<=(const CYISmallVector<T, StackCapacity> &other) const;
131  bool operator>(const CYISmallVector<T, StackCapacity> &other) const;
132  bool operator>=(const CYISmallVector<T, StackCapacity> &other) const;
133 
134 private:
135  ContainerType m_container;
136  typename Allocator::Storage m_storage;
137 };
138 
141 #include "utility/internal/YiSmallVector.inl"
142 
143 #endif // _YI_SMALL_VECTOR_H_
ContainerType & GetContainer()
A std::vector wrapper that makes use of pre-allocated memory for storing up to StackCapacity items...
Definition: YiSmallVector.h:34
auto crbegin() const -> decltype(std::declval< const ContainerType >().crbegin())
typename ContainerType::value_type ValueType
Definition: YiSmallVector.h:38
bool empty() const
T & operator[](size_t index)
STL namespace.
auto rend() -> decltype(std::declval< ContainerType >().rend())
auto rbegin() -> decltype(std::declval< ContainerType >().rbegin())
auto cbegin() const -> decltype(std::declval< const ContainerType >().cbegin())
void Swap(CYISmallVector< T, StackCapacity > &other)
Definition: YiSmallVector.h:10
ContainerType * operator->()
auto end() -> decltype(std::declval< ContainerType >().end())
std::vector< T, NewAllocator > MoveContainer()
auto crend() const -> decltype(std::declval< const ContainerType >().crend())
auto begin() -> decltype(std::declval< ContainerType >().begin())
std::vector< T, NewAllocator > CopyContainer() const
auto cend() const -> decltype(std::declval< const ContainerType >().cend())
decltype(std::declval< ContainerType >().get_allocator()) Allocator
Definition: YiSmallVector.h:39
std::vector< CYIMesh::VertexBuffer, CYIStackAllocator< CYIMesh::VertexBuffer, StackCapacity > > ContainerType
Definition: YiSmallVector.h:37
bool IsStackStorageUsed() const
size_t size() const
CYISmallVector< T, StackCapacity > & operator=(const CYISmallVector< T, StackCapacity > &other)