Re: Setting a list of values

2016-05-03 Thread Joel via Digitalmars-d-learn

On Sunday, 1 May 2016 at 05:42:00 UTC, Ali Çehreli wrote:

On 04/30/2016 10:05 PM, Joel wrote:
> This has no effect:
> _bars.each!(a => { a._plots.fillColor = Color(255, 180, 0);
});

This is a common issue especially for people who know lambdas 
from other languages. :)


Your lambda does not do any work. Rather, your lambda returns 
another lambda, which is promptly ignored:


import std.stdio;
import std.algorithm;

void main() {
auto arr = [ 1, 2 ];
arr.each!(a => { writeln(a); });  // returns lambda for 
each a

}

The lambda that 'each' takes above is "given a, produce this 
lambda". . To do the intended work, you need to remove the 
curly braces (and the semicolon):


arr.each!(a => writeln(a));

Or, you could insert empty () to call the returned lambda but 
that would completely be extra work in this case:


arr.each!(a => { writeln(a); }());

Ali


This seems to work the best:

arr.each!(a => { writeln(a); }());



Re: undefined identifier 'size_t'

2016-05-03 Thread Joshua Hodkinson via Digitalmars-d-learn

On Wednesday, 4 May 2016 at 01:44:31 UTC, Adam D. Ruppe wrote:

Is there a file called object.d in your current directory?


Not anymore,

Thanks for pointing that out


Re: undefined identifier 'size_t'

2016-05-03 Thread Adam D. Ruppe via Digitalmars-d-learn

Is there a file called object.d in your current directory?


undefined identifier 'size_t'

2016-05-03 Thread Joshua Hodkinson via Digitalmars-d-learn
I have run into an issue compiling with dmd (version 2.071.0), it 
seems that the 'size_t' alias isn't resolving properly. I was 
wondering if someone has run into this before and if this is a 
bug or something I'm doing wrong? My call to dmd is:


..dmd2\windows\bin\dmd.exe -run hello.d -de -w -unittest

Here is a sample program:

import std.stdio;

void main () {
stdout.writeln("Hello World!");
}

And the ouput:

..dmd2\windows\bin\..\..\src\druntime\import\core\stdc\time.d(111): Error: 
undefined identifier 'size_t'
..dmd2\windows\bin\..\..\src\druntime\import\core\stdc\time.d(111): Error: 
undefined identifier 'size_t'
..dmd2\windows\bin\..\..\src\druntime\import\core\stdc\wchar_.d(60): Error: 
undefined identifier 'size_t'
..dmd2\windows\bin\..\..\src\druntime\import\core\stdc\wchar_.d(68): Error: 
undefined identifier 'size_t'
..dmd2\windows\bin\..\..\src\druntime\import\core\stdc\wchar_.d(142): Error: 
undefined identifier 'size_t'
..dmd2\windows\bin\..\..\src\druntime\import\core\stdc\wchar_.d(146): Error: 
undefined identifier 'size_t'
..dmd2\windows\bin\..\..\src\druntime\import\core\stdc\wchar_.d(152): Error: 
undefined identifier 'size_t'
..dmd2\windows\bin\..\..\src\druntime\import\core\stdc\wchar_.d(154): Error: 
undefined identifier 'size_t'
..dmd2\windows\bin\..\..\src\druntime\import\core\stdc\wchar_.d(154): Error: 
undefined identifier 'size_t'


Thanks


Re: what is equivalent to template template

2016-05-03 Thread Erik Smith via Digitalmars-d-learn

You're close.

An `alias` template parameter can be any symbol, including a 
template. But you can't pass in a template as a runtime 
parameter, so having `F f` in your parameters list is wrong 
(there's nothing to pass anyway; you already have the template, 
which is F).


static void call(alias F, A...)(A a) {
F(a);
}

Then instantiate and call the `call` function with the template 
you want:


call!myVariadict(1,2,3);



Works. Thanks!



Re: constructed variadic call

2016-05-03 Thread Erik Smith via Digitalmars-d-learn
I don't think it's possible to call a vararg function whose 
number of arguments is only known at runtime, for the same 
reasons it is impossible in C [1].


Your switch statement is probably the best you can do, other 
than rewriting the API to not use varargs (which, depending on 
what the function is doing, I would recommend). You can 
possibly use string mixins or static foreach to avoid repeating 
the case clauses.


[1] Populating a va_list: 
http://stackoverflow.com/questions/988290/populating-a-va-list


That was fast :).  The generation idea helps a little - thanks.  
It works though and I can't use va_list in this case.


erik




Re: what is equivalent to template template

2016-05-03 Thread Alex Parrill via Digitalmars-d-learn

On Tuesday, 3 May 2016 at 21:31:35 UTC, Erik Smith wrote:
C++ has template templates.  I'm not sure how to achieve the 
same effect where (in example below) the template function 
myVariadic is passed to another function.


void myVaridatic(A...)(A a) {}

static void call(alias F,A...)(F f,A a) {
f(a);
}

void foo() {
call(myVaridatic,1,2,3);
}


You're close.

An `alias` template parameter can be any symbol, including a 
template. But you can't pass in a template as a runtime 
parameter, so having `F f` in your parameters list is wrong 
(there's nothing to pass anyway; you already have the template, 
which is F).


static void call(alias F, A...)(A a) {
F(a);
}

Then instantiate and call the `call` function with the template 
you want:


call!myVariadict(1,2,3);


Re: what is equivalent to template template

2016-05-03 Thread ag0aep6g via Digitalmars-d-learn

On 03.05.2016 23:31, Erik Smith wrote:

 void myVaridatic(A...)(A a) {}


Aside: I think it's "variadic", not "varidatic".



 static void call(alias F,A...)(F f,A a) {


static void call(alias f, A...)(A a) {


 f(a);
 }

 void foo() {
 call(myVaridatic,1,2,3);


call!myVaridatic(1, 2, 3);


 }




Re: constructed variadic call

2016-05-03 Thread Alex Parrill via Digitalmars-d-learn

On Monday, 2 May 2016 at 18:22:52 UTC, Erik Smith wrote:
Is there way to construct an "argument pack" from a non-static 
array (like the switch below)?  I need to transport a variadic 
call through a void*.


switch (a.length) {
  case 1: foo(a[1]); break;
  case 2: foo(a[1], a[2]); break;
  case 3: foo(a[1], a[2], a[3]); break;
...
}


I don't think it's possible to call a vararg function whose 
number of arguments is only known at runtime, for the same 
reasons it is impossible in C [1].


Your switch statement is probably the best you can do, other than 
rewriting the API to not use varargs (which, depending on what 
the function is doing, I would recommend). You can possibly use 
string mixins or static foreach to avoid repeating the case 
clauses.


[1] Populating a va_list: 
http://stackoverflow.com/questions/988290/populating-a-va-list


what is equivalent to template template

2016-05-03 Thread Erik Smith via Digitalmars-d-learn
C++ has template templates.  I'm not sure how to achieve the same 
effect where (in example below) the template function myVariadic 
is passed to another function.


void myVaridatic(A...)(A a) {}

static void call(alias F,A...)(F f,A a) {
f(a);
}

void foo() {
call(myVaridatic,1,2,3);
}


Re: constructed variadic call

2016-05-03 Thread Erik Smith via Digitalmars-d-learn

On Monday, 2 May 2016 at 18:56:59 UTC, Stefan Koch wrote:

On Monday, 2 May 2016 at 18:22:52 UTC, Erik Smith wrote:
Is there way to construct an "argument pack" from a non-static 
array (like the switch below)?  I need to transport a variadic 
call through a void*.


switch (a.length) {
  case 1: foo(a[1]); break;
  case 2: foo(a[1], a[2]); break;
  case 3: foo(a[1], a[2], a[3]); break;
...
}


Yes there is.
Using a string mixin.


I'm not sure how to apply mixins here because they require 
compile time evaluation and a.length is runtime.  Ideas?


erik


Re: Strange stack variable corruption error after calling extern(C) function

2016-05-03 Thread cc via Digitalmars-d-learn

On Tuesday, 3 May 2016 at 12:48:37 UTC, Benjamin Thaut wrote:
It seems that one of the fmod functions you declared is not 
correct. Either the fmod api is not using the c calling 
convention or you made a mistake when declaring the paramters 
of the fmod functions. You should double check that the 
functions match the fmod headers.


I see, thanks.  Double checking the original headers, I see the 
function is defined as:


FMOD_RESULT F_API FMOD_System_CreateSound   
(FMOD_SYSTEM *system, const char *name_or_data, FMOD_MODE mode, 
FMOD_CREATESOUNDEXINFO *exinfo, FMOD_SOUND **sound);



F_API seems to be defined as follows:

...
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || 
defined(_WIN64)

#define F_STDCALL _stdcall
#define F_DECLSPEC __declspec
#define F_DLLEXPORT ( dllexport )
...
#ifdef DLL_EXPORTS
#define F_API F_DECLSPEC F_DLLEXPORT F_STDCALL
#else
#define F_API F_STDCALL
#endif


I tried going by the information suggested on this page: 
http://wiki.dlang.org/D_binding_for_C#cdecl.2C_pascal.2C_stdcall

but if I declare the function, in D, as:
extern(Windows) FMOD_RESULT FMOD_System_CreateSound   
(FMOD_SYSTEM *system, const char *name_or_data, FMOD_MODE mode, 
FMOD_CREATESOUNDEXINFO *exinfo, FMOD_SOUND **sound);


it fails to link with "Error 42: Symbol Undefined 
_FMOD_System_CreateSound@20".  With extern(C) it compiles and 
runs but the problem from above persists.




Re: what is missing here?

2016-05-03 Thread Jonathan Villa via Digitalmars-d-learn

On Tuesday, 3 May 2016 at 16:13:07 UTC, ag0aep6g wrote:

On 03.05.2016 18:03, Jonathan Villa wrote:

Types are not values. You cannot return a type from a function. 
Use aliases instead:


alias user_id_t = typeof(dummy1);
alias name_t = typeof(dummy2);
/* ... etc ... */



Thank you, I thought alias was just allowed to be declared 
outside, but declaring them inside as public it now behaves like 
I want.


Re: what is missing here?

2016-05-03 Thread ag0aep6g via Digitalmars-d-learn

On 03.05.2016 18:03, Jonathan Villa wrote:

public final class accounts
{
 public:
 static table_user user;
}

public final class table_user
{
 private:
 static uint32 dummy1;
 static string dummy2;
 static DateTime dummy3;
 static ubyte dummy4;
 public:
 static @property auto user_id_t() { return typeof(dummy1); }
 static @property auto name_t() { return typeof(dummy2); }
 static @property auto alias_t() { return typeof(dummy2);}
 static @property auto pers_email_t() { return typeof(dummy2); }
 static @property auto corp_email_t() { return typeof(dummy2); }
 static @property auto password_t() { return typeof(dummy2); }
 static @property auto last_login_t() { return typeof(dummy3); }
 static @property auto active_t() { return typeof(dummy4); }
 static @property auto id_lang_t() { return typeof(dummy4); }
 static @property auto function_t() { return typeof(dummy4); }
 static @property auto register_date_t() { return typeof(dummy3); }
}

for every property it throws me an error at compile time: type ($) has
no value.
I'm trying to do a wrap of a database so when getting a resultset using
mysql-native I can do
result.front()[0].get!(accounts.user.user_it_t);
si it's more readable.


Types are not values. You cannot return a type from a function. Use 
aliases instead:


alias user_id_t = typeof(dummy1);
alias name_t = typeof(dummy2);
/* ... etc ... */



what is missing here?

2016-05-03 Thread Jonathan Villa via Digitalmars-d-learn

public final class accounts
{
public:
static table_user user;
}

public final class table_user
{
private:
static uint32 dummy1;
static string dummy2;
static DateTime dummy3;
static ubyte dummy4;
public:
static @property auto user_id_t() { return 
typeof(dummy1); }

static @property auto name_t() { return typeof(dummy2); }
static @property auto alias_t() { return typeof(dummy2);}
static @property auto pers_email_t() { return 
typeof(dummy2); }
static @property auto corp_email_t() { return 
typeof(dummy2); }
static @property auto password_t() { return 
typeof(dummy2); }
static @property auto last_login_t() { return 
typeof(dummy3); }
static @property auto active_t() { return typeof(dummy4); 
}
static @property auto id_lang_t() { return 
typeof(dummy4); }
static @property auto function_t() { return 
typeof(dummy4); }
static @property auto register_date_t() { return 
typeof(dummy3); }

}

for every property it throws me an error at compile time: type 
($) has no value.
I'm trying to do a wrap of a database so when getting a resultset 
using mysql-native I can do

result.front()[0].get!(accounts.user.user_it_t);
si it's more readable.


Re: inferred size for static array initialization

2016-05-03 Thread Basile B. via Digitalmars-d-learn

On Monday, 2 May 2016 at 17:43:56 UTC, Namespace wrote:


I still like

auto s(T, size_t n)(T[n] arr) {
return arr;
}


Wooah, this trick is awesome. But actually it does the same thing 
that what I've proposed before. Exactly the same code is 
generated. So I'd say that it's rather a matter of readability.


https://godbolt.org/g/wGTs52
https://godbolt.org/g/cXECyO





Re: ubyte[] -> immutable(ubyte)[]

2016-05-03 Thread vino via Digitalmars-d-learn
On Friday, 10 September 2010 at 15:15:38 UTC, Andrej Mitrovic 
wrote:
Yeah, one would think the destination is on the left (just like 
the standard C way of doing it), but it's not. I checked it in 
the docs and the source. And idup works, thanks.


Kagamin Wrote:


Andrej Mitrovic Wrote:

> foreach (ubyte[] buffer; stdin.byChunk(bufferSize))
> {
> immutable(ubyte)[] copy_buffer;
> copy(buffer, copy_buffer);
> 
> writeln(copy_buffer);  // writes nothing
> 
> send(tid, copy_buffer);

> }

Isn't destination the left argument?
Why you don't use send(tid, buffer.idup);
?


Hi Andrei/All,

 Request your help, I am trying the program written by you with 
few changes such as the example program read the input from stdin 
and prints the data to stdout, but my program reads the input 
from the file(readfile.txt) and writes the output to another 
file(writefile.txt), and I am getting the below errors while 
compiling


Testing:
Read a file(readfile.txt : Contain 20,000 lines) by chunk into a 
buffer(read buffer)
Pass the buffered data to an output buffer(write buffer) and then 
write the output buffer to a to another file(writefile.txt).

Error:

[root@localhost DProjects]# dmd readwriteb.d
readwriteb.d(7): Error: cannot implicitly convert expression 
(__aggr2859.front()) of type ubyte[] to immutable(ubyte)[]
readwriteb.d(15): Error: cannot implicitly convert expression 
(receiveOnly()) of type immutable(ubyte)[] to 
std.outbuffer.OutBuffer

[root@localhost DProjects]#

Version: DMD64 D Compiler v2.071.0

Code:

import std.algorithm, std.concurrency, std.stdio, std.outbuffer, 
std.file;


void main() {
   enum bufferSize = 1024 * 100;
   auto file = File("readfile.txt", "r");
   auto tid = spawn();
   foreach (immutable(ubyte)[] buffer; file.byChunk(bufferSize)) {
  send(tid, buffer);
   }
}

void fileWriter() {
   auto wbuf  = new OutBuffer();
   for (;;) {
  wbuf = receiveOnly!(immutable(ubyte)[])();
  write("writefile.txt", wbuf);
   }
}

After few changes as below I was able to compile, but when i run 
the program there is no data in the writefile.txt


import std.algorithm, std.concurrency, std.stdio, std.file;

void main() {
   enum bufferSize = 1024 * 100;
   auto file = File("readfile.txt", "r");
   auto tid = spawn();
   foreach (ubyte[] buffer; file.byChunk(bufferSize)) {
  send(tid, buffer.idup);
   }
}

void fileWriter() {
auto file = File("writefile.txt", "w");
for (;;) {
 auto  wbuf = receiveOnly!(ubyte[])();
  file.writeln("writefile.txt", wbuf);
   }
}

From,
Vino.B


Re: DlangUI FileDialog not working

2016-05-03 Thread Vadim Lopatin via Digitalmars-d-learn

On Tuesday, 3 May 2016 at 06:14:25 UTC, stunaep wrote:
FileDialog is showing a blank white window for me. Only tested 
on windows 7 so far, but if I run dmledit, the filedialog on 
there works fine. It's weird because I am using almost exactly 
the same code.


Try fetch recent dlangui version (dub upgrade --force-remove).
I fixed this issue last week. (There was a problem with sharing 
of OpenGL context between windows).
Difference in dmledit is probably due to different dlangui 
configuration selected - it uses `minimal` configuration - w/o 
OpenGL acceleration.




Re: struct cannot deduce function from argument types

2016-05-03 Thread chmike via Digitalmars-d-learn

Oops! Stupid of me. There were three bugs in the code.

Correct code is as follow:


import std.stdio;

class Data
{
string m = "Hello world !";
}

struct IdxElem(D)
{
bool inUse;
D data;
}

IdxElem!(Data)[string] idx;


void main()
{
idx["test1"] = IdxElem!Data(true, new Data);
idx["test2"] = IdxElem!Data(false, new Data);

writeln(idx["test2"].data.m);
writeln("Hello world!");
}


struct cannot deduce function from argument types

2016-05-03 Thread chmike via Digitalmars-d-learn


The following code does not compile and I don't understand why.

import std.stdio;

class Data
{
string m = "Hello world !";
}

struct IdxElem(D)
{
bool inUse;
D data;
}
IdxElem!Data[string] idx;


void main()
{
idx["test1"] = IdxElem(true, new Data);
idx["test2"] = IdxElem(false, new Data);

writeln(idx["test2"].data);
writeln("Hello world!");
}

This is the error message I get with DMD64 D Compiler v2.068.2

source/app.d(20,27): Error: struct app.IdxElem cannot deduce 
function from argument types !()(bool, Data), candidates are:

source/app.d(9,1):app.IdxElem(D)
source/app.d(21,27): Error: struct app.IdxElem cannot deduce 
function from argument types !()(bool, Data), candidates are:

source/app.d(9,1):app.IdxElem(D)
dmd failed with exit code 1.

I get the same error even if I add a constructor to IdxElem that 
sets the member variables with its two arguments.




Re: How can I save a class use the RedBlackTree?

2016-05-03 Thread Meta via Digitalmars-d-learn

On Tuesday, 3 May 2016 at 12:12:04 UTC, Jonathan M Davis wrote:

On Tue, 3 May 2016 11:37:13 +0200
Steven Schveighoffer via Digitalmars-d-learn
 wrote:
bleh, Object.opCmp only works with mutable objects. Which 
means RedBlackTree cannot work with objects because it uses 
inout to ensure your objects are not modified (since 2.068)


It doesn't work with const or immutable either, the only 
possible solution is to go back to mutable only.


So annoying, we need to fix Object.opCmp, or using 
const/immutable comparisons with objects doesn't work.


Hopefully someday...

https://issues.dlang.org/show_bug.cgi?id=9770

- Jonathan M Davis


What's stopping us right now from making opCmp a free function in 
object.d?


Re: Strange stack variable corruption error after calling extern(C) function

2016-05-03 Thread Benjamin Thaut via Digitalmars-d-learn

On Tuesday, 3 May 2016 at 11:32:31 UTC, cc wrote:
Hello, I've been encountering a strange problem that seems to 
occur after calling some external C functions.  I've been 
working on a program that incorporates the FMOD C API for 
playing sound, with a simple D binding based off the C headers, 
and actually everything works more or less fine, I've had 
working sound in my program for a few months now.  However I 
recently started noticing some strange behavior, currently 
using DMD v2.070.2 (haven't tried v2.071 yet, will soon).  I 
can't post the entire program but I'll include the relevant 
code, I might try to make a small working compilable sample if 
this isn't enough information.


[...]


It seems that one of the fmod functions you declared is not 
correct. Either the fmod api is not using the c calling 
convention or you made a mistake when declaring the paramters of 
the fmod functions. You should double check that the functions 
match the fmod headers.


Kind Regards
Benjamin Thaut



Re: Stacktraces in static constructors

2016-05-03 Thread Benjamin Thaut via Digitalmars-d-learn

On Tuesday, 3 May 2016 at 10:52:20 UTC, Nordlöw wrote:

On Tuesday, 3 May 2016 at 10:48:51 UTC, Nordlöw wrote:

AFAICT, stacktraces are not emitted with debug information when


Should be static shared module constructors.


errors occur in static module constructors. Is this a know bug?


My stacktraces contain no information of the call stack so it's 
very very tedious work to find the reason for a failing 
unittest.


I assume this is on windows? Yes its a known issue (I know about 
it). I Don't know if its filed though. As a workaround you can 
import "core.sys.windows.stacktrace" into each of your modules. 
That will force the module system to initialize the stacktracing 
code before the module ctors. The underlying issue is that the 
module system does not know about the implicit dependeny of every 
module on the stacktracing module.


Kind Regards
Benjamin Thaut



Re: How can I save a class use the RedBlackTree?

2016-05-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Tue, 3 May 2016 11:37:13 +0200
Steven Schveighoffer via Digitalmars-d-learn
 wrote:
> bleh, Object.opCmp only works with mutable objects. Which means
> RedBlackTree cannot work with objects because it uses inout to ensure
> your objects are not modified (since 2.068)
>
> It doesn't work with const or immutable either, the only possible
> solution is to go back to mutable only.
>
> So annoying, we need to fix Object.opCmp, or using const/immutable
> comparisons with objects doesn't work.

Hopefully someday...

https://issues.dlang.org/show_bug.cgi?id=9770

- Jonathan M Davis


Strange stack variable corruption error after calling extern(C) function

2016-05-03 Thread cc via Digitalmars-d-learn
Hello, I've been encountering a strange problem that seems to 
occur after calling some external C functions.  I've been working 
on a program that incorporates the FMOD C API for playing sound, 
with a simple D binding based off the C headers, and actually 
everything works more or less fine, I've had working sound in my 
program for a few months now.  However I recently started 
noticing some strange behavior, currently using DMD v2.070.2 
(haven't tried v2.071 yet, will soon).  I can't post the entire 
program but I'll include the relevant code, I might try to make a 
small working compilable sample if this isn't enough information.



// fmod/c/fmod.d:
// Adapted from C headers
extern(C):
struct FMOD_SYSTEM;
struct FMOD_SOUND;
enum FMOD_RESULT : int { ... }
enum FMOD_MODE : uint { ... }
FMOD_RESULT FMOD_System_CreateSound(FMOD_SYSTEM *system, const 
char *name_or_data, FMOD_MODE mode, FMOD_CREATESOUNDEXINFO 
*exinfo, FMOD_SOUND **sound);


// sound.d:
class Sound {
static immutable string pathPrefix = "data/sound/";
	enum FMOD_MODE mode = FMOD_MODE.FMOD_LOOP_OFF | 
FMOD_MODE.FMOD_3D | FMOD_MODE.FMOD_3D_HEADRELATIVE | 
FMOD_MODE.FMOD_3D_LINEARSQUAREROLLOFF;


FMOD_SOUND *snd;
FMOD_CHANNEL *channel;
string name;

void load() {
string fullpath = pathPrefix ~ name ~ ".wav";

		writefln("loading sound before: <%s> <%s> [%08x] <%s>", 
pathPrefix, name, fullpath.ptr, fullpath);
		FMOD_System_CreateSound(system, fullpath.toStringz, mode, null, 
);
		writefln("A loading sound after: <%s> <%s> [%08x] <%s>", 
pathPrefix, name, fullpath.ptr, fullpath);
		writefln("B loading sound after: <%s> <%s> [%08x] <%s>", 
pathPrefix, name, fullpath.ptr, fullpath);

if (1) {
			writefln("C loading sound after: <%s> <%s> [%08x] <%s>", 
pathPrefix, name, fullpath.ptr, fullpath);

}
}
}

// Output:
loading sound before:   [04368a40] 

A loading sound after:   [04368a40] 

B loading sound after:   [04368a40] 

C loading sound after:   [005df255] loading sound after: <%s> <%s> [%08x] <%s>>



As you can see I concatenate the path, filename, and extension 
strings, simple enough, then pass the result of .toStringz to the 
function.  What happens next is the bizarre behavior to the 
fullstring variable: Everything is fine until the program enters 
the if check, then for some reason the value of fullpath changes 
to be that of the string literal being passed to writefln().  If 
I try to do something else such as save the value of fullpath as 
a class member variable first, I get some other problem like 
object.Error@(0): Access Violation when it comes time to print 
the string.  The sound itself still plays fine, but something is 
getting corrupted by something, somewhere, and I'm completely at 
a loss as to understand what's going on.  Does anyone have any 
advice on what's happening here?


Re: Stacktraces in static constructors

2016-05-03 Thread Nordlöw via Digitalmars-d-learn

On Tuesday, 3 May 2016 at 10:48:51 UTC, Nordlöw wrote:

AFAICT, stacktraces are not emitted with debug information when


Should be static shared module constructors.


errors occur in static module constructors. Is this a know bug?


My stacktraces contain no information of the call stack so it's 
very very tedious work to find the reason for a failing unittest.




Stacktraces in static constructors

2016-05-03 Thread Nordlöw via Digitalmars-d-learn
AFAICT, stacktraces are not emitted with debug information when 
errors occurr in static module constructors. Is this a know bug?


This is a big problem for me because, in my application, I've 
realized unittests as functions called from within static shared 
module constructors to elide the problem of unittests being 
enabled recursively, which slows down iterative compilation time 
enormously.


Re: How can I save a class use the RedBlackTree?

2016-05-03 Thread Steven Schveighoffer via Digitalmars-d-learn

On 5/3/16 5:10 AM, Dsby wrote:

this is the test Code:


import std.container.rbtree;
import std.stdio;

class TClass
{
 int i;
}

void main()
{
 RedBlackTree!(TClass) list = new RedBlackTree!(TClass)();
 auto t = new TClass();
 list.insert(t);
 writeln("The rbtree length is ",list.length());
 list.removeKey(t);
 writeln("The rbtree length is ",list.length());
}

and thisis erro :
/usr/include/dlang/dmd-2.071.0/phobos/std/functional.d-mixin-206(206):
Error: mutable method object.Object.opCmp is not callable using a inout
object
/usr/include/dlang/dmd-2.071.0/phobos/std/container/rbtree.d(871):
Error: template instance std.functional.binaryFun!("a < b", "a",
"b").binaryFun!(inout(TClass), TClass) error instantiating
rbtree.d(11):instantiated from here: RedBlackTree!(TClass, "a <
b", false)
/usr/include/dlang/dmd-2.071.0/phobos/std/functional.d-mixin-206(206):
Error: function object.Object.opCmp (Object o) is not callable using
argument types (inout(TClass))
/usr/include/dlang/dmd-2.071.0/phobos/std/container/rbtree.d(873):
Error: template instance std.functional.binaryFun!("a < b", "a",
"b").binaryFun!(TClass, inout(TClass)) error instantiating
rbtree.d(11):instantiated from here: RedBlackTree!(TClass, "a <
b", false)




bleh, Object.opCmp only works with mutable objects. Which means 
RedBlackTree cannot work with objects because it uses inout to ensure 
your objects are not modified (since 2.068)


It doesn't work with const or immutable either, the only possible 
solution is to go back to mutable only.


So annoying, we need to fix Object.opCmp, or using const/immutable 
comparisons with objects doesn't work.


-Steve


DlangUI FileDialog not working

2016-05-03 Thread stunaep via Digitalmars-d-learn
FileDialog is showing a blank white window for me. Only tested on 
windows 7 so far, but if I run dmledit, the filedialog on there 
works fine. It's weird because I am using almost exactly the same 
code.


Here is what it looks like
http://i.imgur.com/qslu7tJ.png

handleAction code:


   case ProgramActions.FolderOpen:
UIString caption;
   caption = "OPEN_DIR"c;
   FileDialog dlg = createFileDialog(caption, 
true);
   dlg.dialogResult = delegate(Dialog dlg, 
const Action result) {

   if (result.id == ACTION_OPEN.id) {
   string filename = result.stringParam;
   //TODO
   }
   };
   dlg.show();
   return true;

   case ProgramActions.FileOpen:
UIString caption;
   caption = "FILE_OPEN"c;
   FileDialog dlg = createFileDialog(caption, 
false);
   
dlg.addFilter(FileFilterEntry(UIString("D_FILES"c), "*.d"));
   
dlg.addFilter(FileFilterEntry(UIString("ALL_FILES"c), "*.*"));
   dlg.dialogResult = delegate(Dialog dlg, 
const Action result) {

   if (result.id == ACTION_OPEN.id) {
   string filename = result.stringParam;
   //TODO
   }
   };
   dlg.show();
   return true;


Here is my createFileDialog

   FileDialog createFileDialog(UIString caption, bool folder, 
bool fileMustExist = true) {

   uint flags = DialogFlag.Modal | DialogFlag.Resizable;
   if (fileMustExist)
   flags |= FileDialogFlag.FileMustExist;
   if (folder)
   flags |= FileDialogFlag.SelectDirectory;
   FileDialog dlg = new FileDialog(caption, window, null, 
flags);

   //dlg.filetypeIcons[""] = "";
   return dlg;
   }


also have this in handleActionStateRequest:


   if (!_currentBackgroundOperation)
   a.state = ACTION_STATE_ENABLED;
   else
   a.state = ACTION_STATE_DISABLE;