2003-07-07 14:14:36 +00:00
|
|
|
// (C) Copyright David Abrahams 2002.
|
|
|
|
// (C) Copyright Jeremy Siek 2002.
|
|
|
|
// (C) Copyright Thomas Witt 2002.
|
|
|
|
// Permission to copy, use, modify,
|
|
|
|
// sell and distribute this software is granted provided this
|
|
|
|
// copyright notice appears in all copies. This software is provided
|
|
|
|
// "as is" without express or implied warranty, and with no claim as
|
|
|
|
// to its suitability for any purpose.
|
|
|
|
#ifndef BOOST_INDIRECT_ITERATOR_23022003THW_HPP
|
|
|
|
#define BOOST_INDIRECT_ITERATOR_23022003THW_HPP
|
|
|
|
|
|
|
|
#include <boost/iterator.hpp>
|
|
|
|
#include <boost/iterator/iterator_adaptor.hpp>
|
|
|
|
|
|
|
|
#include <boost/iterator/iterator_traits.hpp>
|
|
|
|
|
2003-07-16 19:35:46 +00:00
|
|
|
#include <boost/type_traits/remove_cv.hpp>
|
|
|
|
|
2003-07-07 14:14:36 +00:00
|
|
|
#include <boost/python/detail/indirect_traits.hpp>
|
2003-07-16 19:35:46 +00:00
|
|
|
#include <boost/mpl/bool.hpp>
|
|
|
|
#include <boost/mpl/identity.hpp>
|
|
|
|
#include <boost/mpl/apply_if.hpp>
|
2003-07-07 14:14:36 +00:00
|
|
|
#include <boost/mpl/not.hpp>
|
|
|
|
#include <boost/mpl/aux_/has_xxx.hpp>
|
|
|
|
|
2003-07-08 05:10:04 +00:00
|
|
|
#ifdef BOOST_MPL_NO_AUX_HAS_XXX
|
2003-07-07 14:14:36 +00:00
|
|
|
# include <boost/shared_ptr.hpp>
|
|
|
|
# include <boost/scoped_ptr.hpp>
|
|
|
|
# include <boost/mpl/bool.hpp>
|
|
|
|
# include <memory>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <boost/iterator/detail/config_def.hpp> // must be last #include
|
|
|
|
|
|
|
|
namespace boost
|
|
|
|
{
|
|
|
|
template <class Iter, class Value, class Category, class Reference, class Difference>
|
2003-07-22 07:56:08 +00:00
|
|
|
class indirect_iterator;
|
2003-07-07 14:14:36 +00:00
|
|
|
|
2003-07-16 19:35:46 +00:00
|
|
|
template <class T>
|
|
|
|
struct referent;
|
|
|
|
|
2003-07-07 14:14:36 +00:00
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
struct unspecified {};
|
|
|
|
|
|
|
|
//
|
|
|
|
// Detection for whether a type has a nested `element_type'
|
|
|
|
// typedef. Used to detect smart pointers. For compilers not
|
|
|
|
// supporting mpl's has_xxx, we supply specializations. However, we
|
|
|
|
// really ought to have a specializable is_pointer template which
|
|
|
|
// can be used instead with something like
|
|
|
|
// boost/python/pointee.hpp to find the value_type.
|
|
|
|
//
|
2003-07-08 05:10:04 +00:00
|
|
|
# ifndef BOOST_MPL_NO_AUX_HAS_XXX
|
2003-07-07 14:14:36 +00:00
|
|
|
namespace aux
|
|
|
|
{
|
|
|
|
BOOST_MPL_HAS_XXX_TRAIT_DEF(element_type)
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
struct has_element_type
|
|
|
|
: mpl::bool_<
|
|
|
|
mpl::if_<
|
|
|
|
is_class<T>
|
|
|
|
, ::boost::detail::aux::has_element_type<T>
|
|
|
|
, mpl::false_
|
|
|
|
>::type::value
|
|
|
|
>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
# else
|
|
|
|
template <class T>
|
|
|
|
struct has_element_type
|
|
|
|
: mpl::false_ {};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
struct has_element_type<boost::shared_ptr<T> >
|
|
|
|
: mpl::true_ {};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
struct has_element_type<boost::scoped_ptr<T> >
|
|
|
|
: mpl::true_ {};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
struct has_element_type<std::auto_ptr<T> >
|
|
|
|
: mpl::true_ {};
|
|
|
|
# endif
|
|
|
|
|
2003-07-16 19:35:46 +00:00
|
|
|
// Metafunction accessing the nested ::element_type
|
2003-07-07 14:14:36 +00:00
|
|
|
template <class T>
|
2003-07-16 19:35:46 +00:00
|
|
|
struct element_type
|
|
|
|
: mpl::identity<typename T::element_type>
|
2003-07-07 14:14:36 +00:00
|
|
|
{};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
struct iterator_is_mutable
|
|
|
|
: mpl::not_<
|
|
|
|
boost::python::detail::is_reference_to_const<
|
|
|
|
typename iterator_reference<T>::type
|
|
|
|
>
|
|
|
|
>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
struct not_int_impl
|
|
|
|
{
|
|
|
|
template <class U>
|
|
|
|
struct apply {
|
|
|
|
typedef T type;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct not_int_impl<int> {};
|
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
struct not_int
|
|
|
|
: not_int_impl<T>::template apply<U> {};
|
|
|
|
|
2003-07-16 19:35:46 +00:00
|
|
|
|
|
|
|
template <class Dereferenceable>
|
|
|
|
struct class_has_element_type
|
|
|
|
: mpl::and_<
|
|
|
|
is_class<Dereferenceable>
|
|
|
|
, has_element_type<Dereferenceable>
|
|
|
|
>
|
|
|
|
{};
|
|
|
|
|
2003-07-07 14:14:36 +00:00
|
|
|
// If the Value parameter is unspecified, we use this metafunction
|
|
|
|
// to deduce the default types
|
2003-07-16 19:35:46 +00:00
|
|
|
template <class Dereferenceable>
|
|
|
|
struct default_indirect_value
|
2003-07-07 14:14:36 +00:00
|
|
|
{
|
2003-07-16 19:35:46 +00:00
|
|
|
typedef typename remove_cv<
|
|
|
|
typename referent<Dereferenceable>::type
|
|
|
|
>::type referent_t;
|
2003-07-07 14:14:36 +00:00
|
|
|
|
|
|
|
typedef typename mpl::if_<
|
|
|
|
mpl::or_<
|
2003-07-16 19:35:46 +00:00
|
|
|
class_has_element_type<Dereferenceable>
|
|
|
|
, iterator_is_mutable<Dereferenceable>
|
2003-07-07 14:14:36 +00:00
|
|
|
>
|
2003-07-16 19:35:46 +00:00
|
|
|
, referent_t
|
|
|
|
, referent_t const
|
|
|
|
>::type type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class Iter, class Value, class Category, class Reference, class Difference>
|
|
|
|
struct indirect_base
|
|
|
|
{
|
|
|
|
typedef typename iterator_traits<Iter>::value_type dereferenceable;
|
|
|
|
|
2003-07-07 14:14:36 +00:00
|
|
|
typedef iterator_adaptor<
|
|
|
|
indirect_iterator<Iter, Value, Category, Reference, Difference>
|
|
|
|
, Iter
|
2003-07-16 19:35:46 +00:00
|
|
|
, typename ia_dflt_help<
|
|
|
|
Value, default_indirect_value<dereferenceable>
|
|
|
|
>::type
|
2003-07-07 14:14:36 +00:00
|
|
|
, Category
|
|
|
|
, Reference
|
|
|
|
, Difference
|
|
|
|
> type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct indirect_base<int, int, int, int, int> {};
|
|
|
|
} // namespace detail
|
|
|
|
|
2003-07-16 19:35:46 +00:00
|
|
|
// User-specializable metafunction which returns the referent of a
|
|
|
|
// dereferenceable type. The default implementation returns
|
|
|
|
// Dereferenceable::element_type if such a member exists (thus
|
|
|
|
// handling the boost smart pointers and auto_ptr), and
|
|
|
|
// iterator_traits<Dereferenceable>::value_type otherwise.
|
|
|
|
template <class Dereferenceable>
|
|
|
|
struct referent
|
|
|
|
: mpl::apply_if<
|
|
|
|
detail::class_has_element_type<Dereferenceable>
|
|
|
|
, detail::element_type<Dereferenceable>
|
|
|
|
, iterator_value<Dereferenceable>
|
|
|
|
>
|
|
|
|
{};
|
|
|
|
|
2003-07-07 14:14:36 +00:00
|
|
|
template <
|
|
|
|
class Iterator
|
|
|
|
, class Value = use_default
|
|
|
|
, class Category = use_default
|
|
|
|
, class Reference = use_default
|
|
|
|
, class Difference = use_default
|
|
|
|
>
|
|
|
|
class indirect_iterator
|
|
|
|
: public detail::indirect_base<
|
|
|
|
Iterator, Value, Category, Reference, Difference
|
|
|
|
>::type
|
|
|
|
{
|
|
|
|
typedef typename detail::indirect_base<
|
|
|
|
Iterator, Value, Category, Reference, Difference
|
|
|
|
>::type super_t;
|
|
|
|
|
|
|
|
friend class iterator_core_access;
|
|
|
|
|
|
|
|
public:
|
|
|
|
indirect_iterator() {}
|
|
|
|
|
|
|
|
indirect_iterator(Iterator iter)
|
|
|
|
: super_t(iter) {}
|
|
|
|
|
|
|
|
template <
|
|
|
|
class Iterator2, class Value2, class Category2
|
|
|
|
, class Reference2, class Difference2
|
|
|
|
>
|
|
|
|
indirect_iterator(
|
|
|
|
indirect_iterator<
|
|
|
|
Iterator2, Value2, Category2, Reference2, Difference2
|
|
|
|
> const& y
|
|
|
|
, typename enable_if_convertible<Iterator2, Iterator>::type* = 0
|
|
|
|
)
|
|
|
|
: super_t(y.base())
|
|
|
|
{}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typename super_t::reference dereference() const
|
|
|
|
{
|
|
|
|
# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
|
|
|
|
return const_cast<super_t::reference>(**this->base());
|
|
|
|
# else
|
|
|
|
return **this->base();
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class Iter>
|
|
|
|
inline
|
|
|
|
indirect_iterator<Iter> make_indirect_iterator(Iter x)
|
|
|
|
{
|
|
|
|
return indirect_iterator<Iter>(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Traits, class Iter>
|
|
|
|
inline
|
|
|
|
indirect_iterator<Iter,Traits> make_indirect_iterator(Iter x, Traits* = 0)
|
|
|
|
{
|
|
|
|
return indirect_iterator<Iter, Traits>(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace boost
|
|
|
|
|
|
|
|
#include <boost/iterator/detail/config_undef.hpp>
|
|
|
|
|
|
|
|
#endif // BOOST_INDIRECT_ITERATOR_23022003THW_HPP
|