Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/poly_collection/detail/callable_wrapper_iterator.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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_CALLABLE_WRAPPER_ITERATOR_HPP
0010 #define BOOST_POLY_COLLECTION_DETAIL_CALLABLE_WRAPPER_ITERATOR_HPP
0011 
0012 #if defined(_MSC_VER)
0013 #pragma once
0014 #endif
0015 
0016 #include <boost/iterator/iterator_adaptor.hpp>
0017 #include <type_traits>
0018 
0019 namespace boost{
0020 
0021 namespace poly_collection{
0022 
0023 namespace detail{
0024 
0025 /* callable_wrapper<Sig>* adaptor convertible to pointer to wrapped entity */
0026 
0027 template<typename CWrapper>
0028 class callable_wrapper_iterator:public boost::iterator_adaptor<
0029   callable_wrapper_iterator<CWrapper>,CWrapper*
0030 >
0031 {
0032 public:
0033   callable_wrapper_iterator()=default;
0034   explicit callable_wrapper_iterator(CWrapper* p)noexcept:
0035     callable_wrapper_iterator::iterator_adaptor_{p}{}
0036   callable_wrapper_iterator(const callable_wrapper_iterator&)=default;
0037   callable_wrapper_iterator& operator=(
0038     const callable_wrapper_iterator&)=default;
0039 
0040   template<
0041     typename NonConstCWrapper,
0042     typename std::enable_if<
0043       std::is_same<CWrapper,const NonConstCWrapper>::value>::type* =nullptr
0044   >
0045   callable_wrapper_iterator(
0046     const callable_wrapper_iterator<NonConstCWrapper>& x)noexcept:
0047     callable_wrapper_iterator::iterator_adaptor_{x.base()}{}
0048 
0049   template<
0050     typename NonConstCWrapper,
0051     typename std::enable_if<
0052       std::is_same<CWrapper,const NonConstCWrapper>::value>::type* =nullptr
0053   >
0054   callable_wrapper_iterator& operator=(
0055     const callable_wrapper_iterator<NonConstCWrapper>& x)noexcept
0056   {
0057     this->base_reference()=x.base();
0058     return *this;
0059   }
0060 
0061   /* interoperability with CWrapper* */
0062 
0063   callable_wrapper_iterator& operator=(CWrapper* p)noexcept
0064     {this->base_reference()=p;return *this;}
0065   operator CWrapper*()const noexcept{return this->base();}
0066 
0067   /* interoperability with Callable* */
0068 
0069   template<
0070     typename Callable,
0071     typename std::enable_if<
0072       std::is_constructible<CWrapper,Callable&>::value&&
0073       (!std::is_const<CWrapper>::value||std::is_const<Callable>::value)
0074     >::type* =nullptr
0075   >
0076   explicit operator Callable*()const noexcept
0077   {
0078     return const_cast<Callable*>(
0079       static_cast<const Callable*>(
0080         const_cast<const void*>(
0081           this->base()->data())));
0082   }
0083 
0084 private:
0085   template<typename>
0086   friend class callable_wrapper_iterator;
0087 };
0088 
0089 } /* namespace poly_collection::detail */
0090 
0091 } /* namespace poly_collection */
0092 
0093 } /* namespace boost */
0094 
0095 #endif