2
0
mirror of https://github.com/boostorg/compat.git synced 2026-01-19 04:02:16 +00:00
Files
compat/test/bind_front_md_test.cpp
2024-03-28 21:12:46 +02:00

102 lines
2.3 KiB
C++

// 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();
}