-
Notifications
You must be signed in to change notification settings - Fork 771
add_const_t
VS plain const
#7845
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
Comments
This comment has been minimized.
This comment has been minimized.
Seems like N1345 already discussed removing the @jwakely compiled the discussion on the topic in 2013 here https://stackoverflow.com/a/16435566/5740428 For what it's worth, I can see the argument that
I feel like it's very difficult to come up with a proper objective guideline for when to use |
Historically, specifically C++03 era when the type traits were adopted for Library TR1, The One thing to be wary of is that we need to be careful of the order of nesting with One nagging doubt is that the traits provide the clarity of East Const, while the library is specified using Const West. Such concerns arise mostly in the context of Final niggle is whether the interaction of |
I'm fairly convinced that if you did template<class T>
-constexpr add_const_t<T>& as_const(T& t) noexcept;
+constexpr const T& as_const(T& t) noexcept; ... this would be clearer to the reader. It's not obvious whether So overall, I think the unnecessary uses of the
That is an interesting insight. I'm not sure if you intend this to be an argument in favor of
It doesn't matter in most cases regardless. Uses like in
I think that the interaction between reference types or functions and |
I see no reason to continue using the traits rather than just const T. |
Looks like we're sold here. Pull request welcome to replace all uses of |
Last thought --- are we sure that this does not run afoul of the ABI concerns that killed https://wg21.link/P0181? |
In general it could do, but I don't see a problem for any of the actual places that use |
The concerns with https://wg21.link/p1715 are maybe more relevant. We could omit the |
My only concern is accidentally making a normative change believing it to be editorial. |
Maybe off-topic: I find that all major implementations have some Lists
libc++:
libstdc++: MSVC STL: Given that ABI break is undesired, perhaps we should accept P1715 (with additional wording that touches |
I agree that P1715 is the right approach here (users of the standard library should simply not depend on ABI stability in this area), but until we get that, we should limit the editorial changes to those that are not at an ABI boundary. |
The standard wording sometimes uses
add_const_t
andadd_volatile_t
when plainconst
andvolatile
are sufficient. IIUC the difference is thatadd_*_t
block template argument deduction liketype_identity_t
, but we never useadd_*_t
in such contexts.Would it be better to use plain
const
andvolatile
?The text was updated successfully, but these errors were encountered: