// https://www.boost.org/doc/libs/1_92_0/libs/contract/doc/html/index.html

#include <boost/contract.hpp>

#include <cassert>
#include <iostream>
#include <vector>

// Preconditions, postconditions and old values on a free function
void push_back(std::vector<int> &v, int x)
{
    boost::contract::old_ptr<std::size_t> old_size =
        BOOST_CONTRACT_OLDOF(v.size());
    boost::contract::check c = boost::contract::function()
        .precondition([&] { BOOST_CONTRACT_ASSERT(v.size() < v.max_size()); })
        .postcondition([&] {
            BOOST_CONTRACT_ASSERT(v.size() == *old_size + 1);
            BOOST_CONTRACT_ASSERT(v.back() == x);
        });

    v.push_back(x);
}

int main()
{
    std::vector<int> v;

    push_back(v, 1);
    push_back(v, 2);
    push_back(v, 3);

    std::cout << "size = " << v.size() << ", back = " << v.back() << std::endl;

    assert(v.size() == 3);
    assert(v.back() == 3);

    return 0;
}
