constify scalar arguments in std.bitmanip to reduce IFTI template bloat

Fixes Issue 19899 - std.bitmanip.bitsSet should accept const arguments

This also makes `swapEndian` not propagate `const` to its return value
which is arguably an improvement
(see https://github.com/dlang/phobos/pull/6682#discussion_r213024113).
This commit is contained in:
Nathan Sashihara 2019-05-24 03:01:38 -04:00
parent 7972cca21f
commit 0c376b40c4

View file

@ -2721,7 +2721,7 @@ public:
/++ /++
Swaps the endianness of the given integral value or character. Swaps the endianness of the given integral value or character.
+/ +/
T swapEndian(T)(T val) @safe pure nothrow @nogc T swapEndian(T)(const T val) @safe pure nothrow @nogc
if (isIntegral!T || isSomeChar!T || isBoolean!T) if (isIntegral!T || isSomeChar!T || isBoolean!T)
{ {
static if (val.sizeof == 1) static if (val.sizeof == 1)
@ -2891,7 +2891,7 @@ if (__traits(isIntegral, T))
and therefore could vary from machine to machine (which could make it and therefore could vary from machine to machine (which could make it
unusable if you tried to transfer it to another machine). unusable if you tried to transfer it to another machine).
+/ +/
auto nativeToBigEndian(T)(T val) @safe pure nothrow @nogc auto nativeToBigEndian(T)(const T val) @safe pure nothrow @nogc
if (canSwapEndianness!T) if (canSwapEndianness!T)
{ {
return nativeToBigEndianImpl(val); return nativeToBigEndianImpl(val);
@ -3093,7 +3093,7 @@ if (isFloatOrDouble!T && n == T.sizeof)
because the FPU will mess up any swapped floating point values. So, you because the FPU will mess up any swapped floating point values. So, you
can't actually have swapped floating point values as floating point values). can't actually have swapped floating point values as floating point values).
+/ +/
auto nativeToLittleEndian(T)(T val) @safe pure nothrow @nogc auto nativeToLittleEndian(T)(const T val) @safe pure nothrow @nogc
if (canSwapEndianness!T) if (canSwapEndianness!T)
{ {
return nativeToLittleEndianImpl(val); return nativeToLittleEndianImpl(val);
@ -3923,7 +3923,7 @@ if (canSwapEndianness!T && isInputRange!R && is(ElementType!R : const ubyte))
index = The index to start writing to. If index is a pointer, then it index = The index to start writing to. If index is a pointer, then it
is updated to the index after the bytes read. is updated to the index after the bytes read.
+/ +/
void write(T, Endian endianness = Endian.bigEndian, R)(R range, T value, size_t index) void write(T, Endian endianness = Endian.bigEndian, R)(R range, const T value, size_t index)
if (canSwapEndianness!T && if (canSwapEndianness!T &&
isForwardRange!R && isForwardRange!R &&
hasSlicing!R && hasSlicing!R &&
@ -3933,7 +3933,7 @@ if (canSwapEndianness!T &&
} }
/++ Ditto +/ /++ Ditto +/
void write(T, Endian endianness = Endian.bigEndian, R)(R range, T value, size_t* index) void write(T, Endian endianness = Endian.bigEndian, R)(R range, const T value, size_t* index)
if (canSwapEndianness!T && if (canSwapEndianness!T &&
isForwardRange!R && isForwardRange!R &&
hasSlicing!R && hasSlicing!R &&
@ -4276,7 +4276,7 @@ if (canSwapEndianness!T &&
range = The range to _append to. range = The range to _append to.
value = The value to _append. value = The value to _append.
+/ +/
void append(T, Endian endianness = Endian.bigEndian, R)(R range, T value) void append(T, Endian endianness = Endian.bigEndian, R)(R range, const T value)
if (canSwapEndianness!T && isOutputRange!(R, ubyte)) if (canSwapEndianness!T && isOutputRange!(R, ubyte))
{ {
static if (endianness == Endian.bigEndian) static if (endianness == Endian.bigEndian)
@ -4489,7 +4489,7 @@ if (canSwapEndianness!T && isOutputRange!(R, ubyte))
Counts the number of set bits in the binary representation of `value`. Counts the number of set bits in the binary representation of `value`.
For signed integers, the sign bit is included in the count. For signed integers, the sign bit is included in the count.
*/ */
private uint countBitsSet(T)(T value) @nogc pure nothrow private uint countBitsSet(T)(const T value) @nogc pure nothrow
if (isIntegral!T) if (isIntegral!T)
{ {
// http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel // http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
@ -4628,7 +4628,7 @@ Range that iterates the indices of the set bits in `value`.
Index 0 corresponds to the least significant bit. Index 0 corresponds to the least significant bit.
For signed integers, the highest index corresponds to the sign bit. For signed integers, the highest index corresponds to the sign bit.
*/ */
auto bitsSet(T)(T value) @nogc pure nothrow auto bitsSet(T)(const T value) @nogc pure nothrow
if (isIntegral!T) if (isIntegral!T)
{ {
return BitsSet!T(value); return BitsSet!T(value);