简体   繁体   中英

How to define a std::function for a generic function?

How to define a std::function for a generic or template function? For example, we can do

std::function<bool(int a)> f = [](int a){return a < 0;};

How to generalize it for other argument types of a like the following

std::function<bool(auto a)> f = [](auto a){return a < 0;};

You don't. Such a construct would require something akin to an entire C++ compiler be type erased by std::function , which seems overkill for most applications.

Odds are your problem does not actually require something that strong.

If ypu have a fixed set of argument types, there are solutions aplenty. For every type? Nope.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM