Hi,
we have that instances of types with an explicit conversion to bool can be used in if statements, with logical operators &&, ||, and ! and with the ?: operator.
When we have strong type wrapping integers, we need to provide access to the underlying type and very often it is provided using an explicit conversion.
However when we use a strong type in a switch we must use the access function or cast it to the integer, as in
switch (st.value()) {
or
switch (int(st)) {
or
switch (underlying(st)) {
where underlying is a function that do the cast to the underlying
type.
I was wondering if we can not extend the switch statement. It could accept any type convertible to an integral type (a type that can be in a switch condition). If more than one of these conversion is possible then the program will not be well formed.
switch (st) {
... switch (i) {
switch (underlying(i)) {
Would the future pattern matching help on this concern? and how?
Vicente
using subframe = bounded_integer<int, 0, 9>
switch (sf) // implicit conversion using explicit int(bi)
{
case subframe{0}: ...
case subframe{1}: ...
default:
}
case sunday: ...
case SUNDAY: ...
case 0: ...
On Thu, Apr 27, 2017 at 12:47 AM, Vicente J. Botet Escriba <vicent...@wanadoo.fr> wrote:Yes it does. What is the status of this proposal?EWG wants some design making std::string matching against string literals cases work out of the box (currently this paper requires casting std::string into std::string_view), and I don't have a good way to naturally satisfy this requirement. Maybe you can help :)
This is not the use case I was looking for, but
anyway.
Sorry I'm missing surely something really
important.
What is the problem with string? That we don't
have string literals? Wouldn't require just an explicit
conversion to string_view solve the issue?
Why not restrict it to string_view that is a literal?
Once we have constexpr_string we could as well relax the switch to this type.
Vicente
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/e3544184-af31-0c97-50d5-8ab4cac2a720%40wanadoo.fr.