I have the following line of code:
temp[fowardI] = temp[fowardI] + temp[backwardI];
Where temp is a byte array (byte[]). When I try to compile it dmd
gives me this error:
source/hash.d(11,25): Error: cannot implicitly convert
expression `cast(int)temp[fowardI] + cast(int)temp[backwar
On Friday, 18 January 2019 at 17:15:09 UTC, Steven Schveighoffer
wrote:
What is 127 + 127? Answer: 254. Which if converted to a byte is
-127. Not what you might expect if you are doing addition.
Quite similar to int.max + int.max
In fact, D promotes all integral types smaller than int to int
I'm rewriting from C# a small library of mine to practice with D.
I have a class:
class WeightedRandom(T, W = float) if(isNumeric!W)
{
// Fields
private W[T] _pairs;
// The total sum of all the weights;
private W _probabilities;
/// Code...
}
An
On Saturday, 6 April 2019 at 17:44:25 UTC, Nicholas Wilson wrote:
Hmm,
import std.traits;
class WeightedRandom(T, W = float) if(isNumeric!W)
{
// Fields
private W[T] _pairs;
// The total sum of all the weights;
private W _probabilities;
/// Code...
On Saturday, 6 April 2019 at 18:08:31 UTC, Mek101 wrote:
On Saturday, 6 April 2019 at 17:44:25 UTC, Nicholas Wilson
wrote:
Hmm,
import std.traits;
class WeightedRandom(T, W = float) if(isNumeric!W)
{
// Fields
private W[T] _pairs;
// The total sum of all the weights;
I'll try to be straight.
I have the following function:
public size_t indexOf(alias pred = "a == b", Range)(Range array)
{
alias predicate = unaryFun!pred;
for(size_t i = 0; i < array.length; i++)
if(predicate(array[i]))
return i;
I didn't know it applied to templates other than lambdas.
Thank you for your explanation.
As the title says, is there a way to test the return type of the
'unaryFun' and 'binaryFun' templates from 'std.functional'?
I have the following code, and I want to to be sure that
'predicate' returns a boolean, but neither 'is(typeof(predicate)
== bool)' or 'is(ReturnType!predicate == bool)'
I made the following enumerations to test the predicates.
private enum bool isUnaryPredicate(alias pred, Range) =
is(typeof(unaryFun!(pred)((ElementType!Range).init)) == bool);
private enum bool isBinaryPredicate(alias pred, Range, V) =
is(typeof(binaryFun!(pred)((ElementType!Range).init, V.ini