mirror of
https://github.com/boostorg/iterator.git
synced 2025-05-11 13:33:56 +00:00
452 lines
16 KiB
HTML
Executable File
452 lines
16 KiB
HTML
Executable File
<?xml version="1.0" encoding="utf-8" ?>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
|
|
<title>Problem with is_writable and is_swappable in N1550</title>
|
|
<meta name="author" content="David Abrahams and Jeremy Siek" />
|
|
<meta name="organization" content="Boost Consulting, Indiana University Bloomington" />
|
|
<meta name="date" content="2003-11-19" />
|
|
<meta name="copyright" content="Copyright David Abrahams, Jeremy Siek 2003. 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)" />
|
|
<style type="text/css">
|
|
|
|
/*
|
|
:Author: David Goodger
|
|
:Contact: goodger@users.sourceforge.net
|
|
:Date: $Date$
|
|
:Revision: $Revision$
|
|
:Copyright: This stylesheet has been placed in the public domain.
|
|
|
|
Default cascading style sheet for the HTML output of Docutils.
|
|
|
|
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
|
|
customize this style sheet.
|
|
*/
|
|
|
|
/* used to remove borders from tables and images */
|
|
.borderless, table.borderless td, table.borderless th {
|
|
border: 0 }
|
|
|
|
table.borderless td, table.borderless th {
|
|
/* Override padding for "table.docutils td" with "! important".
|
|
The right padding separates the table cells. */
|
|
padding: 0 0.5em 0 0 ! important }
|
|
|
|
.first {
|
|
/* Override more specific margin styles with "! important". */
|
|
margin-top: 0 ! important }
|
|
|
|
.last, .with-subtitle {
|
|
margin-bottom: 0 ! important }
|
|
|
|
.hidden {
|
|
display: none }
|
|
|
|
a.toc-backref {
|
|
text-decoration: none ;
|
|
color: black }
|
|
|
|
blockquote.epigraph {
|
|
margin: 2em 5em ; }
|
|
|
|
dl.docutils dd {
|
|
margin-bottom: 0.5em }
|
|
|
|
/* Uncomment (and remove this text!) to get bold-faced definition list terms
|
|
dl.docutils dt {
|
|
font-weight: bold }
|
|
*/
|
|
|
|
div.abstract {
|
|
margin: 2em 5em }
|
|
|
|
div.abstract p.topic-title {
|
|
font-weight: bold ;
|
|
text-align: center }
|
|
|
|
div.admonition, div.attention, div.caution, div.danger, div.error,
|
|
div.hint, div.important, div.note, div.tip, div.warning {
|
|
margin: 2em ;
|
|
border: medium outset ;
|
|
padding: 1em }
|
|
|
|
div.admonition p.admonition-title, div.hint p.admonition-title,
|
|
div.important p.admonition-title, div.note p.admonition-title,
|
|
div.tip p.admonition-title {
|
|
font-weight: bold ;
|
|
font-family: sans-serif }
|
|
|
|
div.attention p.admonition-title, div.caution p.admonition-title,
|
|
div.danger p.admonition-title, div.error p.admonition-title,
|
|
div.warning p.admonition-title {
|
|
color: red ;
|
|
font-weight: bold ;
|
|
font-family: sans-serif }
|
|
|
|
/* Uncomment (and remove this text!) to get reduced vertical space in
|
|
compound paragraphs.
|
|
div.compound .compound-first, div.compound .compound-middle {
|
|
margin-bottom: 0.5em }
|
|
|
|
div.compound .compound-last, div.compound .compound-middle {
|
|
margin-top: 0.5em }
|
|
*/
|
|
|
|
div.dedication {
|
|
margin: 2em 5em ;
|
|
text-align: center ;
|
|
font-style: italic }
|
|
|
|
div.dedication p.topic-title {
|
|
font-weight: bold ;
|
|
font-style: normal }
|
|
|
|
div.figure {
|
|
margin-left: 2em ;
|
|
margin-right: 2em }
|
|
|
|
div.footer, div.header {
|
|
clear: both;
|
|
font-size: smaller }
|
|
|
|
div.line-block {
|
|
display: block ;
|
|
margin-top: 1em ;
|
|
margin-bottom: 1em }
|
|
|
|
div.line-block div.line-block {
|
|
margin-top: 0 ;
|
|
margin-bottom: 0 ;
|
|
margin-left: 1.5em }
|
|
|
|
div.sidebar {
|
|
margin-left: 1em ;
|
|
border: medium outset ;
|
|
padding: 1em ;
|
|
background-color: #ffffee ;
|
|
width: 40% ;
|
|
float: right ;
|
|
clear: right }
|
|
|
|
div.sidebar p.rubric {
|
|
font-family: sans-serif ;
|
|
font-size: medium }
|
|
|
|
div.system-messages {
|
|
margin: 5em }
|
|
|
|
div.system-messages h1 {
|
|
color: red }
|
|
|
|
div.system-message {
|
|
border: medium outset ;
|
|
padding: 1em }
|
|
|
|
div.system-message p.system-message-title {
|
|
color: red ;
|
|
font-weight: bold }
|
|
|
|
div.topic {
|
|
margin: 2em }
|
|
|
|
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
|
|
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
|
|
margin-top: 0.4em }
|
|
|
|
h1.title {
|
|
text-align: center }
|
|
|
|
h2.subtitle {
|
|
text-align: center }
|
|
|
|
hr.docutils {
|
|
width: 75% }
|
|
|
|
img.align-left {
|
|
clear: left }
|
|
|
|
img.align-right {
|
|
clear: right }
|
|
|
|
ol.simple, ul.simple {
|
|
margin-bottom: 1em }
|
|
|
|
ol.arabic {
|
|
list-style: decimal }
|
|
|
|
ol.loweralpha {
|
|
list-style: lower-alpha }
|
|
|
|
ol.upperalpha {
|
|
list-style: upper-alpha }
|
|
|
|
ol.lowerroman {
|
|
list-style: lower-roman }
|
|
|
|
ol.upperroman {
|
|
list-style: upper-roman }
|
|
|
|
p.attribution {
|
|
text-align: right ;
|
|
margin-left: 50% }
|
|
|
|
p.caption {
|
|
font-style: italic }
|
|
|
|
p.credits {
|
|
font-style: italic ;
|
|
font-size: smaller }
|
|
|
|
p.label {
|
|
white-space: nowrap }
|
|
|
|
p.rubric {
|
|
font-weight: bold ;
|
|
font-size: larger ;
|
|
color: maroon ;
|
|
text-align: center }
|
|
|
|
p.sidebar-title {
|
|
font-family: sans-serif ;
|
|
font-weight: bold ;
|
|
font-size: larger }
|
|
|
|
p.sidebar-subtitle {
|
|
font-family: sans-serif ;
|
|
font-weight: bold }
|
|
|
|
p.topic-title {
|
|
font-weight: bold }
|
|
|
|
pre.address {
|
|
margin-bottom: 0 ;
|
|
margin-top: 0 ;
|
|
font-family: serif ;
|
|
font-size: 100% }
|
|
|
|
pre.literal-block, pre.doctest-block {
|
|
margin-left: 2em ;
|
|
margin-right: 2em ;
|
|
background-color: #eeeeee }
|
|
|
|
span.classifier {
|
|
font-family: sans-serif ;
|
|
font-style: oblique }
|
|
|
|
span.classifier-delimiter {
|
|
font-family: sans-serif ;
|
|
font-weight: bold }
|
|
|
|
span.interpreted {
|
|
font-family: sans-serif }
|
|
|
|
span.option {
|
|
white-space: nowrap }
|
|
|
|
span.pre {
|
|
white-space: pre }
|
|
|
|
span.problematic {
|
|
color: red }
|
|
|
|
span.section-subtitle {
|
|
/* font-size relative to parent (h1..h6 element) */
|
|
font-size: 80% }
|
|
|
|
table.citation {
|
|
border-left: solid 1px gray;
|
|
margin-left: 1px }
|
|
|
|
table.docinfo {
|
|
margin: 2em 4em }
|
|
|
|
table.docutils {
|
|
margin-top: 0.5em ;
|
|
margin-bottom: 0.5em }
|
|
|
|
table.footnote {
|
|
border-left: solid 1px black;
|
|
margin-left: 1px }
|
|
|
|
table.docutils td, table.docutils th,
|
|
table.docinfo td, table.docinfo th {
|
|
padding-left: 0.5em ;
|
|
padding-right: 0.5em ;
|
|
vertical-align: top }
|
|
|
|
table.docutils th.field-name, table.docinfo th.docinfo-name {
|
|
font-weight: bold ;
|
|
text-align: left ;
|
|
white-space: nowrap ;
|
|
padding-left: 0 }
|
|
|
|
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
|
|
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
|
|
font-size: 100% }
|
|
|
|
tt.docutils {
|
|
background-color: #eeeeee }
|
|
|
|
ul.auto-toc {
|
|
list-style-type: none }
|
|
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="document" id="problem-with-is-writable-and-is-swappable-in-n1550">
|
|
<h1 class="title">Problem with <tt class="docutils literal"><span class="pre">is_writable</span></tt> and <tt class="docutils literal"><span class="pre">is_swappable</span></tt> in <a class="reference" href="http://www.boost-consulting.com/writing/n1550.html">N1550</a></h1>
|
|
<table class="docinfo" frame="void" rules="none">
|
|
<col class="docinfo-name" />
|
|
<col class="docinfo-content" />
|
|
<tbody valign="top">
|
|
<tr><th class="docinfo-name">Author:</th>
|
|
<td>David Abrahams and Jeremy Siek</td></tr>
|
|
<tr><th class="docinfo-name">Contact:</th>
|
|
<td><a class="first reference" href="mailto:dave@boost-consulting.com">dave@boost-consulting.com</a>, <a class="last reference" href="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</a></td></tr>
|
|
<tr><th class="docinfo-name">Organization:</th>
|
|
<td><a class="first reference" href="http://www.boost-consulting.com">Boost Consulting</a>, Indiana University Bloomington</td></tr>
|
|
<tr><th class="docinfo-name">Date:</th>
|
|
<td>2003-11-19</td></tr>
|
|
<tr><th class="docinfo-name">Copyright:</th>
|
|
<td>Copyright David Abrahams, Jeremy Siek 2003. Use, modification and
|
|
distribution is subject to the Boost Software License,
|
|
Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
|
|
at <a class="reference" href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</td></tr>
|
|
</tbody>
|
|
</table>
|
|
<div class="contents topic">
|
|
<p class="topic-title first"><a id="table-of-contents" name="table-of-contents">Table of Contents</a></p>
|
|
<ul class="simple">
|
|
<li><a class="reference" href="#introduction" id="id1" name="id1">Introduction</a></li>
|
|
<li><a class="reference" href="#proposed-resolution" id="id2" name="id2">Proposed Resolution</a></li>
|
|
<li><a class="reference" href="#rationale" id="id3" name="id3">Rationale</a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="section">
|
|
<h1><a class="toc-backref" href="#id1" id="introduction" name="introduction">Introduction</a></h1>
|
|
<p>The <tt class="docutils literal"><span class="pre">is_writable</span></tt> and <tt class="docutils literal"><span class="pre">is_swappable</span></tt> traits classes in <a class="reference" href="http://www.boost-consulting.com/writing/n1550.html">N1550</a>
|
|
provide a mechanism for determining at compile time if an iterator
|
|
type is a model of the new Writable Iterator and Swappable Iterator
|
|
concepts, analogous to <tt class="docutils literal"><span class="pre">iterator_traits<X>::iterator_category</span></tt>
|
|
for the old iterator concepts. For backward compatibility,
|
|
<tt class="docutils literal"><span class="pre">is_writable</span></tt> and <tt class="docutils literal"><span class="pre">is_swappable</span></tt> not only work with new
|
|
iterators, but they also are intended to work for old
|
|
iterators (iterators that meet the requirements for one of the
|
|
iterator concepts in the current standard). In the case of old
|
|
iterators, the writability and swapability is deduced based on the
|
|
<tt class="docutils literal"><span class="pre">iterator_category</span></tt> and also the <tt class="docutils literal"><span class="pre">reference</span></tt> type. The
|
|
specification for this deduction gives false positives for forward
|
|
iterators that have non-assignable value types.</p>
|
|
<p>To review, the part of the <tt class="docutils literal"><span class="pre">is_writable</span></tt> trait definition which
|
|
applies to old iterators is:</p>
|
|
<pre class="literal-block">
|
|
if (cat is convertible to output_iterator_tag)
|
|
return true;
|
|
else if (cat is convertible to forward_iterator_tag
|
|
and iterator_traits<Iterator>::reference is a
|
|
mutable reference)
|
|
return true;
|
|
else
|
|
return false;
|
|
</pre>
|
|
<p>Suppose the <tt class="docutils literal"><span class="pre">value_type</span></tt> of the iterator <tt class="docutils literal"><span class="pre">It</span></tt> has a private
|
|
assignment operator:</p>
|
|
<pre class="literal-block">
|
|
class B {
|
|
public:
|
|
...
|
|
private:
|
|
B& operator=(const B&);
|
|
};
|
|
</pre>
|
|
<p>and suppose the <tt class="docutils literal"><span class="pre">reference</span></tt> type of the iterator is <tt class="docutils literal"><span class="pre">B&</span></tt>. In
|
|
that case, <tt class="docutils literal"><span class="pre">is_writable<It>::value</span></tt> will be true when in fact
|
|
attempting to write into <tt class="docutils literal"><span class="pre">B</span></tt> will cause an error.</p>
|
|
<p>The same problem applies to <tt class="docutils literal"><span class="pre">is_swappable</span></tt>.</p>
|
|
</div>
|
|
<div class="section">
|
|
<h1><a class="toc-backref" href="#id2" id="proposed-resolution" name="proposed-resolution">Proposed Resolution</a></h1>
|
|
<ol class="arabic">
|
|
<li><p class="first">Remove the <tt class="docutils literal"><span class="pre">is_writable</span></tt> and <tt class="docutils literal"><span class="pre">is_swappable</span></tt> traits, and remove the
|
|
requirements in the Writable Iterator and Swappable Iterator concepts
|
|
that require their models to support these traits.</p>
|
|
</li>
|
|
<li><p class="first">Change the <tt class="docutils literal"><span class="pre">is_readable</span></tt> specification to be:
|
|
<tt class="docutils literal"><span class="pre">is_readable<X>::type</span></tt> is <tt class="docutils literal"><span class="pre">true_type</span></tt> if the
|
|
result type of <tt class="docutils literal"><span class="pre">X::operator*</span></tt> is convertible to
|
|
<tt class="docutils literal"><span class="pre">iterator_traits<X>::value_type</span></tt> and is <tt class="docutils literal"><span class="pre">false_type</span></tt>
|
|
otherwise. Also, <tt class="docutils literal"><span class="pre">is_readable</span></tt> is required to satisfy
|
|
the requirements for the UnaryTypeTrait concept
|
|
(defined in the type traits proposal).</p>
|
|
<p>Remove the requirement for support of the <tt class="docutils literal"><span class="pre">is_readable</span></tt> trait from
|
|
the Readable Iterator concept.</p>
|
|
</li>
|
|
<li><p class="first">Remove the <tt class="docutils literal"><span class="pre">iterator_tag</span></tt> class.</p>
|
|
</li>
|
|
<li><p class="first">Change the specification of <tt class="docutils literal"><span class="pre">traversal_category</span></tt> to:</p>
|
|
<pre class="literal-block">
|
|
traversal-category(Iterator) =
|
|
let cat = iterator_traits<Iterator>::iterator_category
|
|
if (cat is convertible to incrementable_iterator_tag)
|
|
return cat; // Iterator is a new iterator
|
|
else if (cat is convertible to random_access_iterator_tag)
|
|
return random_access_traversal_tag;
|
|
else if (cat is convertible to bidirectional_iterator_tag)
|
|
return bidirectional_traversal_tag;
|
|
else if (cat is convertible to forward_iterator_tag)
|
|
return forward_traversal_tag;
|
|
else if (cat is convertible to input_iterator_tag)
|
|
return single_pass_iterator_tag;
|
|
else if (cat is convertible to output_iterator_tag)
|
|
return incrementable_iterator_tag;
|
|
else
|
|
return null_category_tag;
|
|
</pre>
|
|
</li>
|
|
</ol>
|
|
</div>
|
|
<div class="section">
|
|
<h1><a class="toc-backref" href="#id3" id="rationale" name="rationale">Rationale</a></h1>
|
|
<ol class="arabic simple">
|
|
<li>There are two reasons for removing <tt class="docutils literal"><span class="pre">is_writable</span></tt>
|
|
and <tt class="docutils literal"><span class="pre">is_swappable</span></tt>. The first is that we do not know of
|
|
a way to fix the specification so that it gives the correct
|
|
answer for all iterators. Second, there was only a weak
|
|
motivation for having <tt class="docutils literal"><span class="pre">is_writable</span></tt> and <tt class="docutils literal"><span class="pre">is_swappable</span></tt>
|
|
there in the first place. The main motivation was simply
|
|
uniformity: we have tags for the old iterator categories
|
|
so we should have tags for the new iterator categories.
|
|
While having tags and the capability to dispatch based
|
|
on the traversal categories is often used, we see
|
|
less of a need for dispatching based on writability
|
|
and swappability, since typically algorithms
|
|
that need these capabilities have no alternative if
|
|
they are not provided.</li>
|
|
<li>We discovered that the <tt class="docutils literal"><span class="pre">is_readable</span></tt> trait can be implemented
|
|
using only the iterator type itself and its <tt class="docutils literal"><span class="pre">value_type</span></tt>.
|
|
Therefore we remove the requirement for <tt class="docutils literal"><span class="pre">is_readable</span></tt> from the
|
|
Readable Iterator concept, and change the definition of
|
|
<tt class="docutils literal"><span class="pre">is_readable</span></tt> so that it works for any iterator type.</li>
|
|
<li>The purpose of the <tt class="docutils literal"><span class="pre">iterator_tag</span></tt> class was to
|
|
bundle the traversal and access category tags
|
|
into the <tt class="docutils literal"><span class="pre">iterator_category</span></tt> typedef.
|
|
With <tt class="docutils literal"><span class="pre">is_writable</span></tt> and <tt class="docutils literal"><span class="pre">is_swappable</span></tt> gone, and
|
|
<tt class="docutils literal"><span class="pre">is_readable</span></tt> no longer in need of special hints,
|
|
there is no reason for iterators to provide
|
|
information about the access capabilities of an iterator.
|
|
Thus there is no need for the <tt class="docutils literal"><span class="pre">iterator_tag</span></tt>. The
|
|
traversal tag can be directly used for the
|
|
<tt class="docutils literal"><span class="pre">iterator_category</span></tt>. If a new iterator is intended to be backward
|
|
compatible with old iterator concepts, a tag type
|
|
that is convertible to both one of the new traversal tags
|
|
and also to an old iterator tag can be created and use
|
|
for the <tt class="docutils literal"><span class="pre">iterator_category</span></tt>.</li>
|
|
<li>The changes to the specification of <tt class="docutils literal"><span class="pre">traversal_category</span></tt> are a
|
|
direct result of the removal of <tt class="docutils literal"><span class="pre">iterator_tag</span></tt>.</li>
|
|
</ol>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|