You.i Engine
YiSmallVector.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2020. All rights reserved.
2 #ifndef _YI_SMALL_VECTOR_H_
3 #define _YI_SMALL_VECTOR_H_
4 
5 #include <vector>
6 
7 template<typename T, size_t StackCapacity>
9 
31 template<typename T, size_t StackCapacity>
33 {
34 public:
35  using ContainerType = std::vector<T, CYIStackAllocator<T, StackCapacity>>;
36  using ValueType = typename ContainerType::value_type;
37  using Allocator = decltype(std::declval<ContainerType>().get_allocator());
38 
44 
54 
58  const ContainerType &GetContainer() const;
59 
69  const ContainerType *operator->() const;
70 
74  T &operator[](size_t index);
75  const T &operator[](size_t index) const;
76 
80  size_t size() const;
81 
85  bool empty() const;
86 
90  bool IsStackStorageUsed() const;
91 
98 
102  template<typename NewAllocator = std::allocator<T>>
103  std::vector<T, NewAllocator> CopyContainer() const;
104 
108  template<typename NewAllocator = std::allocator<T>>
109  std::vector<T, NewAllocator> MoveContainer();
110 
111  auto begin() -> decltype(std::declval<ContainerType>().begin());
112  auto begin() const -> decltype(std::declval<const ContainerType>().begin());
113  auto cbegin() const -> decltype(std::declval<const ContainerType>().cbegin());
114  auto end() -> decltype(std::declval<ContainerType>().end());
115  auto end() const -> decltype(std::declval<const ContainerType>().end());
116  auto cend() const -> decltype(std::declval<const ContainerType>().cend());
117 
118  auto rbegin() -> decltype(std::declval<ContainerType>().rbegin());
119  auto rbegin() const -> decltype(std::declval<const ContainerType>().rbegin());
120  auto crbegin() const -> decltype(std::declval<const ContainerType>().crbegin());
121  auto rend() -> decltype(std::declval<ContainerType>().rend());
122  auto rend() const -> decltype(std::declval<const ContainerType>().rend());
123  auto crend() const -> decltype(std::declval<const ContainerType>().crend());
124 
125  bool operator==(const CYISmallVector<T, StackCapacity> &other) const;
126  bool operator!=(const CYISmallVector<T, StackCapacity> &other) const;
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 
132 private:
133  ContainerType m_container;
134  typename Allocator::Storage m_storage;
135 };
136 
139 #include "YiSmallVector.inl"
140 
141 #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:32
auto crbegin() const -> decltype(std::declval< const ContainerType >().crbegin())
typename ContainerType::value_type ValueType
Definition: YiSmallVector.h:36
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:8
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:37
std::vector< CYIMesh::VertexBuffer, CYIStackAllocator< CYIMesh::VertexBuffer, StackCapacity > > ContainerType
Definition: YiSmallVector.h:35
bool IsStackStorageUsed() const
size_t size() const
CYISmallVector< T, StackCapacity > & operator=(const CYISmallVector< T, StackCapacity > &other)