diff --git a/test/Jamfile b/test/Jamfile index 421bf52..212171f 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -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 ; diff --git a/test/bind_front_md_test.cpp b/test/bind_front_md_test.cpp new file mode 100644 index 0000000..c4a87a0 --- /dev/null +++ b/test/bind_front_md_test.cpp @@ -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 +#include +#include + +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(); +}