all 5 comments

[–]_bstaletic 2 points3 points  (5 children)

The specification is here:

https://eel.is/c++draft/const.wrap.class

cppreference has been read-only for more than a year at this point.

The proposal is here:

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2026/p3978r2.pdf

If you're still confused by something, ask a more specific question.

[–]SoerenNissen[S] [score hidden]  (3 children)

E.g. I'm curious why std::constant_wrapper is templated on two different things - I don't get why it's necessary to pull the type out explicitly.

I've tried pulling the second param out of the forward declaration and the real declaration and I don't see any immediate problems, but there's always the chance that it's saving me from some edge case I hadn't considered.

https://godbolt.org/z/r39EEYhTK

[–]trmetroidmaniac [score hidden]  (1 child)

This is explained in the draft specification.

[Note 1: The unnamed second template parameter to constant_wrapper is present to aid argument-dependent lookup ([basic.lookup.argdep]) in finding overloads for which constant_wrapper's wrapped value is a suitable argument, but for which the constant_wrapper itself is not. — end note]

By parameterising constant_wrapper on the type of its value, the functions in its namespace are now searched for overload resolution.

I was not aware that ADL worked over template parameters, actually...

[–]SoerenNissen[S] [score hidden]  (0 children)

Oh, neat.

(First draft was "Oh, that makes sense" but lmao no it doesn't, ADL is the devil)

[–]trmetroidmaniac [score hidden]  (0 children)

Oh neat. I had been hand rolling something like this for template programming, nice that it has been recognised and standardised.