1 /* Copyright 2016 Joaquin M Lopez Munoz.
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
6 * See http://www.boost.org/libs/poly_collection for library home page.
9 #ifndef BOOST_POLY_COLLECTION_DETAIL_ANY_ITERATOR_HPP
10 #define BOOST_POLY_COLLECTION_DETAIL_ANY_ITERATOR_HPP
16 #include <boost/iterator/iterator_adaptor.hpp>
17 #include <boost/type_erasure/any_cast.hpp>
18 #include <type_traits>
23 namespace poly_collection{
27 /* type_erasure::any<Concept>* adaptor convertible to pointer to wrapped
31 template<typename Any>
32 class any_iterator:public boost::iterator_adaptor<any_iterator<Any>,Any*>
35 any_iterator()=default;
36 explicit any_iterator(Any* p)noexcept:any_iterator::iterator_adaptor_{p}{}
37 any_iterator(const any_iterator&)=default;
38 any_iterator& operator=(const any_iterator&)=default;
42 typename std::enable_if<
43 std::is_same<Any,const NonConstAny>::value>::type* =nullptr
45 any_iterator(const any_iterator<NonConstAny>& x)noexcept:
46 any_iterator::iterator_adaptor_{x.base()}{}
50 typename std::enable_if<
51 std::is_same<Any,const NonConstAny>::value>::type* =nullptr
53 any_iterator& operator=(const any_iterator<NonConstAny>& x)noexcept
55 this->base_reference()=x.base();
59 /* interoperability with Any* */
61 any_iterator& operator=(Any* p)noexcept
62 {this->base_reference()=p;return *this;}
63 operator Any*()const noexcept{return this->base();}
65 /* interoperability with Concrete* */
69 typename std::enable_if<
70 /* can't compile-time check concept compliance */
71 !std::is_const<Any>::value||std::is_const<Concrete>::value
74 explicit operator Concrete*()const noexcept
76 return const_cast<Concrete*>(
77 static_cast<typename std::remove_const<Concrete>::type*>(
78 type_erasure::any_cast<void*>(this->base())));
83 friend class any_iterator;
86 } /* namespace poly_collection::detail */
88 } /* namespace poly_collection */
90 } /* namespace boost */