Fix const/non-const interop for transform_iterator

[SVN r21172]
This commit is contained in:
Dave Abrahams 2003-12-07 20:33:18 +00:00
parent 296ce3aa89
commit f14701232a
3 changed files with 31 additions and 18 deletions

View File

@ -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 &lt;class UnaryFunction, template &lt;class UnaryFunction,
class Iterator, class Iterator,
@ -1660,10 +1661,11 @@ public:
transform_iterator(); transform_iterator();
transform_iterator(Iterator const&amp; x, UnaryFunction f); transform_iterator(Iterator const&amp; x, UnaryFunction f);
template&lt;class OtherIterator, class R2, class V2&gt; template&lt;class F2, class I2, class R2, class V2&gt;
transform_iterator( transform_iterator(
transform_iterator&lt;UnaryFunction, OtherIterator, R2, V2&gt; const&amp; t transform_iterator&lt;F2, I2, R2, V2&gt; const&amp; t
, typename enable_if_convertible&lt;OtherIterator, Iterator&gt;::type* = 0 // exposition , typename enable_if_convertible&lt;I2, Iterator&gt;::type* = 0 // exposition
, typename enable_if_convertible&lt;F2, UnaryFunction&gt;::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>

View File

@ -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; }

View File

@ -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;
@ -239,6 +240,10 @@ main()
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;