]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/contract/test/call_if/true_.cpp
Add patch for failing prerm scripts
[ceph.git] / ceph / src / boost / libs / contract / test / call_if / true_.cpp
CommitLineData
11fdf7f2
TL
1
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
6
7// Test call_if with true condition and non-void result type.
8
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>
14#include <sstream>
15
16boost::contract::test::detail::oteststream out;
17
18struct eq {
19 typedef bool result_type; // Test non-void result type.
20
21 template<typename L, typename R>
22 result_type operator()(L left, R right) const {
23 return left == right; // Requires operator==.
24 }
25};
26
27struct x {}; // Doest not have operator==.
28
29int main() {
30 std::ostringstream ok;
31 x x1, x2;;
32
33 out.str("");
34 out <<
35 boost::contract::call_if<boost::has_equal_to<int> >(
36 boost::bind(eq(), 123, 456) // False.
37 ) // Test no else (not called).
38 << std::endl;
39 ok.str(""); ok << false << std::endl;
40 BOOST_TEST(out.eq(ok.str()));
41
42 out.str("");
43 out <<
44 boost::contract::call_if<boost::has_equal_to<int> >(
45 boost::bind(eq(), 123, 123) // True.
46 ).else_([] { return false; }) // Test else not called.
47 << std::endl;
48 ok.str(""); ok << true << std::endl;
49 BOOST_TEST(out.eq(ok.str()));
50
51 out.str("");
52 out << // Test "..._c".
53 boost::contract::call_if_c<boost::has_equal_to<int>::value>(
54 boost::bind(eq(), 123, 123) // True.
55 ).else_( // Test else not called.
56 boost::bind(eq(), x1, x2) // Compiler-error... but not called.
57 )
58 << std::endl;
59 ok.str(""); ok << true << std::endl;
60 BOOST_TEST(out.eq(ok.str()));
61
62 return boost::report_errors();
63}
64