Skip to content

Commit

Permalink
Add bind_front_md_test
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Mar 28, 2024
1 parent 82d8d2d commit cd2b408
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ run is_nothrow_invocable_test.cpp ;
run bind_front_fn_test.cpp ;
run bind_front_obj_test.cpp ;
run bind_front_mfn_test.cpp ;
run bind_front_md_test.cpp ;
101 changes: 101 additions & 0 deletions test/bind_front_md_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/compat/bind_front.hpp>
#include <boost/core/lightweight_test.hpp>
#include <functional>

struct X
{
int m = -1;
};

struct Y: public virtual X
{
};

int main()
{
{
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, X() )(), -1 );
}

{
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, Y() )(), -1 );
}

{
X x;

BOOST_TEST_EQ( boost::compat::bind_front( &X::m, x )(), -1 );
}

{
X x;

BOOST_TEST_EQ( boost::compat::bind_front( &X::m, &x )(), -1 );
boost::compat::bind_front( &X::m, &x )() = +1;
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, &x )(), +1 );
}

{
X x;

BOOST_TEST_EQ( boost::compat::bind_front( &X::m, std::ref(x) )(), -1 );
boost::compat::bind_front( &X::m, std::ref(x) )() = +1;
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, std::ref(x) )(), +1 );
}

{
X x;

BOOST_TEST_EQ( boost::compat::bind_front( &X::m, std::cref(x) )(), -1 );
}

{
Y y;

BOOST_TEST_EQ( boost::compat::bind_front( &X::m, y )(), -1 );
}

{
Y y;

BOOST_TEST_EQ( boost::compat::bind_front( &X::m, &y )(), -1 );
boost::compat::bind_front( &X::m, &y )() = +1;
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, &y )(), +1 );
}

{
Y y;

BOOST_TEST_EQ( boost::compat::bind_front( &X::m, std::ref(y) )(), -1 );
boost::compat::bind_front( &X::m, std::ref(y) )() = +1;
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, std::ref(y) )(), +1 );
}

{
Y y;

BOOST_TEST_EQ( boost::compat::bind_front( &X::m, std::cref(y) )(), -1 );
}

{
X const x = {};

BOOST_TEST_EQ( boost::compat::bind_front( &X::m, x )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, &x )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, std::ref(x) )(), -1 );
}

{
Y const y = {};

BOOST_TEST_EQ( boost::compat::bind_front( &X::m, y )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, &y )(), -1 );
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, std::ref(y) )(), -1 );
}

return boost::report_errors();
}

0 comments on commit cd2b408

Please sign in to comment.