1 
2 #ifndef BOOST_CONTRACT_TEST_DETAIL_COUNTER_HPP_
3 #define BOOST_CONTRACT_TEST_DETAIL_COUNTER_HPP_
4 
5 // Copyright (C) 2008-2018 Lorenzo Caminiti
6 // Distributed under the Boost Software License, Version 1.0 (see accompanying
7 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
8 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
9 
10 namespace boost { namespace contract { namespace test { namespace detail {
11 
12 // Helper to count copies and evaluations of type (e.g., for old values).
13 template<class Tag, typename T>
14 struct counter {
15     T value;
16 
counterboost::contract::test::detail::counter17     counter() : value() { ++ctors_; }
ctorsboost::contract::test::detail::counter18     static unsigned ctors() { return ctors_; }
19 
~counterboost::contract::test::detail::counter20     ~counter() { ++dtors_; }
dtorsboost::contract::test::detail::counter21     static unsigned dtors() { return dtors_; }
22 
counterboost::contract::test::detail::counter23     /* implicit */ counter(counter const& other) : value(other.value) {
24         ++ctor_copies_;
25         ++ctors_;
26     }
27 
operator =boost::contract::test::detail::counter28     counter& operator=(counter const& other) {
29         value = other.value;
30         ++op_copies_;
31         return *this;
32     }
33 
copiesboost::contract::test::detail::counter34     static unsigned copies() { return ctor_copies_ + op_copies_; }
35 
evalboost::contract::test::detail::counter36     static counter const& eval(counter const& me) { ++me.evals_; return me; }
evalsboost::contract::test::detail::counter37     static unsigned evals() { return evals_; }
38 
39 private:
40     static unsigned ctors_; // Total constructions (including copies).
41     static unsigned dtors_;
42     static unsigned ctor_copies_;
43     static unsigned op_copies_;
44     static unsigned evals_;
45 };
46 
47 template<class Tag, typename T> unsigned counter<Tag, T>::ctors_ = 0;
48 template<class Tag, typename T> unsigned counter<Tag, T>::dtors_ = 0;
49 template<class Tag, typename T> unsigned counter<Tag, T>::ctor_copies_ = 0;
50 template<class Tag, typename T> unsigned counter<Tag, T>::op_copies_ = 0;
51 template<class Tag, typename T> unsigned counter<Tag, T>::evals_ = 0;
52 
53 } } } } // namespace
54 
55 #endif // #include guard
56 
57