Is it illegal to invoke a std::function under the standard?

后端 未结 1 1572
我在风中等你
我在风中等你 2020-12-03 07:03

All quotes are from N3797.

4/3 [conv]

An expression e can be implicitly converted to a type T if and only if the

1条回答
  •  自闭症患者
    2020-12-03 07:51

    Yes, your analysis is correct; I came to the same conclusion here.

    According to Daniel Kruegler, this issue should appear on the library defect list subsequent to the next mailing:

    A corresponding library issue has already been submitted, but is not yet visible in the issue list.

    Hopefully once that becomes visible we'll also have a conclusive answer to whether it is allowable to construct a std::function with signature returning void passing a callable with signature returning non-void (Using `std::function` to call non-void function).


    Update: this was entered as LWG 2420, which was resolved in favor of special-casing void return type to static_cast the result of the invoked function to void. This means that a callable returning non-void can be the target of a std::function. LWG2420 was applied as a post-publication correction to C++14; meanwhile, all compilers I'm aware of effectively apply this behavior as an extension in C++11 mode.

    0 讨论(0)
提交回复
热议问题