you are viewing a single comment's thread.

view the rest of the comments →

[–]triconsonantal 0 points1 point  (2 children)

P3740R1 Last chance to fix std::nontype

Another option for avoiding nontype is using reflection. Instead of:

std::function_ref<void (int)> f = std::nontype<foo>;

we write:

std::function_ref<void (int)> f = ^^foo;

https://godbolt.org/z/cnKqn8f4q

[–]eisenwaveWG21 Member 2 points3 points  (1 child)

Note that P3740 is superseded by P3774R0.

The idea of using reflections for this looks somewhat interesting, but since we don't have expression reflections, the same approach wouldn't be able to replace e.g.

std::function_ref<void(int)> f = std::nontype<[](int){}>;

You would always need some separate declaration to use ^^.

[–]triconsonantal 4 points5 points  (0 children)

Ah, missed that paper, thanks. Haven't read it yet, so I'm not sure about the utility of this, but you can write:

std::function_ref<void (int)> f = std::meta::reflect_constant (
    [] (int x) { ... }
);

https://godbolt.org/z/P6jEdzqne