1414#include " xtl/xmeta_utils.hpp"
1515#include " xtl/xvariant.hpp"
1616
17- // TODO: move in xtl:
18- namespace xtl
19- {
20- namespace mpl
21- {
22- namespace detail
23- {
24- template <class L >
25- struct unique_impl ;
26-
27- template <template <class ...> class L , class ... T>
28- struct unique_impl <L<T...>>
29- {
30- using type = merge_set_t <L<>, L<T...>>;
31- };
32- }
33-
34- template <class L >
35- struct unique : detail::unique_impl<L>
36- {
37- };
38-
39- template <class L >
40- using unique_t = typename unique<L>::type;
41- }
42- }
43-
4417namespace xf
4518{
4619
@@ -150,26 +123,25 @@ namespace xf
150123
151124 using iterator = xvector_like_variant_iterator<iterator_traits>;
152125 using const_iterator = xvector_like_variant_iterator<const_iterator_traits>;
126+
153127 // Size and capacity
154128
155129 bool empty () const ;
156130 size_type size () const ;
157131 void resize (size_type new_size);
158- // Needs fix in xtensor
159- /* size_type max_size() const;
132+ size_type max_size () const ;
160133 size_type capacity () const ;
161134 void reserve (size_type new_cap);
162135 void shrink_to_fit ();
163- void clear();*/
136+ void clear ();
164137
165138 // Element access
166139
167140 reference operator [](size_type i);
168141 const_reference operator [](size_type i) const ;
169142
170- // Needs fix in xtensor
171- /* reference at(size_type i);
172- const_reference at(size_type i) const;*/
143+ reference at (size_type i);
144+ const_reference at (size_type i) const ;
173145
174146 reference front ();
175147 const_reference front () const ;
@@ -193,6 +165,11 @@ namespace xf
193165
194166 const_iterator cbegin () const ;
195167 const_iterator cend () const ;
168+
169+ // swap
170+
171+ void swap (self_type& rhs);
172+
196173 // Comparison
197174
198175 bool equal (const self_type& rhs) const ;
@@ -317,6 +294,21 @@ namespace xf
317294 self_type& operator =(self_type&&) = default ;
318295 };
319296
297+ template <class ... V>
298+ void swap (xvector_like_variant<V...>& lhs, xvector_like_variant<V...>& rhs);
299+
300+ template <class T , class ... V>
301+ T& xget_vector (xvector_like_variant<V...>& v);
302+
303+ template <class T , class ... V>
304+ const T& xget_vector (const xvector_like_variant<V...>& v);
305+
306+ template <class T , class ... V>
307+ T&& xget_vector(xvector_like_variant<V...>&& v);
308+
309+ template <class T , class ... V>
310+ const T&& xget_vector(const xvector_like_variant<V...>&& v);
311+
320312 /* ***************************
321313 * xvector_like_variant_ref *
322314 ****************************/
@@ -346,6 +338,21 @@ namespace xf
346338 self_type& operator =(self_type&&) = default ;
347339 };
348340
341+ template <class ... V>
342+ void swap (xvector_like_variant_ref<V...>& lhs, xvector_like_variant_ref<V...>& rhs);
343+
344+ template <class T , class ... V>
345+ T& xget_vector (xvector_like_variant_ref<V...>& v);
346+
347+ template <class T , class ... V>
348+ const T& xget_vector (const xvector_like_variant_ref<V...>& v);
349+
350+ template <class T , class ... V>
351+ T& xget_vector (xvector_like_variant_ref<V...>&& v);
352+
353+ template <class T , class ... V>
354+ const T& xget_vector (const xvector_like_variant_ref<V...>&& v);
355+
349356 /* ***************************
350357 * xvector_like_variant_cref *
351358 ****************************/
@@ -372,6 +379,18 @@ namespace xf
372379 xvector_like_variant_cref (self_type&&) = default ;
373380 };
374381
382+ template <class T , class ... V>
383+ const T& xget_vector (xvector_like_variant_cref<V...>& v);
384+
385+ template <class T , class ... V>
386+ const T& xget_vector (const xvector_like_variant_cref<V...>& v);
387+
388+ template <class T , class ... V>
389+ const T& xget_vector (xvector_like_variant_cref<V...>&& v);
390+
391+ template <class T , class ... V>
392+ const T& xget_vector (const xvector_like_variant_cref<V...>&& v);
393+
375394 /* *******************************************
376395 * xvector_like_variant_base implementation *
377396 ********************************************/
@@ -421,8 +440,7 @@ namespace xf
421440 xtl::visit ([size](auto & arg) { detail::unwrap (arg).resize (size); }, m_storage);
422441 }
423442
424- // Needs fix in xtensor
425- /* template <class T>
443+ template <class T >
426444 inline auto xvector_like_variant_base<T>::max_size() const -> size_type
427445 {
428446 return xtl::visit ([](const auto & arg) { return detail::unwrap (arg).max_size (); }, m_storage);
@@ -450,7 +468,7 @@ namespace xf
450468 inline void xvector_like_variant_base<T>::clear()
451469 {
452470 xtl::visit ([](auto & arg) { detail::unwrap (arg).clear (); }, m_storage);
453- }*/
471+ }
454472
455473 template <class T >
456474 inline auto xvector_like_variant_base<T>::operator [](size_type i) -> reference
@@ -472,8 +490,6 @@ namespace xf
472490 m_storage);
473491 }
474492
475- // Needs a fix in xtensor
476- /*
477493 template <class T >
478494 inline auto xvector_like_variant_base<T>::at(size_type i) -> reference
479495 {
@@ -493,7 +509,6 @@ namespace xf
493509 },
494510 m_storage);
495511 }
496- */
497512
498513 template <class T >
499514 inline auto xvector_like_variant_base<T>::front() -> reference
@@ -595,6 +610,12 @@ namespace xf
595610 return xtl::visit ([](const auto & arg) { return const_iterator (detail::unwrap (arg).cend ()); }, m_storage);
596611 }
597612
613+ template <class T >
614+ inline void xvector_like_variant_base<T>::swap(self_type& rhs)
615+ {
616+ m_storage.swap (rhs.m_storage );
617+ }
618+
598619 template <class T >
599620 inline bool xvector_like_variant_base<T>::equal(const self_type& rhs) const
600621 {
@@ -720,6 +741,98 @@ namespace xf
720741 /* **************************************
721742 * xvector_like_variant implementation *
722743 ***************************************/
744+
745+ template <class ... V>
746+ inline void swap (xvector_like_variant<V...>& lhs, xvector_like_variant<V...>& rhs)
747+ {
748+ lhs.swap (rhs);
749+ }
750+
751+ template <class T , class ... V>
752+ inline T& xget_vector (xvector_like_variant<V...>& v)
753+ {
754+ return xtl::xget<T>(v.storage ());
755+ }
756+
757+ template <class T , class ... V>
758+ inline const T& xget_vector (const xvector_like_variant<V...>& v)
759+ {
760+ return xtl::xget<T>(v.storage ());
761+ }
762+
763+ template <class T , class ... V>
764+ inline T&& xget_vector(xvector_like_variant<V...>&& v)
765+ {
766+ return xtl::xget<T>(std::move (v.storage ()));
767+ }
768+
769+ template <class T , class ... V>
770+ inline const T&& xget_vector(const xvector_like_variant<V...>&& v)
771+ {
772+ return xtl::xget<T>(std::move (v.storage ()));
773+ }
774+
775+ /* ******************************************
776+ * xvector_like_variant_ref implementation *
777+ *******************************************/
778+
779+ template <class ... L>
780+ inline void swap (xvector_like_variant_ref<L...>& lhs, xvector_like_variant_ref<L...>& rhs)
781+ {
782+ lhs.swap (rhs);
783+ }
784+
785+ template <class T , class ... V>
786+ inline T& xget_vector (xvector_like_variant_ref<V...>& v)
787+ {
788+ return xtl::xget<T&>(v.storage ());
789+ }
790+
791+ template <class T , class ... V>
792+ inline const T& xget_vector (const xvector_like_variant_ref<V...>& v)
793+ {
794+ return xtl::xget<const T&>(v.storage ());
795+ }
796+
797+ template <class T , class ... V>
798+ inline T& xget_vector (xvector_like_variant_ref<V...>&& v)
799+ {
800+ return xtl::xget<T&>(std::move (v.storage ()));
801+ }
802+
803+ template <class T , class ... V>
804+ inline const T& xget_vector (const xvector_like_variant_ref<V...>&& v)
805+ {
806+ return xtl::xget<const T&>(std::move (v.storage ()));
807+ }
808+
809+ /* *******************************************
810+ * xvector_like_variant_cref implementation *
811+ ********************************************/
812+
813+ template <class T , class ... V>
814+ const T& xget_vector (xvector_like_variant_cref<V...>& v)
815+ {
816+ return xtl::xget<const T&>(v.storage ());
817+ }
818+
819+ template <class T , class ... V>
820+ const T& xget_vector (const xvector_like_variant_cref<V...>& v)
821+ {
822+ return xtl::xget<const T&>(v.storage ());
823+ }
824+
825+ template <class T , class ... V>
826+ const T& xget_vector (xvector_like_variant_cref<V...>&& v)
827+ {
828+ return xtl::xget<const T&>(std::move (v.storage ()));
829+ }
830+
831+ template <class T , class ... V>
832+ const T& xget_vector (const xvector_like_variant_cref<V...>&& v)
833+ {
834+ return xtl::xget<const T&>(std::move (v.storage ()));
835+ }
723836}
724837
725838#endif
0 commit comments