2 // Copyright (C) 2008-2018 Lorenzo Caminiti
3 // Distributed under the Boost Software License, Version 1.0 (see accompanying
4 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
5 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
7 #include <boost/contract.hpp>
13 friend class boost::contract::access;
15 void invariant() const {
16 BOOST_CONTRACT_ASSERT(capacity() <= max_size());
20 virtual void push_back(T const& value, boost::contract::virtual_* v = 0)
24 virtual unsigned capacity() const = 0;
25 virtual unsigned max_size() const = 0;
29 void pushable<T>::push_back(T const& value, boost::contract::virtual_* v) {
30 boost::contract::old_ptr<unsigned> old_capacity =
31 BOOST_CONTRACT_OLDOF(v, capacity());
32 boost::contract::check c = boost::contract::public_function(v, this)
34 BOOST_CONTRACT_ASSERT(capacity() < max_size());
37 BOOST_CONTRACT_ASSERT(capacity() >= *old_capacity);
46 #define BASES public pushable<T>
48 { // Private section of the class.
49 friend class boost::contract::access; // Friend `access` class so...
51 typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; // ...private bases.
54 void invariant() const { // ...private invariants.
55 BOOST_CONTRACT_ASSERT(size() <= capacity());
58 BOOST_CONTRACT_OVERRIDE(push_back) // ...private overrides.
60 public: // Public section of the class.
61 void push_back(T const& value, boost::contract::virtual_* v = 0)
63 boost::contract::old_ptr<unsigned> old_size =
64 BOOST_CONTRACT_OLDOF(v, size());
65 boost::contract::check c = boost::contract::public_function<
66 override_push_back>(v, &vector::push_back, this, value)
68 BOOST_CONTRACT_ASSERT(size() < max_size());
71 BOOST_CONTRACT_ASSERT(size() == *old_size + 1);
75 vect_.push_back(value);
81 unsigned size() const { return vect_.size(); }
82 unsigned max_size() const { return vect_.max_size(); }
83 unsigned capacity() const { return vect_.capacity(); }
85 private: // Another private section.
92 assert(vect.size() == 1);