Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r49423 - in branches/release/libs/dynamic_bitset: . example
From: gennaro.prota_at_[hidden]
Date: 2008-10-21 13:57:40


Author: gennaro_prota
Date: 2008-10-21 13:57:39 EDT (Tue, 21 Oct 2008)
New Revision: 49423
URL: http://svn.boost.org/trac/boost/changeset/49423

Log:
dynamic_bitset: full (recursive) sync with trunk for libs/dynamic_bitset/
Properties modified:
   branches/release/libs/dynamic_bitset/Jamfile.v2 (props changed)
   branches/release/libs/dynamic_bitset/bitset_test.hpp (props changed)
   branches/release/libs/dynamic_bitset/dyn_bitset_unit_tests1.cpp (props changed)
   branches/release/libs/dynamic_bitset/dyn_bitset_unit_tests2.cpp (contents, props changed)
   branches/release/libs/dynamic_bitset/dyn_bitset_unit_tests3.cpp (contents, props changed)
   branches/release/libs/dynamic_bitset/dyn_bitset_unit_tests4.cpp (contents, props changed)
   branches/release/libs/dynamic_bitset/dynamic_bitset.html (props changed)
   branches/release/libs/dynamic_bitset/example/Jamfile (contents, props changed)
   branches/release/libs/dynamic_bitset/example/example1.cpp (contents, props changed)
   branches/release/libs/dynamic_bitset/example/example2.cpp (contents, props changed)
   branches/release/libs/dynamic_bitset/example/example3.cpp (contents, props changed)
   branches/release/libs/dynamic_bitset/example/timing_tests.cpp (contents, props changed)
   branches/release/libs/dynamic_bitset/index.html (props changed)
Text files modified:
   branches/release/libs/dynamic_bitset/dyn_bitset_unit_tests2.cpp | 8 +--
   branches/release/libs/dynamic_bitset/dyn_bitset_unit_tests3.cpp | 8 +--
   branches/release/libs/dynamic_bitset/dyn_bitset_unit_tests4.cpp | 8 +--
   branches/release/libs/dynamic_bitset/example/Jamfile | 8 +--
   branches/release/libs/dynamic_bitset/example/example1.cpp | 42 +++++++++++-------
   branches/release/libs/dynamic_bitset/example/example2.cpp | 15 ++++--
   branches/release/libs/dynamic_bitset/example/example3.cpp | 88 ++++++++++++++++++++++++++++-----------
   branches/release/libs/dynamic_bitset/example/timing_tests.cpp | 10 ++--
   8 files changed, 114 insertions(+), 73 deletions(-)

Modified: branches/release/libs/dynamic_bitset/dyn_bitset_unit_tests2.cpp
==============================================================================
--- branches/release/libs/dynamic_bitset/dyn_bitset_unit_tests2.cpp (original)
+++ branches/release/libs/dynamic_bitset/dyn_bitset_unit_tests2.cpp 2008-10-21 13:57:39 EDT (Tue, 21 Oct 2008)
@@ -1,14 +1,12 @@
-// --------------------------------------------------------
-// (C) Copyright Jeremy Siek 2001.
-// (C) Copyright Gennaro Prota 2003 - 2006.
+// -----------------------------------------------------------
+// Copyright (c) 2001 Jeremy Siek
+// Copyright (c) 2003-2006 Gennaro Prota
 //
 // Distributed under 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)
 //
 // -----------------------------------------------------------
-//
-// $Id$
 
 #include "bitset_test.hpp"
 #include "boost/dynamic_bitset/dynamic_bitset.hpp"

Modified: branches/release/libs/dynamic_bitset/dyn_bitset_unit_tests3.cpp
==============================================================================
--- branches/release/libs/dynamic_bitset/dyn_bitset_unit_tests3.cpp (original)
+++ branches/release/libs/dynamic_bitset/dyn_bitset_unit_tests3.cpp 2008-10-21 13:57:39 EDT (Tue, 21 Oct 2008)
@@ -1,14 +1,12 @@
-// --------------------------------------------------------
-// (C) Copyright Jeremy Siek 2001.
-// (C) Copyright Gennaro Prota 2003 - 2006.
+// -----------------------------------------------------------
+// Copyright (c) 2001 Jeremy Siek
+// Copyright (c) 2003-2006 Gennaro Prota
 //
 // Distributed under 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)
 //
 // -----------------------------------------------------------
-//
-// $Id$
 
 #include <assert.h>
 #include "bitset_test.hpp"

Modified: branches/release/libs/dynamic_bitset/dyn_bitset_unit_tests4.cpp
==============================================================================
--- branches/release/libs/dynamic_bitset/dyn_bitset_unit_tests4.cpp (original)
+++ branches/release/libs/dynamic_bitset/dyn_bitset_unit_tests4.cpp 2008-10-21 13:57:39 EDT (Tue, 21 Oct 2008)
@@ -1,14 +1,12 @@
-// --------------------------------------------------------
-// (C) Copyright Jeremy Siek 2001.
-// (C) Copyright Gennaro Prota 2003 - 2006.
+// -----------------------------------------------------------
+// Copyright (c) 2001 Jeremy Siek
+// Copyright (c) 2003-2006 Gennaro Prota
 //
 // Distributed under 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)
 //
 // -----------------------------------------------------------
-//
-// $Id$
 
 #include <fstream>
 #include <string>

Modified: branches/release/libs/dynamic_bitset/example/Jamfile
==============================================================================
--- branches/release/libs/dynamic_bitset/example/Jamfile (original)
+++ branches/release/libs/dynamic_bitset/example/Jamfile 2008-10-21 13:57:39 EDT (Tue, 21 Oct 2008)
@@ -1,13 +1,11 @@
-// (C) Copyright Gennaro Prota 2002
+// -----------------------------------------------------------
+// Copyright (c) 2002 Gennaro Prota
 //
 // Distributed under 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)
 //
-// ----------------------------------------------------------
-//
-// $Id$
-
+// -----------------------------------------------------------
 exe timing_tests
     : timing_tests.cpp
     ;

Modified: branches/release/libs/dynamic_bitset/example/example1.cpp
==============================================================================
--- branches/release/libs/dynamic_bitset/example/example1.cpp (original)
+++ branches/release/libs/dynamic_bitset/example/example1.cpp 2008-10-21 13:57:39 EDT (Tue, 21 Oct 2008)
@@ -3,23 +3,33 @@
 // accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
-// Sample output:
-// 1
-// 1
-// 0
-// 0
-// 1
+
+
+// An example of setting and reading some bits. Note that operator[]
+// goes from the least-significant bit at 0 to the most significant
+// bit at size()-1. The operator<< for dynamic_bitset prints the
+// bitset from most-significant to least-significant, since that is
+// the format most people are used to reading.
+//
+// The output is:
+//
+// 11001
+// 10011
+// ---------------------------------------------------------------------
 
 #include <iostream>
 #include <boost/dynamic_bitset.hpp>
-int main() {
- boost::dynamic_bitset<> x(5); // all 0's by default
- x[0] = 1;
- x[1] = 1;
- x[4] = 1;
- for (boost::dynamic_bitset<>::size_type i = 0; i < x.size(); ++i)
- std::cout << x[i];
- std::cout << "\n";
- std::cout << x << "\n";
- return EXIT_SUCCESS;
+
+int main()
+{
+ boost::dynamic_bitset<> x(5); // all 0's by default
+ x[0] = 1;
+ x[1] = 1;
+ x[4] = 1;
+ for (boost::dynamic_bitset<>::size_type i = 0; i < x.size(); ++i)
+ std::cout << x[i];
+ std::cout << "\n";
+ std::cout << x << "\n";
+
+ return 0;
 }

Modified: branches/release/libs/dynamic_bitset/example/example2.cpp
==============================================================================
--- branches/release/libs/dynamic_bitset/example/example2.cpp (original)
+++ branches/release/libs/dynamic_bitset/example/example2.cpp 2008-10-21 13:57:39 EDT (Tue, 21 Oct 2008)
@@ -3,27 +3,30 @@
 // accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 //
-// Sample output:
+// Sample output:
+//
 // bits(0) = 00
 // bits(1) = 01
 // bits(2) = 10
 // bits(3) = 11
 
+
 #include <iostream>
 #include <boost/dynamic_bitset.hpp>
+
 int main()
 {
- const boost::dynamic_bitset<> b0(2, 0ul);
+ const boost::dynamic_bitset<> b0(2, 0ul);
   std::cout << "bits(0) = " << b0 << std::endl;
 
- const boost::dynamic_bitset<> b1(2, 1ul);
+ const boost::dynamic_bitset<> b1(2, 1ul);
   std::cout << "bits(1) = " << b1 << std::endl;
 
- const boost::dynamic_bitset<> b2(2, 2ul);
+ const boost::dynamic_bitset<> b2(2, 2ul);
   std::cout << "bits(2) = " << b2 << std::endl;
 
- const boost::dynamic_bitset<> b3(2, 3ul);
+ const boost::dynamic_bitset<> b3(2, 3ul);
   std::cout << "bits(3) = " << b3 << std::endl;
 
- return EXIT_SUCCESS;
+ return 0;
 }

Modified: branches/release/libs/dynamic_bitset/example/example3.cpp
==============================================================================
--- branches/release/libs/dynamic_bitset/example/example3.cpp (original)
+++ branches/release/libs/dynamic_bitset/example/example3.cpp 2008-10-21 13:57:39 EDT (Tue, 21 Oct 2008)
@@ -1,35 +1,71 @@
-// (C) Copyright Jeremy Siek 2001.
+// Copyright (c) 2001 Jeremy Siek
+// Copyright (c) 2008 Gennaro Prota
 // Distributed under 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)
 //
-// Sample output:
-// mask = 101010101010
-// Enter a 12-bit bitset in binary: 100110101101
-// x = 100110101101
-// As ulong: 2477
-// And with mask: 100010101000
-// Or with mask: 101110101111
+// Sample run:
+//
+// mask = 101010101010
+// x.size() = 0
+// Enter a bitset in binary: x = 100100010
+//
+// Input number: 100100010
+// x.size() is now: 9
+// As unsigned long: 290
+// Mask (possibly resized): 010101010
+// And with mask: 000100010
+// Or with mask: 110101010
+// Shifted left by 1: 001000100
+// Shifted right by 1: 010010001
+
 
 
+#include "boost/dynamic_bitset.hpp"
+
+#include <ostream>
 #include <iostream>
-#include <boost/dynamic_bitset.hpp>
 
-int main(int, char*[]) {
- const boost::dynamic_bitset<> mask(12, 2730ul);
- std::cout << "mask = " << mask << std::endl;
-
- boost::dynamic_bitset<> x(12);
- std::cout << "x.size()=" << x.size() << std::endl;
-
- std::cout << "Enter a 12-bit bitset in binary: " << std::flush;
- if (std::cin >> x) {
- std::cout << "input number: " << x << std::endl;
- std::cout << "As unsigned long: " << x.to_ulong() << std::endl;
- std::cout << "And with mask: " << (x & mask) << std::endl;
- std::cout << "Or with mask: " << (x | mask) << std::endl;
- std::cout << "Shifted left: " << (x << 1) << std::endl;
- std::cout << "Shifted right: " << (x >> 1) << std::endl;
- }
- return EXIT_SUCCESS;
+int main()
+{
+ boost::dynamic_bitset<> mask(12, 2730ul);
+ std::cout << "mask = " << mask << std::endl;
+
+ boost::dynamic_bitset<> x;
+ std::cout << "x.size() = " << x.size() << std::endl;
+
+ std::cout << "Enter a bitset in binary: x = " << std::flush;
+ if (std::cin >> x) {
+ const std::size_t sz = x.size();
+ std::cout << std::endl;
+ std::cout << "Input number: " << x << std::endl;
+ std::cout << "x.size() is now: " << sz << std::endl;
+
+ bool fits_in_ulong = true;
+ unsigned long ul = 0;
+ try {
+ ul = x.to_ulong();
+ } catch(std::overflow_error &) {
+ fits_in_ulong = false;
+ }
+
+ std::cout << "As unsigned long: ";
+ if(fits_in_ulong) {
+ std::cout << ul;
+ } else {
+ std::cout << "(overflow exception)";
+ }
+
+ std::cout << std::endl;
+
+ mask.resize(sz);
+
+ std::cout << "Mask (possibly resized): " << mask << std::endl;
+
+ std::cout << "And with mask: " << (x & mask) << std::endl;
+ std::cout << "Or with mask: " << (x | mask) << std::endl;
+ std::cout << "Shifted left by 1: " << (x << 1) << std::endl;
+ std::cout << "Shifted right by 1: " << (x >> 1) << std::endl;
+ }
+ return 0;
 }

Modified: branches/release/libs/dynamic_bitset/example/timing_tests.cpp
==============================================================================
--- branches/release/libs/dynamic_bitset/example/timing_tests.cpp (original)
+++ branches/release/libs/dynamic_bitset/example/timing_tests.cpp 2008-10-21 13:57:39 EDT (Tue, 21 Oct 2008)
@@ -1,7 +1,6 @@
 // -----------------------------------------------------------
-// boost::dynamic_bitset timing tests
-
-// (C) Copyright Gennaro Prota 2003 - 2004.
+//
+// Copyright (c) 2003-2004 Gennaro Prota
 //
 // Distributed under the Boost Software License, Version 1.0.
 // (See accompanying file LICENSE_1_0.txt or copy at
@@ -9,6 +8,8 @@
 //
 // -----------------------------------------------------------
 
+// boost::dynamic_bitset timing tests
+//
 // NOTE:
 // ~~~~~
 // This is a preliminary, incomplete version.
@@ -25,8 +26,7 @@
 //
 //
 // -----------------------------------------------------------------------//
-//
-// $Id$
+
 
 #include "boost/config.hpp"
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk