<?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.3.10: http://docutils.sourceforge.net/" />
<title>2 of the least crazy ideas for the standard library in C++0x</title>
<meta name="author" content="Thorsten Ottosen" />
<meta name="organization" content="Dezide Aps" />
<meta name="date" content="2007-16-04" />
<style type="text/css">

/*
:Author: David Goodger
:Contact: goodger@users.sourceforge.net
:Date: $Date: 2007/04/19 08:52:05 $
:Revision: $Revision: 1.3 $
: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.
*/

/* "! important" is used here to override other ``margin-top`` and
   ``margin-bottom`` styles that are later in the stylesheet or 
   more specific.  See http://www.w3.org/TR/CSS1#the-cascade */
.first {
  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 }

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 }

img.borderless {
  border: 0 }

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.line-block {
  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 thin gray }

table.docinfo {
  margin: 2em 4em }

table.docutils {
  margin-top: 0.5em ;
  margin-bottom: 0.5em }

table.footnote {
  border-left: solid thin black }

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="of-the-least-crazy-ideas-for-the-standard-library-in-c-0x">
<h1 class="title">2 of the least crazy ideas for the standard library in C++0x</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>Thorsten Ottosen</td></tr>
<tr><th class="docinfo-name">Contact:</th>
<td><a class="first last reference" href="mailto:thorsten.ottosen&#64;dezide.com">thorsten.ottosen&#64;dezide.com</a></td></tr>
<tr><th class="docinfo-name">Organization:</th>
<td><a class="first last reference" href="http://www.dezide.com">Dezide Aps</a></td></tr>
<tr><th class="docinfo-name">Date:</th>
<td>2007-04-16</td></tr>
<tr class="field"><th class="docinfo-name">Number:</th><td class="field-body">WG21/N2246 and J16/07-0106 (revision of <a class="reference" href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1870.html">n1870</a>, <a class="reference" href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2006/n2099.html">n2099</a>)</td>
</tr>
<tr class="field"><th class="docinfo-name">Working Group:</th><td class="field-body">Library</td>
</tr>
</tbody>
</table>
<div class="abstract topic">
<p class="topic-title first">Abstract</p>
<p>This paper provides wording for 2 of the least controversial 
of the 3 crazy ideas for enhancing
the standard library in <a class="reference" href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2006/n2099.html">n2099</a>.</p>
</div>
<!-- ######################### -->
<!-- # Roles -->
<!-- ######################### -->
<!-- ######################### -->
<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="#addition-to-iterator" id="id2" name="id2">Addition to &lt;iterator&gt;</a></li>
<li><a class="reference" href="#additions-to-algorithm" id="id3" name="id3">Additions to &lt;algorithm&gt;</a><ul>
<li><a class="reference" href="#is-sorted" id="id4" name="id4">25.3.1.5 is_sorted</a></li>
<li><a class="reference" href="#is-heap" id="id5" name="id5">25.3.6.5 is_heap</a></li>
</ul>
</li>
</ul>
</div>
<!-- section-numbering: -->
<div class="section">
<h1><a class="toc-backref" href="#id1" id="introduction" name="introduction">Introduction</a></h1>
<p>The motivation for these additions
is discussed in <a class="reference" href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1870.html">n1870</a>.</p>
<p>Each numbered section below describes a new section for the standard or 
modifications to an existing section.  Comments are written in bold and 
are not part of the wording.</p>
</div>
<div class="section">
<h1><a class="toc-backref" href="#id2" id="addition-to-iterator" name="addition-to-iterator">Addition to &lt;iterator&gt;</a></h1>
<p><strong>Extend the synopsis after distance() of 24.2 to include</strong>:</p>
<pre class="literal-block">
template&lt;class InputIterator&gt;
InputIterator next(InputIterator x, typename std::iterator_traits&lt;InputIterator&gt;::difference_type n = 1);

template&lt; class BidirectionalIterator&gt;
BidirectionalIterator prev(BidirectionalIterator x, typename std::iterator_traits&lt;BidirectionalIterator&gt;::difference_type n = 1);
</pre>
<p><strong>Extend 24.3.4 to include</strong>:</p>
<p><tt class="docutils literal"><span class="pre">template&lt;class</span> <span class="pre">InputIterator&gt;</span> <span class="pre">InputIterator</span> <span class="pre">next(InputIterator</span> <span class="pre">x,</span> <span class="pre">typename</span> <span class="pre">std::iterator_traits&lt;InputIterator&gt;::difference_type</span> <span class="pre">n</span> <span class="pre">=</span> <span class="pre">1);</span></tt></p>
<ul class="simple">
<li><em>Effects</em>: Equivalent to <tt class="docutils literal"><span class="pre">std::advance(x,</span> <span class="pre">n);</span> <span class="pre">return</span> <span class="pre">x;</span></tt></li>
</ul>
<p><tt class="docutils literal"><span class="pre">template&lt;class</span> <span class="pre">BidirectionalIterator&gt;</span> <span class="pre">BidirectionalIterator</span> <span class="pre">prev(BidirectionalIterator</span> <span class="pre">x,</span> <span class="pre">typename</span> <span class="pre">std::iterator_traits&lt;BidirectionalIterator&gt;::difference_type</span> <span class="pre">n</span> <span class="pre">=</span> <span class="pre">1);</span></tt></p>
<ul class="simple">
<li><em>Effects</em>: Equivalent to <tt class="docutils literal"><span class="pre">std::advance(x,</span> <span class="pre">-n);</span> <span class="pre">return</span> <span class="pre">x;</span></tt></li>
</ul>
</div>
<div class="section">
<h1><a class="toc-backref" href="#id3" id="additions-to-algorithm" name="additions-to-algorithm">Additions to &lt;algorithm&gt;</a></h1>
<p><strong>Add the following as paragraphs</strong>:</p>
<div class="section">
<h2><a class="toc-backref" href="#id4" id="is-sorted" name="is-sorted">25.3.1.5 is_sorted</a></h2>
<p><tt class="docutils literal"><span class="pre">template&lt;class</span> <span class="pre">ForwardIterator&gt;</span>
<span class="pre">ForwardIterator</span> <span class="pre">is_sorted_until(ForwardIterator</span> <span class="pre">first,</span> <span class="pre">ForwardIterator</span> <span class="pre">last);</span></tt></p>
<p><tt class="docutils literal"><span class="pre">template&lt;class</span> <span class="pre">ForwardIterator,</span> <span class="pre">class</span> <span class="pre">Compare&gt;</span>
<span class="pre">ForwardIterator</span> <span class="pre">is_sorted_until(ForwardIterator</span> <span class="pre">first,</span> <span class="pre">ForwardIterator</span> <span class="pre">last,</span> <span class="pre">Compare</span> <span class="pre">comp</span> <span class="pre">);</span></tt></p>
<ul class="simple">
<li><em>Effects</em>: Returns the last iterator <tt class="docutils literal"><span class="pre">i</span></tt> in <tt class="docutils literal"><span class="pre">[first,last]</span></tt> for which the range <tt class="docutils literal"><span class="pre">[first,i)</span></tt> is sorted. If <tt class="docutils literal"><span class="pre">std::distance(first,last)</span> <span class="pre">&lt;</span> <span class="pre">2</span></tt>, <tt class="docutils literal"><span class="pre">last</span></tt> is returned.</li>
<li><em>Complexity</em>: Linear</li>
</ul>
<p><tt class="docutils literal"><span class="pre">template&lt;class</span> <span class="pre">ForwardIterator&gt;</span>
<span class="pre">bool</span> <span class="pre">is_sorted(ForwardIterator</span> <span class="pre">first,</span> <span class="pre">ForwardIterator</span> <span class="pre">last);</span></tt></p>
<ul class="simple">
<li><em>Returns</em>: <tt class="docutils literal"><span class="pre">std::is_sorted_until(first,last)==last</span></tt></li>
</ul>
<p><tt class="docutils literal"><span class="pre">template&lt;class</span> <span class="pre">ForwardIterator,</span> <span class="pre">class</span> <span class="pre">Compare&gt;</span>
<span class="pre">bool</span> <span class="pre">is_sorted(ForwardIterator</span> <span class="pre">first,</span> <span class="pre">ForwardIterator</span> <span class="pre">last,</span> <span class="pre">Compare</span> <span class="pre">comp</span> <span class="pre">);</span></tt></p>
<ul class="simple">
<li><em>Returns</em>: <tt class="docutils literal"><span class="pre">std::is_sorted_until(first,last,comp)==last</span></tt></li>
</ul>
</div>
<div class="section">
<h2><a class="toc-backref" href="#id5" id="is-heap" name="is-heap">25.3.6.5 is_heap</a></h2>
<p><tt class="docutils literal"><span class="pre">template</span> <span class="pre">&lt;class</span> <span class="pre">RandomAccessIterator&gt;</span>
<span class="pre">RandomAccessIterator</span> <span class="pre">is_heap_until(RandomAccessIterator</span> <span class="pre">first,</span> <span class="pre">RandomAccessIterator</span> <span class="pre">last);</span></tt></p>
<p><tt class="docutils literal"><span class="pre">template</span> <span class="pre">&lt;class</span> <span class="pre">ForwardIterator,</span> <span class="pre">class</span> <span class="pre">Compare&gt;</span>
<span class="pre">RandomAccessIterator</span> <span class="pre">is_heap_until(RandomAccessIterator</span> <span class="pre">first,</span> <span class="pre">RandomAccessIterator</span> <span class="pre">last,</span> <span class="pre">Compare</span> <span class="pre">comp)</span></tt></p>
<blockquote>
<ul class="simple">
<li><em>Effects</em>: Returns the last iterator <tt class="docutils literal"><span class="pre">i</span></tt> in <tt class="docutils literal"><span class="pre">[first,last]</span></tt> for which the range <tt class="docutils literal"><span class="pre">[first,i)</span></tt> is a heap. If <tt class="docutils literal"><span class="pre">std::distance(first,last)</span> <span class="pre">&lt;</span> <span class="pre">2</span></tt>, <tt class="docutils literal"><span class="pre">last</span></tt> is returned.</li>
<li><em>Complexity</em>: Linear</li>
</ul>
</blockquote>
<p><tt class="docutils literal"><span class="pre">template</span> <span class="pre">&lt;class</span> <span class="pre">RandomAccessIterator&gt;</span>
<span class="pre">bool</span> <span class="pre">is_heap(RandomAccessIterator</span> <span class="pre">first,</span> <span class="pre">RandomAccessIterator</span> <span class="pre">last);</span></tt></p>
<p><tt class="docutils literal"><span class="pre">template</span> <span class="pre">&lt;class</span> <span class="pre">RandomAccessIterator,</span> <span class="pre">class</span> <span class="pre">Compare&gt;</span>
<span class="pre">bool</span> <span class="pre">is_heap(RandomAccessIterator</span> <span class="pre">first,</span> <span class="pre">RandomAccessIterator</span> <span class="pre">last,</span> <span class="pre">Compare</span> <span class="pre">comp)</span></tt></p>
<ul class="simple">
<li><em>Returns</em>: <tt class="docutils literal"><span class="pre">std::is_heap_until(first,last)==last</span></tt></li>
</ul>
<!-- ############################################### -->
<!-- ################## Links ###################### -->
<!-- ############################################### -->
<!-- ############################################### -->
<!-- ################## Footnotes ################## -->
<!-- ############################################### -->
<!-- 1] At the Berlin meeting we discussed that I could choose to
provide wording for ``is_heap_until()`` just like we have
wording for ``is_sorted_until()``. However, I have no use cases for such
a beast. -->
<!-- 2] A single pass algorithm is prone to floating point inaccuracies. -->
</div>
</div>
</div>
</body>
</html>
