-
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
<string_view>: Problem: static_assert() in a template or type #2131
Comments
While other libraries can reject invalid template arguments as early as possible using the technique you mentioned, in the Standard Library we're constrained by the Standard's very strict requirements. In particular, forming types like |
Well here is the idea for the c++23 paper. IMHO that is a loophole. The user is allowed to create an illegal type. Until some other user in the future tries to make use of it when it bombs. Thanks for your reply... |
@StephanTLavavej of course one should not engage in anything after a long day of coding :) Thus I forgot the obvious and simple C++20 solution template< typename T, std::size_t k>
#if __cplusplus >= 202002L
// C++20 (and later) code
requires // requires-clause (ad-hoc constraint)
(k >= 4 && k <= 30)
#endif
class constrained_hyper_log_log ;
using constrained_derived_type = constrained_hyper_log_log<bool, 13> ; I might assume the standard is not constraining you not to use constraints. |
I am becoming a pest by now :) |
If the Standard doesn't depict a class template as being constrained, then we are not required to add such constraints to user-visible types. Even if we theoretically were permitted by the Standard to do this, we would not be comfortable making this change to existing types and risking significant disruption to existing code for this small benefit. Thanks for bringing this to our attention, but we don't plan on making any changes regarding this issue. |
Thanks for the reply. I understand and condone it. But being a wanderer I am wandering. How would MISRA or another less known safe coding for mission-critical apps standards, react to this? Until now I was recommending MS STL because of its "no exceptions" aka "/kernel" switch mode implementation. Using SEH and all that foundational stuff. In that mode, MS STL selection is a no-brainer compared to EASTL and similar "magical" STL implementations. Actually implementing just a subset of But now one has to "manage around" this not-a-issue. End of discussion, many thanks ... |
My comment on MS STL admirers issue
static_assert()
inside a template controls only the instatiation of the type definition. Not the mechanism of type definition.Consider instead imposing the type definition requirement.
better_not_a_vector<T>
can not be promoted to type definition if the author's requirement is not satisfied.Gobolt here
The text was updated successfully, but these errors were encountered: