// Copyright (C) 2008-2017 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 "no_lambdas.hpp" #include #include //[no_lambdas_cpp template array::array(unsigned count) : boost::contract::constructor_precondition(boost::bind( &array::constructor_precondition, count)), values_(new T[MaxSize]) // Member initializations can be here. { boost::contract::old_ptr old_instances; 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))) ; for(unsigned i = 0; i < count; ++i) values_[i] = T(); size_ = count; ++instances_; } template array::~array() { boost::contract::old_ptr old_instances; 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, boost::cref(old_instances))) ; delete[] values_; --instances_; } template void array::push_back(T const& value, boost::contract::virtual_* v) { boost::contract::old_ptr old_size; 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))) .postcondition(boost::bind(&array::push_back_postcondition, this, boost::cref(old_size))) ; values_[size_++] = value; } template unsigned array::size() const { // Check invariants. boost::contract::check c = boost::contract::public_function(this); return size_; } template int array::instances() { // Check static invariants. boost::contract::check c = boost::contract::public_function(); return instances_; } template int array::instances_ = 0; //] int main() { array a(2); assert(a.size() == 2); a.push_back('x'); assert(a.size() == 3); return 0; }