In Patterns of Human Error, the slide 31 point that you should replce int with
size_t
why that consider an error ?
%u:
In Patterns of Human Error, the slide 31 point that you should replce int with
size_t
why that consider an error ?
If T is a byte and the array size is 5 billion items, on 64 bit systems...? In
the little find() function you compare it with the length, that's a size_t.
Someone else will
void main()
{
size_t val = int.max+1;
int val2 = val;
writeln(val2);
}
writes -2147483648
That should give you a hint.
size_t val1 = int.max+1;
int val2 = int.max+1;
writeln(val1); // 2147483648
writeln(val2); // -2147483648
very clear example
thanks you both
Actually my example was bad. What I wanted to say is that size_t will
be 64bit on 64bit platforms while int will stay 32bit. Another
difference is that size_t is unsigned. So it's bad to use int even if
you're sure you're only going to compile only on 32bit platforms.
Here's the relevant
Edit: I just saw you've already figured this out. :)
On 07/05/2011 23:36, Andrej Mitrovic wrote:
Not too sure, CTFE is a pain in the ass sometimes. What exactly are
you trying to do, print field names in a custom way?
No, I have a struct that I don't have access to in the scope I'm in, I
do however have its type - by using the above, I can
One simplistic solution is to use alias this to simulate the same type:
struct Foo
{
int x, y;
}
string structClone(T)()
{
return struct ~ T.stringof ~ _ {
~ T.stringof ~ _inner;
alias _inner this;
this(T...)(T t) { _inner = typeof(_inner)(t); } };;
}
void
On 08/05/2011 00:39, Andrej Mitrovic wrote:
One simplistic solution is to use alias this to simulate the same type:
struct Foo
{
int x, y;
}
string structClone(T)()
{
return struct ~ T.stringof ~ _ {
~ T.stringof ~ _inner;
alias _inner this;
this(T...)(T
I'm not talking about function overloading, but functions with the same
parameters inside the same class definition:
class Foo
{
int foo(int i)
{
return 1;
}
int foo(int i)
{
return 1;
}
void bar()
{
foo(1);
}
}
void
I want to turn this:
auto arr = [1, 1, 2, 3, 4, 4];
into this:
auto arr2 = [[1, 1], [2], [3], [4, 4]];
I want an array of arrays of the same elements. Lazy or not, I don't care.
I thought I could get away with this inside some while loop:
auto equals = array(filter!a == b(arr));
arr =
11 matches
Mail list logo