Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77071 - in trunk/libs: scope_exit/test utility/identity_type/test
From: lorcaminiti_at_[hidden]
Date: 2012-02-18 14:29:37


Author: lcaminiti
Date: 2012-02-18 14:29:35 EST (Sat, 18 Feb 2012)
New Revision: 77071
URL: http://svn.boost.org/trac/boost/changeset/77071

Log:
Updated ScopeExit "world" tests making person a struct instead of a class.
Added a code comment to Utility/IdentityType tmp_assert test.
Text files modified:
   trunk/libs/scope_exit/test/world.cpp | 9 +++++--
   trunk/libs/scope_exit/test/world_checkpoint.cpp | 45 +++++++++++++++++----------------------
   trunk/libs/scope_exit/test/world_checkpoint_all.cpp | 45 +++++++++++++++++----------------------
   trunk/libs/scope_exit/test/world_checkpoint_all_seq.cpp | 45 +++++++++++++++++----------------------
   trunk/libs/scope_exit/test/world_checkpoint_seq.cpp | 44 +++++++++++++++++---------------------
   trunk/libs/scope_exit/test/world_lambda.cpp | 2
   trunk/libs/scope_exit/test/world_seq.cpp | 9 +++++--
   trunk/libs/scope_exit/test/world_this.cpp | 9 +++++--
   trunk/libs/scope_exit/test/world_this_seq.cpp | 9 +++++--
   trunk/libs/scope_exit/test/world_tpl.cpp | 9 +++++--
   trunk/libs/scope_exit/test/world_tpl_seq.cpp | 9 +++++--
   trunk/libs/scope_exit/test/world_void.cpp | 2
   trunk/libs/utility/identity_type/test/tmp_assert.cpp | 8 ++++--
   13 files changed, 123 insertions(+), 122 deletions(-)

Modified: trunk/libs/scope_exit/test/world.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world.cpp (original)
+++ trunk/libs/scope_exit/test/world.cpp 2012-02-18 14:29:35 EST (Sat, 18 Feb 2012)
@@ -17,14 +17,17 @@
 #include <boost/test/unit_test.hpp>
 #include <vector>
 
-struct person; BOOST_TYPEOF_REGISTER_TYPE(person)
 struct person {};
+BOOST_TYPEOF_REGISTER_TYPE(person)
 
-struct world; BOOST_TYPEOF_REGISTER_TYPE(world)
 struct world {
     void add_person(person const& a_person);
+ size_t population(void) const { return persons_.size(); }
+
+private:
     std::vector<person> persons_;
 };
+BOOST_TYPEOF_REGISTER_TYPE(world)
 
 //[world
 void world::add_person(person const& a_person) {
@@ -46,7 +49,7 @@
     world w;
     person p;
     w.add_person(p);
- BOOST_CHECK( w.persons_.size() == 1 );
+ BOOST_CHECK( w.population() == 1 );
 }
 
 #else

Modified: trunk/libs/scope_exit/test/world_checkpoint.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world_checkpoint.cpp (original)
+++ trunk/libs/scope_exit/test/world_checkpoint.cpp 2012-02-18 14:29:35 EST (Sat, 18 Feb 2012)
@@ -20,30 +20,23 @@
 #include <iostream>
 #include <sstream>
 
-class person; BOOST_TYPEOF_REGISTER_TYPE(person)
-class person {
- friend class world;
-public:
+struct person {
     typedef unsigned int id_t;
     typedef unsigned int evolution_t;
+
+ id_t id;
+ evolution_t evolution;
 
- person(void) : id_(0), evolution_(0) {}
+ person(void) : id(0), evolution(0) {}
 
     friend std::ostream& operator<<(std::ostream& o, person const& p) {
- return o << "person(" << p.id_ << ", " << p.evolution_ << ")";
+ return o << "person(" << p.id << ", " << p.evolution << ")";
     }
-private:
- id_t id_;
- evolution_t evolution_;
 };
+BOOST_TYPEOF_REGISTER_TYPE(person)
 
-class world; BOOST_TYPEOF_REGISTER_TYPE(world)
-class world {
-public:
- typedef unsigned int id_t;
-
+struct world {
     world(void) : next_id_(1) {}
-
     void add_person(person const& a_person);
 
     friend std::ostream& operator<<(std::ostream& o, world const& w) {
@@ -53,10 +46,12 @@
         }
         return o << "})";
     }
+
 private:
- id_t next_id_;
+ person::id_t next_id_;
     std::vector<person> persons_;
 };
+BOOST_TYPEOF_REGISTER_TYPE(world)
 
 //[world_checkpoint
 void world::add_person(person const& a_person) {
@@ -64,28 +59,28 @@
 
     // This block must be no-throw.
     person& p = persons_.back();
- person::evolution_t checkpoint = p.evolution_;
+ person::evolution_t checkpoint = p.evolution;
     BOOST_SCOPE_EXIT(checkpoint, &p, &persons_) {
- if(checkpoint == p.evolution_) persons_.pop_back();
+ if(checkpoint == p.evolution) persons_.pop_back();
     } BOOST_SCOPE_EXIT_END
 
     // ...
 
- checkpoint = ++p.evolution_;
+ checkpoint = ++p.evolution;
 
     // Assign new identifier to the person.
- world::id_t const prev_id = p.id_;
- p.id_ = next_id_++;
+ person::id_t const prev_id = p.id;
+ p.id = next_id_++;
     BOOST_SCOPE_EXIT(checkpoint, &p, &next_id_, prev_id) {
- if(checkpoint == p.evolution_) {
- next_id_ = p.id_;
- p.id_ = prev_id;
+ if(checkpoint == p.evolution) {
+ next_id_ = p.id;
+ p.id = prev_id;
         }
     } BOOST_SCOPE_EXIT_END
 
     // ...
 
- checkpoint = ++p.evolution_;
+ checkpoint = ++p.evolution;
 }
 //]
 

Modified: trunk/libs/scope_exit/test/world_checkpoint_all.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world_checkpoint_all.cpp (original)
+++ trunk/libs/scope_exit/test/world_checkpoint_all.cpp 2012-02-18 14:29:35 EST (Sat, 18 Feb 2012)
@@ -20,30 +20,23 @@
 #include <iostream>
 #include <sstream>
 
-class person; BOOST_TYPEOF_REGISTER_TYPE(person)
-class person {
- friend class world;
-public:
+struct person {
     typedef unsigned int id_t;
     typedef unsigned int evolution_t;
+
+ id_t id;
+ evolution_t evolution;
 
- person(void) : id_(0), evolution_(0) {}
+ person(void) : id(0), evolution(0) {}
 
     friend std::ostream& operator<<(std::ostream& o, person const& p) {
- return o << "person(" << p.id_ << ", " << p.evolution_ << ")";
+ return o << "person(" << p.id << ", " << p.evolution << ")";
     }
-private:
- id_t id_;
- evolution_t evolution_;
 };
+BOOST_TYPEOF_REGISTER_TYPE(person)
 
-class world; BOOST_TYPEOF_REGISTER_TYPE(world)
-class world {
-public:
- typedef unsigned int id_t;
-
+struct world {
     world(void) : next_id_(1) {}
-
     void add_person(person const& a_person);
 
     friend std::ostream& operator<<(std::ostream& o, world const& w) {
@@ -53,10 +46,12 @@
         }
         return o << "})";
     }
+
 private:
- id_t next_id_;
+ person::id_t next_id_;
     std::vector<person> persons_;
 };
+BOOST_TYPEOF_REGISTER_TYPE(world)
 
 //[world_checkpoint_all
 void world::add_person(person const& a_person) {
@@ -64,28 +59,28 @@
 
     // This block must be no-throw.
     person& p = persons_.back();
- person::evolution_t checkpoint = p.evolution_;
+ person::evolution_t checkpoint = p.evolution;
     BOOST_SCOPE_EXIT_ALL(&, checkpoint, this_) { // Capture all by ref (C++11).
- if(checkpoint == p.evolution_) this_->persons_.pop_back();
+ if(checkpoint == p.evolution) this_->persons_.pop_back();
     } BOOST_SCOPE_EXIT_END
 
     // ...
 
- checkpoint = ++p.evolution_;
+ checkpoint = ++p.evolution;
 
     // Assign new identifier to the person.
- world::id_t const prev_id = p.id_;
- p.id_ = next_id_++;
+ person::id_t const prev_id = p.id;
+ p.id = next_id_++;
     BOOST_SCOPE_EXIT_ALL(=, &p, this) { // Capture all by value, `this` (C++11).
- if(checkpoint == p.evolution_) {
- this->next_id_ = p.id_;
- p.id_ = prev_id;
+ if(checkpoint == p.evolution) {
+ this->next_id_ = p.id;
+ p.id = prev_id;
         }
     }; // Use `;` instead of `SCOPE_EXIT_END` (C++11).
 
     // ...
 
- checkpoint = ++p.evolution_;
+ checkpoint = ++p.evolution;
 }
 //]
 

Modified: trunk/libs/scope_exit/test/world_checkpoint_all_seq.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world_checkpoint_all_seq.cpp (original)
+++ trunk/libs/scope_exit/test/world_checkpoint_all_seq.cpp 2012-02-18 14:29:35 EST (Sat, 18 Feb 2012)
@@ -20,30 +20,23 @@
 #include <iostream>
 #include <sstream>
 
-class person; BOOST_TYPEOF_REGISTER_TYPE(person)
-class person {
- friend class world;
-public:
+struct person {
     typedef unsigned int id_t;
     typedef unsigned int evolution_t;
 
- person(void) : id_(0), evolution_(0) {}
+ id_t id;
+ evolution_t evolution;
+
+ person(void) : id(0), evolution(0) {}
 
     friend std::ostream& operator<<(std::ostream& o, person const& p) {
- return o << "person(" << p.id_ << ", " << p.evolution_ << ")";
+ return o << "person(" << p.id << ", " << p.evolution << ")";
     }
-private:
- id_t id_;
- evolution_t evolution_;
 };
+BOOST_TYPEOF_REGISTER_TYPE(person)
 
-class world; BOOST_TYPEOF_REGISTER_TYPE(world)
-class world {
-public:
- typedef unsigned int id_t;
-
+struct world {
     world(void) : next_id_(1) {}
-
     void add_person(person const& a_person);
 
     friend std::ostream& operator<<(std::ostream& o, world const& w) {
@@ -53,10 +46,12 @@
         }
         return o << "})";
     }
+
 private:
- id_t next_id_;
+ person::id_t next_id_;
     std::vector<person> persons_;
 };
+BOOST_TYPEOF_REGISTER_TYPE(world)
 
 //[world_checkpoint_all_seq
 void world::add_person(person const& a_person) {
@@ -64,28 +59,28 @@
 
     // This block must be no-throw.
     person& p = persons_.back();
- person::evolution_t checkpoint = p.evolution_;
+ person::evolution_t checkpoint = p.evolution;
     BOOST_SCOPE_EXIT_ALL( (&) (checkpoint) (this_) ) {
- if(checkpoint == p.evolution_) this_->persons_.pop_back();
+ if(checkpoint == p.evolution) this_->persons_.pop_back();
     } BOOST_SCOPE_EXIT_END
 
     // ...
 
- checkpoint = ++p.evolution_;
+ checkpoint = ++p.evolution;
 
     // Assign new identifier to the person.
- world::id_t const prev_id = p.id_;
- p.id_ = next_id_++;
+ person::id_t const prev_id = p.id;
+ p.id = next_id_++;
     BOOST_SCOPE_EXIT_ALL( (=) (&p) (this) ) {
- if(checkpoint == p.evolution_) {
- this->next_id_ = p.id_;
- p.id_ = prev_id;
+ if(checkpoint == p.evolution) {
+ this->next_id_ = p.id;
+ p.id = prev_id;
         }
     };
 
     // ...
 
- checkpoint = ++p.evolution_;
+ checkpoint = ++p.evolution;
 }
 //]
 

Modified: trunk/libs/scope_exit/test/world_checkpoint_seq.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world_checkpoint_seq.cpp (original)
+++ trunk/libs/scope_exit/test/world_checkpoint_seq.cpp 2012-02-18 14:29:35 EST (Sat, 18 Feb 2012)
@@ -17,28 +17,22 @@
 #include <iostream>
 #include <sstream>
 
-class person; BOOST_TYPEOF_REGISTER_TYPE(person)
-class person {
- friend class world;
-public:
+struct person {
     typedef unsigned int id_t;
     typedef unsigned int evolution_t;
 
- person(void) : id_(0), evolution_(0) {}
+ id_t id;
+ evolution_t evolution;
+
+ person(void) : id(0), evolution(0) {}
 
     friend std::ostream& operator<<(std::ostream& o, person const& p) {
- return o << "person(" << p.id_ << ", " << p.evolution_ << ")";
+ return o << "person(" << p.id << ", " << p.evolution << ")";
     }
-private:
- id_t id_;
- evolution_t evolution_;
 };
+BOOST_TYPEOF_REGISTER_TYPE(person)
 
-class world; BOOST_TYPEOF_REGISTER_TYPE(world)
-class world {
-public:
- typedef unsigned int id_t;
-
+struct world {
     world(void) : next_id_(1) {}
 
     void add_person(person const& a_person);
@@ -50,10 +44,12 @@
         }
         return o << "})";
     }
+
 private:
- id_t next_id_;
+ person::id_t next_id_;
     std::vector<person> persons_;
 };
+BOOST_TYPEOF_REGISTER_TYPE(world)
 
 //[world_checkpoint_seq
 void world::add_person(person const& a_person) {
@@ -61,28 +57,28 @@
 
     // This block must be no-throw.
     person& p = persons_.back();
- person::evolution_t checkpoint = p.evolution_;
+ person::evolution_t checkpoint = p.evolution;
     BOOST_SCOPE_EXIT( (checkpoint) (&p) (&persons_) ) { // Sequence, not commas.
- if(checkpoint == p.evolution_) persons_.pop_back();
+ if(checkpoint == p.evolution) persons_.pop_back();
     } BOOST_SCOPE_EXIT_END
 
     // ...
 
- checkpoint = ++p.evolution_;
+ checkpoint = ++p.evolution;
 
     // Assign new identifier to the person.
- world::id_t const prev_id = p.id_;
- p.id_ = next_id_++;
+ person::id_t const prev_id = p.id;
+ p.id = next_id_++;
     BOOST_SCOPE_EXIT( (checkpoint) (&p) (&next_id_) (prev_id) ) {
- if(checkpoint == p.evolution_) {
- next_id_ = p.id_;
- p.id_ = prev_id;
+ if(checkpoint == p.evolution) {
+ next_id_ = p.id;
+ p.id = prev_id;
         }
     } BOOST_SCOPE_EXIT_END
 
     // ...
 
- checkpoint = ++p.evolution_;
+ checkpoint = ++p.evolution;
 }
 //]
 

Modified: trunk/libs/scope_exit/test/world_lambda.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world_lambda.cpp (original)
+++ trunk/libs/scope_exit/test/world_lambda.cpp 2012-02-18 14:29:35 EST (Sat, 18 Feb 2012)
@@ -34,7 +34,7 @@
     bool commit = false;
 
     persons_.push_back(a_person);
- scope_exit on_exit1([&commit, &persons_]() { // Use C++11 lambda.
+ scope_exit on_exit1([&commit, &persons_](void) { // Use C++11 lambda.
         if(!commit) persons_.pop_back();
     });
 

Modified: trunk/libs/scope_exit/test/world_seq.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world_seq.cpp (original)
+++ trunk/libs/scope_exit/test/world_seq.cpp 2012-02-18 14:29:35 EST (Sat, 18 Feb 2012)
@@ -14,14 +14,17 @@
 #include <boost/test/unit_test.hpp>
 #include <vector>
 
-struct person; BOOST_TYPEOF_REGISTER_TYPE(person)
 struct person {};
+BOOST_TYPEOF_REGISTER_TYPE(person)
 
-struct world; BOOST_TYPEOF_REGISTER_TYPE(world)
 struct world {
     void add_person(person const& a_person);
+ size_t population(void) const { return persons_.size(); }
+
+private:
     std::vector<person> persons_;
 };
+BOOST_TYPEOF_REGISTER_TYPE(world)
 
 //[world_seq
 void world::add_person(person const& a_person) {
@@ -42,6 +45,6 @@
     world w;
     person p;
     w.add_person(p);
- BOOST_CHECK( w.persons_.size() == 1 );
+ BOOST_CHECK( w.population() == 1 );
 }
 

Modified: trunk/libs/scope_exit/test/world_this.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world_this.cpp (original)
+++ trunk/libs/scope_exit/test/world_this.cpp 2012-02-18 14:29:35 EST (Sat, 18 Feb 2012)
@@ -18,14 +18,17 @@
 #include <boost/config.hpp>
 #include <vector>
 
-struct person; BOOST_TYPEOF_REGISTER_TYPE(person)
 struct person {};
+BOOST_TYPEOF_REGISTER_TYPE(person)
 
-struct world; BOOST_TYPEOF_REGISTER_TYPE(world)
 struct world {
     void add_person(person const& a_person);
+ size_t population(void) const { return persons_.size(); }
+
+private:
     std::vector<person> persons_;
 };
+BOOST_TYPEOF_REGISTER_TYPE(world)
 
 void world::add_person(person const& a_person) {
     bool commit = false;
@@ -54,7 +57,7 @@
     world w;
     person p;
     w.add_person(p);
- BOOST_CHECK( w.persons_.size() == 1 );
+ BOOST_CHECK( w.population() == 1 );
 }
 
 #else

Modified: trunk/libs/scope_exit/test/world_this_seq.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world_this_seq.cpp (original)
+++ trunk/libs/scope_exit/test/world_this_seq.cpp 2012-02-18 14:29:35 EST (Sat, 18 Feb 2012)
@@ -15,14 +15,17 @@
 #include <boost/config.hpp>
 #include <vector>
 
-struct person; BOOST_TYPEOF_REGISTER_TYPE(person)
 struct person {};
+BOOST_TYPEOF_REGISTER_TYPE(person)
 
-struct world; BOOST_TYPEOF_REGISTER_TYPE(world)
 struct world {
     void add_person(person const& a_person);
+ size_t population(void) const { return persons_.size(); }
+
+private:
     std::vector<person> persons_;
 };
+BOOST_TYPEOF_REGISTER_TYPE(world)
 
 void world::add_person(person const& a_person) {
     bool commit = false;
@@ -51,6 +54,6 @@
     world w;
     person p;
     w.add_person(p);
- BOOST_CHECK( w.persons_.size() == 1 );
+ BOOST_CHECK( w.population() == 1 );
 }
 

Modified: trunk/libs/scope_exit/test/world_tpl.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world_tpl.cpp (original)
+++ trunk/libs/scope_exit/test/world_tpl.cpp 2012-02-18 14:29:35 EST (Sat, 18 Feb 2012)
@@ -17,15 +17,18 @@
 #include <boost/test/unit_test.hpp>
 #include <vector>
 
-struct person; BOOST_TYPEOF_REGISTER_TYPE(peron)
 struct person {};
+BOOST_TYPEOF_REGISTER_TYPE(peron)
 
-template<typename Person> struct world; BOOST_TYPEOF_REGISTER_TEMPLATE(world, 1)
 template<typename Person>
 struct world {
     void add_person(Person const& a_person);
+ size_t population(void) const { return persons_.size(); }
+
+private:
     std::vector<Person> persons_;
 };
+BOOST_TYPEOF_REGISTER_TEMPLATE(world, 1)
 
 //[world_tpl
 template<typename Person>
@@ -47,7 +50,7 @@
     world<person> w;
     person p;
     w.add_person(p);
- BOOST_CHECK( w.persons_.size() == 1 );
+ BOOST_CHECK( w.population() == 1 );
 }
 
 #else

Modified: trunk/libs/scope_exit/test/world_tpl_seq.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world_tpl_seq.cpp (original)
+++ trunk/libs/scope_exit/test/world_tpl_seq.cpp 2012-02-18 14:29:35 EST (Sat, 18 Feb 2012)
@@ -14,15 +14,18 @@
 #include <boost/test/unit_test.hpp>
 #include <vector>
 
-struct person; BOOST_TYPEOF_REGISTER_TYPE(person)
 struct person {};
+BOOST_TYPEOF_REGISTER_TYPE(person)
 
-template<typename Person> struct world; BOOST_TYPEOF_REGISTER_TEMPLATE(world, 1)
 template<typename Person>
 struct world {
     void add_person(Person const& a_person);
+ size_t population(void) const { return persons_.size(); }
+
+private:
     std::vector<Person> persons_;
 };
+BOOST_TYPEOF_REGISTER_TEMPLATE(world, 1)
 
 //[world_tpl_seq
 template<typename Person>
@@ -44,6 +47,6 @@
     world<person> w;
     person p;
     w.add_person(p);
- BOOST_CHECK( w.persons_.size() == 1 );
+ BOOST_CHECK( w.population() == 1 );
 }
 

Modified: trunk/libs/scope_exit/test/world_void.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world_void.cpp (original)
+++ trunk/libs/scope_exit/test/world_void.cpp 2012-02-18 14:29:35 EST (Sat, 18 Feb 2012)
@@ -14,8 +14,8 @@
 #include <boost/test/unit_test.hpp>
 #include <vector>
 
-struct person; BOOST_TYPEOF_REGISTER_TYPE(person)
 struct person {};
+BOOST_TYPEOF_REGISTER_TYPE(person)
 
 struct world_t; BOOST_TYPEOF_REGISTER_TYPE(world_t)
 //[world_void

Modified: trunk/libs/utility/identity_type/test/tmp_assert.cpp
==============================================================================
--- trunk/libs/utility/identity_type/test/tmp_assert.cpp (original)
+++ trunk/libs/utility/identity_type/test/tmp_assert.cpp 2012-02-18 14:29:35 EST (Sat, 18 Feb 2012)
@@ -19,7 +19,7 @@
 template<typename T, bool b>
 struct abstract {
     static const bool value = b;
- virtual void f(T const& x) = 0;
+ virtual void f(T const& x) = 0; // Pure virtual function.
 };
 
 TMP_ASSERT(
@@ -38,13 +38,15 @@
     /* use `BOOST_IDENTITY_TYPE` in macro definition instead of invocation */ \
     BOOST_STATIC_ASSERT(BOOST_IDENTITY_TYPE(parenthesized_metafunction)::value)
 
+// Specify only extra parenthesis `((...))`.
 TMP_ASSERT_PAREN(( boost::is_const<std::map<int, char> const> ));
+// Specify both the extra parenthesis `((...))` and `BOOST_IDENTITY_TYPE` macro.
 TMP_ASSERT( BOOST_IDENTITY_TYPE((boost::is_const<std::map<int, char> const>)) );
 //]
 
 //[tmp_assert_alternative_always
-TMP_ASSERT_PAREN(( boost::is_const<int const> )); // Always extra `()`.
-TMP_ASSERT( boost::is_const<int const> ); // No extra `()` and no macro.
+TMP_ASSERT_PAREN(( boost::is_const<int const> )); // Always extra `((...))`.
+TMP_ASSERT( boost::is_const<int const> ); // No extra `((...))` and no macro.
 //]
 
 int main() { return 0; }


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