summaryrefslogtreecommitdiff
path: root/src/bindings/cxx/eina_cxx/eina_variant.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/bindings/cxx/eina_cxx/eina_variant.hh')
-rw-r--r--src/bindings/cxx/eina_cxx/eina_variant.hh38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/bindings/cxx/eina_cxx/eina_variant.hh b/src/bindings/cxx/eina_cxx/eina_variant.hh
index fb92954..df24aea 100644
--- a/src/bindings/cxx/eina_cxx/eina_variant.hh
+++ b/src/bindings/cxx/eina_cxx/eina_variant.hh
@@ -99,7 +99,7 @@ struct copy_visitor
99 new (buffer) T(other); 99 new (buffer) T(other);
100 } 100 }
101}; 101};
102 102
103struct move_visitor 103struct move_visitor
104{ 104{
105 typedef void result_type; 105 typedef void result_type;
@@ -111,7 +111,7 @@ struct move_visitor
111 new (buffer) type(std::move(other)); 111 new (buffer) type(std::move(other));
112 } 112 }
113}; 113};
114 114
115struct assign_visitor 115struct assign_visitor
116{ 116{
117 typedef void result_type; 117 typedef void result_type;
@@ -125,6 +125,19 @@ struct assign_visitor
125 } 125 }
126}; 126};
127 127
128struct move_assign_visitor
129{
130 typedef void result_type;
131 void* buffer;
132 template <typename T>
133 void operator()(T& other) const
134 {
135 typedef typename std::remove_cv<typename std::remove_reference<T>::type>::type type;
136 type* assigned = static_cast<type*>(buffer);
137 *assigned = std::move(other);
138 }
139};
140
128struct destroy_visitor 141struct destroy_visitor
129{ 142{
130 typedef void result_type; 143 typedef void result_type;
@@ -187,6 +200,27 @@ struct variant
187 } 200 }
188 return *this; 201 return *this;
189 } 202 }
203 variant(variant&& other)
204 : type(other.type)
205 {
206 if(other.type != -1)
207 other.visit(move_visitor{static_cast<void*>(&buffer)});
208 }
209 variant& operator=(variant&& other)
210 {
211 if(type == other.type && type != -1)
212 {
213 other.visit(move_assign_visitor{static_cast<void*>(&buffer)});
214 }
215 else if(type != other.type)
216 {
217 if(type != -1)
218 destroy_unsafe();
219 type = other.type;
220 other.visit(move_visitor{static_cast<void*>(&buffer)});
221 }
222 return *this;
223 }
190 ~variant() 224 ~variant()
191 { 225 {
192 if(type != -1) 226 if(type != -1)