]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/contract/example/features/old.cpp
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>
12 char replace(std::string
& s
, unsigned index
, char x
) {
14 boost::contract::old_ptr
<char> old_y
; // Null, old value copied later...
15 boost::contract::check c
= boost::contract::function()
17 BOOST_CONTRACT_ASSERT(index
< s
.size());
19 .old([&] { // ...after preconditions (and invariants) checked.
20 old_y
= BOOST_CONTRACT_OLDOF(s
[index
]);
23 BOOST_CONTRACT_ASSERT(s
[index
] == x
);
24 BOOST_CONTRACT_ASSERT(result
== *old_y
);
35 std::string s
= "abc";
36 char r
= replace(s
, 1, '_');