-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_Not_quite_object
has outlived its usefulness
#4097
Comments
Hmm, niebloids effectively become CPOs with I found that @ericniebler once said that they should be the same. Should we have a paper to turn niebloids into Standard-guaranteed CPOs? |
Yes they do.
I assure you he has said it many times, though I can provide no citations.
I would like to have such a paper, although I don't have time to write one now. I don't think a paper is a prerequisite for implementing the change in the STL. |
Vindication 😉 |
I'm in favor of doing this. The user code is reasonable, and expecting Library weirdness to drive Core changes was... unrealistic. (Sometimes it happens, as with |
I just re-read @brevzin's https://brevzin.github.io/c++/2020/12/19/cpo-niebloid/ and now you want to make it untrue?! 😂 I'm not generally in favour of "it works on two implementations so the other one must be buggy". In this case, I don't really care either way. I'm fine with making them CPOs, I'm also fine with leaving them as things with some unspecified properties. |
For what it's worth, even if we had some cool language facility, it's still super valuable for these to be objects to pass into algorithms. Right now, we're in this situation where |
We had various discussions in libc++ about this. In fact we originally started with something like So FWIW I think it is 100% reasonable for MSVC to make this change, and we should write a paper to simply officialize this in the Standard (I am not volunteering to write that paper either, though). |
Making the niebloids into objects lets us use them easily as arguments. Making overload sets first-class lets us use everything in the standard library (and other libraries) easily as arguments and does so without the performance penalties inherent in using function objects instead of function( template)s. I would much rather that the language solve this problem for everyone but I will settle for making a few dozen niebloids be objects. |
I think it's worthwhile to have something that merely bans ADL for functions without turning them into other things. With such a thing, library authors can avoid qualifying function calls or writing wrapping classes and function objects to suppress ADL (see also #140). However, such a thing doesn't seem suitable for a standard attribute, since ignoring it can heavily change the semantics of a well-defined program. |
A keyword then, like |
So |
The Standard denotes some overload sets of function templates as having special properties which make it possible to implement them as function objects. For example [algorithms.requirements]/2:
together with [algorithms.requirements]/15:
provides such properties for the algorithms implemented in namespace
std::ranges
. The Standard doesn't make these explicitly function objects in the hopes that C++ will eventually provide core language support for overload sets as first-class objects, mechanisms to forbid finding selected function( template)s via ADL, and mechanisms for selected function( template)s to inhibit ADL when found by normal unqualified name lookup. The fear is that allowing users to take advantage of the fact that these algorithms are implemented as function objects today may create breakage if and when they transition into overload sets of function templates using future tech to provide the desired properties.These overload sets not guaranteed to be implemented via function objects but in practice implemented exactly so are colloquially known as niebloids, much to the chagrin of Eric Niebler who wanted them to simply be function objects until being swayed by my starry-eyed naivete (as a relatively new WG21 member) into believing we could change the language in a reasonable timeframe. The STL uses an internal type
_Not_quite_object
:STL/stl/inc/xutility
Lines 3220 to 3243 in 1c59a20
to help define niebloids with as little object-like behavior as possible to avoid users depending on their object-ness.
Fast-forward to 2023. No core language support for niebloids has materialized, nor is likely to do so in time for C++26. Both libstdc++ and libc++ have implemented the niebloids as simple function objects. C++20 code in the wild has begun to depend on that object-ness, and the STL is beginning to receive bug reports like DevCom-10450794 for code that compiles fine with GCC and Clang (well, it would if libc++ had shipped
chunk_by
). Niebloids have failed both to encourage C++ core language support, and to prevent users from depending on implementation as function objects.There seems to be no reason to keep our
_Not_quite_object
around; I propose that we remove it and the resulting implementation divergence.The text was updated successfully, but these errors were encountered: