added .except(...), renamed old_ptr_noncopyable to old_ptr_if_copyable, and renamed OLDOF to OLD

This commit is contained in:
Lorenzo Caminiti
2016-08-21 09:54:10 -07:00
parent a2ac52ffd7
commit ff02b449dd
163 changed files with 1808 additions and 1491 deletions

View File

@@ -38,7 +38,7 @@ public:
// Create stack for max of n items, if n < 0 set error (no preconditions).
explicit stack3(int n, T const& default_value = T()) :
stack_(0), error_(no_error) {
boost::contract::guard c = boost::contract::constructor(this)
boost::contract::check c = boost::contract::constructor(this)
.postcondition([&] {
// Error if impossible.
BOOST_CONTRACT_ASSERT((n < 0) == (error() == size_error));
@@ -58,20 +58,20 @@ public:
// Max number of stack items.
int capacity() const {
// Check invariants.
boost::contract::guard c = boost::contract::public_function(this);
boost::contract::check c = boost::contract::public_function(this);
return stack_.capacity();
}
// Number of stack items.
int count() const {
// Check invariants.
boost::contract::guard c = boost::contract::public_function(this);
boost::contract::check c = boost::contract::public_function(this);
return stack_.count();
}
// Top item if present, otherwise none and set error (no preconditions).
boost::optional<T const&> item() const {
boost::contract::guard c = boost::contract::public_function(this)
boost::contract::check c = boost::contract::public_function(this)
.postcondition([&] {
// Error if impossible.
BOOST_CONTRACT_ASSERT(empty() == (error() == underflow_error));
@@ -94,19 +94,19 @@ public:
// Error indicator set by various operations.
error_code error() const {
// Check invariants.
boost::contract::guard c = boost::contract::public_function(this);
boost::contract::check c = boost::contract::public_function(this);
return error_;
}
bool empty() const {
// Check invariants.
boost::contract::guard c = boost::contract::public_function(this);
boost::contract::check c = boost::contract::public_function(this);
return stack_.empty();
}
bool full() const {
// Check invariants.
boost::contract::guard c = boost::contract::public_function(this);
boost::contract::check c = boost::contract::public_function(this);
return stack_.full();
}
@@ -114,9 +114,9 @@ public:
// Add x to top if capacity allows, otherwise set error (no preconditions).
void put(T const& x) {
boost::contract::old_ptr<bool> old_full = BOOST_CONTRACT_OLDOF(full());
boost::contract::old_ptr<int> old_count = BOOST_CONTRACT_OLDOF(count());
boost::contract::guard c = boost::contract::public_function(this)
boost::contract::old_ptr<bool> old_full = BOOST_CONTRACT_OLD(full());
boost::contract::old_ptr<int> old_count = BOOST_CONTRACT_OLD(count());
boost::contract::check c = boost::contract::public_function(this)
.postcondition([&] {
// Error if impossible.
BOOST_CONTRACT_ASSERT(*old_full == (error() == overflow_error));
@@ -140,10 +140,9 @@ public:
// Remove top item if possible, otherwise set error (no preconditions).
void remove() {
boost::contract::old_ptr<bool> old_empty =
BOOST_CONTRACT_OLDOF(empty());
boost::contract::old_ptr<int> old_count = BOOST_CONTRACT_OLDOF(count());
boost::contract::guard c = boost::contract::public_function(this)
boost::contract::old_ptr<bool> old_empty = BOOST_CONTRACT_OLD(empty());
boost::contract::old_ptr<int> old_count = BOOST_CONTRACT_OLD(count());
boost::contract::check c = boost::contract::public_function(this)
.postcondition([&] {
// Error if impossible.
BOOST_CONTRACT_ASSERT(*old_empty == (error() ==

View File

@@ -36,7 +36,7 @@ public:
BOOST_CONTRACT_ASSERT(n >= 0); // Non-negative capacity.
})
{
boost::contract::guard c = boost::contract::constructor(this)
boost::contract::check c = boost::contract::constructor(this)
.postcondition([&] {
BOOST_CONTRACT_ASSERT(capacity() == n); // Capacity set.
})
@@ -49,7 +49,7 @@ public:
// Deep copy via constructor.
/* implicit */ stack4(stack4 const& other) {
boost::contract::guard c = boost::contract::constructor(this)
boost::contract::check c = boost::contract::constructor(this)
.postcondition([&] {
BOOST_CONTRACT_ASSERT(capacity() == other.capacity());
BOOST_CONTRACT_ASSERT(count() == other.count());
@@ -65,7 +65,7 @@ public:
// Deep copy via assignment.
stack4& operator=(stack4 const& other) {
boost::contract::guard c = boost::contract::public_function(this)
boost::contract::check c = boost::contract::public_function(this)
.postcondition([&] {
BOOST_CONTRACT_ASSERT(capacity() == other.capacity());
BOOST_CONTRACT_ASSERT(count() == other.count());
@@ -84,7 +84,7 @@ public:
// Destroy this stack.
virtual ~stack4() {
// Check invariants.
boost::contract::guard c = boost::contract::destructor(this);
boost::contract::check c = boost::contract::destructor(this);
delete[] array_;
}
@@ -93,20 +93,20 @@ public:
// Max number of stack items.
int capacity() const {
// Check invariants.
boost::contract::guard c = boost::contract::public_function(this);
boost::contract::check c = boost::contract::public_function(this);
return capacity_;
}
// Number of stack items.
int count() const {
// Check invariants.
boost::contract::guard c = boost::contract::public_function(this);
boost::contract::check c = boost::contract::public_function(this);
return count_;
}
// Top item.
T const& item() const {
boost::contract::guard c = boost::contract::public_function(this)
boost::contract::check c = boost::contract::public_function(this)
.precondition([&] {
BOOST_CONTRACT_ASSERT(!empty()); // Not empty (count > 0).
})
@@ -120,7 +120,7 @@ public:
// Is stack empty?
bool empty() const {
bool result;
boost::contract::guard c = boost::contract::public_function(this)
boost::contract::check c = boost::contract::public_function(this)
.postcondition([&] {
// Empty definition.
BOOST_CONTRACT_ASSERT(result == (count() == 0));
@@ -133,7 +133,7 @@ public:
// Is stack full?
bool full() const {
bool result;
boost::contract::guard c = boost::contract::public_function(this)
boost::contract::check c = boost::contract::public_function(this)
.postcondition([&] {
BOOST_CONTRACT_ASSERT( // Full definition.
result == (count() == capacity()));
@@ -147,8 +147,8 @@ public:
// Add x on top.
void put(T const& x) {
boost::contract::old_ptr<int> old_count = BOOST_CONTRACT_OLDOF(count());
boost::contract::guard c = boost::contract::public_function(this)
boost::contract::old_ptr<int> old_count = BOOST_CONTRACT_OLD(count());
boost::contract::check c = boost::contract::public_function(this)
.precondition([&] {
BOOST_CONTRACT_ASSERT(!full()); // Not full.
})
@@ -164,8 +164,8 @@ public:
// Remove top item.
void remove() {
boost::contract::old_ptr<int> old_count = BOOST_CONTRACT_OLDOF(count());
boost::contract::guard c = boost::contract::public_function(this)
boost::contract::old_ptr<int> old_count = BOOST_CONTRACT_OLD(count());
boost::contract::check c = boost::contract::public_function(this)
.precondition([&] {
BOOST_CONTRACT_ASSERT(!empty()); // Not empty (count > 0).
})