<!--This file created 2/28/03 9:00 AM by Claris Home Page version 2.0-->
<HTML>
<HEAD>
   <TITLE>issues 225 226 229</TITLE>
   <META NAME=GENERATOR CONTENT="Claris Home Page 2.0">
   <X-SAS-WINDOW TOP=44 BOTTOM=748 LEFT=305 RIGHT=973>
</HEAD>
<BODY BGCOLOR="#FFFFFF">

<ADDRESS>Document number: N1439=03-0021</ADDRESS>

<ADDRESS>&nbsp;</ADDRESS>

<ADDRESS>Howard E. Hinnant</ADDRESS>

<ADDRESS><A HREF="mailto:hinnant@twcny.rr.com">hinnant@twcny.rr.com</A>
</ADDRESS>

<ADDRESS>February 28, 2003</ADDRESS>

<H1>Proposed Resolution To LWG issues 225, 226, 229</H1>

<H2>Introduction</H2>

<P>The LWG met in Santa Cruz and reviewed
<A HREF="../2002/n1387.htm">n1387</A>. The consensus to come out of
that meeting is that we want to create " swappable requirements" and
then endow specific algorithms with this new requirement. This paper
is an attempt to address that desire.</P>

<H2>Swappable Requirements</H2>

<P>Add new section: 20.1.6</P>

<BLOCKQUOTE><H3>20.1.6 - Swappable requirements
[lib.swappable.requirements]</H3>

<P>-1- In the following Table ??, <TT>T</TT> is a non-const type to
be supplied by a C++ program instantiating a template, <TT>t</TT> and
<TT>u</TT> are values of type <TT>T</TT>.</P>

<P><CENTER><B>Swappable</B> requirements</CENTER></P>

<P><CENTER><TABLE BORDER=1>
   <TR>
      <TD WIDTH=64>
         <P>expression
      </TD><TD WIDTH=64>
         <P>return type
      </TD><TD WIDTH=196>
         <P>post-condition
      </TD></TR>
   <TR>
      <TD WIDTH=64>
         <P>swap(t, u)
      </TD><TD WIDTH=64>
         <P>void
      </TD><TD WIDTH=196>
         <P><TT>t </TT>has the value originally held by <TT>u</TT>,
         and <TT>u</TT> has the value originally held by <TT>t </TT>
      </TD></TR>
</TABLE></CENTER></P>

<P>-2- The swappable requirement is met by satisfying either (or
both) of the following conditions:</P>

<BLOCKQUOTE><P>a. <TT>T</TT> is swappable if <TT>T</TT> is
copyconstructible and assignable.</P>

<P>b. <TT>T</TT> is swappable if a namespace scope function named
swap exists in the same namespace as the definition of <TT>T</TT>,
accepts two arguments of type <TT>T</TT>, and provides the
post-condition from Table ??.</P></BLOCKQUOTE></BLOCKQUOTE>

<H2>Algorithms</H2>

<P><B>25.2.2:</B> swap_ranges</P>

<BLOCKQUOTE><P>-4- Requires: The two ranges [first1 ,last1 )and
[first2 ,first2 + ( last1 -first1 )) shall not overlap.
ForwardIterator1::value_type and ForwardIterator2::value_type must be
the same type, and that type must be <TT>swappable</TT>.</P>
</BLOCKQUOTE>

<P><B>25.2.2:</B> iter_swap</P>

<BLOCKQUOTE><P>-7- Effects: Calls swap with the values pointed to by
the two iterators a and b.</P>

<P>-8- Requires: ForwardIterator1::value_type and
ForwardIterator2::value_type must be the same type, and that type
must be <TT>swappable</TT>.</P></BLOCKQUOTE>

<P><B>25.2.9:</B> reverse</P>

<BLOCKQUOTE><P>-0- Requires: BidirectionalIterator::value_type must
be <TT>swappable</TT>.</P></BLOCKQUOTE>

<P><B>25.2.10:</B> rotate</P>

<BLOCKQUOTE><P>-3- Requires: [first ,middle )and [middle ,last )are
valid ranges. ForwardIterator::value_type must be <TT>swappable</TT>.
</P></BLOCKQUOTE>

<P><B>25.2.11:</B> random_shuffle</P>

<BLOCKQUOTE><P>-4- Requires: RandomAccessIterator::value_type must be
<TT>swappable</TT>.</P></BLOCKQUOTE>

<P><B>25.2.12:</B> partition</P>

<BLOCKQUOTE><P>-4- Requires: BidirectionalIterator::value_type must
be <TT>swappable</TT>.</P></BLOCKQUOTE>

<P><B>25.2.12:</B> stable_partition</P>

<BLOCKQUOTE><P>-7- Requires: BidirectionalIterator::value_type must
be <TT>swappable</TT>.</P></BLOCKQUOTE>

<P><B>25.3.1.1:</B> sort</P>

<BLOCKQUOTE><P>-3- Requires: RandomAccessIterator::value_type must be
<TT>swappable</TT>.</P></BLOCKQUOTE>

<P><B>25.3.1.2:</B> stable_sort</P>

<BLOCKQUOTE><P>-4- Requires: RandomAccessIterator::value_type must be
<TT>swappable</TT>.</P></BLOCKQUOTE>

<P><B>25.3.1.3:</B> partial_sort</P>

<BLOCKQUOTE><P>-3- Requires: RandomAccessIterator::value_type must be
<TT>swappable</TT>.</P></BLOCKQUOTE>

<P><B>25.3.1.4:</B> partial_sort_copy</P>

<BLOCKQUOTE><P>-4- Requires: RandomAccessIterator::value_type must be
<TT>swappable</TT>.</P></BLOCKQUOTE>

<P><B>25.3.2:</B> nth_element</P>

<BLOCKQUOTE><P>-3- Requires: RandomAccessIterator::value_type must be
<TT>swappable</TT>.</P></BLOCKQUOTE>

<P><B>25.3.4:</B> inplace_merge</P>

<BLOCKQUOTE><P>-9- Requires: BidirectionalIterator::value_type must
be <TT>swappable</TT>.</P></BLOCKQUOTE>

<P><B>25.3.6.2:</B> pop_heap</P>

<BLOCKQUOTE><P>-1- Requires: The range [first ,last )shall be a valid
heap. RandomAccessIterator::value_type must be <TT>swappable</TT>.
</P></BLOCKQUOTE>

<P><B>25.3.6.4:</B> sort_heap</P>

<BLOCKQUOTE><P>-4- Requires: RandomAccessIterator::value_type must be
<TT>swappable</TT>.</P></BLOCKQUOTE>

<P><B>25.3.9:</B> next_permutation</P>

<BLOCKQUOTE><P>-?- Requires: BidirectionalIterator::value_type must
be <TT>swappable</TT>.</P></BLOCKQUOTE>

<P><B>25.3.9:</B> prev_permutation</P>

<BLOCKQUOTE><P>-6- Requires: BidirectionalIterator::value_type must
be <TT>swappable</TT>.</P></BLOCKQUOTE>

<P><B>26.3.3.3/1:</B> valarray transcendentals</P>

<BLOCKQUOTE><P>-1- Each of these functions may only be instantiated
for a type T to which a unique function with the indicated name can
be applied (unqualified). This function shall return a value which is
of type T or which can be unambiguously converted to type T .</P>
</BLOCKQUOTE>
</BODY>
</HTML>
