1// Copyright 2021 Peter Dimov
2// Distributed under the Boost Software License, Version 1.0.
3// https://www.boost.org/LICENSE_1_0.txt
4
5#include <boost/lambda2.hpp>
6#include <boost/core/lightweight_test.hpp>
7#include <utility>
8
9struct X
10{
11 int m1;
12 int m2;
13
14 int f1() const
15 {
16 return m1;
17 }
18
19 int& f2()
20 {
21 return m2;
22 }
23};
24
25int main()
26{
27 using namespace boost::lambda2;
28
29 {
30 X const x{ .m1: 1, .m2: 2 };
31
32 BOOST_TEST_EQ( (_1->*&X::m1)( x ), 1 );
33 BOOST_TEST_EQ( (_1->*&X::m2)( x ), 2 );
34 BOOST_TEST_EQ( (_1->*&X::f1)( x ), 1 );
35 }
36
37 {
38 X x{ .m1: 0, .m2: 0 };
39
40 BOOST_TEST_EQ( (_1->*&X::m1)( x ), 0 );
41 BOOST_TEST_EQ( (_1->*&X::m2)( x ), 0 );
42 BOOST_TEST_EQ( (_1->*&X::f1)( x ), 0 );
43 BOOST_TEST_EQ( (_1->*&X::f2)( x ), 0 );
44
45#if defined(_LIBCPP_VERSION)
46
47 // https://bugs.llvm.org/show_bug.cgi?id=51753
48 using std::placeholders::_1;
49
50#endif
51
52 BOOST_TEST_EQ( (_1->*&X::m1 += 1)( x ), 1 );
53 BOOST_TEST_EQ( (_1->*&X::m2 += 2)( x ), 2 );
54
55 BOOST_TEST_EQ( (_1->*&X::f1)( x ), 1 );
56 BOOST_TEST_EQ( (_1->*&X::f2)( x ), 2 );
57
58 BOOST_TEST_EQ( (_1->*&X::f2 += 3)( x ), 5 );
59 }
60
61 {
62 std::pair<int, int> const x( 1, 2 );
63
64 BOOST_TEST_EQ( (_1->*&std::pair<int, int>::first)( x ), 1 );
65 BOOST_TEST_EQ( (_1->*&std::pair<int, int>::second)( x ), 2 );
66
67#if defined(_LIBCPP_VERSION)
68
69 // https://bugs.llvm.org/show_bug.cgi?id=51753
70 using std::placeholders::_1;
71
72#endif
73
74 BOOST_TEST_EQ( (_1->*first)( x ), 1 );
75 BOOST_TEST_EQ( (_1->*second)( x ), 2 );
76 }
77
78 return boost::report_errors();
79}
80

source code of boost/libs/lambda2/test/project.cpp