Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:56:56

0001 /* Copyright 2016 Joaquin M Lopez Munoz.
0002  * Distributed under the Boost Software License, Version 1.0.
0003  * (See accompanying file LICENSE_1_0.txt or copy at
0004  * http://www.boost.org/LICENSE_1_0.txt)
0005  *
0006  * See http://www.boost.org/libs/poly_collection for library home page.
0007  */
0008 
0009 #ifndef BOOST_POLY_COLLECTION_DETAIL_ANY_ITERATOR_HPP
0010 #define BOOST_POLY_COLLECTION_DETAIL_ANY_ITERATOR_HPP
0011 
0012 #if defined(_MSC_VER)
0013 #pragma once
0014 #endif
0015 
0016 #include <boost/iterator/iterator_adaptor.hpp>
0017 #include <boost/type_erasure/any_cast.hpp>
0018 #include <type_traits>
0019 #include <utility>
0020 
0021 namespace boost{
0022 
0023 namespace poly_collection{
0024 
0025 namespace detail{
0026 
0027 /* type_erasure::any<Concept>* adaptor convertible to pointer to wrapped
0028  * entity.
0029  */
0030 
0031 template<typename Any>
0032 class any_iterator:public boost::iterator_adaptor<any_iterator<Any>,Any*>
0033 {
0034 public:
0035   any_iterator()=default;
0036   explicit any_iterator(Any* p)noexcept:any_iterator::iterator_adaptor_{p}{}
0037   any_iterator(const any_iterator&)=default;
0038   any_iterator& operator=(const any_iterator&)=default;
0039 
0040   template<
0041     typename NonConstAny,
0042     typename std::enable_if<
0043       std::is_same<Any,const NonConstAny>::value>::type* =nullptr
0044   >
0045   any_iterator(const any_iterator<NonConstAny>& x)noexcept:
0046     any_iterator::iterator_adaptor_{x.base()}{}
0047 
0048   template<
0049     typename NonConstAny,
0050     typename std::enable_if<
0051       std::is_same<Any,const NonConstAny>::value>::type* =nullptr
0052   >
0053   any_iterator& operator=(const any_iterator<NonConstAny>& x)noexcept
0054   {
0055     this->base_reference()=x.base();
0056     return *this;
0057   }
0058 
0059   /* interoperability with Any* */
0060 
0061   any_iterator& operator=(Any* p)noexcept
0062     {this->base_reference()=p;return *this;}
0063   operator Any*()const noexcept{return this->base();}
0064 
0065   /* interoperability with Concrete* */
0066 
0067   template<
0068     typename Concrete,
0069     typename std::enable_if<
0070       /* can't compile-time check concept compliance */
0071       !std::is_const<Any>::value||std::is_const<Concrete>::value
0072     >::type* =nullptr
0073   >
0074   explicit operator Concrete*()const noexcept
0075   {
0076     return const_cast<Concrete*>(
0077       static_cast<typename std::remove_const<Concrete>::type*>(
0078         type_erasure::any_cast<void*>(this->base())));
0079   }
0080 
0081 private:
0082   template<typename>
0083   friend class any_iterator;
0084 };
0085 
0086 } /* namespace poly_collection::detail */
0087 
0088 } /* namespace poly_collection */
0089 
0090 } /* namespace boost */
0091 
0092 #endif