]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/contract/example/n1962/circle.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
8 #include <boost/contract.hpp>
15 virtual unsigned compute_area(boost::contract::virtual_
* v
= 0) const = 0;
18 unsigned shape::compute_area(boost::contract::virtual_
* v
) const {
20 boost::contract::check c
= boost::contract::public_function(v
, result
, this)
21 .postcondition([&] (int const& result
) {
22 BOOST_CONTRACT_ASSERT(result
> 0);
30 #define BASES public shape
33 friend class boost::contract::access
;
35 typedef BOOST_CONTRACT_BASE_TYPES(BASES
) base_types
;
38 BOOST_CONTRACT_OVERRIDE(compute_area
);
41 static int const pi
= 3; // Truncated to int from 3.14...
43 explicit circle(unsigned a_radius
) : radius_(a_radius
) {
44 boost::contract::check c
= boost::contract::constructor(this)
46 BOOST_CONTRACT_ASSERT(radius() == a_radius
);
51 virtual unsigned compute_area(boost::contract::virtual_
* v
= 0) const
54 boost::contract::check c
= boost::contract::public_function
<
55 override_compute_area
>(v
, result
, &circle::compute_area
, this)
56 .postcondition([&] (unsigned const& result
) {
57 BOOST_CONTRACT_ASSERT(result
== pi
* radius() * radius());
61 return result
= pi
* radius() * radius();
64 unsigned radius() const {
65 boost::contract::check c
= boost::contract::public_function(this);
75 assert(c
.radius() == 2);
76 assert(c
.compute_area() == 12);