sources/list.h

changeset 87
53c2aecb9704
parent 73
07dda51a7a8e
child 88
08ccaf26cffd
equal deleted inserted replaced
86:3c02a728a681 87:53c2aecb9704
30 30
31 #pragma once 31 #pragma once
32 #include "basics.h" 32 #include "basics.h"
33 #include <algorithm> 33 #include <algorithm>
34 #include <deque> 34 #include <deque>
35 #include <initializer_list>
36 #include <functional> 35 #include <functional>
37 #include <cassert> 36 #include <cassert>
37 #include <vector>
38 #include "range.h" 38 #include "range.h"
39 39
40 // ------------------------------------------------------------------------------------------------- 40 // -------------------------------------------------------------------------------------------------
41 // 41 //
42 template<typename T, typename C> 42 template<typename T, typename C>
55 m_container (numvalues) {} 55 m_container (numvalues) {}
56 56
57 Container (const C& other) : 57 Container (const C& other) :
58 m_container (other) {} 58 m_container (other) {}
59 59
60 Container (std::initializer_list<T>&& a) :
61 m_container (a) {}
62
63 T& append (const T& value) 60 T& append (const T& value)
64 { 61 {
65 m_container.push_back (value); 62 m_container.push_back (value);
66 return m_container[m_container.size() - 1]; 63 return m_container[m_container.size() - 1];
67 } 64 }
327 324
328 // ------------------------------------------------------------------------------------------------- 325 // -------------------------------------------------------------------------------------------------
329 // 326 //
330 327
331 template<typename T> 328 template<typename T>
332 using List = Container<T, std::deque<T>>; 329 class List : public Container<T, std::deque<T> >
330 {
331 public:
332 typedef Container<T, std::deque<T> > Super;
333
334 List(){}
335
336 List (int numvalues) :
337 Super (numvalues) {}
338
339 List (const Super& other) :
340 Super (other) {}
341 };
333 342
334 // ------------------------------------------------------------------------------------------------- 343 // -------------------------------------------------------------------------------------------------
335 // 344 //
336 345
337 template<typename T> 346 template<typename T>
338 class Vector : public Container<T, std::vector<T>> 347 class Vector : public Container<T, std::vector<T> >
339 { 348 {
340 public: 349 public:
341 using Super = Container<T, std::vector<T>>; 350 typedef Container<T, std::vector<T> > Super;
342 using typename Super::Container;
343 351
344 Vector(){} 352 Vector(){}
345 353
346 Vector (T* data, size_t length) : 354 Vector (T* data, size_t length) :
347 Super (std::vector<T> (data, data + length)) {} 355 Super (std::vector<T> (data, data + length)) {}

mercurial