Re: @property not available for classes?

2016-01-01 Thread Shriramana Sharma via Digitalmars-d-learn
John wrote: > It's nothing to do with the @property attribute. So you need to > define a constructor. Also, use "new" when creating instances. Thanks Simon and John. First actual usage of D classes and mistaken assumption that C++ syntax is valid. :-) -- Shriramana Sharma, Penguin #395953

Re: to!string(double) at compile time

2016-01-01 Thread timothee cour via Digitalmars-d-learn
On Thursday, 23 August 2012 at 13:56:05 UTC, Philippe Sigaud wrote: On Tue, Aug 21, 2012 at 6:43 AM, Bobby Bingham wrote: [...] [...] A possibility is to use a function template, passing the double as a template argument: string test(double d)() // d is a template

Re: Can't find windows' CreateThread function / concurrency.spawn crashes host application

2016-01-01 Thread alkololl via Digitalmars-d-learn
Here is my code: // File dllmain.d module dllmain; import core.runtime; import std.c.stdlib; import std.string; import std.c.windows.windows; import honmod; private HINSTANCE g_hInst; extern (Windows) BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved) { g_hInst

Re: Can't find windows' CreateThread function / concurrency.spawn crashes host application

2016-01-01 Thread alkololl via Digitalmars-d-learn
On Friday, 1 January 2016 at 22:45:20 UTC, Adam D. Ruppe wrote: On Friday, 1 January 2016 at 22:02:46 UTC, alkololl wrote: I've found that std.c.windows.windows doesn't include a std.c.windows is basically useless. The new version should have it in core.sys.windows.windows though I'm not

Deit variable referencing

2016-01-01 Thread Jason Jeffory via Digitalmars-d-learn
Ok, So Deit allows D code inside html... looks great. But how do external variables work? If I create a variable in the server(such as a class), can an html file access it easily? (not having to jump through hoops) doctype html html head title D string interpolations

Why can't a Regex object be immutable?

2016-01-01 Thread Shriramana Sharma via Digitalmars-d-learn
Hello. With this code: import std.stdio, std.regex; void main() { immutable numbers = regex(r"\d+"); foreach (match; "a1b2c3d4e5".matchAll(numbers)) writeln(match[0]); } compiling gives the error: (4): Error: cannot implicitly convert expression (regex("\\d+", "")) of type

Re: Why can't a Regex object be immutable?

2016-01-01 Thread Shriramana Sharma via Digitalmars-d-learn
Shriramana Sharma wrote: > Why is it impossible for a Regex object to be > `immutable`? I find that I can't declare it as `const` either... This is most curious! -- Shriramana Sharma, Penguin #395953

Why isn't field-wise constructor automatic for structs and not classes?

2016-01-01 Thread Shriramana Sharma via Digitalmars-d-learn
If I have: struct TimeSpan { double start, end; } Then both the following automatically work: auto s = TimeSpan(); auto t = TimeSpan(1, 2); But if I make it a class (I need to) then I have to explicitly define a field-wise constructor else only a constructor with no args is automatically

Re: Why can't a Regex object be immutable?

2016-01-01 Thread cym13 via Digitalmars-d-learn
On Saturday, 2 January 2016 at 02:03:13 UTC, Shriramana Sharma wrote: Shriramana Sharma wrote: Why is it impossible for a Regex object to be `immutable`? I find that I can't declare it as `const` either... This is most curious! I think it's because regex() only compiles the regex at

Re: Why can't a Regex object be immutable?

2016-01-01 Thread Shriramana Sharma via Digitalmars-d-learn
cym13 wrote: > Is it that you > can't make an immutable regex()? In that case it is a > runtime-related issue and those variables just have to be > mutable. Or is it that you want to be able to use an immutable or > const regex (be it from regex() or ctRegex!()) with matchAll()? > In the latter

Re: Why does this not work?

2016-01-01 Thread israel via Digitalmars-d-learn
On Friday, 1 January 2016 at 14:00:41 UTC, TheDGuy wrote: writeln("Which number should i guess?"); string input = readln(); int i = to!int(input); You fell for the C# syntax like me... According to Ahli. You have to use the old C way of doing it with readf.

Re: GTKD Cairo get pixel color

2016-01-01 Thread TheDGuy via Digitalmars-d-learn
On Friday, 1 January 2016 at 22:00:04 UTC, TheDGuy wrote: On Friday, 1 January 2016 at 19:32:40 UTC, Basile B. wrote: On Wednesday, 30 December 2015 at 23:20:23 UTC, Basile B. wrote: On Wednesday, 30 December 2015 at 20:44:44 UTC, TheDGuy wrote: Hello, is there any way to get the pixel color

Re: Why can't a Regex object be immutable?

2016-01-01 Thread cym13 via Digitalmars-d-learn
On Saturday, 2 January 2016 at 02:39:36 UTC, Shriramana Sharma wrote: Aw come on. The immutability of the variable is *after* it has been created at runtime. Sure, but still... > you'll find that using ctRegex() instead will allow you to declare it immutable for example. I didn't look at

Re: Can't find windows' CreateThread function / concurrency.spawn crashes host application

2016-01-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 1 January 2016 at 22:02:46 UTC, alkololl wrote: I've found that std.c.windows.windows doesn't include a std.c.windows is basically useless. The new version should have it in core.sys.windows.windows though I'm not sure if it has actually been released yet. If it isn't in there

Re: Why can't a Regex object be immutable?

2016-01-01 Thread cym13 via Digitalmars-d-learn
On Saturday, 2 January 2016 at 02:56:35 UTC, cym13 wrote: On Saturday, 2 January 2016 at 02:39:36 UTC, Shriramana Sharma wrote: Aw come on. The immutability of the variable is *after* it has been created at runtime. Sure, but still... > you'll find that using ctRegex() instead will allow

Re: Can't find windows' CreateThread function / concurrency.spawn crashes host application

2016-01-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 2 January 2016 at 00:32:20 UTC, alkololl wrote: Why is that? I'm not sure, but in the switch you posted, you didn't handle the DLL_THREAD_ATTACH and DLL_THREAD_DETACH cases, the runtime might be incrementing the refcount there. Check this out:

Re: GTKD Cairo get pixel color

2016-01-01 Thread TheDGuy via Digitalmars-d-learn
On Friday, 1 January 2016 at 19:32:40 UTC, Basile B. wrote: On Wednesday, 30 December 2015 at 23:20:23 UTC, Basile B. wrote: On Wednesday, 30 December 2015 at 20:44:44 UTC, TheDGuy wrote: Hello, is there any way to get the pixel color of a single pixel by x and y coordinates of a context?

Can't find windows' CreateThread function / concurrency.spawn crashes host application

2016-01-01 Thread alkololl via Digitalmars-d-learn
Hey there and a happy new year, I wrote a C++ Dll which gets injecrted into another process. Now I want to port that Dll to D. In my C++ Dll I used a while loop which captures all keystrokes via GetAsyncKeyState and waited for F7 to be pressed and lastly unloads the dll via

Re: Why can't a Regex object be immutable?

2016-01-01 Thread Shriramana Sharma via Digitalmars-d-learn
cym13 wrote: > I think it's because regex() only compiles the regex at runtime > so it needs to be modified later ; Aw come on. The immutability of the variable is *after* it has been created at runtime. > > you'll find that using > ctRegex() instead will allow you to declare it immutable for

Re: CTFE with C functions not possible?

2016-01-01 Thread Shriramana Sharma via Digitalmars-d-learn
Rikki Cattermole wrote: > How exactly is a D version more bulky then C? > After all everything C can do, D can do with a very similar syntax. Source-code wise D is much leaner than C, obviously, but object-code wise it is *huge* even with dynamically linking Phobos: The binary size of

Re: CTFE with C functions not possible?

2016-01-01 Thread Rikki Cattermole via Digitalmars-d-learn
On 01/01/16 11:15 PM, Shriramana Sharma wrote: Rikki Cattermole wrote: Either port it to D and extern(C) it so it is accesible from other languages or not have CTFE support. I already wrote it in D, then I ported to C with much effort. The option to extern(C)-ing it didn't occur to me. :-(

Re: CTFE with C functions not possible?

2016-01-01 Thread Shriramana Sharma via Digitalmars-d-learn
Rikki Cattermole wrote: > Either port it to D and extern(C) it so it is accesible from other > languages or not have CTFE support. I already wrote it in D, then I ported to C with much effort. The option to extern(C)-ing it didn't occur to me. :-( Also, the D version is really much too bulky.

Re: @property not available for classes?

2016-01-01 Thread John via Digitalmars-d-learn
On Friday, 1 January 2016 at 10:14:58 UTC, Shriramana Sharma wrote: Hello. I'm trying the following code: import std.stdio; class TimeSpan { immutable double start, end; @property double length() { return end - start; } } void main() { auto p = TimeSpan(1, 2); writeln(p.length);

@property not available for classes?

2016-01-01 Thread Shriramana Sharma via Digitalmars-d-learn
Hello. I'm trying the following code: import std.stdio; class TimeSpan { immutable double start, end; @property double length() { return end - start; } } void main() { auto p = TimeSpan(1, 2); writeln(p.length); } ...and I'm getting the error: Error: no property 'opCall' for

Re: @property not available for classes?

2016-01-01 Thread SimonN via Digitalmars-d-learn
On Friday, 1 January 2016 at 10:14:58 UTC, Shriramana Sharma wrote: auto p = TimeSpan(1, 2); Error: no property 'opCall' for type '.TimeSpan' The error should be in 'auto p = ...', not in the line using the property. Instantiate with 'new TimeSpan(1, 2)' instead of 'TimeSpan(1, 2)'.

UFCS assignment syntax for templated function

2016-01-01 Thread rcorre via Digitalmars-d-learn
The following works: --- struct Foo { float x; } auto val(Foo foo) { return foo.x; } auto val(ref Foo foo, float val) { return foo.x = val; } unittest { auto f = Foo(); f.val = 5; assert(f.val == 5); } --- But the following fails to compile with 'val(b) is not an lvalue'. --- struct

Re: Why does this not work?

2016-01-01 Thread Tobi G. via Digitalmars-d-learn
On Friday, 1 January 2016 at 14:00:41 UTC, TheDGuy wrote: writeln("Which number should i guess?"); string input = readln(); int i = to!int(input); The solution is that readln() returns a string that also contains the newline this can be solved by easily stripping the

How to build dfmt?

2016-01-01 Thread Suliman via Digitalmars-d-learn
https://github.com/Hackerpilot/dfmt After run build.bat nothing do not happens. How can I build it?

Re: Why does this not work?

2016-01-01 Thread Tobi G. via Digitalmars-d-learn
On Friday, 1 January 2016 at 14:20:26 UTC, Tobi G. wrote: The solution is that readln() returns a string that also contains the newline this can be solved by easily stripping the newline off import std.string; int i = to!int(input.strip); Sorry my bad english.. i wrote solution but meant

Re: Why does this not work?

2016-01-01 Thread bachmeier via Digitalmars-d-learn
On Friday, 1 January 2016 at 14:47:20 UTC, TheDGuy wrote: On Friday, 1 January 2016 at 14:29:34 UTC, Tobi G. wrote: On Friday, 1 January 2016 at 14:20:26 UTC, Tobi G. wrote: The solution is that readln() returns a string that also contains the newline this can be solved by easily stripping

Re: UFCS assignment syntax for templated function

2016-01-01 Thread rcorre via Digitalmars-d-learn
On Friday, 1 January 2016 at 11:59:39 UTC, rcorre wrote: auto val(T)(ref Bar!T bar, float val) { return bar.x = val; } Uh, never mind. That `float` should have been `T`. Seems to work now.

DList access the previous element

2016-01-01 Thread Tobi G. via Digitalmars-d-learn
I'd like to implement a Skyline Rectangle packing algorithm. A DList should store the actual Skyline. (So the order is important, it will mostly have to access the right or left node element) And a Binary Heap which should hold a pointer to every DList element. (Mostly for fast accessing the

Why does this not work?

2016-01-01 Thread TheDGuy via Digitalmars-d-learn
writeln("Which number should i guess?"); string input = readln(); int i = to!int(input);

Re: Deducing a template argument from an aliased parameter

2016-01-01 Thread anonymous via Digitalmars-d-learn
On 31.12.2015 23:37, rcorre wrote: struct Vector(T, int N) { } alias Vector2(T) = Vector!(T, 2); void fun1(T)(Vector!(T, 2) vec) { } void fun2(T)(Vector2!T vec) { } unittest { fun1(Vector!(float, 2).init); fun2(Vector!(float, 2).init); } Why can fun1 deduce `T`, but fun2 can't?

Re: Why does this not work?

2016-01-01 Thread TheDGuy via Digitalmars-d-learn
On Friday, 1 January 2016 at 14:29:34 UTC, Tobi G. wrote: On Friday, 1 January 2016 at 14:20:26 UTC, Tobi G. wrote: The solution is that readln() returns a string that also contains the newline this can be solved by easily stripping the newline off import std.string; int i =

Re: GTKD Cairo get pixel color

2016-01-01 Thread Mike Wey via Digitalmars-d-learn
On 01/01/2016 01:37 PM, TheDGuy wrote: On Wednesday, 30 December 2015 at 23:20:23 UTC, Basile B. wrote: On Wednesday, 30 December 2015 at 20:44:44 UTC, TheDGuy wrote: Hello, is there any way to get the pixel color of a single pixel by x and y coordinates of a context? render to a png back

Re: regex - match/matchAll and bmatch - different output

2016-01-01 Thread anonymous via Digitalmars-d-learn
On 30.12.2015 12:06, Ivan Kazmenko wrote: import std.regex, std.stdio; void main () { writeln (bmatch ("abab", r"(..).*\1")); // [["abab", "ab"]] writeln (match("abab", r"(..).*\1")); // [["abab", "ab"]] writeln (matchAll ("abab", r"(..).*\1")); // [["abab", "ab"]]

Re: GTKD Cairo get pixel color

2016-01-01 Thread TheDGuy via Digitalmars-d-learn
On Wednesday, 30 December 2015 at 23:20:23 UTC, Basile B. wrote: On Wednesday, 30 December 2015 at 20:44:44 UTC, TheDGuy wrote: Hello, is there any way to get the pixel color of a single pixel by x and y coordinates of a context? render to a png back buffer. see

Re: How to build dfmt?

2016-01-01 Thread Tobi G. via Digitalmars-d-learn
On Friday, 1 January 2016 at 14:20:05 UTC, Suliman wrote: https://github.com/Hackerpilot/dfmt After run build.bat nothing do not happens. How can I build it? The easiest way to do it is to download and install dub - the package manager from https://code.dlang.org/ and then run dub fetch

Re: Why does this not work?

2016-01-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 1 January 2016 at 15:06:53 UTC, bachmeier wrote: I've battled with a few times, not having any idea what was going on. I now almost automatically use strip when it's not working. This is one of the most frequently asked questions by new users.. I added a tip to my new docs:

Re: GTKD Cairo get pixel color

2016-01-01 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 30 December 2015 at 23:20:23 UTC, Basile B. wrote: On Wednesday, 30 December 2015 at 20:44:44 UTC, TheDGuy wrote: Hello, is there any way to get the pixel color of a single pixel by x and y coordinates of a context? render to a png back buffer. see

Re: GTKD Cairo get pixel color

2016-01-01 Thread TheDGuy via Digitalmars-d-learn
On Friday, 1 January 2016 at 15:22:18 UTC, Mike Wey wrote: On 01/01/2016 01:37 PM, TheDGuy wrote: [...] you would either cr.getTarget(); or cairo.ImageSurface.ImageSurface.create. I'm not sure how those would get you access to the pixel data. Okay, thanks for your answer. So which

Re: Why does this not work?

2016-01-01 Thread TheDGuy via Digitalmars-d-learn
On Friday, 1 January 2016 at 15:16:36 UTC, Adam D. Ruppe wrote: On Friday, 1 January 2016 at 15:06:53 UTC, bachmeier wrote: I've battled with a few times, not having any idea what was going on. I now almost automatically use strip when it's not working. This is one of the most frequently

Re: Why does this not work?

2016-01-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 1 January 2016 at 17:00:23 UTC, TheDGuy wrote: If i had known that blog existed. I think your example at the end of the page explains the problem really well. Thanks! I just wrote that example in response to this thread :P (the overall thing there is something i started last week

Re: Why does this not work?

2016-01-01 Thread bachmeier via Digitalmars-d-learn
On Friday, 1 January 2016 at 15:16:36 UTC, Adam D. Ruppe wrote: On Friday, 1 January 2016 at 15:06:53 UTC, bachmeier wrote: I've battled with a few times, not having any idea what was going on. I now almost automatically use strip when it's not working. This is one of the most frequently