separate_body.cpp 913 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (C) 2008-2018 Lorenzo Caminiti
  2. // Distributed under the Boost Software License, Version 1.0 (see accompanying
  3. // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
  4. // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
  5. #include "separate_body.hpp"
  6. #include <cassert>
  7. //[separate_body_cpp
  8. void iarray::constructor_body(unsigned max, unsigned count) {
  9. for(unsigned i = 0; i < count; ++i) values_[i] = int();
  10. size_ = count;
  11. }
  12. void iarray::destructor_body() { delete[] values_; }
  13. void iarray::push_back_body(int value) { values_[size_++] = value; }
  14. /* ... */
  15. //]
  16. unsigned iarray::capacity_body() const { return capacity_; }
  17. unsigned iarray::size_body() const { return size_; }
  18. int main() {
  19. iarray a(3, 2);
  20. assert(a.capacity() == 3);
  21. assert(a.size() == 2);
  22. a.push_back(-123);
  23. assert(a.size() == 3);
  24. return 0;
  25. }