-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fixing transform - Fixed transform for C++20, deprecated older names, and updated sources - Add cmake preset for C++20 - Cleaned up docs in functional.hpp * Use of deprecated type in deprecated function generated warning on Visual Studio. * Added noexcept propogation Added noexcept propagation Added unit test * Adding parentheses to improve formatting Cleaned out unused properties in build matrix. * Adding static casts for Visual C++
- Loading branch information
1 parent
fcd6fb1
commit d9f4321
Showing
11 changed files
with
172 additions
and
65 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
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
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
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
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 @@ | ||
asl_test(BOOST NAME functional_transpose SOURCES functional_test.cpp) |
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,93 @@ | ||
/* | ||
Copyright 2013 Adobe | ||
Distributed under the Boost Software License, Version 1.0. | ||
(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
*/ | ||
/**************************************************************************************************/ | ||
|
||
#include <adobe/functional.hpp> // file be tested included first | ||
|
||
#include <utility> | ||
|
||
#include <adobe/enum_ops.hpp> | ||
|
||
#define BOOST_TEST_MAIN | ||
|
||
// boost | ||
#include <boost/test/unit_test.hpp> | ||
|
||
/**************************************************************************************************/ | ||
|
||
using namespace std; | ||
using namespace adobe; | ||
|
||
namespace { | ||
|
||
/// An enumeration of member function qualifiers as bit fields to identify or mask an overload. | ||
enum member_function_qualifiers { | ||
_none = 0, | ||
_const_lvalue = 1 << 0, | ||
_lvalue = 1 << 1, | ||
_rvalue = 1 << 2, | ||
_all = _const_lvalue | _lvalue | _rvalue | ||
}; | ||
|
||
auto adobe_enable_bitmask_enum(member_function_qualifiers) -> std::true_type; | ||
|
||
/// An overload of a binary function that returns a tuple of its arguments and the qualifiers used. | ||
/// Only the members specified by the noexcept_qualifier mask are noexcept. | ||
template <member_function_qualifiers noexcept_qualifier> | ||
struct test_binary_function { | ||
auto operator()(int x, int y) const& noexcept((noexcept_qualifier & _const_lvalue) != _none) { | ||
return tuple(x, y, _const_lvalue); | ||
} | ||
auto operator()(int x, int y) & noexcept((noexcept_qualifier & _lvalue) != _none) { | ||
return tuple(x, y, _lvalue); | ||
} | ||
auto operator()(int x, int y) && noexcept((noexcept_qualifier & _rvalue) != _none) { | ||
return tuple(x, y, _rvalue); | ||
} | ||
}; | ||
|
||
} // namespace | ||
|
||
/* | ||
REVISIT(sean-parent) : The static casts are necessary to get this code to compile on VC++14. | ||
It is unclear why the compiler is unable to find the enum operators. | ||
*/ | ||
|
||
|
||
BOOST_AUTO_TEST_CASE(functional_transpose) { | ||
|
||
// Test that the transpose functional object correctly transposes the arguments of a binary | ||
// function. It also tests that the correct overload is selected and that the noexcept | ||
// qualifier is correctly propagated. | ||
|
||
transpose lvalue{ | ||
test_binary_function<static_cast<member_function_qualifiers>(_all ^ _lvalue)>{}}; | ||
const transpose const_lvalue{ | ||
test_binary_function<static_cast<member_function_qualifiers>(_all ^ _const_lvalue)>{}}; | ||
transpose lvalue_noexcept{test_binary_function<_lvalue>{}}; | ||
const transpose const_lvalue_noexcept{test_binary_function<_const_lvalue>{}}; | ||
|
||
BOOST_TEST((lvalue(1, 2) == tuple(2, 1, _lvalue))); | ||
BOOST_TEST(!noexcept(lvalue(1, 2))); | ||
|
||
BOOST_TEST((const_lvalue(1, 2) == tuple(2, 1, _const_lvalue))); | ||
BOOST_TEST(!noexcept(const_lvalue(1, 2))); | ||
|
||
BOOST_TEST((lvalue_noexcept(1, 2) == tuple(2, 1, _lvalue))); | ||
BOOST_TEST(noexcept(lvalue_noexcept(1, 2))); | ||
|
||
BOOST_TEST((const_lvalue_noexcept(1, 2) == tuple(2, 1, _const_lvalue))); | ||
BOOST_TEST(noexcept(const_lvalue_noexcept(1, 2))); | ||
|
||
BOOST_TEST( | ||
(transpose(test_binary_function<static_cast<member_function_qualifiers>(_all ^ _rvalue)>{})( | ||
1, 2) == tuple(2, 1, _rvalue))); | ||
BOOST_TEST(!noexcept(transpose( | ||
test_binary_function<static_cast<member_function_qualifiers>(_all ^ _rvalue)>{})(1, 2))); | ||
|
||
BOOST_TEST((transpose(test_binary_function<_rvalue>{})(1, 2) == tuple(2, 1, _rvalue))); | ||
BOOST_TEST(noexcept(transpose(test_binary_function<_rvalue>{})(1, 2))); | ||
} |
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,5 @@ | ||
# Jamfile for building functional test | ||
|
||
project adobe/functional ; | ||
|
||
run functional_test.cpp ; |