Loading...
Searching...
No Matches
tucontainable.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#include "core/ast/param.hpp"
5#include <type_traits>
6
7namespace by {
8
9 class node;
10 template <typename T, typename R, typename RSquare> class tnucontainer;
11 template <typename T, typename TACTIC> class tnarr;
12 typedef class _nout tnarr<node, strTactic> narr;
13 template <typename K, typename V> class tbicontainable;
14
20 template <typename T, typename R = T*, typename RSquare = T&> class tucontainable {
22 static constexpr nbool _IS_POINTER = std::is_pointer_v<R>;
23
24 public:
26
27 public:
28 virtual ~tucontainable();
29
30 // len:
31 virtual ncnt len() const = 0;
32
33 nbool in(const T& it) const;
34 nbool in(const T* it) const BY_SIDE_FUNC(in);
35 nbool in(std::function<nbool(const T&)> l) const;
36 template <typename T1> nbool in(std::function<nbool(const T1&)> l) const;
37
38 nbool isEmpty() const;
39
40 // get:
41 template <typename T1> std::conditional_t<_IS_POINTER, T1*, tmay<T1>> get(std::function<nbool(const T1&)> l) {
42 for(auto e = begin(); e; ++e) {
43 if constexpr(_IS_POINTER) {
44 T1& val = e->template cast<T1>() OR_CONTINUE;
45 if(!l(val)) continue;
46 return &val;
47 } else {
48 T1& val = e.get().template cast<T1>() OR_CONTINUE;
49 if(!l(val)) continue;
50 return tmay<T1>(val);
51 }
52 }
53
54 if constexpr(_IS_POINTER) return nullptr;
55 else return tmay<T1>();
56 }
57
58 std::conditional_t<_IS_POINTER, R, tmay<R>> get(std::function<nbool(const T&)> l) { return this->get<T>(l); }
59
60 template <typename T1>
61 std::conditional_t<_IS_POINTER, const T1*, tmay<T1>> get(std::function<nbool(const T1&)> l) const
62 BY_CONST_FUNC(get(l))
63 std::conditional_t<_IS_POINTER, const R, tmay<R>> get(std::function<nbool(const T&)> l) const
64 BY_CONST_FUNC(get(l))
65
66 template <typename T1> tnarr<T1, strTactic> getAll(std::function<nbool(const T1&)> l) const;
67 tnarr<T, strTactic> getAll(std::function<nbool(const T&)> l) const;
68
69 template <typename T1> void each(std::function<nbool(T1&)> l);
70 void each(std::function<nbool(T&)> l);
71 template <typename T1> void each(std::function<nbool(const T1&)> l) const BY_CONST_FUNC(each(l))
72 void each(std::function<nbool(const T&)> l) const BY_CONST_FUNC(each(l))
73
74 // iter:
75 iter begin() const;
76 iter rbegin() const;
77
78 virtual iter end() const;
79 virtual iter rend() const;
80
81 virtual iter last() const;
82
83 iter iterate(ncnt step) const;
84 iter iterate(const T& it) const;
85
86 iter riterate(ncnt step) const;
87 iter riterate(const T& it) const;
88
89 // set:
90 virtual nbool set(const iter& at, const T& new1) = 0;
91 virtual nbool set(const iter& at, const T* new1) BY_SIDE_FUNC(new1, set(at, *new1), false);
92
93 // add:
94 virtual nbool add(const iter& at, const T& new1) = 0;
95 nbool add(const iter& at, const T* new1) BY_SIDE_FUNC(new1, add(at, *new1), false);
96 nbool add(std::initializer_list<const T*> elems);
97 nbool add(const T& new1);
98 nbool add(const T* it) BY_SIDE_FUNC(add);
99 virtual void add(const iter& here, const iter& from, const iter& to) = 0;
100 void add(const iter& from, const iter& to);
101 void add(const iter& here, me& rhs);
102 void add(const me& rhs);
103 void add(const me* rhs) BY_SIDE_FUNC(rhs, add(*rhs), void());
104
105 template <typename E>
106 ncnt add(const typename tucontainable<E>::iter& from, const typename tucontainable<E>::iter& to) {
107 static_assert(areBaseOfT<T, E>::value, "given type 'E' is not subtype of 'T'");
108 int ret = 0;
109 for(auto e = from; e != to; ++e)
110 if(add(*e)) ret++;
111 return ret;
112 }
113
114 template <typename E> ncnt add(const tucontainable<E>& rhs) { return add(rhs.begin(), rhs.end()); }
115
116 template <typename K, typename V> ncnt add(const tbicontainable<K, V>& rhs);
117
118 // del:
123 nbool del(const T& it);
124 nbool del(const T* it) BY_SIDE_FUNC(del);
125 virtual nbool del(const iter& it) = 0;
126 virtual nbool del(const iter& from, const iter& end) = 0;
127 nbool del(const me& rhs);
128 nbool del(const me* rhs) BY_SIDE_FUNC(rhs, del(*rhs), false);
129
130 // etc:
131 virtual void rel() = 0;
132
133 protected:
134 virtual iteration* _onMakeIteration(ncnt step, nbool isReversed) const = 0;
135 };
136
138} // namespace by
Definition tnarr.hpp:9
Template unidirectional container interface.
Definition tucontainable.hpp:20
Bidirectional iterator for key-value containers.
Definition biter.hpp:10
Definition biteration.hpp:5
to Top