mirror of
https://github.com/boostorg/iterator.git
synced 2025-05-10 07:33:53 +00:00
Fix const/non-const interop for transform_iterator
[SVN r21172]
This commit is contained in:
parent
296ce3aa89
commit
f14701232a
@ -1647,6 +1647,7 @@ base iterator, passes the result of this to the function object, and
|
|||||||
then returns the result.</p>
|
then returns the result.</p>
|
||||||
<div class="section" id="class-template-transform-iterator">
|
<div class="section" id="class-template-transform-iterator">
|
||||||
<h4><a class="toc-backref" href="#id48" name="class-template-transform-iterator">Class template <tt class="literal"><span class="pre">transform_iterator</span></tt></a></h4>
|
<h4><a class="toc-backref" href="#id48" name="class-template-transform-iterator">Class template <tt class="literal"><span class="pre">transform_iterator</span></tt></a></h4>
|
||||||
|
<!-- Version 1.3 of this document was accepted for TR1 -->
|
||||||
<pre class="literal-block">
|
<pre class="literal-block">
|
||||||
template <class UnaryFunction,
|
template <class UnaryFunction,
|
||||||
class Iterator,
|
class Iterator,
|
||||||
@ -1660,10 +1661,11 @@ public:
|
|||||||
transform_iterator();
|
transform_iterator();
|
||||||
transform_iterator(Iterator const& x, UnaryFunction f);
|
transform_iterator(Iterator const& x, UnaryFunction f);
|
||||||
|
|
||||||
template<class OtherIterator, class R2, class V2>
|
template<class F2, class I2, class R2, class V2>
|
||||||
transform_iterator(
|
transform_iterator(
|
||||||
transform_iterator<UnaryFunction, OtherIterator, R2, V2> const& t
|
transform_iterator<F2, I2, R2, V2> const& t
|
||||||
, typename enable_if_convertible<OtherIterator, Iterator>::type* = 0 // exposition
|
, typename enable_if_convertible<I2, Iterator>::type* = 0 // exposition
|
||||||
|
, typename enable_if_convertible<F2, UnaryFunction>::type* = 0 // exposition
|
||||||
);
|
);
|
||||||
|
|
||||||
UnaryFunction functor() const;
|
UnaryFunction functor() const;
|
||||||
@ -2132,7 +2134,7 @@ LocalWords: OtherIncrementable Coplien -->
|
|||||||
<hr class="footer" />
|
<hr class="footer" />
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
<a class="reference" href="facade-and-adaptor.rst">View document source</a>.
|
<a class="reference" href="facade-and-adaptor.rst">View document source</a>.
|
||||||
Generated on: 2003-11-24 05:11 UTC.
|
Generated on: 2003-12-07 20:30 UTC.
|
||||||
Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
|
Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
@ -111,12 +111,18 @@ namespace boost
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class OtherIterator>
|
template<
|
||||||
|
class OtherUnaryFunction
|
||||||
|
, class OtherIterator
|
||||||
|
, class OtherReference
|
||||||
|
, class OtherValue>
|
||||||
transform_iterator(
|
transform_iterator(
|
||||||
transform_iterator<UnaryFunction, OtherIterator, Reference, Value> const& t
|
transform_iterator<OtherUnaryFunction, OtherIterator, OtherReference, OtherValue> const& t
|
||||||
, typename enable_if_convertible<OtherIterator, Iterator>::type* = 0
|
, typename enable_if_convertible<OtherIterator, Iterator>::type* = 0
|
||||||
|
, typename enable_if_convertible<OtherUnaryFunction, UnaryFunction>::type* = 0
|
||||||
)
|
)
|
||||||
: super_t(t.base()), m_f(t.functor()) {}
|
: super_t(t.base()), m_f(t.functor())
|
||||||
|
{}
|
||||||
|
|
||||||
UnaryFunction functor() const
|
UnaryFunction functor() const
|
||||||
{ return m_f; }
|
{ return m_f; }
|
||||||
|
@ -59,7 +59,18 @@ struct adaptable_mult_functor
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct const_select_first
|
||||||
|
{
|
||||||
|
typedef int const& result_type;
|
||||||
|
|
||||||
|
int const& operator()(std::pair<int, int>const& p) const
|
||||||
|
{
|
||||||
|
return p.first;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct select_first
|
struct select_first
|
||||||
|
: const_select_first // derivation to allow conversions
|
||||||
{
|
{
|
||||||
typedef int& result_type;
|
typedef int& result_type;
|
||||||
|
|
||||||
@ -79,16 +90,6 @@ struct select_second
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct const_select_first
|
|
||||||
{
|
|
||||||
typedef int const& result_type;
|
|
||||||
|
|
||||||
int const& operator()(std::pair<int, int>const& p) const
|
|
||||||
{
|
|
||||||
return p.first;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct value_select_first
|
struct value_select_first
|
||||||
{
|
{
|
||||||
typedef int result_type;
|
typedef int result_type;
|
||||||
@ -237,8 +238,12 @@ main()
|
|||||||
boost::make_transform_iterator((pair_t*)values, const_select_first()), x[0]);
|
boost::make_transform_iterator((pair_t*)values, const_select_first()), x[0]);
|
||||||
|
|
||||||
boost::non_const_lvalue_iterator_test(
|
boost::non_const_lvalue_iterator_test(
|
||||||
boost::make_transform_iterator((pair_t*)values, select_first()), x[0], 17);
|
boost::make_transform_iterator((pair_t*)values, select_first()), x[0], 17);
|
||||||
|
|
||||||
|
boost::const_nonconst_iterator_test(
|
||||||
|
++boost::make_transform_iterator((pair_t*)values, select_first())
|
||||||
|
, boost::make_transform_iterator((pair_t*)values, const_select_first())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "test successful " << std::endl;
|
std::cout << "test successful " << std::endl;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user