gul-cpp / gul14

General Utility Library for C++14
https://gul14.info/
GNU Lesser General Public License v2.1
2 stars 1 forks source link

Feature is_invocable_v #70

Closed Finii closed 7 months ago

Finii commented 8 months ago

[why] We backported is_invocable<> but there you have to write is_invocable<>::value all the time.

Same with is_invocable_r<>.

C++17 in fact also has the helper templates with the _v suffix.

[how] Just add the helper template, but leave out the inline part. That can result in multiple identical symbols in the resulting executable, but apart from the space issue this is 100% safe.

The duplication is from the symbol name and a small bit of the data itself (a boolean). Duplication happens once for each TU the template is used in with a specific signature.

Here an example when we use the same

REQUIRE(gul14::is_invocable_v<void(*)()> == true);

in two TUs (i.e. two test_*.cc files):

$ nm -C build/tests/libgul-test | grep invoc
00000000003b7614 r gul14::is_invocable_v<void (*)()>
00000000003b7d5c r gul14::is_invocable_v<void (*)()>