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