fixing issues in MSVC, adding comments in MSVC-failing examples

This commit is contained in:
badair
2016-03-31 01:47:45 -05:00
parent 040dfe0088
commit 9cc2840b31
8 changed files with 196 additions and 55 deletions

View File

@@ -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() {}