mirror of
https://github.com/boostorg/contract.git
synced 2026-02-26 04:32:22 +00:00
added .except(...), renamed old_ptr_noncopyable to old_ptr_if_copyable, and renamed OLDOF to OLD
This commit is contained in:
@@ -17,7 +17,6 @@ test-suite features :
|
||||
[ subdir-run features : private_protected ]
|
||||
[ subdir-run features : private_protected_virtual ]
|
||||
[ subdir-run features : private_protected_virtual_multi ]
|
||||
[ subdir-run features : friend ]
|
||||
[ subdir-run features : check ]
|
||||
|
||||
[ subdir-run features : old ]
|
||||
@@ -28,8 +27,8 @@ test-suite features :
|
||||
[ subdir-run features : move ]
|
||||
[ subdir-run features : union ]
|
||||
[ subdir-run features : volatile ]
|
||||
[ subdir-run features : old_noncopyable ]
|
||||
[ subdir-run features : check_if ]
|
||||
[ subdir-run features : old_if_copyable ]
|
||||
[ subdir-run features : condition_if ]
|
||||
[ subdir-run features : access ]
|
||||
[ subdir-run features : separate_body ]
|
||||
[ subdir-run features : throw_on_failure ]
|
||||
@@ -39,6 +38,11 @@ test-suite features :
|
||||
[ subdir-run features : no_lambdas ]
|
||||
[ subdir-run features : no_lambdas_local_func ]
|
||||
;
|
||||
test-suite features-cxx14 : # Requires C++14.
|
||||
[ subdir-run features : call_if_cxx14 :
|
||||
<toolset>clang:<cxxflags>-std=c++1y ]
|
||||
;
|
||||
explicit features-cxx14 ;
|
||||
|
||||
test-suite n1962 :
|
||||
[ subdir-run n1962 : vector ]
|
||||
|
||||
@@ -20,7 +20,7 @@ class calendar {
|
||||
|
||||
public:
|
||||
calendar() : month_(1), date_(31) {
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(month() == 1);
|
||||
BOOST_CONTRACT_ASSERT(date() == 31);
|
||||
@@ -30,23 +30,23 @@ public:
|
||||
|
||||
virtual ~calendar() {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
int month() const {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return month_;
|
||||
}
|
||||
|
||||
int date() const {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return date_;
|
||||
}
|
||||
|
||||
void reset(int new_month) {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(new_month >= 1);
|
||||
BOOST_CONTRACT_ASSERT(new_month <= 12);
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
private:
|
||||
static int days_in(int month) {
|
||||
int result;
|
||||
boost::contract::guard c = boost::contract::function()
|
||||
boost::contract::check c = boost::contract::function()
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(month >= 1);
|
||||
BOOST_CONTRACT_ASSERT(month <= 12);
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
}),
|
||||
data_(new T[capacity]), capacity_(capacity), size_(0)
|
||||
{
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(empty());
|
||||
BOOST_CONTRACT_ASSERT(full() == (capacity == 0));
|
||||
@@ -36,22 +36,22 @@ public:
|
||||
}
|
||||
|
||||
virtual ~stack() {
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
delete[] data_;
|
||||
}
|
||||
|
||||
bool empty() const {
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return size_ == 0;
|
||||
}
|
||||
|
||||
bool full() const {
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return size_ == capacity_;
|
||||
}
|
||||
|
||||
void push(T const& value) {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!full());
|
||||
})
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
}
|
||||
|
||||
T pop() {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!empty());
|
||||
})
|
||||
|
||||
@@ -32,7 +32,7 @@ public:
|
||||
data_(new T[count]),
|
||||
size_(count)
|
||||
{
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(size() == count);
|
||||
})
|
||||
@@ -42,17 +42,17 @@ public:
|
||||
}
|
||||
|
||||
virtual ~vector() {
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
delete[] data_;
|
||||
}
|
||||
|
||||
int size() const {
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return size_; // Non-negative result already checked by invariant.
|
||||
}
|
||||
|
||||
void resize(int count) {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(count >= 0);
|
||||
})
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
}
|
||||
|
||||
T& operator[](int index) {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(index >= 0);
|
||||
BOOST_CONTRACT_ASSERT(index < size());
|
||||
@@ -80,7 +80,7 @@ public:
|
||||
}
|
||||
|
||||
T const& operator[](int index) const {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(index >= 0);
|
||||
BOOST_CONTRACT_ASSERT(index < size());
|
||||
|
||||
@@ -15,19 +15,19 @@ template<typename T>
|
||||
class abstract_stack {
|
||||
public:
|
||||
abstract_stack() {
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
// Postcondition: empty() (but it cannot be checked here to avoid
|
||||
// calling pure virtual function length() during construction).
|
||||
;
|
||||
}
|
||||
|
||||
virtual ~abstract_stack() {
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
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(result == (length() == capacity()));
|
||||
})
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
|
||||
bool empty() 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(result = (length() == 0));
|
||||
})
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
template<typename T>
|
||||
int abstract_stack<T>::length(boost::contract::virtual_* v) const {
|
||||
int result;
|
||||
boost::contract::guard c = boost::contract::public_function(v, result, this)
|
||||
boost::contract::check c = boost::contract::public_function(v, result, this)
|
||||
.postcondition([&] (int const& result) {
|
||||
BOOST_CONTRACT_ASSERT(result >= 0);
|
||||
})
|
||||
@@ -73,7 +73,7 @@ int abstract_stack<T>::length(boost::contract::virtual_* v) const {
|
||||
template<typename T>
|
||||
int abstract_stack<T>::capacity(boost::contract::virtual_* v) const {
|
||||
int result;
|
||||
boost::contract::guard c = boost::contract::public_function(v, result, this)
|
||||
boost::contract::check c = boost::contract::public_function(v, result, this)
|
||||
.postcondition([&] (int const& result) {
|
||||
BOOST_CONTRACT_ASSERT(result >= 0);
|
||||
})
|
||||
@@ -85,7 +85,7 @@ int abstract_stack<T>::capacity(boost::contract::virtual_* v) const {
|
||||
template<typename T>
|
||||
T const& abstract_stack<T>::item(boost::contract::virtual_* v) const {
|
||||
boost::optional<T const&> result;
|
||||
boost::contract::guard c = boost::contract::public_function(v, result, this)
|
||||
boost::contract::check c = boost::contract::public_function(v, result, this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!empty());
|
||||
})
|
||||
@@ -96,7 +96,7 @@ T const& abstract_stack<T>::item(boost::contract::virtual_* v) const {
|
||||
|
||||
template<typename T>
|
||||
void abstract_stack<T>::push(T const& value, boost::contract::virtual_* v) {
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!full());
|
||||
})
|
||||
@@ -110,8 +110,8 @@ void abstract_stack<T>::push(T const& value, boost::contract::virtual_* v) {
|
||||
template<typename T>
|
||||
T const& abstract_stack<T>::pop(boost::contract::virtual_* v) {
|
||||
boost::optional<T const&> result;
|
||||
boost::contract::old_ptr<T> old_item = BOOST_CONTRACT_OLDOF(v, item());
|
||||
boost::contract::guard c = boost::contract::public_function(v, result, this)
|
||||
boost::contract::old_ptr<T> old_item = BOOST_CONTRACT_OLD(v, item());
|
||||
boost::contract::check c = boost::contract::public_function(v, result, this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!empty());
|
||||
})
|
||||
@@ -126,7 +126,7 @@ T const& abstract_stack<T>::pop(boost::contract::virtual_* v) {
|
||||
|
||||
template<typename T>
|
||||
void abstract_stack<T>::clear(boost::contract::virtual_* v) {
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(empty());
|
||||
})
|
||||
@@ -158,7 +158,7 @@ public:
|
||||
vect_(count), // OK, executed after precondition so count >= 0.
|
||||
len_(0)
|
||||
{
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(length() == 0);
|
||||
BOOST_CONTRACT_ASSERT(capacity() == count);
|
||||
@@ -167,14 +167,14 @@ public:
|
||||
}
|
||||
|
||||
virtual ~vstack() {
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
// Inherited from abstract_stack.
|
||||
|
||||
virtual int length(boost::contract::virtual_* v = 0) const /* override */ {
|
||||
int result;
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_length>(v, result, &vstack::length, this);
|
||||
return result = len_;
|
||||
}
|
||||
@@ -182,7 +182,7 @@ public:
|
||||
virtual int capacity(boost::contract::virtual_* v = 0)
|
||||
const /* override */ {
|
||||
int result;
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_capacity>(v, result, &vstack::capacity, this);
|
||||
return result = vect_.size();
|
||||
}
|
||||
@@ -190,27 +190,27 @@ public:
|
||||
virtual T const& item(boost::contract::virtual_* v = 0)
|
||||
const /* override */ {
|
||||
boost::optional<T const&> result;
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_item>(v, result, &vstack::item, this);
|
||||
return *(result = vect_[len_ - 1]);
|
||||
}
|
||||
|
||||
virtual void push(T const& value, boost::contract::virtual_* v = 0)
|
||||
/* override */ {
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_push>(v, &vstack::push, this, value);
|
||||
vect_[len_++] = value;
|
||||
}
|
||||
|
||||
virtual T const& pop(boost::contract::virtual_* v = 0) /* override */ {
|
||||
boost::optional<T const&> result;
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_pop>(v, result, &vstack::pop, this);
|
||||
return *(result = vect_[--len_]);
|
||||
}
|
||||
|
||||
virtual void clear(boost::contract::virtual_* v = 0) /* override */ {
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_clear>(v, &vstack::clear, this);
|
||||
len_ = 0;
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ protected:
|
||||
template<typename T>
|
||||
void pushable<T>::push_back(T const& value, boost::contract::virtual_* v) {
|
||||
boost::contract::old_ptr<unsigned> old_capacity =
|
||||
BOOST_CONTRACT_OLDOF(v, capacity());
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
BOOST_CONTRACT_OLD(v, capacity());
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(capacity() < max_size());
|
||||
})
|
||||
@@ -63,8 +63,8 @@ public:
|
||||
void push_back(T const& value, boost::contract::virtual_* v = 0)
|
||||
/* override */ {
|
||||
boost::contract::old_ptr<unsigned> old_size =
|
||||
BOOST_CONTRACT_OLDOF(v, size());
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
BOOST_CONTRACT_OLD(v, size());
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_push_back>(v, &vector::push_back, this, value)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(size() < max_size());
|
||||
|
||||
@@ -24,8 +24,8 @@ protected:
|
||||
template<typename T>
|
||||
void pushable<T>::push_back(T x, boost::contract::virtual_* v) {
|
||||
boost::contract::old_ptr<int> old_capacity =
|
||||
BOOST_CONTRACT_OLDOF(v, capacity());
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
BOOST_CONTRACT_OLD(v, capacity());
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(capacity() < max_size());
|
||||
})
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
BOOST_CONTRACT_ASSERT(from <= to);
|
||||
})
|
||||
{
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(size() == (to - from + 1));
|
||||
})
|
||||
@@ -62,17 +62,17 @@ public:
|
||||
}
|
||||
|
||||
virtual ~unique_chars() {
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
int size() const {
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return vect_.size();
|
||||
}
|
||||
|
||||
bool find(char x) const {
|
||||
bool result;
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
if(size() == 0) BOOST_CONTRACT_ASSERT(!result);
|
||||
})
|
||||
@@ -83,10 +83,9 @@ public:
|
||||
|
||||
virtual void push_back(char x, boost::contract::virtual_* v = 0) {
|
||||
boost::contract::old_ptr<bool> old_find =
|
||||
BOOST_CONTRACT_OLDOF(v, find(x));
|
||||
boost::contract::old_ptr<int> old_size =
|
||||
BOOST_CONTRACT_OLDOF(v, size());
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
BOOST_CONTRACT_OLD(v, find(x));
|
||||
boost::contract::old_ptr<int> old_size = BOOST_CONTRACT_OLD(v, size());
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!find(x));
|
||||
})
|
||||
@@ -132,7 +131,7 @@ public:
|
||||
}
|
||||
|
||||
chars(char from, char to) : unique_chars(from, to) {
|
||||
boost::contract::guard c = boost::contract::constructor(this);
|
||||
boost::contract::check c = boost::contract::constructor(this);
|
||||
}
|
||||
|
||||
chars(char const* const c_str) :
|
||||
@@ -140,17 +139,16 @@ public:
|
||||
BOOST_CONTRACT_ASSERT(c_str[0] != '\0');
|
||||
})
|
||||
{
|
||||
boost::contract::guard c = boost::contract::constructor(this);
|
||||
boost::contract::check c = boost::contract::constructor(this);
|
||||
|
||||
for(int i = 0; c_str[i] != '\0'; ++i) push_back(c_str[i]);
|
||||
}
|
||||
|
||||
void push_back(char x, boost::contract::virtual_* v = 0) /* override */ {
|
||||
boost::contract::old_ptr<bool> old_find =
|
||||
BOOST_CONTRACT_OLDOF(v, find(x));
|
||||
boost::contract::old_ptr<int> old_size =
|
||||
BOOST_CONTRACT_OLDOF(v, size());
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
BOOST_CONTRACT_OLD(v, find(x));
|
||||
boost::contract::old_ptr<int> old_size = BOOST_CONTRACT_OLD(v, size());
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_push_back>(v, &chars::push_back, this, x)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(find(x));
|
||||
@@ -165,7 +163,7 @@ public:
|
||||
BOOST_CONTRACT_OVERRIDE(push_back);
|
||||
|
||||
bool empty() const {
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ protected:
|
||||
template<typename T>
|
||||
void pushable<T>::push_back(T x, boost::contract::virtual_* v) {
|
||||
boost::contract::old_ptr<int> old_capacity =
|
||||
BOOST_CONTRACT_OLDOF(v, capacity());
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
BOOST_CONTRACT_OLD(v, capacity());
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(capacity() < max_size());
|
||||
})
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
BOOST_CONTRACT_ASSERT(from <= to);
|
||||
})
|
||||
{
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(size() == (to - from + 1));
|
||||
})
|
||||
@@ -62,17 +62,17 @@ public:
|
||||
}
|
||||
|
||||
virtual ~unique_chars() {
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
int size() const {
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return vect_.size();
|
||||
}
|
||||
|
||||
bool find(char x) const {
|
||||
bool result;
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
if(size() == 0) BOOST_CONTRACT_ASSERT(!result);
|
||||
})
|
||||
@@ -83,10 +83,9 @@ public:
|
||||
|
||||
virtual void push_back(char x, boost::contract::virtual_* v = 0) {
|
||||
boost::contract::old_ptr<bool> old_find =
|
||||
BOOST_CONTRACT_OLDOF(v, find(x));
|
||||
boost::contract::old_ptr<int> old_size =
|
||||
BOOST_CONTRACT_OLDOF(v, size());
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
BOOST_CONTRACT_OLD(v, find(x));
|
||||
boost::contract::old_ptr<int> old_size = BOOST_CONTRACT_OLD(v, size());
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!find(x));
|
||||
})
|
||||
@@ -132,7 +131,7 @@ public:
|
||||
}
|
||||
|
||||
chars(char from, char to) : unique_chars(from, to) {
|
||||
boost::contract::guard c = boost::contract::constructor(this);
|
||||
boost::contract::check c = boost::contract::constructor(this);
|
||||
}
|
||||
|
||||
chars(char const* const c_str) :
|
||||
@@ -140,17 +139,16 @@ public:
|
||||
BOOST_CONTRACT_ASSERT(c_str[0] != '\0');
|
||||
})
|
||||
{
|
||||
boost::contract::guard c = boost::contract::constructor(this);
|
||||
boost::contract::check c = boost::contract::constructor(this);
|
||||
|
||||
for(int i = 0; c_str[i] != '\0'; ++i) push_back(c_str[i]);
|
||||
}
|
||||
|
||||
void push_back(char x, boost::contract::virtual_* v = 0) /* override */ {
|
||||
boost::contract::old_ptr<bool> old_find =
|
||||
BOOST_CONTRACT_OLDOF(v, find(x));
|
||||
boost::contract::old_ptr<int> old_size =
|
||||
BOOST_CONTRACT_OLDOF(v, size());
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
BOOST_CONTRACT_OLD(v, find(x));
|
||||
boost::contract::old_ptr<int> old_size = BOOST_CONTRACT_OLD(v, size());
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_push_back>(v, &chars::push_back, this, x)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(find(x));
|
||||
@@ -165,7 +163,7 @@ public:
|
||||
BOOST_CONTRACT_OVERRIDE(push_back);
|
||||
|
||||
bool empty() const {
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
|
||||
92
example/features/call_if_cxx14.cpp
Normal file
92
example/features/call_if_cxx14.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
|
||||
// Copyright (C) 2008-2016 Lorenzo Caminiti
|
||||
// Distributed under the Boost Software License, Version 1.0 (see accompanying
|
||||
// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
|
||||
// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
|
||||
|
||||
#include <boost/contract/call_if.hpp>
|
||||
#include <type_traits>
|
||||
#include <iterator>
|
||||
#include <functional> // std::bind for generic lambdas.
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <sstream>
|
||||
|
||||
template<typename Iter>
|
||||
struct is_random_access_iterator : std::is_same<
|
||||
typename std::iterator_traits<Iter>::iterator_category,
|
||||
std::random_access_iterator_tag
|
||||
> {};
|
||||
|
||||
template<typename Iter>
|
||||
struct is_bidirectional_iterator : std::is_same<
|
||||
typename std::iterator_traits<Iter>::iterator_category,
|
||||
std::bidirectional_iterator_tag
|
||||
> {};
|
||||
|
||||
template<typename Iter>
|
||||
struct is_input_iterator : std::is_same<
|
||||
typename std::iterator_traits<Iter>::iterator_category,
|
||||
std::input_iterator_tag
|
||||
> {};
|
||||
|
||||
//[call_if_cxx14
|
||||
template<typename Iter, typename Dist>
|
||||
void myadvance(Iter& i, Dist n) {
|
||||
Iter *p = &i; // So captures change actual pointed iterator value.
|
||||
boost::contract::call_if<is_random_access_iterator<Iter> >(
|
||||
std::bind([] (auto p, auto n) { // C++14 generic lambda.
|
||||
*p += n;
|
||||
}, p, n)
|
||||
).template else_if<is_bidirectional_iterator<Iter> >(
|
||||
std::bind([] (auto p, auto n) {
|
||||
if(n >= 0) while(n--) ++*p;
|
||||
else while(n++) --*p;
|
||||
}, p, n)
|
||||
).template else_if<is_input_iterator<Iter> >(
|
||||
std::bind([] (auto p, auto n) {
|
||||
while(n--) ++*p;
|
||||
}, p, n)
|
||||
).else_(
|
||||
std::bind([] (auto false_) {
|
||||
static_assert(false_, "requires at least input iterator");
|
||||
}, std::false_type()) // Use constexpr value.
|
||||
);
|
||||
}
|
||||
//]
|
||||
|
||||
struct x {}; // Test not an iterator (static_assert failure in else_ above).
|
||||
|
||||
namespace std {
|
||||
template<>
|
||||
struct iterator_traits<x> {
|
||||
typedef void iterator_category;
|
||||
};
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::vector<char> v;
|
||||
v.push_back('a');
|
||||
v.push_back('b');
|
||||
v.push_back('c');
|
||||
v.push_back('d');
|
||||
std::vector<char>::iterator r = v.begin(); // Random iterator.
|
||||
myadvance(r, 1);
|
||||
assert(*r == 'b');
|
||||
|
||||
std::list<char> l(v.begin(), v.end());
|
||||
std::list<char>::iterator b = l.begin(); // Bidirectional iterator.
|
||||
myadvance(b, 2);
|
||||
assert(*b == 'c');
|
||||
|
||||
std::istringstream s("a b c d");
|
||||
std::istream_iterator<char> i(s);
|
||||
myadvance(i, 3);
|
||||
assert(*i == 'd');
|
||||
|
||||
// x j;
|
||||
// myadvance(j, 0); // Error (correctly because x not even input iter).
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ int gcd(int const a, int const b) {
|
||||
|
||||
//[check_macro
|
||||
while(x != y) {
|
||||
BOOST_CONTRACT_CHECK(x > 0); // Body checks with macro (preferred).
|
||||
BOOST_CONTRACT_CHECK(x > 0); // Body checks with macros (preferred).
|
||||
BOOST_CONTRACT_CHECK(y > 0);
|
||||
|
||||
if(x > y) x = x - y;
|
||||
|
||||
@@ -15,7 +15,7 @@ template<typename T>
|
||||
class vector {
|
||||
public:
|
||||
void push_back(T const& value) {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
// Instead of `ASSERT(back() == value)` for T without `==`.
|
||||
BOOST_CONTRACT_ASSERT(
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
|
||||
#include <boost/contract.hpp>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
class y;
|
||||
class z;
|
||||
|
||||
class x {
|
||||
public:
|
||||
void invariant() const {
|
||||
std::cout << "x::inv" << std::endl;
|
||||
BOOST_CONTRACT_ASSERT(get() >= 0);
|
||||
}
|
||||
|
||||
x() : value_(0) {}
|
||||
int get() const { return value_; }
|
||||
friend void set_all(x&, y&, int value);
|
||||
|
||||
private:
|
||||
int value_;
|
||||
};
|
||||
|
||||
class y {
|
||||
public:
|
||||
void invariant() const {
|
||||
std::cout << "y::inv" << std::endl;
|
||||
BOOST_CONTRACT_ASSERT(get() >= 0);
|
||||
}
|
||||
|
||||
y() : value_(0) {}
|
||||
int get() const { return value_; }
|
||||
friend void set_all(x&, y&, int value);
|
||||
|
||||
private:
|
||||
int value_;
|
||||
};
|
||||
|
||||
void set_all(x& a, y& b, int value) {
|
||||
boost::contract::guard post = boost::contract::function()
|
||||
.postcondition([&] {
|
||||
std::cout << "f::post" << std::endl;
|
||||
BOOST_CONTRACT_ASSERT(a.get() == value);
|
||||
BOOST_CONTRACT_ASSERT(b.get() == value);
|
||||
})
|
||||
;
|
||||
boost::contract::guard inv_b = boost::contract::public_function(&b);
|
||||
boost::contract::guard inv_a = boost::contract::public_function(&a);
|
||||
boost::contract::guard pre = boost::contract::function()
|
||||
.precondition([&] {
|
||||
std::cout << "f::pre" << std::endl;
|
||||
BOOST_CONTRACT_ASSERT(value > 0);
|
||||
})
|
||||
;
|
||||
|
||||
std::cout << "f::body" << std::endl;
|
||||
a.value_ = b.value_ = value;
|
||||
}
|
||||
|
||||
int main() {
|
||||
x a;
|
||||
y b;
|
||||
set_all(a, b, 123);
|
||||
assert(a.get() == 123);
|
||||
assert(b.get() == 123);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
|
||||
int inc(int& x) {
|
||||
int result;
|
||||
boost::contract::old_ptr<int> old_x = BOOST_CONTRACT_OLDOF(x);
|
||||
boost::contract::guard c = boost::contract::function()
|
||||
boost::contract::old_ptr<int> old_x = BOOST_CONTRACT_OLD(x);
|
||||
boost::contract::check c = boost::contract::function()
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(x < std::numeric_limits<int>::max());
|
||||
})
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
int inc(int& x) {
|
||||
int result;
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
boost::contract::old_ptr<int> old_x = BOOST_CONTRACT_OLDOF(x);
|
||||
boost::contract::old_ptr<int> old_x = BOOST_CONTRACT_OLD(x);
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_FUNCTIONS
|
||||
boost::contract::guard c = boost::contract::function()
|
||||
boost::contract::check c = boost::contract::function()
|
||||
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(x < std::numeric_limits<int>::max());
|
||||
@@ -72,10 +72,10 @@ void pushable<T>::push_back(
|
||||
) {
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
boost::contract::old_ptr<unsigned> old_capacity =
|
||||
BOOST_CONTRACT_OLDOF(v, capacity());
|
||||
BOOST_CONTRACT_OLD(v, capacity());
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(capacity() < max_size());
|
||||
@@ -127,7 +127,7 @@ public:
|
||||
vect_(to - from + 1)
|
||||
{
|
||||
#ifndef BOOST_CONTRACT_NO_CONSTRUCTORS
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(int(size()) == (to - from + 1));
|
||||
@@ -142,7 +142,7 @@ public:
|
||||
virtual ~integers() {
|
||||
#ifndef BOOST_CONTRACT_NO_DESTRUCTORS
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ public:
|
||||
boost::contract::old_ptr<unsigned> old_size;
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_push_back>(v, &integers::push_back, this, x)
|
||||
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
|
||||
.precondition([&] {
|
||||
@@ -165,7 +165,7 @@ public:
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
.old([&] {
|
||||
old_size = BOOST_CONTRACT_OLDOF(v, size());
|
||||
old_size = BOOST_CONTRACT_OLD(v, size());
|
||||
})
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(size() == *old_size + 1);
|
||||
|
||||
@@ -28,8 +28,8 @@ public:
|
||||
virtual void push_back(T const& value, boost::contract::virtual_* v = 0)
|
||||
/* override */ {
|
||||
boost::contract::old_ptr<unsigned> old_size =
|
||||
BOOST_CONTRACT_OLDOF(v, size()); // Old values.
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
BOOST_CONTRACT_OLD(v, size()); // Old values.
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_push_back>(v, &vector::push_back, this, value)
|
||||
.precondition([&] { // Checked in OR with base preconditions.
|
||||
BOOST_CONTRACT_ASSERT(size() < max_size()); // Line 35.
|
||||
@@ -71,8 +71,8 @@ protected:
|
||||
template<typename T> // Contract for pure virtual function.
|
||||
void pushable<T>::push_back(T const& value, boost::contract::virtual_* v) {
|
||||
boost::contract::old_ptr<unsigned> old_capacity =
|
||||
BOOST_CONTRACT_OLDOF(v, capacity());
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
BOOST_CONTRACT_OLD(v, capacity());
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(capacity() < max_size());
|
||||
})
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
index_(start),
|
||||
moved_(false)
|
||||
{
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!moved());
|
||||
})
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
|
||||
~circular_buffer() {
|
||||
// Moved-from can always be destroyed (so no pre `!moved()` here).
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
// Copy constructor.
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
BOOST_CONTRACT_ASSERT(!other.moved());
|
||||
})
|
||||
{
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!moved());
|
||||
})
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
// Copy assignment.
|
||||
circular_buffer& operator=(circular_buffer const& other) {
|
||||
// Moved-from can be (copy) assigned (so no pre `!moved()` here).
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!other.moved());
|
||||
})
|
||||
@@ -76,7 +76,7 @@ public:
|
||||
BOOST_CONTRACT_ASSERT(!other.moved());
|
||||
})
|
||||
{
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!moved());
|
||||
BOOST_CONTRACT_ASSERT(other.moved());
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
// Move assignment.
|
||||
circular_buffer& operator=(circular_buffer&& other) {
|
||||
// Moved-from can be (move) assigned (so no pre `!moved()` here).
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!other.moved());
|
||||
})
|
||||
@@ -103,7 +103,7 @@ public:
|
||||
}
|
||||
|
||||
char read() {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!moved());
|
||||
})
|
||||
@@ -115,7 +115,7 @@ public:
|
||||
}
|
||||
|
||||
bool moved() const {
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return moved_;
|
||||
}
|
||||
|
||||
@@ -144,12 +144,12 @@ private:
|
||||
|
||||
public:
|
||||
unsigned index() const {
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return index_;
|
||||
}
|
||||
|
||||
unsigned size() const {
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return data_.size();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
|
||||
template<typename T>
|
||||
void generic_unary_pack<T>::_1(T const& value, boost::contract::virtual_* v) {
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.precondition([&] {
|
||||
// Derived concrete classes will enforce preconditions.
|
||||
BOOST_CONTRACT_ASSERT(false);
|
||||
@@ -33,7 +33,7 @@ void generic_unary_pack<T>::_1(T const& value, boost::contract::virtual_* v) {
|
||||
template<typename T>
|
||||
T generic_unary_pack<T>::_1(boost::contract::virtual_* v) const {
|
||||
boost::optional<T> result; // Do not assume T has default constructor.
|
||||
boost::contract::guard c = boost::contract::public_function(v, result, this)
|
||||
boost::contract::check c = boost::contract::public_function(v, result, this)
|
||||
.postcondition([&] (boost::optional<T const&> const& result) {
|
||||
BOOST_CONTRACT_ASSERT(*result == _1());
|
||||
})
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
virtual void _1(T const& value, boost::contract::virtual_* v = 0)
|
||||
/* override */ {
|
||||
// Use `override1` type generated by NAMED_OVERRIDE macro above.
|
||||
boost::contract::guard c = boost::contract::public_function<override1>(
|
||||
boost::contract::check c = boost::contract::public_function<override1>(
|
||||
v,
|
||||
static_cast<void (positive_unary_pack::*)(T const&,
|
||||
boost::contract::virtual_*)>(&positive_unary_pack::_1),
|
||||
@@ -78,7 +78,7 @@ public:
|
||||
|
||||
virtual T _1(boost::contract::virtual_* v = 0) const /* override */ {
|
||||
T result; // Class default constructor already used T's default ctor.
|
||||
boost::contract::guard c = boost::contract::public_function<override1>(
|
||||
boost::contract::check c = boost::contract::public_function<override1>(
|
||||
v,
|
||||
result,
|
||||
static_cast<T (positive_unary_pack::*)(boost::contract::virtual_*)
|
||||
|
||||
@@ -16,7 +16,7 @@ array<T, MaxSize>::array(unsigned count) :
|
||||
values_(new T[MaxSize]) // Member initializations can be here.
|
||||
{
|
||||
boost::contract::old_ptr<int> old_instances;
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.old(boost::bind(&array::constructor_old, boost::ref(old_instances)))
|
||||
.postcondition(boost::bind(&array::constructor_postcondition, this,
|
||||
boost::cref(count), boost::cref(old_instances)))
|
||||
@@ -30,7 +30,7 @@ array<T, MaxSize>::array(unsigned count) :
|
||||
template<typename T, unsigned MaxSize>
|
||||
array<T, MaxSize>::~array() {
|
||||
boost::contract::old_ptr<int> old_instances;
|
||||
boost::contract::guard c = boost::contract::destructor(this)
|
||||
boost::contract::check c = boost::contract::destructor(this)
|
||||
.old(boost::bind(&array::destructor_old, this,
|
||||
boost::ref(old_instances)))
|
||||
.postcondition(boost::bind(&array::destructor_postcondition,
|
||||
@@ -45,7 +45,7 @@ template<typename T, unsigned MaxSize>
|
||||
void array<T, MaxSize>::push_back(T const& value,
|
||||
boost::contract::virtual_* v) {
|
||||
boost::contract::old_ptr<unsigned> old_size;
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.precondition(boost::bind(&array::push_back_precondition, this))
|
||||
.old(boost::bind(&array::push_back_old, this, boost::cref(v),
|
||||
boost::ref(old_size)))
|
||||
@@ -59,14 +59,14 @@ void array<T, MaxSize>::push_back(T const& value,
|
||||
template<typename T, unsigned MaxSize>
|
||||
unsigned array<T, MaxSize>::size() const {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return size_;
|
||||
}
|
||||
|
||||
template<typename T, unsigned MaxSize>
|
||||
int array<T, MaxSize>::instances() {
|
||||
// Check static invariants.
|
||||
boost::contract::guard c = boost::contract::public_function<array>();
|
||||
boost::contract::check c = boost::contract::public_function<array>();
|
||||
return instances_;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
}
|
||||
static void constructor_old(boost::contract::old_ptr<int>&
|
||||
old_instances) {
|
||||
old_instances = BOOST_CONTRACT_OLDOF(instances());
|
||||
old_instances = BOOST_CONTRACT_OLD(instances());
|
||||
}
|
||||
void constructor_postcondition(unsigned const count,
|
||||
boost::contract::old_ptr<int> const old_instances) const {
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
virtual ~array();
|
||||
void destructor_old(boost::contract::old_ptr<int>& old_instances)
|
||||
const {
|
||||
old_instances = BOOST_CONTRACT_OLDOF(instances());
|
||||
old_instances = BOOST_CONTRACT_OLD(instances());
|
||||
}
|
||||
static void destructor_postcondition(boost::contract::old_ptr<int> const
|
||||
old_instances) {
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
}
|
||||
void push_back_old(boost::contract::virtual_* v,
|
||||
boost::contract::old_ptr<unsigned>& old_size) const {
|
||||
old_size = BOOST_CONTRACT_OLDOF(v, size());
|
||||
old_size = BOOST_CONTRACT_OLD(v, size());
|
||||
}
|
||||
void push_back_postcondition(
|
||||
boost::contract::old_ptr<unsigned> const old_size) const {
|
||||
|
||||
@@ -33,14 +33,14 @@ public:
|
||||
{
|
||||
boost::contract::old_ptr<int> old_instances;
|
||||
void BOOST_LOCAL_FUNCTION_TPL(bind& old_instances) {
|
||||
old_instances = BOOST_CONTRACT_OLDOF(array::instances());
|
||||
old_instances = BOOST_CONTRACT_OLD(array::instances());
|
||||
} BOOST_LOCAL_FUNCTION_NAME_TPL(old)
|
||||
void BOOST_LOCAL_FUNCTION_TPL(const bind this_, const bind& count,
|
||||
const bind& old_instances) {
|
||||
BOOST_CONTRACT_ASSERT(this_->size() == count);
|
||||
BOOST_CONTRACT_ASSERT(this_->instances() == *old_instances + 1);
|
||||
} BOOST_LOCAL_FUNCTION_NAME_TPL(post)
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.old(old).postcondition(post);
|
||||
|
||||
for(unsigned i = 0; i < count; ++i) values_[i] = T();
|
||||
@@ -51,12 +51,12 @@ public:
|
||||
virtual ~array() {
|
||||
boost::contract::old_ptr<int> old_instances;
|
||||
void BOOST_LOCAL_FUNCTION_TPL(const bind this_, bind& old_instances) {
|
||||
old_instances = BOOST_CONTRACT_OLDOF(this_->instances());
|
||||
old_instances = BOOST_CONTRACT_OLD(this_->instances());
|
||||
} BOOST_LOCAL_FUNCTION_NAME_TPL(old)
|
||||
void BOOST_LOCAL_FUNCTION_TPL(const bind& old_instances) {
|
||||
BOOST_CONTRACT_ASSERT(array::instances() == *old_instances - 1);
|
||||
} BOOST_LOCAL_FUNCTION_NAME_TPL(post)
|
||||
boost::contract::guard c = boost::contract::destructor(this)
|
||||
boost::contract::check c = boost::contract::destructor(this)
|
||||
.old(old).postcondition(post);
|
||||
|
||||
delete[] values_;
|
||||
@@ -70,12 +70,12 @@ public:
|
||||
} BOOST_LOCAL_FUNCTION_NAME_TPL(pre)
|
||||
void BOOST_LOCAL_FUNCTION_TPL(const bind v, const bind this_,
|
||||
bind& old_size) {
|
||||
old_size = BOOST_CONTRACT_OLDOF(v, this_->size());
|
||||
old_size = BOOST_CONTRACT_OLD(v, this_->size());
|
||||
} BOOST_LOCAL_FUNCTION_NAME_TPL(old)
|
||||
void BOOST_LOCAL_FUNCTION_TPL(const bind this_, const bind& old_size) {
|
||||
BOOST_CONTRACT_ASSERT(this_->size() == *old_size + 1);
|
||||
} BOOST_LOCAL_FUNCTION_NAME_TPL(post)
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.precondition(pre).old(old).postcondition(post);
|
||||
|
||||
values_[size_++] = value;
|
||||
@@ -83,13 +83,13 @@ public:
|
||||
|
||||
unsigned size() const {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return size_;
|
||||
}
|
||||
|
||||
static int instances() {
|
||||
// Check static invariants.
|
||||
boost::contract::guard c = boost::contract::public_function<array>();
|
||||
boost::contract::check c = boost::contract::public_function<array>();
|
||||
return instances_;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
char replace(std::string& s, std::size_t index, char x) {
|
||||
char result;
|
||||
boost::contract::old_ptr<char> old_y; // But old value copied later...
|
||||
boost::contract::guard c = boost::contract::function()
|
||||
boost::contract::check c = boost::contract::function()
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(index < s.size());
|
||||
})
|
||||
|
||||
@@ -13,7 +13,7 @@ void accumulate(T& total, T const& x) {
|
||||
// No compiler error if T has no copy constructor...
|
||||
boost::contract::old_ptr_if_copyable<T> old_total =
|
||||
BOOST_CONTRACT_OLD(total);
|
||||
boost::contract::guard c = boost::contract::function()
|
||||
boost::contract::check c = boost::contract::function()
|
||||
.postcondition([&] {
|
||||
// ...but old value null if T has no copy constructor.
|
||||
if(old_total) BOOST_CONTRACT_ASSERT(total == *old_total + x);
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
size() : boost::contract::null_old())
|
||||
;
|
||||
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(size() == *old_size + 1);
|
||||
})
|
||||
|
||||
@@ -19,7 +19,7 @@ struct surface {
|
||||
|
||||
surface square_surface(int edge) {
|
||||
boost::optional<surface> result; // No default constructor so use optional.
|
||||
boost::contract::guard c = boost::contract::function()
|
||||
boost::contract::check c = boost::contract::function()
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(edge > 0);
|
||||
})
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
|
||||
std::string lines::str(boost::contract::virtual_* v) const {
|
||||
std::string result;
|
||||
boost::contract::guard c = boost::contract::public_function(v, result, this)
|
||||
boost::contract::check c = boost::contract::public_function(v, result, this)
|
||||
.postcondition([&] (std::string const& result) {
|
||||
if(result != "") BOOST_CONTRACT_ASSERT(*result.rbegin() == '\n');
|
||||
})
|
||||
@@ -36,7 +36,7 @@ std::string lines::str(boost::contract::virtual_* v) const {
|
||||
|
||||
std::string& lines::str(boost::contract::virtual_* v) {
|
||||
boost::optional<std::string&> result;
|
||||
boost::contract::guard c = boost::contract::public_function(v, result, this)
|
||||
boost::contract::check c = boost::contract::public_function(v, result, this)
|
||||
.postcondition([&] (boost::optional<std::string const&> const& result) {
|
||||
if(*result != "") BOOST_CONTRACT_ASSERT(*result->rbegin() == '\n');
|
||||
})
|
||||
@@ -46,7 +46,7 @@ std::string& lines::str(boost::contract::virtual_* v) {
|
||||
}
|
||||
|
||||
void lines::put(std::string const& x, boost::contract::virtual_* v) {
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(*x.rbegin() != '\n');
|
||||
})
|
||||
@@ -55,7 +55,7 @@ void lines::put(std::string const& x, boost::contract::virtual_* v) {
|
||||
}
|
||||
|
||||
void lines::put(char x, boost::contract::virtual_* v) {
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(x != '\n');
|
||||
})
|
||||
@@ -65,7 +65,7 @@ void lines::put(char x, boost::contract::virtual_* v) {
|
||||
|
||||
void lines::put(int x, bool tab,
|
||||
boost::contract::virtual_* v) {
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(x >= 0);
|
||||
})
|
||||
@@ -86,7 +86,7 @@ public:
|
||||
|
||||
std::string str(boost::contract::virtual_* v = 0) const /* override */ {
|
||||
std::string result;
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_str
|
||||
// Note the use of `static_cast` (and same in other overloads below).
|
||||
>(v, result, static_cast<std::string (string_lines::*)(
|
||||
@@ -97,7 +97,7 @@ public:
|
||||
|
||||
// Overload on (absence of) `const` qualifier.
|
||||
std::string& str(boost::contract::virtual_* v = 0) /* override */ {
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_str
|
||||
>(v, str_, static_cast<std::string& (string_lines::*)(
|
||||
boost::contract::virtual_*)>(&string_lines::str), this);
|
||||
@@ -110,8 +110,8 @@ public:
|
||||
void put(std::string const& x,
|
||||
boost::contract::virtual_* v = 0) /* override */ {
|
||||
boost::contract::old_ptr<std::string> old_str =
|
||||
BOOST_CONTRACT_OLDOF(v, str());
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
BOOST_CONTRACT_OLD(v, str());
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_put
|
||||
>(v, static_cast<void (string_lines::*)(std::string const&,
|
||||
boost::contract::virtual_*)>(&string_lines::put), this, x)
|
||||
@@ -126,8 +126,8 @@ public:
|
||||
// Overload on argument type.
|
||||
void put(char x, boost::contract::virtual_* v = 0) /* override */ {
|
||||
boost::contract::old_ptr<std::string> old_str =
|
||||
BOOST_CONTRACT_OLDOF(v, str());
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
BOOST_CONTRACT_OLD(v, str());
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_put
|
||||
>(v, static_cast<void (string_lines::*)(char, boost::contract::
|
||||
virtual_*)>(&string_lines::put), this, x)
|
||||
@@ -143,8 +143,8 @@ public:
|
||||
void put(int x, bool tab = false,
|
||||
boost::contract::virtual_* v = 0) /* override */ {
|
||||
boost::contract::old_ptr<std::string> old_str =
|
||||
BOOST_CONTRACT_OLDOF(v, str());
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
BOOST_CONTRACT_OLD(v, str());
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_put
|
||||
>(v, static_cast<void (string_lines::*)(int, bool, boost::contract::
|
||||
virtual_*)>(&string_lines::put), this, x, tab)
|
||||
|
||||
@@ -16,8 +16,8 @@ private:
|
||||
int n_;
|
||||
|
||||
void dec() {
|
||||
boost::contract::old_ptr<int> old_get = BOOST_CONTRACT_OLDOF(get());
|
||||
boost::contract::guard c = boost::contract::function()
|
||||
boost::contract::old_ptr<int> old_get = BOOST_CONTRACT_OLD(get());
|
||||
boost::contract::check c = boost::contract::function()
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(
|
||||
get() + 1 >= std::numeric_limits<int>::min());
|
||||
@@ -32,7 +32,7 @@ private:
|
||||
|
||||
protected:
|
||||
virtual void set(int n, boost::contract::virtual_* = 0) {
|
||||
boost::contract::guard c = boost::contract::function()
|
||||
boost::contract::check c = boost::contract::function()
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(n <= 0);
|
||||
})
|
||||
@@ -50,7 +50,7 @@ protected:
|
||||
public:
|
||||
virtual int get(boost::contract::virtual_* v = 0) const {
|
||||
int result;
|
||||
boost::contract::guard c = boost::contract::public_function(
|
||||
boost::contract::check c = boost::contract::public_function(
|
||||
v, result, this)
|
||||
.postcondition([&] (int const result) {
|
||||
BOOST_CONTRACT_ASSERT(result <= 0);
|
||||
|
||||
@@ -17,8 +17,8 @@ private:
|
||||
int n_;
|
||||
|
||||
virtual void dec(boost::contract::virtual_* = 0) {
|
||||
boost::contract::old_ptr<int> old_get = BOOST_CONTRACT_OLDOF(get());
|
||||
boost::contract::guard c = boost::contract::function()
|
||||
boost::contract::old_ptr<int> old_get = BOOST_CONTRACT_OLD(get());
|
||||
boost::contract::check c = boost::contract::function()
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(
|
||||
get() + 1 >= std::numeric_limits<int>::min());
|
||||
@@ -33,7 +33,7 @@ private:
|
||||
|
||||
protected:
|
||||
virtual void set(int n, boost::contract::virtual_* = 0) {
|
||||
boost::contract::guard c = boost::contract::function()
|
||||
boost::contract::check c = boost::contract::function()
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(n <= 0);
|
||||
})
|
||||
@@ -51,7 +51,7 @@ protected:
|
||||
public:
|
||||
virtual int get(boost::contract::virtual_* v = 0) const {
|
||||
int result;
|
||||
boost::contract::guard c = boost::contract::public_function(
|
||||
boost::contract::check c = boost::contract::public_function(
|
||||
v, result, this)
|
||||
.postcondition([&] (int const result) {
|
||||
BOOST_CONTRACT_ASSERT(result <= 0);
|
||||
@@ -83,8 +83,8 @@ public:
|
||||
// Not overriding from public members so no `override_...`.
|
||||
|
||||
virtual void dec(boost::contract::virtual_* v = 0) {
|
||||
boost::contract::old_ptr<int> old_get = BOOST_CONTRACT_OLDOF(v, get());
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
boost::contract::old_ptr<int> old_get = BOOST_CONTRACT_OLD(v, get());
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(
|
||||
get() + 10 >= std::numeric_limits<int>::min());
|
||||
@@ -98,7 +98,7 @@ public:
|
||||
}
|
||||
|
||||
virtual void set(int n, boost::contract::virtual_* v = 0) {
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(n % 10 == 0);
|
||||
})
|
||||
@@ -115,7 +115,7 @@ public:
|
||||
|
||||
virtual int get(boost::contract::virtual_* v = 0) const {
|
||||
int result;
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_get>(v, result, &counter10::get, this);
|
||||
|
||||
return result = counter::get();
|
||||
|
||||
@@ -31,8 +31,8 @@ private:
|
||||
int n_;
|
||||
|
||||
virtual void dec(boost::contract::virtual_* = 0) {
|
||||
boost::contract::old_ptr<int> old_get = BOOST_CONTRACT_OLDOF(get());
|
||||
boost::contract::guard c = boost::contract::function()
|
||||
boost::contract::old_ptr<int> old_get = BOOST_CONTRACT_OLD(get());
|
||||
boost::contract::check c = boost::contract::function()
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(
|
||||
get() + 1 >= std::numeric_limits<int>::min());
|
||||
@@ -47,7 +47,7 @@ private:
|
||||
|
||||
protected:
|
||||
virtual void set(int n, boost::contract::virtual_* = 0) {
|
||||
boost::contract::guard c = boost::contract::function()
|
||||
boost::contract::check c = boost::contract::function()
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(n <= 0);
|
||||
})
|
||||
@@ -65,7 +65,7 @@ protected:
|
||||
public:
|
||||
virtual int get(boost::contract::virtual_* v = 0) const {
|
||||
int result;
|
||||
boost::contract::guard c = boost::contract::public_function(
|
||||
boost::contract::check c = boost::contract::public_function(
|
||||
v, result, this)
|
||||
.postcondition([&] (int const result) {
|
||||
BOOST_CONTRACT_ASSERT(result <= 0);
|
||||
@@ -101,8 +101,8 @@ public:
|
||||
//]
|
||||
|
||||
void countable::dec(boost::contract::virtual_* v) {
|
||||
boost::contract::old_ptr<int> old_get = BOOST_CONTRACT_OLDOF(v, get());
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
boost::contract::old_ptr<int> old_get = BOOST_CONTRACT_OLD(v, get());
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(get() > std::numeric_limits<int>::min());
|
||||
})
|
||||
@@ -114,7 +114,7 @@ void countable::dec(boost::contract::virtual_* v) {
|
||||
}
|
||||
|
||||
void countable::set(int n, boost::contract::virtual_* v) {
|
||||
boost::contract::guard c = boost::contract::public_function(
|
||||
boost::contract::check c = boost::contract::public_function(
|
||||
v, this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(n <= 0);
|
||||
@@ -128,7 +128,7 @@ void countable::set(int n, boost::contract::virtual_* v) {
|
||||
|
||||
int countable::get(boost::contract::virtual_* v) const {
|
||||
int result;
|
||||
boost::contract::guard c = boost::contract::public_function(
|
||||
boost::contract::check c = boost::contract::public_function(
|
||||
v, result, this);
|
||||
assert(false); // Never executed by this library.
|
||||
}
|
||||
@@ -145,8 +145,8 @@ public:
|
||||
// Overriding from public members from `countable` so use `override_...`.
|
||||
|
||||
virtual void dec(boost::contract::virtual_* v = 0) {
|
||||
boost::contract::old_ptr<int> old_get = BOOST_CONTRACT_OLDOF(v, get());
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
boost::contract::old_ptr<int> old_get = BOOST_CONTRACT_OLD(v, get());
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_dec>(v, &counter10::dec, this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(
|
||||
@@ -161,7 +161,7 @@ public:
|
||||
}
|
||||
|
||||
virtual void set(int n, boost::contract::virtual_* v = 0) {
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_set>(v, &counter10::set, this, n)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(n % 10 == 0);
|
||||
@@ -181,7 +181,7 @@ public:
|
||||
|
||||
virtual int get(boost::contract::virtual_* v = 0) const {
|
||||
int result;
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_get>(v, result, &counter10::get, this);
|
||||
|
||||
return result = counter::get();
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
BOOST_CONTRACT_ASSERT(from <= to);
|
||||
})
|
||||
{
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(size() == (to - from + 1));
|
||||
})
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
//[public_destructor
|
||||
virtual ~unique_identifiers() {
|
||||
// Following contract checks invariants.
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
|
||||
// Destructor body here... (do nothing in this example).
|
||||
}
|
||||
@@ -41,14 +41,14 @@ public:
|
||||
|
||||
int size() const {
|
||||
// Following contract checks invariants.
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return vect_.size();
|
||||
}
|
||||
|
||||
//[public_function
|
||||
bool find(int id) const {
|
||||
bool result;
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
if(size() == 0) BOOST_CONTRACT_ASSERT(!result);
|
||||
})
|
||||
@@ -65,10 +65,10 @@ public:
|
||||
virtual int push_back(int id, boost::contract::virtual_* v = 0) {
|
||||
int result;
|
||||
boost::contract::old_ptr<bool> old_find =
|
||||
BOOST_CONTRACT_OLDOF(v, find(id)); // Pass `v`.
|
||||
BOOST_CONTRACT_OLD(v, find(id)); // Pass `v`.
|
||||
boost::contract::old_ptr<int> old_size =
|
||||
BOOST_CONTRACT_OLDOF(v, size()); // Pass `v`.
|
||||
boost::contract::guard c = boost::contract::public_function(
|
||||
BOOST_CONTRACT_OLD(v, size()); // Pass `v`.
|
||||
boost::contract::check c = boost::contract::public_function(
|
||||
v, result, this) // Pass `v` and `result`.
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!find(id));
|
||||
@@ -111,10 +111,9 @@ public:
|
||||
int push_back(int id, boost::contract::virtual_* v = 0) /* override */ {
|
||||
int result;
|
||||
boost::contract::old_ptr<bool> old_find =
|
||||
BOOST_CONTRACT_OLDOF(v, find(id));
|
||||
boost::contract::old_ptr<int> old_size =
|
||||
BOOST_CONTRACT_OLDOF(v, size());
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
BOOST_CONTRACT_OLD(v, find(id));
|
||||
boost::contract::old_ptr<int> old_size = BOOST_CONTRACT_OLD(v, size());
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_push_back // Pass override plus below function pointer...
|
||||
>(v, result, &identifiers::push_back, this, id) // ...and arguments.
|
||||
.precondition([&] { // Check in OR with bases.
|
||||
@@ -136,13 +135,13 @@ public:
|
||||
|
||||
bool empty() const {
|
||||
// Following contract checks invariants.
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
identifiers(int from, int to) : unique_identifiers(from, to) {
|
||||
// Following contract checks invariants.
|
||||
boost::contract::guard c = boost::contract::constructor(this);
|
||||
boost::contract::check c = boost::contract::constructor(this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
// Pure-virtual function definition (and contract) out-of-line (usual in C++).
|
||||
surface shape::get_surface(boost::contract::virtual_* v) const {
|
||||
boost::optional<surface> result;
|
||||
boost::contract::guard c = boost::contract::public_function(v, result, this)
|
||||
boost::contract::check c = boost::contract::public_function(v, result, this)
|
||||
.postcondition([&] (boost::optional<surface const&> const& result) {
|
||||
BOOST_CONTRACT_ASSERT(result->area > 0);
|
||||
BOOST_CONTRACT_ASSERT(result->perimeter > 0);
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
|
||||
surface get_surface(boost::contract::virtual_* v = 0) const /* override */ {
|
||||
boost::optional<surface> result;
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_get_surface>(v, result, &square::get_surface, this)
|
||||
.postcondition([&] (boost::optional<surface const&> const& result) {
|
||||
BOOST_CONTRACT_ASSERT(result->area == edge() * edge());
|
||||
@@ -69,17 +69,17 @@ public:
|
||||
edge_(edge)
|
||||
{
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::constructor(this);
|
||||
boost::contract::check c = boost::contract::constructor(this);
|
||||
}
|
||||
|
||||
~square() {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
int edge() const {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return edge_;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
}),
|
||||
values_(new T[MaxSize]) // Still, member initializations must be here.
|
||||
{
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(size() == count);
|
||||
})
|
||||
@@ -33,14 +33,14 @@ public:
|
||||
}
|
||||
|
||||
virtual ~array() {
|
||||
boost::contract::guard c = boost::contract::destructor(this); // Inv.
|
||||
boost::contract::check c = boost::contract::destructor(this); // Inv.
|
||||
destructor_body(); // Separate destructor body implementation.
|
||||
}
|
||||
|
||||
virtual void push_back(T const& value, boost::contract::virtual_* v = 0) {
|
||||
boost::contract::old_ptr<unsigned> old_size =
|
||||
BOOST_CONTRACT_OLDOF(v, size());
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
BOOST_CONTRACT_OLD(v, size());
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(size() < MaxSize);
|
||||
})
|
||||
@@ -63,7 +63,7 @@ private:
|
||||
public:
|
||||
unsigned size() const {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return size_body();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
|
||||
static int instances() {
|
||||
// Explicit template parameter `make` (to check static invariants).
|
||||
boost::contract::guard c = boost::contract::public_function<make>();
|
||||
boost::contract::check c = boost::contract::public_function<make>();
|
||||
|
||||
return instances_; // Function body.
|
||||
}
|
||||
@@ -27,8 +27,8 @@ public:
|
||||
|
||||
make() : object() {
|
||||
boost::contract::old_ptr<int> old_instances =
|
||||
BOOST_CONTRACT_OLDOF(instances());
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
BOOST_CONTRACT_OLD(instances());
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(instances() == *old_instances + 1);
|
||||
})
|
||||
@@ -39,8 +39,8 @@ public:
|
||||
|
||||
~make() {
|
||||
boost::contract::old_ptr<int> old_instances =
|
||||
BOOST_CONTRACT_OLDOF(instances());
|
||||
boost::contract::guard c = boost::contract::destructor(this)
|
||||
BOOST_CONTRACT_OLD(instances());
|
||||
boost::contract::check c = boost::contract::destructor(this)
|
||||
.postcondition([&] { // (An example of destructor postconditions.)
|
||||
BOOST_CONTRACT_ASSERT(instances() == *old_instances - 1);
|
||||
})
|
||||
|
||||
@@ -32,7 +32,7 @@ public:
|
||||
|
||||
/* ... */
|
||||
//]
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(size() == std::strlen(chars));
|
||||
})
|
||||
@@ -45,12 +45,12 @@ public:
|
||||
|
||||
~cstring() {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
std::size_t size() const {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return size_;
|
||||
}
|
||||
|
||||
@@ -66,15 +66,21 @@ private:
|
||||
};
|
||||
|
||||
//[throw_on_failure_handler
|
||||
void throwing_handler(boost::contract::from context) {
|
||||
if(context == boost::contract::from_destructor) {
|
||||
// Ignore exception because destructors should never throw.
|
||||
std::clog << "destructor contract failed (ignored)" << std::endl;
|
||||
} else throw; // Re-throw (assertion_failure, too_large_error, etc.).
|
||||
}
|
||||
|
||||
int main() {
|
||||
boost::contract::set_failure(&throwing_handler);
|
||||
boost::contract::set_specification_failure(
|
||||
[] (boost::contract::from context) {
|
||||
if(context == boost::contract::from_destructor) {
|
||||
// Ignore exception because destructors should never throw.
|
||||
std::clog << "destructor contract failed (ignored)" <<
|
||||
std::endl;
|
||||
} else throw; // Rethrow (assertion_failure, too_large_error, etc.).
|
||||
}
|
||||
);
|
||||
boost::contract::set_check_failure( // Then do not use CHECK in destructors.
|
||||
[] {
|
||||
throw; // Rethrow (assertion_failure, too_large_error, etc.).
|
||||
}
|
||||
);
|
||||
|
||||
/* ... */
|
||||
//]
|
||||
|
||||
@@ -29,8 +29,8 @@ union positive {
|
||||
BOOST_CONTRACT_ASSERT(x > 0);
|
||||
});
|
||||
boost::contract::old_ptr<int> old_instances =
|
||||
BOOST_CONTRACT_OLDOF(instances());
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
BOOST_CONTRACT_OLD(instances());
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(instances() == *old_instances + 1);
|
||||
})
|
||||
@@ -46,8 +46,8 @@ union positive {
|
||||
BOOST_CONTRACT_ASSERT(x > 0);
|
||||
});
|
||||
boost::contract::old_ptr<int> old_instances =
|
||||
BOOST_CONTRACT_OLDOF(instances());
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
BOOST_CONTRACT_OLD(instances());
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(instances() == *old_instances + 1);
|
||||
})
|
||||
@@ -59,8 +59,8 @@ union positive {
|
||||
|
||||
~positive() {
|
||||
boost::contract::old_ptr<int> old_instances =
|
||||
BOOST_CONTRACT_OLDOF(instances());
|
||||
boost::contract::guard c = boost::contract::destructor(this)
|
||||
BOOST_CONTRACT_OLD(instances());
|
||||
boost::contract::check c = boost::contract::destructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(instances() == *old_instances - 1);
|
||||
})
|
||||
@@ -70,7 +70,7 @@ union positive {
|
||||
}
|
||||
|
||||
void get(int& x) {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(x > 0);
|
||||
});
|
||||
@@ -80,7 +80,7 @@ union positive {
|
||||
}
|
||||
|
||||
void get(double& x) {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(x > 0);
|
||||
});
|
||||
@@ -90,7 +90,7 @@ union positive {
|
||||
}
|
||||
|
||||
static int instances() {
|
||||
boost::contract::guard c = boost::contract::public_function<positive>();
|
||||
boost::contract::check c = boost::contract::public_function<positive>();
|
||||
return instances_;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,27 +14,27 @@ public:
|
||||
void invariant() const; // Invariants const qualified.
|
||||
|
||||
a() { // Check both cv and const invariant (at exit if no throw).
|
||||
boost::contract::guard c= boost::contract::constructor(this);
|
||||
boost::contract::check c= boost::contract::constructor(this);
|
||||
}
|
||||
|
||||
~a() { // Check both cv and const invariant (at entry).
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
void m() { // Check const invariant (at entry and exit if no throw).
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
}
|
||||
|
||||
void c() const { // Check const invariant (at entry and exit if no throw).
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
}
|
||||
|
||||
void v() volatile { // Check cv invariant (at entry and exit if no throw).
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
}
|
||||
|
||||
void cv() const volatile { // Check cv inv. (at entry and exit if no throw).
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
}
|
||||
};
|
||||
//]
|
||||
|
||||
@@ -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() ==
|
||||
|
||||
@@ -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).
|
||||
})
|
||||
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
|
||||
// Construct counter with specified value.
|
||||
explicit counter(int a_value = 10) : value_(a_value) {
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(value() == a_value); // Value set.
|
||||
})
|
||||
@@ -33,14 +33,14 @@ public:
|
||||
|
||||
// Destroy counter.
|
||||
virtual ~counter() {
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
/* Queries */
|
||||
|
||||
// Current counter value.
|
||||
int value() const {
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return value_;
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ public:
|
||||
|
||||
// Decrement counter value.
|
||||
void decrement() {
|
||||
boost::contract::old_ptr<int> old_value = BOOST_CONTRACT_OLDOF(value());
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::old_ptr<int> old_value = BOOST_CONTRACT_OLD(value());
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(value() == *old_value - 1); // Decrement.
|
||||
})
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
/* Creation */
|
||||
|
||||
explicit decrement_button(counter& a_counter) : counter_(a_counter) {
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
// Enable iff positive value.
|
||||
BOOST_CONTRACT_ASSERT(enabled() == (a_counter.value() > 0));
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
|
||||
// Destroy button.
|
||||
virtual ~decrement_button() {
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
/* Commands */
|
||||
@@ -47,8 +47,8 @@ public:
|
||||
virtual void on_bn_clicked(boost::contract::virtual_* v = 0)
|
||||
/* override */ {
|
||||
boost::contract::old_ptr<int> old_value =
|
||||
BOOST_CONTRACT_OLDOF(v, counter_.value());
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
BOOST_CONTRACT_OLD(v, counter_.value());
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_on_bn_clicked
|
||||
>(v, &decrement_button::on_bn_clicked, this)
|
||||
.postcondition([&] {
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
virtual bool up_to_date_with_subject(boost::contract::virtual_* v = 0)
|
||||
const /* override */ {
|
||||
bool result;
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_up_to_date_with_subject
|
||||
>(v, result, &decrement_button::up_to_date_with_subject, this);
|
||||
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
}
|
||||
|
||||
virtual void update(boost::contract::virtual_* v = 0) /* override */ {
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_update>(v, &decrement_button::update, this)
|
||||
.postcondition([&] {
|
||||
// Enabled iff positive value.
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
|
||||
// Create an enabled button.
|
||||
push_button() : enabled_(true) {
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(enabled()); // Enabled.
|
||||
})
|
||||
@@ -28,14 +28,14 @@ public:
|
||||
|
||||
// Destroy button.
|
||||
virtual ~push_button() {
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
/* Queries */
|
||||
|
||||
// If button is enabled.
|
||||
bool enabled() const {
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return enabled_;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
|
||||
// Enable button.
|
||||
void enable() {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(enabled()); // Enabled.
|
||||
})
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
|
||||
// Disable button.
|
||||
void disable() {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!enabled()); // Disabled.
|
||||
})
|
||||
@@ -71,7 +71,7 @@ private:
|
||||
};
|
||||
|
||||
void push_button::on_bn_clicked(boost::contract::virtual_* v) {
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(enabled()); // Enabled.
|
||||
})
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
|
||||
// Create view associated with given counter.
|
||||
explicit view_of_counter(counter& a_counter) : counter_(a_counter) {
|
||||
boost::contract::guard c = boost::contract::constructor(this);
|
||||
boost::contract::check c = boost::contract::constructor(this);
|
||||
|
||||
counter_.attach(this);
|
||||
assert(counter_.value() == test_counter);
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
|
||||
// Destroy view.
|
||||
virtual ~view_of_counter() {
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
/* Commands */
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
virtual bool up_to_date_with_subject(boost::contract::virtual_* v = 0)
|
||||
const /* override */ {
|
||||
bool result;
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_up_to_date_with_subject
|
||||
>(v, result, &view_of_counter::up_to_date_with_subject, this);
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
}
|
||||
|
||||
virtual void update(boost::contract::virtual_* v = 0) /* override */ {
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_update>(v, &view_of_counter::update, this);
|
||||
|
||||
assert(counter_.value() == test_counter);
|
||||
|
||||
@@ -61,13 +61,13 @@ public:
|
||||
insurance_cover_usd_(_insurance_cover_usd)
|
||||
{
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::constructor(this);
|
||||
boost::contract::check c = boost::contract::constructor(this);
|
||||
}
|
||||
|
||||
// Destroy courier.
|
||||
virtual ~courier() {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
/* Queries */
|
||||
@@ -75,7 +75,7 @@ public:
|
||||
// Return insurance cover.
|
||||
double insurance_cover_usd() const {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return insurance_cover_usd_;
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public:
|
||||
std::string const& destination,
|
||||
boost::contract::virtual_* v = 0
|
||||
) {
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.precondition([&] {
|
||||
// Within max weight of this delivery.
|
||||
BOOST_CONTRACT_ASSERT(package_delivery.weight_kg < 5.0);
|
||||
@@ -148,13 +148,13 @@ public:
|
||||
courier(insurance_cover_usd)
|
||||
{
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::constructor(this);
|
||||
boost::contract::check c = boost::contract::constructor(this);
|
||||
}
|
||||
|
||||
// Destroy courier.
|
||||
virtual ~different_courier() {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
/* Commands */
|
||||
@@ -164,7 +164,7 @@ public:
|
||||
std::string const& destination,
|
||||
boost::contract::virtual_* v = 0
|
||||
) /* override */ {
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_deliver
|
||||
>(v, &different_courier::deliver, this, package_delivery, destination)
|
||||
.precondition([&] {
|
||||
|
||||
@@ -41,32 +41,32 @@ public:
|
||||
|
||||
customer_manager() {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::constructor(this);
|
||||
boost::contract::check c = boost::contract::constructor(this);
|
||||
}
|
||||
|
||||
virtual ~customer_manager() {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
/* Basic Queries */
|
||||
|
||||
int count() const {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return customers_.size();
|
||||
}
|
||||
|
||||
bool id_active(customer_info::identifier const& id) const {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return customers_.find(id) != customers_.cend();
|
||||
}
|
||||
|
||||
/* Derived Queries */
|
||||
|
||||
std::string const& name_for(customer_info::identifier const& id) const {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(id_active(id)); // Active.
|
||||
})
|
||||
@@ -79,8 +79,8 @@ public:
|
||||
/* Commands */
|
||||
|
||||
void add(customer_info const& info) {
|
||||
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([&] {
|
||||
// Not already active.
|
||||
BOOST_CONTRACT_ASSERT(!id_active(info.id));
|
||||
@@ -96,7 +96,7 @@ public:
|
||||
|
||||
void set_name(customer_info::identifier const& id,
|
||||
std::string const& name) {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(id_active(id)); // Already active.
|
||||
})
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
|
||||
// Create empty dictionary.
|
||||
dictionary() {
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(count() == 0); // Empty.
|
||||
})
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
// Destroy dictionary.
|
||||
~dictionary() {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
/* Basic Queries */
|
||||
@@ -41,14 +41,14 @@ public:
|
||||
// Number of key entries.
|
||||
int count() const {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return items_.size();
|
||||
}
|
||||
|
||||
// Has entry for key?
|
||||
bool has(K const& key) const {
|
||||
bool result;
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
// Empty has no key.
|
||||
if(count() == 0) BOOST_CONTRACT_ASSERT(!result);
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
|
||||
// Value for a given key.
|
||||
T const& value_for(K const& key) const {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(has(key)); // Has key.
|
||||
})
|
||||
@@ -74,8 +74,8 @@ public:
|
||||
|
||||
// Add value of a given key.
|
||||
void put(K const& key, T const& value) {
|
||||
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(!has(key)); // Has not key already.
|
||||
})
|
||||
@@ -92,8 +92,8 @@ public:
|
||||
|
||||
// Remove value for given key.
|
||||
void remove(K const& key) {
|
||||
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(has(key)); // Has key.
|
||||
})
|
||||
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
|
||||
// Create an empty list.
|
||||
name_list() {
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(count() == 0); // Empty list.
|
||||
})
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
// Destroy list.
|
||||
virtual ~name_list() {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
/* Basic Queries */
|
||||
@@ -42,14 +42,14 @@ public:
|
||||
// Number of names in list.
|
||||
int count() const {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return names_.size();
|
||||
}
|
||||
|
||||
// Is name in list?
|
||||
bool has(std::string const& name) const {
|
||||
bool result;
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
// If empty, has not.
|
||||
if(count() == 0) BOOST_CONTRACT_ASSERT(!result);
|
||||
@@ -66,10 +66,10 @@ public:
|
||||
virtual void put(std::string const& name,
|
||||
boost::contract::virtual_* v = 0) {
|
||||
boost::contract::old_ptr<bool> old_has_name =
|
||||
BOOST_CONTRACT_OLDOF(v, has(name));
|
||||
BOOST_CONTRACT_OLD(v, has(name));
|
||||
boost::contract::old_ptr<int> old_count =
|
||||
BOOST_CONTRACT_OLDOF(v, count());
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
BOOST_CONTRACT_OLD(v, count());
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!has(name)); // Not already in list.
|
||||
})
|
||||
@@ -104,10 +104,10 @@ public:
|
||||
void put(std::string const& name,
|
||||
boost::contract::virtual_* v = 0) /* override */ {
|
||||
boost::contract::old_ptr<bool> old_has_name =
|
||||
BOOST_CONTRACT_OLDOF(v, has(name));
|
||||
BOOST_CONTRACT_OLD(v, has(name));
|
||||
boost::contract::old_ptr<int> old_count =
|
||||
BOOST_CONTRACT_OLDOF(v, count());
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
BOOST_CONTRACT_OLD(v, count());
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_put>(v, &relaxed_name_list::put, this, name)
|
||||
.precondition([&] { // Relax inherited preconditions.
|
||||
BOOST_CONTRACT_ASSERT(has(name)); // Already in list.
|
||||
|
||||
@@ -20,11 +20,11 @@ public:
|
||||
/* Creation */
|
||||
|
||||
observer() {
|
||||
boost::contract::guard c = boost::contract::constructor(this);
|
||||
boost::contract::check c = boost::contract::constructor(this);
|
||||
}
|
||||
|
||||
virtual ~observer() {
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
/* Commands */
|
||||
@@ -38,13 +38,13 @@ public:
|
||||
};
|
||||
|
||||
bool observer::up_to_date_with_subject(boost::contract::virtual_* v) const {
|
||||
boost::contract::guard c = boost::contract::public_function(v, this);
|
||||
boost::contract::check c = boost::contract::public_function(v, this);
|
||||
assert(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
void observer::update(boost::contract::virtual_* v) {
|
||||
boost::contract::guard c = boost::contract::public_function(v, this)
|
||||
boost::contract::check c = boost::contract::public_function(v, this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(up_to_date_with_subject()); // Up-to-date.
|
||||
})
|
||||
|
||||
@@ -35,20 +35,20 @@ public:
|
||||
// Construct subject with no observer.
|
||||
subject() {
|
||||
// Check invariant.
|
||||
boost::contract::guard c = boost::contract::constructor(this);
|
||||
boost::contract::check c = boost::contract::constructor(this);
|
||||
}
|
||||
|
||||
// Destroy subject.
|
||||
virtual ~subject() {
|
||||
// Check invariant.
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
/* Queries */
|
||||
|
||||
// If given object is attached.
|
||||
bool attached(observer const* ob) const {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(ob); // Not null.
|
||||
})
|
||||
@@ -63,8 +63,8 @@ public:
|
||||
// Attach given object as an observer.
|
||||
void attach(observer* ob) {
|
||||
boost::contract::old_ptr<std::vector<observer const*> > old_observers =
|
||||
BOOST_CONTRACT_OLDOF(observers());
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
BOOST_CONTRACT_OLD(observers());
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(ob); // Not null.
|
||||
BOOST_CONTRACT_ASSERT(!attached(ob)); // Not already attached.
|
||||
@@ -102,7 +102,7 @@ protected:
|
||||
// Update all attached observers.
|
||||
void notify() {
|
||||
// Protected members use `function` (no inv and no subcontracting).
|
||||
boost::contract::guard c = boost::contract::function()
|
||||
boost::contract::check c = boost::contract::function()
|
||||
.postcondition([&] {
|
||||
if(O_N <= COMPLEXITY_MAX) {
|
||||
// All updated.
|
||||
@@ -137,7 +137,7 @@ private:
|
||||
observer const* ob
|
||||
) {
|
||||
// Private members use `function` (no inv and no subcontracting).
|
||||
boost::contract::guard c = boost::contract::function()
|
||||
boost::contract::check c = boost::contract::function()
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(ob); // Not null.
|
||||
})
|
||||
|
||||
@@ -25,15 +25,15 @@ public:
|
||||
typedef int state; // Some state being observed.
|
||||
|
||||
concrete_subject() : state_() {
|
||||
boost::contract::guard c = boost::contract::constructor(this);
|
||||
boost::contract::check c = boost::contract::constructor(this);
|
||||
}
|
||||
|
||||
~concrete_subject() {
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
void set_state(state const& new_state) {
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
|
||||
state_ = new_state;
|
||||
assert(state_ == test_state);
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
}
|
||||
|
||||
state get_state() const {
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return state_;
|
||||
}
|
||||
|
||||
@@ -63,11 +63,11 @@ public:
|
||||
// Create concrete observer.
|
||||
explicit concrete_observer(concrete_subject const& subj) :
|
||||
subject_(subj), observed_state_() {
|
||||
boost::contract::guard c = boost::contract::constructor(this);
|
||||
boost::contract::check c = boost::contract::constructor(this);
|
||||
}
|
||||
|
||||
~concrete_observer() {
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
// Implement base virtual functions.
|
||||
@@ -75,7 +75,7 @@ public:
|
||||
bool up_to_date_with_subject(boost::contract::virtual_* v = 0)
|
||||
const /* override */ {
|
||||
bool result;
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_up_to_date_with_subject
|
||||
>(v, result, &concrete_observer::up_to_date_with_subject, this);
|
||||
|
||||
@@ -83,7 +83,7 @@ public:
|
||||
}
|
||||
|
||||
void update(boost::contract::virtual_* v = 0) /* override */ {
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_update>(v, &concrete_observer::update, this);
|
||||
|
||||
observed_state_ = subject_.get_state();
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
BOOST_CONTRACT_ASSERT(a_capacity > 0); // Positive capacity.
|
||||
})
|
||||
{
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
// Capacity set.
|
||||
BOOST_CONTRACT_ASSERT(capacity() == a_capacity);
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
// Destroy queue.
|
||||
virtual ~simple_queue() {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
/* Basic Queries */
|
||||
@@ -62,14 +62,14 @@ public:
|
||||
// (Somewhat exposes implementation but allows to check more contracts.)
|
||||
std::vector<T> const& items() const {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return items_;
|
||||
}
|
||||
|
||||
// Max number of items queue can hold.
|
||||
int capacity() const {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return items_.capacity();
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public:
|
||||
// Number of items.
|
||||
int count() const {
|
||||
int result;
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
// Return items count.
|
||||
BOOST_CONTRACT_ASSERT(result == int(items().size()));
|
||||
@@ -91,7 +91,7 @@ public:
|
||||
// Item at head.
|
||||
T const& head() const {
|
||||
boost::optional<T const&> result;
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!is_empty()); // Not empty.
|
||||
})
|
||||
@@ -107,7 +107,7 @@ public:
|
||||
// If queue contains no item.
|
||||
bool is_empty() const {
|
||||
bool result;
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
// Consistent with count.
|
||||
BOOST_CONTRACT_ASSERT(result == (count() == 0));
|
||||
@@ -120,7 +120,7 @@ public:
|
||||
// If queue as no room for another item.
|
||||
bool is_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( // Consistent with size and capacity.
|
||||
result == (capacity() == int(items().size())));
|
||||
@@ -136,9 +136,9 @@ public:
|
||||
void remove() {
|
||||
// Expensive all_equal postcond. and old_items copy might be skipped.
|
||||
boost::contract::old_ptr<std::vector<T> > old_items;
|
||||
if(O_N <= COMPLEXITY_MAX) old_items = BOOST_CONTRACT_OLDOF(items());
|
||||
boost::contract::old_ptr<int> old_count = BOOST_CONTRACT_OLDOF(count());
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
if(O_N <= COMPLEXITY_MAX) old_items = BOOST_CONTRACT_OLD(items());
|
||||
boost::contract::old_ptr<int> old_count = BOOST_CONTRACT_OLD(count());
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!is_empty()); // Not empty.
|
||||
})
|
||||
@@ -155,9 +155,9 @@ public:
|
||||
void put(T const& item) {
|
||||
// Expensive all_equal postcond. and old_items copy might be skipped.
|
||||
boost::contract::old_ptr<std::vector<T> > old_items;
|
||||
if(O_N <= COMPLEXITY_MAX) old_items = BOOST_CONTRACT_OLDOF(items());
|
||||
boost::contract::old_ptr<int> old_count = BOOST_CONTRACT_OLDOF(count());
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
if(O_N <= COMPLEXITY_MAX) old_items = BOOST_CONTRACT_OLD(items());
|
||||
boost::contract::old_ptr<int> old_count = BOOST_CONTRACT_OLD(count());
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(count() < capacity()); // Room for add.
|
||||
})
|
||||
@@ -176,7 +176,7 @@ private:
|
||||
// Contract helper.
|
||||
static bool all_equal(std::vector<T> const& left,
|
||||
std::vector<T> const& right, unsigned offset = 0) {
|
||||
boost::contract::guard c = boost::contract::function()
|
||||
boost::contract::check c = boost::contract::function()
|
||||
.precondition([&] {
|
||||
// Correct offset.
|
||||
BOOST_CONTRACT_ASSERT(right.size() == left.size() + offset);
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
|
||||
// Create empty stack.
|
||||
stack() {
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(count() == 0); // Empty.
|
||||
})
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
// Destroy stack.
|
||||
virtual ~stack() {
|
||||
// Check invariants.
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
/* Basic Queries */
|
||||
@@ -41,13 +41,13 @@ public:
|
||||
// Number of 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 items_.size();
|
||||
}
|
||||
|
||||
// Item at index in [1, count()] (as in Eiffel).
|
||||
T const& item_at(int index) const {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(index > 0); // Positive index.
|
||||
BOOST_CONTRACT_ASSERT(index <= count()); // Index within count.
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
// If no items.
|
||||
bool is_empty() const {
|
||||
bool result;
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
// Consistent with count.
|
||||
BOOST_CONTRACT_ASSERT(result == (count() == 0));
|
||||
@@ -75,7 +75,7 @@ public:
|
||||
// Top item.
|
||||
T const& item() const {
|
||||
boost::optional<T const&> result; // Avoid extra construction of T.
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(count() > 0); // Not empty.
|
||||
})
|
||||
@@ -92,8 +92,8 @@ public:
|
||||
|
||||
// Push item to the top.
|
||||
void put(T const& new_item) {
|
||||
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)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(count() == *old_count + 1); // Count inc.
|
||||
BOOST_CONTRACT_ASSERT(item() == new_item); // Item set.
|
||||
@@ -105,8 +105,8 @@ public:
|
||||
|
||||
// Pop 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(count() > 0); // Not empty.
|
||||
})
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
|
||||
unsigned shape::compute_area(boost::contract::virtual_* v) const {
|
||||
unsigned result;
|
||||
boost::contract::guard c = boost::contract::public_function(v, result, this)
|
||||
boost::contract::check c = boost::contract::public_function(v, result, this)
|
||||
.postcondition([&] (int const& result) {
|
||||
BOOST_CONTRACT_ASSERT(result > 0);
|
||||
})
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
static int const pi = 3; // Truncated to int from 3.14...
|
||||
|
||||
explicit circle(unsigned a_radius) : radius_(a_radius) {
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(radius() == a_radius);
|
||||
})
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
virtual unsigned compute_area(boost::contract::virtual_* v = 0) const
|
||||
/* override */ {
|
||||
unsigned result;
|
||||
boost::contract::guard c = boost::contract::public_function<
|
||||
boost::contract::check c = boost::contract::public_function<
|
||||
override_compute_area>(v, result, &circle::compute_area, this)
|
||||
.postcondition([&] (unsigned const& result) {
|
||||
BOOST_CONTRACT_ASSERT(result == pi * radius() * radius());
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
}
|
||||
|
||||
unsigned radius() const {
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return radius_;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ bool operator==(T const& left, T const& right);
|
||||
template<typename T>
|
||||
bool operator!=(T const& left, T const& right) {
|
||||
bool result;
|
||||
boost::contract::guard c = boost::contract::function()
|
||||
boost::contract::check c = boost::contract::function()
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(result == !(left == right));
|
||||
})
|
||||
@@ -27,7 +27,7 @@ bool operator!=(T const& left, T const& right) {
|
||||
template<typename T>
|
||||
bool operator==(T const& left, T const& right) {
|
||||
bool result;
|
||||
boost::contract::guard c = boost::contract::function()
|
||||
boost::contract::check c = boost::contract::function()
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(result == !(left != right));
|
||||
})
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
int factorial(int n ) {
|
||||
int result;
|
||||
boost::contract::guard c = boost::contract::function()
|
||||
boost::contract::check c = boost::contract::function()
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(n >= 0); // Non-negative natural number.
|
||||
BOOST_CONTRACT_ASSERT(n <= 12); // Max function input.
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
double mysqrt(double x, double precision = 1e-6) {
|
||||
double result;
|
||||
boost::contract::guard c = boost::contract::function()
|
||||
boost::contract::check c = boost::contract::function()
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(x >= 0.0);
|
||||
})
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
int sum(int count, int* array) {
|
||||
int result;
|
||||
boost::contract::guard c = boost::contract::function()
|
||||
boost::contract::check c = boost::contract::function()
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(count % 4 == 0);
|
||||
})
|
||||
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
const_reverse_iterator;
|
||||
|
||||
vector() : vect_() {
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(empty());
|
||||
})
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
}
|
||||
|
||||
explicit vector(Allocator const& alloc) : vect_(alloc) {
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(empty());
|
||||
BOOST_CONTRACT_ASSERT(get_allocator() == alloc);
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
}
|
||||
|
||||
explicit vector(size_type count) : vect_(count) {
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(size() == count);
|
||||
BOOST_CONTRACT_ASSERT(
|
||||
@@ -86,7 +86,7 @@ public:
|
||||
}
|
||||
|
||||
vector(size_type count, T const& value) : vect_(count, value) {
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(size() == count);
|
||||
BOOST_CONTRACT_ASSERT(
|
||||
@@ -101,7 +101,7 @@ public:
|
||||
|
||||
vector(size_type count, const T& value, Allocator const& alloc) :
|
||||
vect_(count, value, alloc) {
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(size() == count);
|
||||
BOOST_CONTRACT_ASSERT(
|
||||
@@ -117,7 +117,7 @@ public:
|
||||
|
||||
template<typename InputIter>
|
||||
vector(InputIter first, InputIter last) : vect_(first, last) {
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(std::distance(first, last) ==
|
||||
int(size()));
|
||||
@@ -128,7 +128,7 @@ public:
|
||||
template<typename InputIter>
|
||||
vector(InputIter first, InputIter last, Allocator const& alloc) :
|
||||
vect_(first, last, alloc) {
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(std::distance(first, last) ==
|
||||
int(size()));
|
||||
@@ -138,7 +138,7 @@ public:
|
||||
}
|
||||
|
||||
/* implicit */ vector(vector const& other) : vect_(other.vect_) {
|
||||
boost::contract::guard c = boost::contract::constructor(this)
|
||||
boost::contract::check c = boost::contract::constructor(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(
|
||||
boost::contract::condition_if<boost::has_equal_to<T> >(
|
||||
@@ -152,7 +152,7 @@ public:
|
||||
|
||||
vector& operator=(vector const& other) {
|
||||
boost::optional<vector&> result;
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(
|
||||
boost::contract::condition_if<boost::has_equal_to<T> >(
|
||||
@@ -174,11 +174,11 @@ public:
|
||||
}
|
||||
|
||||
virtual ~vector() {
|
||||
boost::contract::guard c = boost::contract::destructor(this);
|
||||
boost::contract::check c = boost::contract::destructor(this);
|
||||
}
|
||||
|
||||
void reserve(size_type count) {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(count < max_size());
|
||||
})
|
||||
@@ -192,7 +192,7 @@ public:
|
||||
|
||||
size_type capacity() const {
|
||||
size_type result;
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(result >= size());
|
||||
})
|
||||
@@ -203,7 +203,7 @@ public:
|
||||
|
||||
iterator begin() {
|
||||
iterator result;
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
if(empty()) BOOST_CONTRACT_ASSERT(result == end());
|
||||
})
|
||||
@@ -214,7 +214,7 @@ public:
|
||||
|
||||
const_iterator begin() const {
|
||||
const_iterator result;
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
if(empty()) BOOST_CONTRACT_ASSERT(result == end());
|
||||
})
|
||||
@@ -224,18 +224,18 @@ public:
|
||||
}
|
||||
|
||||
iterator end() {
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return vect_.end();
|
||||
}
|
||||
|
||||
const_iterator end() const {
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return vect_.end();
|
||||
}
|
||||
|
||||
reverse_iterator rbegin() {
|
||||
iterator result;
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
if(empty()) BOOST_CONTRACT_ASSERT(result == rend());
|
||||
})
|
||||
@@ -246,7 +246,7 @@ public:
|
||||
|
||||
const_reverse_iterator rbegin() const {
|
||||
const_reverse_iterator result;
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
if(empty()) BOOST_CONTRACT_ASSERT(result == rend());
|
||||
})
|
||||
@@ -256,19 +256,19 @@ public:
|
||||
}
|
||||
|
||||
reverse_iterator rend() {
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return vect_.rend();
|
||||
}
|
||||
|
||||
const_reverse_iterator rend() const {
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return vect_.rend();
|
||||
}
|
||||
|
||||
void resize(size_type count, T const& value = T()) {
|
||||
boost::contract::old_ptr<size_type> old_size =
|
||||
BOOST_CONTRACT_OLD(size());
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(size() == count);
|
||||
if(count > *old_size) {
|
||||
@@ -287,7 +287,7 @@ public:
|
||||
|
||||
size_type size() const {
|
||||
size_type result;
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(result <= capacity());
|
||||
})
|
||||
@@ -298,7 +298,7 @@ public:
|
||||
|
||||
size_type max_size() const {
|
||||
size_type result;
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(result >= capacity());
|
||||
})
|
||||
@@ -309,7 +309,7 @@ public:
|
||||
|
||||
bool empty() 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(result == (size() == 0));
|
||||
})
|
||||
@@ -319,24 +319,24 @@ public:
|
||||
}
|
||||
|
||||
Allocator get_allocator() const {
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return vect_.get_allocator();
|
||||
}
|
||||
|
||||
reference at(size_type index) {
|
||||
// No precondition because throws out_of_range for invalid index.
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return vect_.at(index);
|
||||
}
|
||||
|
||||
const_reference at(size_type index) const {
|
||||
// No precondition because throws out_of_range for invalid index.
|
||||
boost::contract::guard c = boost::contract::public_function(this);
|
||||
boost::contract::check c = boost::contract::public_function(this);
|
||||
return vect_.at(index);
|
||||
}
|
||||
|
||||
reference operator[](size_type index) {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(index < size());
|
||||
})
|
||||
@@ -346,7 +346,7 @@ public:
|
||||
}
|
||||
|
||||
const_reference operator[](size_type index) const {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(index < size());
|
||||
})
|
||||
@@ -356,7 +356,7 @@ public:
|
||||
}
|
||||
|
||||
reference front() {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!empty());
|
||||
})
|
||||
@@ -366,7 +366,7 @@ public:
|
||||
}
|
||||
|
||||
const_reference front() const {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!empty());
|
||||
})
|
||||
@@ -376,7 +376,7 @@ public:
|
||||
}
|
||||
|
||||
reference back() {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!empty());
|
||||
})
|
||||
@@ -386,7 +386,7 @@ public:
|
||||
}
|
||||
|
||||
const_reference back() const {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!empty());
|
||||
})
|
||||
@@ -400,7 +400,7 @@ public:
|
||||
BOOST_CONTRACT_OLD(size());
|
||||
boost::contract::old_ptr<size_type> old_capacity =
|
||||
BOOST_CONTRACT_OLD(capacity());
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(size() < max_size());
|
||||
})
|
||||
@@ -422,7 +422,7 @@ public:
|
||||
void pop_back() {
|
||||
boost::contract::old_ptr<size_type> old_size =
|
||||
BOOST_CONTRACT_OLD(size());
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!empty());
|
||||
})
|
||||
@@ -436,7 +436,7 @@ public:
|
||||
|
||||
template<typename InputIter>
|
||||
void assign(InputIter first, InputIter last) {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
// Precondition: [begin(), end()) does not contain [first, last).
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(std::distance(first, last) ==
|
||||
@@ -448,7 +448,7 @@ public:
|
||||
}
|
||||
|
||||
void assign(size_type count, T const& value) {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(count <= max_size());
|
||||
})
|
||||
@@ -469,7 +469,7 @@ public:
|
||||
iterator result;
|
||||
boost::contract::old_ptr<size_type> old_size =
|
||||
BOOST_CONTRACT_OLD(size());
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(size() < max_size());
|
||||
})
|
||||
@@ -498,7 +498,7 @@ public:
|
||||
BOOST_CONTRACT_OLD(capacity());
|
||||
boost::contract::old_ptr<iterator> old_where =
|
||||
BOOST_CONTRACT_OLD(where);
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(size() + count < max_size());
|
||||
})
|
||||
@@ -530,7 +530,7 @@ public:
|
||||
BOOST_CONTRACT_OLD(size());
|
||||
boost::contract::old_ptr<size_type> old_capacity =
|
||||
BOOST_CONTRACT_OLD(capacity());
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(size() + std::distance(first, last) <
|
||||
max_size());
|
||||
@@ -550,7 +550,7 @@ public:
|
||||
iterator result;
|
||||
boost::contract::old_ptr<size_type> old_size =
|
||||
BOOST_CONTRACT_OLD(size());
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(!empty());
|
||||
BOOST_CONTRACT_ASSERT(where != end());
|
||||
@@ -569,7 +569,7 @@ public:
|
||||
iterator result;
|
||||
boost::contract::old_ptr<size_type> old_size =
|
||||
BOOST_CONTRACT_OLD(size());
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.precondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(size() >= std::distance(first, last));
|
||||
})
|
||||
@@ -585,7 +585,7 @@ public:
|
||||
}
|
||||
|
||||
void clear() {
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(empty());
|
||||
})
|
||||
@@ -597,7 +597,7 @@ public:
|
||||
void swap(vector& other) {
|
||||
boost::contract::old_ptr<vector> old_me = BOOST_CONTRACT_OLD(*this);
|
||||
boost::contract::old_ptr<vector> old_other = BOOST_CONTRACT_OLD(other);
|
||||
boost::contract::guard c = boost::contract::public_function(this)
|
||||
boost::contract::check c = boost::contract::public_function(this)
|
||||
.postcondition([&] {
|
||||
BOOST_CONTRACT_ASSERT(
|
||||
boost::contract::condition_if<boost::has_equal_to<
|
||||
|
||||
Reference in New Issue
Block a user