]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/contract/test/call_if/true_void.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 // Test call_if with true condition and void result type.
9 #include "../detail/oteststream.hpp"
10 #include <boost/contract/call_if.hpp>
11 #include <boost/bind.hpp>
12 #include <boost/type_traits/has_equal_to.hpp>
13 #include <boost/detail/lightweight_test.hpp>
16 boost::contract::test::detail::oteststream out
;
19 typedef void result_type
; // Test void result type.
21 template<typename L
, typename R
>
22 result_type
operator()(L left
, R right
) const {
23 out
<< (left
== right
) << std::endl
; // Requires operator==.
27 struct x
{}; // Doest not have operator==.
30 std::ostringstream ok
;
34 boost::contract::call_if
<boost::has_equal_to
<int> >(
35 boost::bind(eq(), 123, 456) // False.
36 ); // Test no else (not called).
37 ok
.str(""); ok
<< false << std::endl
;
38 BOOST_TEST(out
.eq(ok
.str()));
41 boost::contract::call_if
<boost::has_equal_to
<int> >(
42 boost::bind(eq(), 123, 123) // True.
45 ); // Test else (not called).
46 ok
.str(""); ok
<< true << std::endl
;
47 BOOST_TEST(out
.eq(ok
.str()));
51 boost::contract::call_if_c
<boost::has_equal_to
<int>::value
>(
52 boost::bind(eq(), 123, 123) // True.
53 ).else_( // Test else (not called).
54 boost::bind(eq(), x1
, x2
) // Compiler-error... but not called.
56 ok
.str(""); ok
<< true << std::endl
;
57 BOOST_TEST(out
.eq(ok
.str()));
59 return boost::report_errors();