std::is_invocable is false but std::invoke works

前端 未结 1 980
滥情空心
滥情空心 2021-02-01 15:04

The following program\'s output seems to contradict itself:

#include 
#include 
#include 

void foo(int&         


        
相关标签:
1条回答
  • 2021-02-01 15:37

    decltype(a) is int. This corresponds to invoking f with an int prvalue -- something like f(7). That one indeed doesn't compile, because a non-const lvalue reference cannot bind to a prvalue.

    What you're doing instead in main is calling f with an lvalue, a, to which the reference can bind just fine.

    To get the correct result from std::is_invocable, use the expression form of decltype by adding parentheses:

    std::is_invocable_v<decltype(foo), decltype((a))>
    //                                          ^ ^
    
    0 讨论(0)
提交回复
热议问题