epoc32/include/stdapis/boost/iterator/transform_iterator.hpp
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/boost/iterator/transform_iterator.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,188 @@
     1.4 +// (C) Copyright David Abrahams 2002.
     1.5 +// (C) Copyright Jeremy Siek    2002.
     1.6 +// (C) Copyright Thomas Witt    2002.
     1.7 +// Distributed under the Boost Software License, Version 1.0. (See
     1.8 +// accompanying file LICENSE_1_0.txt or copy at
     1.9 +// http://www.boost.org/LICENSE_1_0.txt)
    1.10 +#ifndef BOOST_TRANSFORM_ITERATOR_23022003THW_HPP
    1.11 +#define BOOST_TRANSFORM_ITERATOR_23022003THW_HPP
    1.12 +
    1.13 +#include <boost/function.hpp>
    1.14 +#include <boost/iterator.hpp>
    1.15 +#include <boost/iterator/detail/enable_if.hpp>
    1.16 +#include <boost/iterator/iterator_adaptor.hpp>
    1.17 +#include <boost/iterator/iterator_categories.hpp>
    1.18 +#include <boost/mpl/not.hpp>
    1.19 +#include <boost/mpl/bool.hpp>
    1.20 +#include <boost/type_traits/function_traits.hpp>
    1.21 +#include <boost/type_traits/is_const.hpp>
    1.22 +#include <boost/type_traits/is_class.hpp>
    1.23 +#include <boost/type_traits/is_function.hpp>
    1.24 +#include <boost/type_traits/is_reference.hpp>
    1.25 +#include <boost/type_traits/remove_const.hpp>
    1.26 +#include <boost/type_traits/remove_reference.hpp>
    1.27 +
    1.28 +#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
    1.29 +# include <boost/type_traits/is_base_and_derived.hpp>
    1.30 +
    1.31 +#endif 
    1.32 +#include <boost/iterator/detail/config_def.hpp>
    1.33 +
    1.34 +
    1.35 +namespace boost
    1.36 +{
    1.37 +  template <class UnaryFunction, class Iterator, class Reference = use_default, class Value = use_default>
    1.38 +  class transform_iterator;
    1.39 +
    1.40 +  namespace detail 
    1.41 +  {
    1.42 +
    1.43 +    template <class UnaryFunction>
    1.44 +    struct function_object_result
    1.45 +    {
    1.46 +      typedef typename UnaryFunction::result_type type;
    1.47 +    };
    1.48 +
    1.49 +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
    1.50 +    template <class Return, class Argument>
    1.51 +    struct function_object_result<Return(*)(Argument)>
    1.52 +    {
    1.53 +      typedef Return type;
    1.54 +    };
    1.55 +#endif
    1.56 +
    1.57 +    // Compute the iterator_adaptor instantiation to be used for transform_iterator
    1.58 +    template <class UnaryFunction, class Iterator, class Reference, class Value>
    1.59 +    struct transform_iterator_base
    1.60 +    {
    1.61 +     private:
    1.62 +        // By default, dereferencing the iterator yields the same as
    1.63 +        // the function.  Do we need to adjust the way
    1.64 +        // function_object_result is computed for the standard
    1.65 +        // proposal (e.g. using Doug's result_of)?
    1.66 +        typedef typename ia_dflt_help<
    1.67 +            Reference
    1.68 +          , function_object_result<UnaryFunction>
    1.69 +        >::type reference;
    1.70 +
    1.71 +        // To get the default for Value: remove any reference on the
    1.72 +        // result type, but retain any constness to signal
    1.73 +        // non-writability.  Note that if we adopt Thomas' suggestion
    1.74 +        // to key non-writability *only* on the Reference argument,
    1.75 +        // we'd need to strip constness here as well.
    1.76 +        typedef typename ia_dflt_help<
    1.77 +            Value
    1.78 +          , remove_reference<reference>
    1.79 +        >::type cv_value_type;
    1.80 +
    1.81 +     public:
    1.82 +        typedef iterator_adaptor<
    1.83 +            transform_iterator<UnaryFunction, Iterator, Reference, Value>
    1.84 +          , Iterator
    1.85 +          , cv_value_type
    1.86 +          , use_default    // Leave the traversal category alone
    1.87 +          , reference
    1.88 +        > type;
    1.89 +    };
    1.90 +  }
    1.91 +
    1.92 +  template <class UnaryFunction, class Iterator, class Reference, class Value>
    1.93 +  class transform_iterator
    1.94 +    : public detail::transform_iterator_base<UnaryFunction, Iterator, Reference, Value>::type
    1.95 +  {
    1.96 +    typedef typename
    1.97 +    detail::transform_iterator_base<UnaryFunction, Iterator, Reference, Value>::type
    1.98 +    super_t;
    1.99 +
   1.100 +    friend class iterator_core_access;
   1.101 +
   1.102 +  public:
   1.103 +    transform_iterator() { }
   1.104 +
   1.105 +    transform_iterator(Iterator const& x, UnaryFunction f)
   1.106 +      : super_t(x), m_f(f) { }
   1.107 +
   1.108 +    explicit transform_iterator(Iterator const& x)
   1.109 +      : super_t(x)
   1.110 +    {
   1.111 +        // Pro8 is a little too aggressive about instantiating the
   1.112 +        // body of this function.
   1.113 +#if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
   1.114 +        // don't provide this constructor if UnaryFunction is a
   1.115 +        // function pointer type, since it will be 0.  Too dangerous.
   1.116 +        BOOST_STATIC_ASSERT(is_class<UnaryFunction>::value);
   1.117 +#endif 
   1.118 +    }
   1.119 +
   1.120 +    template<
   1.121 +        class OtherUnaryFunction
   1.122 +      , class OtherIterator
   1.123 +      , class OtherReference
   1.124 +      , class OtherValue>
   1.125 +    transform_iterator(
   1.126 +         transform_iterator<OtherUnaryFunction, OtherIterator, OtherReference, OtherValue> const& t
   1.127 +       , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0
   1.128 +#if !BOOST_WORKAROUND(BOOST_MSVC, == 1310)
   1.129 +       , typename enable_if_convertible<OtherUnaryFunction, UnaryFunction>::type* = 0
   1.130 +#endif 
   1.131 +    )
   1.132 +      : super_t(t.base()), m_f(t.functor())
   1.133 +   {}
   1.134 +
   1.135 +    UnaryFunction functor() const
   1.136 +      { return m_f; }
   1.137 +
   1.138 +  private:
   1.139 +    typename super_t::reference dereference() const
   1.140 +    { return m_f(*this->base()); }
   1.141 +
   1.142 +    // Probably should be the initial base class so it can be
   1.143 +    // optimized away via EBO if it is an empty class.
   1.144 +    UnaryFunction m_f;
   1.145 +  };
   1.146 +
   1.147 +  template <class UnaryFunction, class Iterator>
   1.148 +  transform_iterator<UnaryFunction, Iterator>
   1.149 +  make_transform_iterator(Iterator it, UnaryFunction fun)
   1.150 +  {
   1.151 +      return transform_iterator<UnaryFunction, Iterator>(it, fun);
   1.152 +  }
   1.153 +
   1.154 +  // Version which allows explicit specification of the UnaryFunction
   1.155 +  // type.
   1.156 +  //
   1.157 +  // This generator is not provided if UnaryFunction is a function
   1.158 +  // pointer type, because it's too dangerous: the default-constructed
   1.159 +  // function pointer in the iterator be 0, leading to a runtime
   1.160 +  // crash.
   1.161 +  template <class UnaryFunction, class Iterator>
   1.162 +#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
   1.163 +  typename mpl::if_<
   1.164 +#else 
   1.165 +  typename iterators::enable_if<
   1.166 +#endif 
   1.167 +      is_class<UnaryFunction>   // We should probably find a cheaper test than is_class<>
   1.168 +    , transform_iterator<UnaryFunction, Iterator>
   1.169 +#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
   1.170 +    , int[3]
   1.171 +#endif 
   1.172 +  >::type
   1.173 +  make_transform_iterator(Iterator it)
   1.174 +  {
   1.175 +      return transform_iterator<UnaryFunction, Iterator>(it, UnaryFunction());
   1.176 +  }
   1.177 +
   1.178 +#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
   1.179 +  template <class Return, class Argument, class Iterator>
   1.180 +  transform_iterator< Return (*)(Argument), Iterator, Return>
   1.181 +  make_transform_iterator(Iterator it, Return (*fun)(Argument))
   1.182 +  {
   1.183 +    return transform_iterator<Return (*)(Argument), Iterator, Return>(it, fun);
   1.184 +  }
   1.185 +#endif
   1.186 +
   1.187 +} // namespace boost
   1.188 +
   1.189 +#include <boost/iterator/detail/config_undef.hpp>
   1.190 +
   1.191 +#endif // BOOST_TRANSFORM_ITERATOR_23022003THW_HPP