omw  0.2.1-beta
vector.h
1 /*
2 author Oliver Blaser
3 date 13.03.2023
4 copyright MIT - Copyright (c) 2023 Oliver Blaser
5 */
6 
7 #ifndef IG_OMW_VECTOR_H
8 #define IG_OMW_VECTOR_H
9 
10 #include <cstddef>
11 #include <cstdint>
12 #include <initializer_list>
13 #include <memory>
14 #include <string>
15 #include <vector>
16 
17 #include "../omw/string.h"
18 
19 namespace omw
20 {
25  template <class T, class Allocator = std::allocator<T>>
28  bool contains(const typename std::vector<T, Allocator>& v, const T& item)
29  {
30  bool r = false;
31  for (typename std::vector<T, Allocator>::size_type i = 0; i < v.size(); ++i) { if (v[i] == item) { r = true; break; } }
32  return r;
33  }
34 
35  //template <class T, class Allocator = std::allocator<T>>
36  //bool contains(const std::vector<T, Allocator>& v, const T::value_type* item)
37  //{
38  // bool r = false;
39  // for (std::vector<T, Allocator>::size_type i = 0; i < v.size(); ++i) { if (v[i] == item) { r = true; break; } }
40  // return r;
41  //}
42  //template<> bool contains(const std::vector<std::string>&, const std::string::value_type*);
43  //template<> bool contains(const std::vector<omw::string>&, const omw::string::value_type*);
45 
46  template <class T, class Allocator = std::allocator<T>>
47  class vector : public std::vector<T, Allocator>
48  {
49 #ifndef OMWi_DOXYGEN_PREDEFINE
50  public:
51  using value_type = typename std::vector<T, Allocator>::value_type;
52  using size_type = typename std::vector<T, Allocator>::size_type;
53 #endif // OMWi_DOXYGEN_PREDEFINE
54 
55  public:
56  static constexpr size_type maxsz = static_cast<size_type>(-1);
57 
58  public:
59  vector() : std::vector<T, Allocator>() {}
60  explicit vector(size_type count) : std::vector<T, Allocator>(count) {}
61  vector(size_type count, const T& value) : std::vector<T, Allocator>(count, value) {}
62  vector(const T* first, const T* last) : std::vector<T, Allocator>(first, last) {}
63  vector(std::initializer_list<T> init) : std::vector<T, Allocator>(init) {}
64  vector(const std::vector<T, Allocator>& other) : std::vector<T, Allocator>(other) {}
65  ~vector() {}
66 
67  bool contains(const T& item) const { return omw::contains(*this, item); }
68 
69  void reserveAdd(size_type additionalCapacity) { this->reserve(this->size() + additionalCapacity); }
70  };
71 
73 }
74 
75 #endif // IG_OMW_VECTOR_H
omw::vector
Definition: vector.h:48
omw::vector::reserveAdd
void reserveAdd(size_type additionalCapacity)
Definition: vector.h:69
omw
Main namespace.