-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef BOOST_COMPAT_DETAIL_RETURNS_HPP_INCLUDED | ||
#define BOOST_COMPAT_DETAIL_RETURNS_HPP_INCLUDED | ||
|
||
// Copyright 2024 Peter Dimov | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#define BOOST_COMPAT_RETURNS(...) noexcept(noexcept(__VA_ARGS__)) -> decltype(__VA_ARGS__) { return __VA_ARGS__; } | ||
|
||
#endif // BOOST_COMPAT_DETAIL_RETURNS_HPP_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef BOOST_COMPAT_INVOKE_HPP_INCLUDED | ||
#define BOOST_COMPAT_INVOKE_HPP_INCLUDED | ||
|
||
// Copyright 2024 Peter Dimov | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#include <boost/compat/mem_fn.hpp> | ||
#include <boost/compat/detail/returns.hpp> | ||
#include <utility> | ||
|
||
namespace boost { | ||
namespace compat { | ||
|
||
template<class F, class... A> | ||
auto invoke( F&& f, A&&... a ) | ||
BOOST_COMPAT_RETURNS( std::forward<F>(f)(std::forward<A>(a)...) ) | ||
|
||
template<class M, class T, class... A> | ||
auto invoke( M T::* pm, A&&... a ) | ||
BOOST_COMPAT_RETURNS( mem_fn(pm)(std::forward<A>(a)...) ) | ||
|
||
} // namespace compat | ||
} // namespace boost | ||
|
||
#endif // BOOST_COMPAT_INVOKE_HPP_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef BOOST_COMPAT_MEM_FN_HPP_INCLUDED | ||
#define BOOST_COMPAT_MEM_FN_HPP_INCLUDED | ||
|
||
// Copyright 2024 Peter Dimov | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#include <functional> | ||
|
||
namespace boost { | ||
namespace compat { | ||
|
||
using std::mem_fn; | ||
|
||
} // namespace compat | ||
} // namespace boost | ||
|
||
#endif // BOOST_COMPAT_MEM_FN_HPP_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2024 Peter Dimov | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#include <boost/compat/invoke.hpp> | ||
#include <boost/core/lightweight_test.hpp> | ||
|
||
int f0() | ||
{ | ||
return -1; | ||
} | ||
|
||
int f1( int x1 ) | ||
{ | ||
return x1; | ||
} | ||
|
||
int f2( int x1, int x2 ) | ||
{ | ||
return 10*x1+x2; | ||
} | ||
|
||
int f3( int x1, int x2, int x3 ) | ||
{ | ||
return 100*x1 + 10*x2 + x3; | ||
} | ||
|
||
int main() | ||
{ | ||
BOOST_TEST_EQ( boost::compat::invoke( f0 ), -1 ); | ||
BOOST_TEST_EQ( boost::compat::invoke( f1, 1 ), 1 ); | ||
BOOST_TEST_EQ( boost::compat::invoke( f2, 1, 2 ), 12 ); | ||
BOOST_TEST_EQ( boost::compat::invoke( f3, 1, 2, 3 ), 123 ); | ||
|
||
return boost::report_errors(); | ||
} |