Jan 7, 2019

[C++] std::function duh

Read: https://quuxplusone.github.io/blog/2019/01/06/hyper-function/
Reference: https://vsdmars.blogspot.com/2018/10/c-kinds-of-variance-in-subtyping.html


This was mentioned in Scott Meyers' Overview of the New C++
(i.e void can accept return type in std::function declaration)
and formalized in Eli Bendersky's post : Covariance and contravariance in subtyping

Take away:
Use std::function judiciously safes compile time in large project.


// oops, void function shouldn't return anything
std::function<void()> f = []() { return false; };

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.