Re: BitArray in custom class initialize it in ctor with arguments

2014-03-23 Thread MarisaLovesUsAll

On Saturday, 22 March 2014 at 10:02:39 UTC, bearophile wrote:

MarisaLovesUsAll:


Hi! I need to use array of bits in my custom class. I tried to
add std.bitmanip.BitArray as field, but got a strange error. 
What

am I doing wrong?

import std.bitmanip;
class Scene
{
BitArray collisionMap;
this(int w, int h)
{
collisionMap.init([0,0,0]);
}
}

C:\D\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d
line 606
Error: btr cannot be interpreted at compile time, because it 
has

no available source code


To me this program compiles:


import std.bitmanip;

class Scene {
 BitArray collisionMap;
 this(int w, int h) {
 collisionMap.init([0,0,0]);
 }
}
void main() {}


Errors like btr cannot be interpreted at compile time mean 
that you are trying to run at compile-time something that can 
only run at run-time. So are you using enums or static 
immutables or static constructors or something like that?


Bye,
bearophile


Thanks for help! It was static(?) ctor, I had been trying to 
create Scene from another class via

class App
{
Scene scene = new Scene(13,10);
}


BitArray in custom class initialize it in ctor with arguments

2014-03-22 Thread MarisaLovesUsAll

Hi! I need to use array of bits in my custom class. I tried to
add std.bitmanip.BitArray as field, but got a strange error. What
am I doing wrong?

import std.bitmanip;
class Scene
{
 BitArray collisionMap;
 this(int w, int h)
 {
 collisionMap.init([0,0,0]);
 }
}

C:\D\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d
line 606
Error: btr cannot be interpreted at compile time, because it has
no available source code


If I use collisionMap.length(w*h), I get:

C:\D\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d
line 554
Error: non-constant expression [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,


And if I use BitArray in default ctor ( this() ), or in other
function in class, or in main function, all is OK. But I need
only ctor with arguments that initialize the BitArray with '0'
and sets 'w*h' length.

DMD version 2.065.0

Sorry for bad English.


Re: BitArray in custom class initialize it in ctor with arguments

2014-03-22 Thread bearophile

MarisaLovesUsAll:


Hi! I need to use array of bits in my custom class. I tried to
add std.bitmanip.BitArray as field, but got a strange error. 
What

am I doing wrong?

import std.bitmanip;
class Scene
{
 BitArray collisionMap;
 this(int w, int h)
 {
 collisionMap.init([0,0,0]);
 }
}

C:\D\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d
line 606
Error: btr cannot be interpreted at compile time, because it has
no available source code


To me this program compiles:


import std.bitmanip;

class Scene {
 BitArray collisionMap;
 this(int w, int h) {
 collisionMap.init([0,0,0]);
 }
}
void main() {}


Errors like btr cannot be interpreted at compile time mean that 
you are trying to run at compile-time something that can only run 
at run-time. So are you using enums or static immutables or 
static constructors or something like that?


Bye,
bearophile