mirror of
https://github.com/boostorg/contract.git
synced 2026-01-26 06:22:42 +00:00
added all files for release 0.3.490
This commit is contained in:
40
example/struct/main.cpp
Executable file
40
example/struct/main.cpp
Executable file
@@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2009-2010 Lorenzo Caminiti.
|
||||
// Use, modification, and distribution is subject to the
|
||||
// Contract++ Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt.)
|
||||
|
||||
// Struct handled exactly same as class.
|
||||
|
||||
#include <contract.hpp>
|
||||
#include <iostream>
|
||||
|
||||
//[ struct_cpp
|
||||
|
||||
struct positive {
|
||||
const double& number;
|
||||
|
||||
// Remember to always specify the access level (public, etc).
|
||||
positive(const double& n): number(n)
|
||||
CONTRACT_CONSTRUCTOR( (struct) (positive) // (struct) in sequence.
|
||||
(public) (positive)( (const double&)(n) )
|
||||
(precondition) ({
|
||||
CONTRACT_ASSERT( n > 0.0 );
|
||||
})
|
||||
(body) ({
|
||||
}) )
|
||||
|
||||
private:
|
||||
// Remember to always specify class invariants in a private section.
|
||||
CONTRACT_INVARIANT( ({
|
||||
CONTRACT_ASSERT( number > 0.0 );
|
||||
}) )
|
||||
};
|
||||
|
||||
//]
|
||||
|
||||
int main() {
|
||||
positive p(1.23);
|
||||
std::cout << p.number << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user