123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- //
- // Boost.Pointer Container
- //
- // Copyright Thorsten Ottosen 2008. Use, modification and
- // distribution is subject to the Boost Software License, Version
- // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
- // http://www.boost.org/LICENSE_1_0.txt)
- //
- // For more information, see http://www.boost.org/libs/ptr_container/
- //
- #ifndef BOOST_PTR_CONTAINER_PTR_INSERTER_HPP
- #define BOOST_PTR_CONTAINER_PTR_INSERTER_HPP
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- #pragma once
- #endif
- #include <boost/config.hpp>
- #include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp>
- #include <iterator>
- #include <memory>
- #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
- #endif
- namespace boost
- {
- namespace ptr_container
- {
- template< class PtrContainer >
- class ptr_back_insert_iterator;
- template< class PtrContainer >
- class ptr_front_insert_iterator;
-
- template< class PtrContainer >
- class ptr_insert_iterator;
- template< class PtrContainer >
- ptr_back_insert_iterator<PtrContainer>
- ptr_back_inserter( PtrContainer& cont );
- template< class PtrContainer >
- ptr_front_insert_iterator<PtrContainer>
- ptr_front_inserter( PtrContainer& cont );
- template< class PtrContainer >
- ptr_insert_iterator<PtrContainer>
- ptr_inserter( PtrContainer& cont, typename PtrContainer::iterator before );
- //////////////////////////////////////////////////////////////////////////
- // Implementation
- //////////////////////////////////////////////////////////////////////////
- template< class PtrContainer >
- class ptr_back_insert_iterator
- {
- public:
- typedef std::output_iterator_tag iterator_category;
- typedef void value_type;
- typedef void difference_type;
- typedef void pointer;
- typedef void reference;
- typedef PtrContainer container_type;
- public:
- explicit ptr_back_insert_iterator( PtrContainer& cont )
- : container(&cont)
- { }
- ptr_back_insert_iterator&
- operator=( typename PtrContainer::value_type r )
- {
- typename PtrContainer::value_type obj
- = container->null_policy_allocate_clone(r);
- container->push_back( obj );
- return *this;
- }
- #ifndef BOOST_NO_AUTO_PTR
- template< class T >
- ptr_back_insert_iterator&
- operator=( std::auto_ptr<T> r )
- {
- container->push_back( r );
- return *this;
- }
- #endif
- #ifndef BOOST_NO_CXX11_SMART_PTR
- template< class T >
- ptr_back_insert_iterator&
- operator=( std::unique_ptr<T> r )
- {
- container->push_back( std::move( r ) );
- return *this;
- }
- #endif
- ptr_back_insert_iterator&
- operator=( typename PtrContainer::const_reference r )
- {
- container->push_back( container->null_policy_allocate_clone(&r) );
- return *this;
- }
- ptr_back_insert_iterator& operator*()
- {
- return *this;
- }
- ptr_back_insert_iterator& operator++()
- {
- return *this;
- }
- ptr_back_insert_iterator operator++(int)
- {
- return *this;
- }
-
- protected:
- PtrContainer* container;
- };
-
- template< class PtrContainer >
- class ptr_front_insert_iterator
- {
- public:
- typedef std::output_iterator_tag iterator_category;
- typedef void value_type;
- typedef void difference_type;
- typedef void pointer;
- typedef void reference;
- typedef PtrContainer container_type;
- public:
- explicit ptr_front_insert_iterator( PtrContainer& cont )
- : container(&cont)
- { }
- ptr_front_insert_iterator&
- operator=( typename PtrContainer::value_type r )
- {
- typename PtrContainer::value_type obj
- = container->null_policy_allocate_clone(r);
- container->push_front( obj );
- return *this;
- }
- #ifndef BOOST_NO_AUTO_PTR
- template< class T >
- ptr_front_insert_iterator&
- operator=( std::auto_ptr<T> r )
- {
- container->push_front( r );
- return *this;
- }
- #endif
- #ifndef BOOST_NO_CXX11_SMART_PTR
- template< class T >
- ptr_front_insert_iterator&
- operator=( std::unique_ptr<T> r )
- {
- container->push_front( std::move( r ) );
- return *this;
- }
- #endif
-
- ptr_front_insert_iterator&
- operator=( typename PtrContainer::const_reference r )
- {
- container->push_front( container->null_policy_allocate_clone(&r) );
- return *this;
- }
- ptr_front_insert_iterator& operator*()
- {
- return *this;
- }
- ptr_front_insert_iterator& operator++()
- {
- return *this;
- }
- ptr_front_insert_iterator operator++(int)
- {
- return *this;
- }
-
- protected:
- PtrContainer* container;
- };
-
- template< class PtrContainer >
- class ptr_insert_iterator
- {
- public:
- typedef std::output_iterator_tag iterator_category;
- typedef void value_type;
- typedef void difference_type;
- typedef void pointer;
- typedef void reference;
- typedef PtrContainer container_type;
- public:
- ptr_insert_iterator( PtrContainer& cont,
- typename PtrContainer::iterator before )
- : container(&cont), iter(before)
- { }
- ptr_insert_iterator&
- operator=( typename PtrContainer::value_type r )
- {
- typename PtrContainer::value_type obj =
- container->null_policy_allocate_clone(r);
- iter = container->insert( iter, obj );
- return *this;
- }
- #ifndef BOOST_NO_AUTO_PTR
- template< class T >
- ptr_insert_iterator&
- operator=( std::auto_ptr<T> r )
- {
- iter = container->insert( iter, r );
- return *this;
- }
- #endif
- #ifndef BOOST_NO_CXX11_SMART_PTR
- template< class T >
- ptr_insert_iterator&
- operator=( std::unique_ptr<T> r )
- {
- iter = container->insert( iter, std::move( r ) );
- return *this;
- }
- #endif
-
- ptr_insert_iterator&
- operator=( typename PtrContainer::const_reference r )
- {
- iter = container->insert( iter,
- container->null_policy_allocate_clone(&r) );
- return *this;
- }
- ptr_insert_iterator& operator*()
- {
- return *this;
- }
- ptr_insert_iterator& operator++()
- {
- return *this;
- }
- ptr_insert_iterator operator++(int)
- {
- return *this;
- }
-
- protected:
- PtrContainer* container;
- typename PtrContainer::iterator iter;
- };
- template< class PtrContainer >
- inline ptr_back_insert_iterator<PtrContainer>
- ptr_back_inserter( PtrContainer& cont )
- {
- return ptr_back_insert_iterator<PtrContainer>( cont );
- }
- template< class PtrContainer >
- inline ptr_front_insert_iterator<PtrContainer>
- ptr_front_inserter( PtrContainer& cont )
- {
- return ptr_front_insert_iterator<PtrContainer>( cont );
- }
- template< class PtrContainer >
- inline ptr_insert_iterator<PtrContainer>
- ptr_inserter( PtrContainer& cont,
- typename PtrContainer::iterator before )
- {
- return ptr_insert_iterator<PtrContainer>( cont, before );
- }
-
- } // namespace 'ptr_container'
- } // namespace 'boost'
- #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
- #pragma GCC diagnostic pop
- #endif
- #endif
|