mirror of
https://github.com/boostorg/callable_traits.git
synced 2026-02-13 00:12:11 +00:00
fixing issues in MSVC, adding comments in MSVC-failing examples
This commit is contained in:
@@ -4,6 +4,10 @@ Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
|
||||
// NOTE: This does not compile in MSVC, which can't handle
|
||||
// the trailing return type on the generic lambda 'add'
|
||||
|
||||
#include <type_traits>
|
||||
#include <callable_traits/callable_traits.hpp>
|
||||
|
||||
@@ -27,11 +31,12 @@ static_assert(ct::can_invoke(subtract, 1, 2), ""); // <-- success
|
||||
static_assert(!ct::can_invoke(subtract, 1, 2, 3), "");
|
||||
static_assert(!ct::can_invoke(subtract, bad, bad), "");
|
||||
|
||||
|
||||
// Generic function objects (such as `add` and `multiply` below)
|
||||
// must be SFINAE-friendly in order for failing can_invoke calls
|
||||
// to actually compile. This applies to both generic lambdas and
|
||||
// templated function objects.
|
||||
// templated function objects. Note: MSVC does not compile this
|
||||
// source code file because of the trailing return type below (MSVC
|
||||
// is non-conforming in this respect)
|
||||
|
||||
auto add = [](auto x, auto y) -> decltype(x + y) {
|
||||
return x + y; // ^^^^^^^^^^^^^^^^^^ explicit return type allows SFINAE
|
||||
@@ -46,7 +51,6 @@ static_assert(ct::can_invoke(add, 1, 2), ""); // <-- success
|
||||
static_assert(!ct::can_invoke(add, 1, 2, 3), "");
|
||||
static_assert(!ct::can_invoke(add, bad, bad), "");
|
||||
|
||||
|
||||
// 'multiply' isn't SFINAE-safe, because the return type depends
|
||||
// on an expression in the body. However, it still works if we
|
||||
// only try to call can_invoke with arguments where x * y is
|
||||
@@ -66,4 +70,4 @@ static_assert(!ct::can_invoke(multiply, 1, 2, 3), "");
|
||||
// the call cannot be SFINAE'd away. Error message in Clang:
|
||||
// "invalid operands to binary expression ('Bad' and 'Bad')"
|
||||
|
||||
int main() {}
|
||||
int main() {}
|
||||
|
||||
Reference in New Issue
Block a user