Ticket #2056: swap_to_trunk.patch

File swap_to_trunk.patch, 43.8 KB (added by joseph.gauterin, 14 years ago)
  • boost/swap.hpp

     
     1// Copyright (C) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0. (See
     4// accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7#ifndef BOOST_SWAP_HPP
     8#define BOOST_SWAP_HPP
     9
     10#include "./utility/swap.hpp"
     11
     12#endif
  • boost/utility/swap.hpp

    Property changes on: boost\swap.hpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (C) 2007, 2008 Steven Watanabe, Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0. (See
     4// accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6// For more information, see http://www.boost.org
     7//
     8// Update:
     9// 29 June 2008 (Added support for built-in arrays.) Niels Dekker 
     10
     11
     12#ifndef BOOST_UTILITY_SWAP_HPP
     13#define BOOST_UTILITY_SWAP_HPP
     14
     15#include <algorithm> //for std::swap
     16#include <cstddef> //for std::size_t
     17
     18namespace boost_swap_impl
     19{
     20  template<class T>
     21  void swap_impl(T& left, T& right)
     22  {
     23    using std::swap;//use std::swap if argument dependent lookup fails
     24    swap(left,right);
     25  }
     26
     27  template<class T, std::size_t N>
     28  void swap_impl(T (& left)[N], T (& right)[N])
     29  {
     30    for (std::size_t i = 0; i < N; ++i)
     31    {
     32      ::boost_swap_impl::swap_impl(left[i], right[i]);
     33    }
     34  }
     35}
     36
     37namespace boost
     38{
     39  namespace swap_adl_barrier
     40  {
     41    template<class T>
     42    void swap(T& left, T& right)
     43    {
     44      ::boost_swap_impl::swap_impl(left, right);
     45    }
     46  }
     47
     48  using swap_adl_barrier::swap;
     49}
     50
     51#endif
  • libs/libraries.htm

    Property changes on: boost\utility\swap.hpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
    251251    Guzman, Hartmut Kaiser, Dan Nuffer and team.</li>
    252252    <li><a href="algorithm/string/index.html">string_algo</a> -
    253253    String algorithms library, from Pavol Droba.</li>
     254    <li><a href="utility/swap.html">swap</a> -
     255    Enhanced generic swap function, from Joseph Gauterin.</li>
    254256    <li><a href="system/doc/index.html">system</a> - Operating system support,
    255257    including the diagnostics support that will be part of the C++0x standard
    256258    library, from Beman Dawes.</li>
     
    664666    <li><a href="statechart/doc/index.html">statechart</a> - Arbitrarily
    665667    complex finite state machines can be implemented in easily readable and
    666668    maintainable C++ code, from Andreas Huber.</li>
     669    <li><a href="utility/swap.html">swap</a> -
     670    Enhanced generic swap function, from Joseph Gauterin.</li>
    667671    <li><a href="system/doc/index.html">system</a> - Operating
    668672    system support, including the diagnostics support that will be part of the
    669673    C++0x standard library, from Beman Dawes.</li>
  • libs/maintainers.txt

     
    8282unordered             Daniel James <daniel_james -at- fmail.co.uk>
    8383utility
    8484utility/enable_if     Jaakko Jarvi <jarvi -at- cs.tamu.edu>, Jeremiah Willcock <jewillco -at- osl.iu.edu>
     85utility/swap          Joseph Gauterin <joseph.gauterin -at- googlemail.com>
    8586variant               Eric Friedman <ericbrandon -at- gmail.com>
    8687wave                  Hartmut Kaiser <hartmut.kaiser -at- gmail.com>
    8788xpressive             Eric Niebler <eric -at- boost-consulting.com>
  • libs/utility/index.html

     
    2424            <a href="iterator_adaptors.htm">iterator_adaptors</a><br>
    2525            <a href="generator_iterator.htm">generator iterator adaptors</a><br>
    2626                                <a href="operators.htm">operators</a><br>
     27                                <a href="swap.html">swap</a><br>
    2728                                <a href="throw_exception.html">throw_exception</a><br>
    2829                                <a href="utility.htm">utility</a><br>
    2930                <a href="value_init.htm">value_init</a></p>
  • libs/utility/swap.html

     
     1<?xml version="1.0" encoding="utf-8"?>
     2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
     3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
     4  <head>
     5    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     6    <title>Boost: Swap Documentation</title>
     7   </head>
     8  <body>
     9    <!-- Page header -->
     10    <img src="../../boost.png" alt="C++ Boost" align="middle" width="277" height="86"/>
     11    <h1>Swap</h1>
     12   
     13    <p>
     14      <tt>template&lt;class T&gt; void swap(T&amp; <em>left</em>, T&amp; <em>right</em>);</tt>
     15    </p>
     16     
     17    <!-- Intoduction -->
     18    <p>
     19      The template function <tt>boost::swap</tt> allows the values of two variables to be swapped, using argument dependent lookup to select a specialized swap function if available. If no specialized swap function is available, <tt>std::swap</tt> is used.
     20    </p>
     21   
     22    <!-- Rationale -->
     23    <h2>Rationale</h2>
     24    <p>
     25      The generic <tt>std::swap</tt> function requires that the elements to be swapped are assignable and copy constructible. It is usually implemented using one copy construction and two assignments - this is often both unnecessarily restrictive and unnecessarily slow. In addition, where the generic swap implementation provides only the basic guarantee, specialized swap functions are often able to provide the no-throw exception guarantee (and it is considered best practice to do so where possible<sup><a href="#ref1">1</a></sup>).</p>
     26    <p>
     27      The alternative to using argument dependent lookup in this situation is to provide a template specialization of std::swap for every type that requires a specialized swap. Although this is legal C++, no Boost libraries use this method, whereas many Boost libraries provide specialized swap functions in their own namespaces.
     28    </p>
     29    <p>
     30      <tt>boost::swap</tt> also supports swapping built-in arrays. Note that <tt>std::swap</tt> doesn't yet do so, but a request to add an overload of <tt>std::swap</tt> for built-in arrays has been well-received by the Library Working Group of the C++ Standards Committee<sup><a href="#ref2">2</a></sup>.     
     31    </p>
     32   
     33    <!-- Exception Safety -->
     34    <h2>Exception Safety</h2>
     35    <p>
     36      <tt>boost::swap</tt> provides the same exception guarantee as the underlying swap function used, with one exception; for an array of type <tt>T[n]</tt>, where <tt>n > 1</tt> and the underlying swap function for <tt>T</tt> provides the strong exception guarantee, <tt>boost::swap</tt> provides only the basic exception guarantee.
     37    </p>
     38   
     39    <!-- Requirements -->
     40    <h2>Requirements</h2>
     41    <p>Either:</p>
     42    <ul>     
     43      <li>T must be assignable</li>
     44      <li>T must be copy constructible</li>
     45    </ul>
     46    <p>Or:</p>
     47    <ul>
     48      <li>A function with the signature <tt>swap(T&,T&)</tt> is available via argument dependent lookup</li>
     49    </ul>
     50    <p>Or:</p>
     51    <ul>
     52      <li>A template specialization of std::swap exists for T</li>
     53    </ul>
     54    <p>Or:</p>
     55    <ul>
     56      <li>T is a built-in array of swappable elements</li>
     57    </ul>
     58
     59   
     60    <!-- Portability -->
     61    <h2>Portability</h2>
     62    <p>
     63      Several older compilers do not support argument dependent lookup – on these compilers <tt>boost::swap</tt> will call <tt>std::swap</tt>, ignoring any specialized swap functions that could be found as a result of argument dependent lookup.
     64    </p>
     65   
     66    <!-- Credits -->
     67    <h2>Credits</h2>
     68    <ul>
     69      <li>
     70        <em>Niels Dekker</em> - for implementing and documenting support for built-in arrays
     71      </li>
     72      <li>
     73        <em><a href="mailto:Joseph.Gauterin@googlemail.com">Joseph Gauterin</a></em> - for the initial idea, implementation, tests, and documentation
     74      </li>
     75      <li>
     76        <em>Steven Wanatabe</em> - for the idea to use a barrier namespace, enabling the function to have the name '<tt>swap</tt>' without introducing ambiguity or infinite recursion
     77      </li>     
     78    </ul>
     79
     80    <!-- References -->
     81    <hr/>
     82    <p><sup><a id="ref1"/>[1]</sup>Scott Meyers, Effective C++ Third Edition, Item 25: "Consider support for a non-throwing swap"</p>
     83    <p><sup><a id="ref2"/>[2]</sup><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#809">LWG issue 809 (std::swap should be overloaded for array types)</a></p>
     84
     85    <!-- Copyright info -->   
     86    <hr/>
     87    <p>Revised: 3 July 2008</p>
     88    <p>
     89      Copyright 2007, 2008 Joseph Gauterin. Use, modification, and distribution are subject to the Boost Software License, Version 1.0.
     90      (See accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or a copy at &lt;<a href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>&gt;.)
     91    </p>
     92   
     93  </body>
     94</html>
     95 No newline at end of file
  • libs/utility/swap/test/lib_header_1.cpp

    Property changes on: libs\utility\swap.html
    ___________________________________________________________________
    Name: svn:mime-type
       + text/html
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7// Tests that the swap header compiles as a standalone translation unit
     8
     9#include <boost/utility/swap.hpp>
  • libs/utility/swap/test/lib_header_2.cpp

    Property changes on: libs\utility\swap\test\lib_header_1.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7// Tests that the swap header include guards work correctly
     8
     9#include <boost/utility/swap.hpp>
     10#include <boost/utility/swap.hpp>
  • libs/utility/swap/test/mixed_headers_1.cpp

    Property changes on: libs\utility\swap\test\lib_header_2.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7// Tests that the swap headers work when both are included
     8
     9#include <boost/swap.hpp>
     10#include <boost/utility/swap.hpp>
  • libs/utility/swap/test/mixed_headers_2.cpp

    Property changes on: libs\utility\swap\test\mixed_headers_1.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7// Tests that the swap headers work when both are included
     8
     9#include <boost/utility/swap.hpp>
     10#include <boost/swap.hpp>
  • libs/utility/swap/test/specialized_in_global.cpp

    Property changes on: libs\utility\swap\test\mixed_headers_2.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7#include <boost/utility/swap.hpp>
     8#define BOOST_INCLUDE_MAIN
     9#include <boost/test/test_tools.hpp>
     10
     11//Put test class in the global namespace
     12#include "./swap_test_class.hpp"
     13
     14//Provide swap function in gloabl namespace
     15void swap(swap_test_class& left, swap_test_class& right)
     16{
     17  left.swap(right);
     18}
     19
     20int test_main(int, char*[])
     21{
     22  swap_test_class object1;
     23  swap_test_class object2;
     24  boost::swap(object1,object2);
     25
     26  BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1);
     27  BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
     28
     29  return 0;
     30}
     31 No newline at end of file
  • libs/utility/swap/test/specialized_in_other.cpp

    Property changes on: libs\utility\swap\test\specialized_in_global.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7#include <boost/utility/swap.hpp>
     8#define BOOST_INCLUDE_MAIN
     9#include <boost/test/test_tools.hpp>
     10
     11//Put test class in namespace other
     12namespace other
     13{
     14  #include "./swap_test_class.hpp"
     15}
     16
     17//Provide swap function in namespace other
     18namespace other
     19{
     20  void swap(swap_test_class& left, swap_test_class& right)
     21  {
     22    left.swap(right);
     23  }
     24}
     25
     26int test_main(int, char*[])
     27{
     28  other::swap_test_class object1;
     29  other::swap_test_class object2;
     30  boost::swap(object1,object2);
     31
     32  BOOST_CHECK_EQUAL(other::swap_test_class::swap_count(),1);
     33  BOOST_CHECK_EQUAL(other::swap_test_class::copy_count(),0);
     34
     35  return 0;
     36}
     37 No newline at end of file
  • libs/utility/swap/test/swap_test_class.hpp

    Property changes on: libs\utility\swap\test\specialized_in_other.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7// Tests that the swap header compiles as a standalone translation unit
     8
     9#ifndef BOOST_UTILITY_SWAP_TEST_CLASS_HPP
     10#define BOOST_UTILITY_SWAP_TEST_CLASS_HPP
     11
     12
     13class swap_test_class
     14{
     15public:
     16  swap_test_class()
     17  {
     18    ++constructCount();
     19  }
     20
     21  ~swap_test_class()
     22  {
     23    ++destructCount();
     24  }
     25
     26  swap_test_class(const swap_test_class&)
     27  {
     28    ++copyCount();
     29    ++destructCount();
     30  }
     31
     32  swap_test_class& operator=(const swap_test_class&)
     33  {
     34    ++copyCount();
     35    return *this;
     36  }
     37
     38  void swap(swap_test_class& other)
     39  {
     40    ++swapCount();
     41  }
     42
     43
     44  static unsigned int swap_count(){ return swapCount(); }
     45  static unsigned int copy_count(){ return copyCount(); }
     46  static unsigned int construct_count(){ return constructCount(); }
     47  static unsigned int destruct_count(){ return destructCount(); }
     48
     49  static void reset()
     50  {
     51    swapCount() = 0;
     52    copyCount() = 0;   
     53    constructCount() = 0;
     54    destructCount() = 0;
     55  }
     56
     57private:
     58  static unsigned int& swapCount()
     59  {
     60    static unsigned int value = 0;
     61    return value;
     62  }
     63
     64  static unsigned int& copyCount()   
     65  {
     66    static unsigned int value = 0;
     67    return value;
     68  }
     69
     70  static unsigned int& constructCount()   
     71  {
     72    static unsigned int value = 0;
     73    return value;
     74  }
     75
     76  static unsigned int& destructCount()   
     77  {
     78    static unsigned int value = 0;
     79    return value;
     80  }
     81
     82};
     83
     84#endif
     85
  • libs/utility/swap/test/primitive.cpp

    Property changes on: libs\utility\swap\test\swap_test_class.hpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7#include <boost/utility/swap.hpp>
     8#define BOOST_INCLUDE_MAIN
     9#include <boost/test/test_tools.hpp>
     10
     11int test_main(int, char*[])
     12{
     13  int object1 = 1;
     14  int object2 = 2;
     15
     16  boost::swap(object1,object2);
     17
     18  BOOST_CHECK_EQUAL(object1,2);
     19  BOOST_CHECK_EQUAL(object2,1);
     20
     21  return 0;
     22}
     23 No newline at end of file
  • libs/utility/swap/test/specialized_in_boost.cpp

    Property changes on: libs\utility\swap\test\primitive.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7#include <boost/utility/swap.hpp>
     8#define BOOST_INCLUDE_MAIN
     9#include <boost/test/test_tools.hpp>
     10
     11//Put test class in namespace boost
     12namespace boost
     13{
     14  #include "./swap_test_class.hpp"
     15}
     16
     17//Provide swap function in namespace boost
     18namespace boost
     19{
     20  void swap(swap_test_class& left, swap_test_class& right)
     21  {
     22    left.swap(right);
     23  }
     24}
     25
     26int test_main(int, char*[])
     27{
     28  boost::swap_test_class object1;
     29  boost::swap_test_class object2;
     30  boost::swap(object1,object2);
     31
     32  BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),1);
     33  BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),0);
     34
     35  return 0;
     36}
     37 No newline at end of file
  • libs/utility/swap/test/root_header_1.cpp

    Property changes on: libs\utility\swap\test\specialized_in_boost.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7// Tests that the swap header compiles as a standalone translation unit
     8
     9#include <boost/swap.hpp>
  • libs/utility/swap/test/swap_arrays.cpp

    Property changes on: libs\utility\swap\test\root_header_1.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2008 Joseph Gauterin, Niels Dekker
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7#include <boost/utility/swap.hpp>
     8#define BOOST_INCLUDE_MAIN
     9#include <boost/test/test_tools.hpp>
     10
     11//Put test class in the global namespace
     12#include "./swap_test_class.hpp"
     13
     14
     15int test_main(int, char*[])
     16{
     17  const std::size_t dimension = 7;
     18
     19  swap_test_class array1[dimension];
     20  swap_test_class array2[dimension];
     21  boost::swap(array1, array2);
     22
     23  BOOST_CHECK_EQUAL(swap_test_class::swap_count(), dimension);
     24  BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0);
     25
     26  swap_test_class::reset();
     27
     28  const std::size_t firstDimension = 3;
     29  const std::size_t secondDimension = 4;
     30
     31  swap_test_class two_d_array1[firstDimension][secondDimension];
     32  swap_test_class two_d_array2[firstDimension][secondDimension];
     33  boost::swap(two_d_array1, two_d_array1);
     34
     35  BOOST_CHECK_EQUAL(swap_test_class::swap_count(), firstDimension*secondDimension);
     36  BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0);
     37
     38  return 0;
     39}
  • libs/utility/swap/test/Jamfile.v2

    Property changes on: libs\utility\swap\test\swap_arrays.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1# Copyright (c) 2007, 2008 Joseph Gauterin
     2#
     3# Distributed under the Boost Software License, Version 1.0.
     4# (See accompanying file LICENSE_1_0.txt or copy at
     5# http://www.boost.org/LICENSE_1_0.txt)
     6
     7# bring in rules for testing
     8import testing ;
     9
     10test-suite utility/swap
     11    :
     12    [ compile root_header_1.cpp                                  ]
     13    [ compile root_header_2.cpp                                  ]
     14    [ compile lib_header_1.cpp                                   ]
     15    [ compile lib_header_2.cpp                                   ]
     16    [ compile mixed_headers_1.cpp                                ]
     17    [ compile mixed_headers_2.cpp                                ]
     18    [ run primitive.cpp ../../../test/build//boost_test_exec_monitor/<link>static             ]
     19    [ run specialized_in_boost.cpp ../../../test/build//boost_test_exec_monitor/<link>static  ]
     20    [ run specialized_in_global.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
     21    [ run specialized_in_other.cpp ../../../test/build//boost_test_exec_monitor/<link>static  ]
     22    [ run specialized_in_std.cpp ../../../test/build//boost_test_exec_monitor/<link>static    ]
     23    [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/<link>static    ]
     24    ;
     25   
     26
  • libs/utility/swap/test/root_header_2.cpp

    Property changes on: libs\utility\swap\test\Jamfile.v2
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7// Tests that the swap header include guards work correctly
     8
     9#include <boost/swap.hpp>
     10#include <boost/swap.hpp>
  • libs/utility/swap/test/specialized_in_std.cpp

    Property changes on: libs\utility\swap\test\root_header_2.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7#include <boost/utility/swap.hpp>
     8#define BOOST_INCLUDE_MAIN
     9#include <boost/test/test_tools.hpp>
     10
     11//Put test class in the global namespace
     12#include "./swap_test_class.hpp"
     13
     14
     15//Provide swap function in namespace std
     16namespace std
     17{
     18  template <>
     19  void swap(swap_test_class& left, swap_test_class& right)
     20  {
     21    left.swap(right);
     22  }
     23}
     24
     25int test_main(int, char*[])
     26{
     27  swap_test_class object1;
     28  swap_test_class object2;
     29  boost::swap(object1,object2);
     30
     31  BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1);
     32  BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
     33
     34  return 0;
     35}
     36 No newline at end of file
  • libs/utility/swap/test/Jamfile.v2

    Property changes on: libs\utility\swap\test\specialized_in_std.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1# Copyright (c) 2007, 2008 Joseph Gauterin
     2#
     3# Distributed under the Boost Software License, Version 1.0.
     4# (See accompanying file LICENSE_1_0.txt or copy at
     5# http://www.boost.org/LICENSE_1_0.txt)
     6
     7# bring in rules for testing
     8import testing ;
     9
     10test-suite utility/swap
     11    :
     12    [ compile root_header_1.cpp                                  ]
     13    [ compile root_header_2.cpp                                  ]
     14    [ compile lib_header_1.cpp                                   ]
     15    [ compile lib_header_2.cpp                                   ]
     16    [ compile mixed_headers_1.cpp                                ]
     17    [ compile mixed_headers_2.cpp                                ]
     18    [ run primitive.cpp ../../../test/build//boost_test_exec_monitor/<link>static             ]
     19    [ run specialized_in_boost.cpp ../../../test/build//boost_test_exec_monitor/<link>static  ]
     20    [ run specialized_in_global.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
     21    [ run specialized_in_other.cpp ../../../test/build//boost_test_exec_monitor/<link>static  ]
     22    [ run specialized_in_std.cpp ../../../test/build//boost_test_exec_monitor/<link>static    ]
     23    [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/<link>static    ]
     24    ;
     25   
     26
  • libs/utility/swap/test/lib_header_1.cpp

    Property changes on: libs\utility\swap\test\Jamfile.v2
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7// Tests that the swap header compiles as a standalone translation unit
     8
     9#include <boost/utility/swap.hpp>
  • libs/utility/swap/test/lib_header_2.cpp

    Property changes on: libs\utility\swap\test\lib_header_1.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7// Tests that the swap header include guards work correctly
     8
     9#include <boost/utility/swap.hpp>
     10#include <boost/utility/swap.hpp>
  • libs/utility/swap/test/mixed_headers_1.cpp

    Property changes on: libs\utility\swap\test\lib_header_2.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7// Tests that the swap headers work when both are included
     8
     9#include <boost/swap.hpp>
     10#include <boost/utility/swap.hpp>
  • libs/utility/swap/test/mixed_headers_2.cpp

    Property changes on: libs\utility\swap\test\mixed_headers_1.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7// Tests that the swap headers work when both are included
     8
     9#include <boost/utility/swap.hpp>
     10#include <boost/swap.hpp>
  • libs/utility/swap/test/primitive.cpp

    Property changes on: libs\utility\swap\test\mixed_headers_2.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7#include <boost/utility/swap.hpp>
     8#define BOOST_INCLUDE_MAIN
     9#include <boost/test/test_tools.hpp>
     10
     11int test_main(int, char*[])
     12{
     13  int object1 = 1;
     14  int object2 = 2;
     15
     16  boost::swap(object1,object2);
     17
     18  BOOST_CHECK_EQUAL(object1,2);
     19  BOOST_CHECK_EQUAL(object2,1);
     20
     21  return 0;
     22}
     23 No newline at end of file
  • libs/utility/swap/test/root_header_1.cpp

    Property changes on: libs\utility\swap\test\primitive.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7// Tests that the swap header compiles as a standalone translation unit
     8
     9#include <boost/swap.hpp>
  • libs/utility/swap/test/root_header_2.cpp

    Property changes on: libs\utility\swap\test\root_header_1.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7// Tests that the swap header include guards work correctly
     8
     9#include <boost/swap.hpp>
     10#include <boost/swap.hpp>
  • libs/utility/swap/test/specialized_in_boost.cpp

    Property changes on: libs\utility\swap\test\root_header_2.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7#include <boost/utility/swap.hpp>
     8#define BOOST_INCLUDE_MAIN
     9#include <boost/test/test_tools.hpp>
     10
     11//Put test class in namespace boost
     12namespace boost
     13{
     14  #include "./swap_test_class.hpp"
     15}
     16
     17//Provide swap function in namespace boost
     18namespace boost
     19{
     20  void swap(swap_test_class& left, swap_test_class& right)
     21  {
     22    left.swap(right);
     23  }
     24}
     25
     26int test_main(int, char*[])
     27{
     28  boost::swap_test_class object1;
     29  boost::swap_test_class object2;
     30  boost::swap(object1,object2);
     31
     32  BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),1);
     33  BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),0);
     34
     35  return 0;
     36}
     37 No newline at end of file
  • libs/utility/swap/test/specialized_in_global.cpp

    Property changes on: libs\utility\swap\test\specialized_in_boost.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7#include <boost/utility/swap.hpp>
     8#define BOOST_INCLUDE_MAIN
     9#include <boost/test/test_tools.hpp>
     10
     11//Put test class in the global namespace
     12#include "./swap_test_class.hpp"
     13
     14//Provide swap function in gloabl namespace
     15void swap(swap_test_class& left, swap_test_class& right)
     16{
     17  left.swap(right);
     18}
     19
     20int test_main(int, char*[])
     21{
     22  swap_test_class object1;
     23  swap_test_class object2;
     24  boost::swap(object1,object2);
     25
     26  BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1);
     27  BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
     28
     29  return 0;
     30}
     31 No newline at end of file
  • libs/utility/swap/test/specialized_in_other.cpp

    Property changes on: libs\utility\swap\test\specialized_in_global.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7#include <boost/utility/swap.hpp>
     8#define BOOST_INCLUDE_MAIN
     9#include <boost/test/test_tools.hpp>
     10
     11//Put test class in namespace other
     12namespace other
     13{
     14  #include "./swap_test_class.hpp"
     15}
     16
     17//Provide swap function in namespace other
     18namespace other
     19{
     20  void swap(swap_test_class& left, swap_test_class& right)
     21  {
     22    left.swap(right);
     23  }
     24}
     25
     26int test_main(int, char*[])
     27{
     28  other::swap_test_class object1;
     29  other::swap_test_class object2;
     30  boost::swap(object1,object2);
     31
     32  BOOST_CHECK_EQUAL(other::swap_test_class::swap_count(),1);
     33  BOOST_CHECK_EQUAL(other::swap_test_class::copy_count(),0);
     34
     35  return 0;
     36}
     37 No newline at end of file
  • libs/utility/swap/test/specialized_in_std.cpp

    Property changes on: libs\utility\swap\test\specialized_in_other.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7#include <boost/utility/swap.hpp>
     8#define BOOST_INCLUDE_MAIN
     9#include <boost/test/test_tools.hpp>
     10
     11//Put test class in the global namespace
     12#include "./swap_test_class.hpp"
     13
     14
     15//Provide swap function in namespace std
     16namespace std
     17{
     18  template <>
     19  void swap(swap_test_class& left, swap_test_class& right)
     20  {
     21    left.swap(right);
     22  }
     23}
     24
     25int test_main(int, char*[])
     26{
     27  swap_test_class object1;
     28  swap_test_class object2;
     29  boost::swap(object1,object2);
     30
     31  BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1);
     32  BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
     33
     34  return 0;
     35}
     36 No newline at end of file
  • libs/utility/swap/test/swap_arrays.cpp

    Property changes on: libs\utility\swap\test\specialized_in_std.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2008 Joseph Gauterin, Niels Dekker
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7#include <boost/utility/swap.hpp>
     8#define BOOST_INCLUDE_MAIN
     9#include <boost/test/test_tools.hpp>
     10
     11//Put test class in the global namespace
     12#include "./swap_test_class.hpp"
     13
     14
     15int test_main(int, char*[])
     16{
     17  const std::size_t dimension = 7;
     18
     19  swap_test_class array1[dimension];
     20  swap_test_class array2[dimension];
     21  boost::swap(array1, array2);
     22
     23  BOOST_CHECK_EQUAL(swap_test_class::swap_count(), dimension);
     24  BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0);
     25
     26  swap_test_class::reset();
     27
     28  const std::size_t firstDimension = 3;
     29  const std::size_t secondDimension = 4;
     30
     31  swap_test_class two_d_array1[firstDimension][secondDimension];
     32  swap_test_class two_d_array2[firstDimension][secondDimension];
     33  boost::swap(two_d_array1, two_d_array1);
     34
     35  BOOST_CHECK_EQUAL(swap_test_class::swap_count(), firstDimension*secondDimension);
     36  BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0);
     37
     38  return 0;
     39}
  • libs/utility/swap/test/swap_test_class.hpp

    Property changes on: libs\utility\swap\test\swap_arrays.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
     1// Copyright (c) 2007 Joseph Gauterin
     2//
     3// Distributed under the Boost Software License, Version 1.0.
     4// (See accompanying file LICENSE_1_0.txt or copy at
     5// http://www.boost.org/LICENSE_1_0.txt)
     6
     7// Tests that the swap header compiles as a standalone translation unit
     8
     9#ifndef BOOST_UTILITY_SWAP_TEST_CLASS_HPP
     10#define BOOST_UTILITY_SWAP_TEST_CLASS_HPP
     11
     12
     13class swap_test_class
     14{
     15public:
     16  swap_test_class()
     17  {
     18    ++constructCount();
     19  }
     20
     21  ~swap_test_class()
     22  {
     23    ++destructCount();
     24  }
     25
     26  swap_test_class(const swap_test_class&)
     27  {
     28    ++copyCount();
     29    ++destructCount();
     30  }
     31
     32  swap_test_class& operator=(const swap_test_class&)
     33  {
     34    ++copyCount();
     35    return *this;
     36  }
     37
     38  void swap(swap_test_class& other)
     39  {
     40    ++swapCount();
     41  }
     42
     43
     44  static unsigned int swap_count(){ return swapCount(); }
     45  static unsigned int copy_count(){ return copyCount(); }
     46  static unsigned int construct_count(){ return constructCount(); }
     47  static unsigned int destruct_count(){ return destructCount(); }
     48
     49  static void reset()
     50  {
     51    swapCount() = 0;
     52    copyCount() = 0;   
     53    constructCount() = 0;
     54    destructCount() = 0;
     55  }
     56
     57private:
     58  static unsigned int& swapCount()
     59  {
     60    static unsigned int value = 0;
     61    return value;
     62  }
     63
     64  static unsigned int& copyCount()   
     65  {
     66    static unsigned int value = 0;
     67    return value;
     68  }
     69
     70  static unsigned int& constructCount()   
     71  {
     72    static unsigned int value = 0;
     73    return value;
     74  }
     75
     76  static unsigned int& destructCount()   
     77  {
     78    static unsigned int value = 0;
     79    return value;
     80  }
     81
     82};
     83
     84#endif
     85
  • status/Jamfile.v2

    Property changes on: libs\utility\swap\test\swap_test_class.hpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
    112112    spirit/test                 # test-suite spirit_v2
    113113    statechart/test             # test-suite statechart
    114114    static_assert               # test-suite static_assert
     115    static_assert               # test-suite static_assert
    115116    system/test                 # test-suite system
    116117    test/test                   # test-suite test
    117118    thread/test                 # test-suite thread
     
    125126    unordered/test/unordered    # test-suite unordered
    126127    unordered/test/exception    # test-suite unordered-exception
    127128    utility/enable_if/test      # test-suite utility/enable_if
     129    utility/swap/test           # test-suite utility/swap
    128130    utility/test                # test-suite utility
    129131    variant/test                # test-suite variant
    130132    wave/test/build             # test-suite wave