The question is whether your concerns are serious enough to open a
library issue. The usual criteria (wording is unclear, wording is
contradictory) seem not to apply here, so the problem could be that
the committee could be hesitant to change the specification, but this
is just a guess and I don't want to discourage you.
IMO you *could* try to submit an additional library issue (post it to
the address given in the reply-to field of
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html),
especially if you are careful to describe the situation pointing out
the *inconsistency* as you did above. The good news would be that the
original intended characteristics of the trait - as described in the
original proposing paper
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2255.html#int
should still hold in the revised form.
- Daniel
we need a good answer for make_[un]signed, because bool is not in the
set of supported types, albeit from the current definition of these
traits this enum would have a well-defined type (which seems a bit
questionable, given that we forbid plain bool).
Two new traits have been added: make_signed and make_unsigned. These traits have been found to be useful in practice and reinvented multiple times. The multiple implementations in the field tend to have different behaviors in the corner cases. This specification standardizes these traits, even for the corner cases.
Invariants for make_signed and make_unsigned:
Let S be make_signed<T>::type and U be make_unsigned<T>::type.
- is_signed<S>::value
- is_unsigned<U>::value
- sizeof(T) == sizeof(S)
- sizeof(T) == sizeof(U)
- !is_same<S, U>::value
- is_convertible<S, U>::value
- is_convertible<U, S>::value
- numeric_limits<U>::digits == numeric_limits<S>::digits + 1
- If is_integral<T>::value and is_signed<T>::value then
- numeric_limits<T>::digits == numeric_limits<S>::digits, else
- numeric_limits<T>::digits == numeric_limits<U>::digits.
On 2014-02-28 06:42, David Krauss wrote:[Un]signed enumeration types are nonsense for the same reason as with bool.
Why? I could have an enumeration (probably weakly-typed) for well-known values of some field that is of type (e.g.) int.
Actually I do this in real code; I have enumerations for symbolic names of columns in QTreeView's which takes 'int' as the column index (since being a template class taking an enum for column index would have oh so many issues). And that's one example; I could give others.
I don't know that I'd ever be using make_[un]signed on these, but the enum itself having an associated type, sign and all, is certainly relevant.
That (IMHO) would be really silly in the example I gave above; the API I am calling takes an int, not an enum. What would be the point of explicitly casting the enum to int? There is no type safety gained; just more verbose code.
That (IMHO) would be really silly in the example I gave above; the API I am calling takes an int, not an enum. What would be the point of explicitly casting the enum to int? There is no type safety gained; just more verbose code.
2014-02-26 21:20 GMT+01:00 <tru...@gmail.com>:
> On Tuesday, February 25, 2014 10:17:55 PM UTC+1, Daniel Krügler wrote:
> Thank you. I will make an attempt to come up with improved wording when I
> have some free time. Note that there is one type that would be left
> unaddressed by that approach: plain char has no underlying type, is neither
> a signed integer type nor an unsigned integer type, and has no underlying
> type.
Well, but that could be defined for my recommended changes to
std::underlying_type, even if the core language does not define it
that way.
> The current wording requires make_signed<char>::type to be signed
> char, and make_unsigned<char>::type to be unsigned char. (Assuming no
> extended integer type has a lower rank than char, anyway.) That makes sense
> to me, and should probably remain that way.
Yes.
> It should require no compiler support beyond what already exists for
> enumeration types, unless I am misunderstanding: it could be implemented as
> an implementation-specific specialisation for char16_t, char32_t and
> wchar_t. I do like your suggestion of extending std::underlying_type.
Yes, but this specialization is more or less requiring
compiler-support, because it depends on compiler-defined types.
Therefore it would be better to move all of this into a single point,
preferably into underlying_type.
>> The question is whether your concerns are serious enough to open a
>> library issue. The usual criteria (wording is unclear, wording is
>> contradictory) seem not to apply here, so the problem could be that
>> the committee could be hesitant to change the specification, but this
>> is just a guess and I don't want to discourage you.
>
> In that case, might it be more likely to be accepted if it based on the
> types' ranges?
I don't think so, I believe that the route via the underlying type
better reflects the original intentions.
> On an implementation where INT_MIN == LONG_MIN, when given an
> enum E : long { }, make_signed<E>::type would remain int. It has the benefit
> that existing implementations, using sizeof, do continue to be valid for
> systems without padding bits, and on those implementations, int would be as
> equally a usable result as long. I will try to come up with two alternative
> suggested wordings.
>>
>> IMO you *could* try to submit an additional library issue (post it to
>> the address given in the reply-to field of
>> http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html),