Re: Static struct?

2019-04-24 Thread Rubn via Digitalmars-d-learn
On Wednesday, 24 April 2019 at 21:12:10 UTC, JN wrote: I noticed a construct I haven't seen before in D when reading the description for automem - https://github.com/atilaneves/automem static struct Point { int x; int y; } What does "static" do in this case? How does it

Re: How to pass variables to string mixins?

2019-02-25 Thread Rubn via Digitalmars-d-learn
On Tuesday, 26 February 2019 at 00:07:54 UTC, Victor Porton wrote: I want to create a string mixin based on a supplementary variable (name2 below): Let we have something like: mixin template X(string name) { immutable string name2 = '_' ~ name; mixin("struct " ~ name2 ~ "{ int i; }"); }

Re: Am I misusing with?

2019-01-19 Thread Rubn via Digitalmars-d-learn
On Saturday, 19 January 2019 at 17:49:31 UTC, faissaloo wrote: This seems to work fine file = File("test.txt", "r"); with (file) { scope(exit) close(); foreach (string line; file.lines()) { line_array ~= line; } } however: file =

Re: Forward declaration inside Function block, no error?

2019-01-06 Thread Rubn via Digitalmars-d-learn
On Sunday, 6 January 2019 at 18:38:44 UTC, Benjamin Thaut wrote: Today I found a bug in my D code. import std.stdio; // Type your code here, or load an example. void grow() { writeln("grow"); } void someFunc(bool condition) { if(condition) { void grow(); } } I tried

Re: How to initialize a globle variable nicely and properly?

2018-12-14 Thread Rubn via Digitalmars-d-learn
On Saturday, 15 December 2018 at 02:54:55 UTC, Heromyth wrote: We have a module including many globle variables which are needed to be initialized firstly in "shared static this() {}", see here https://github.com/huntlabs/hunt/blob/master/source/hunt/time/Init.d. The problem is that these

Re: difficulties with const structs and alias this / template functions

2018-11-18 Thread Rubn via Digitalmars-d-learn
On Sunday, 18 November 2018 at 17:30:18 UTC, Dennis wrote: I'm making a fixed point numeric type and want it to work correctly with const. First problem: ``` const q16 a = 6; a /= 2; // compiles! despite `a` being const. writeln(a); // still 6 a.toQ32 /= 2;// what's actually

Re: UFCS syntax I never saw before.

2018-05-21 Thread Rubn via Digitalmars-d-learn
On Monday, 21 May 2018 at 11:38:12 UTC, SrMordred wrote: After all this time I saw this: writeln = iota = 5; what?? I never saw that before! This is interesting, there is something useful that i can do with this kind of call? I probably wouldn't use that. That wasn't what it was intended

Re: C++ / const class pointer signature / unable to find correct D syntax

2018-05-06 Thread Rubn via Digitalmars-d-learn
On Friday, 4 May 2018 at 07:57:26 UTC, Uknown wrote: On Friday, 4 May 2018 at 07:49:02 UTC, Robert M. Münch wrote: I have a static C++ and can't make it to get a correct binding for one function: DMD: public: unsigned int __cdecl b2d::Context2D::_begin(class b2d::Image & __ptr64,class

Re: C++ / Wrong function signature generated for reference parameter

2018-05-02 Thread Rubn via Digitalmars-d-learn
On Wednesday, 2 May 2018 at 21:55:31 UTC, Robert M. Münch wrote: I have the following C++ function signature: uint _begin(Image& image, const InitParams* initParams) and the following D code: class InitParams { } class B2D { uint _begin(ref Image image, InitParams initParams); }

Add property-like Function to Type ?

2018-04-24 Thread Rubn via Digitalmars-d-learn
I was wondering if I could create my own property in a way that can be used the same way as something like "T.sizeof". Right now I have the following to replace length: uint length32(T)(T[] array) { return cast(uint)array.length; } I want something similar to be able to do the following:

Re: Declare and Define Before Use? [rant]

2018-04-04 Thread Rubn via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 20:01:55 UTC, Ali wrote: On Wednesday, 4 April 2018 at 19:51:27 UTC, kdevel wrote: On Wednesday, 4 April 2018 at 19:19:30 UTC, Ali wrote: BTW: You can't write void main () { x.writeln; int x; } import std.stdio; This is because x is not

Re: Fast GC allocation of many small objects

2018-03-31 Thread Rubn via Digitalmars-d-learn
On Friday, 30 March 2018 at 20:46:43 UTC, Per Nordlöw wrote: On Friday, 30 March 2018 at 20:38:35 UTC, rikki cattermole wrote: Use a custom allocator (that could be backed by the GC) using std.experimental.allocators :) https://dlang.org/phobos/std_experimental_allocator.html is massive. I

Re: Are there any working instructions about how to build and test dmd on Windows?

2018-03-13 Thread Rubn via Digitalmars-d-learn
Yah it's not fun. Some notes: You might need to set MSVC_CC environment variable cause it doesn't use the right format for VS path, depending on your version. https://github.com/dlang/dmd/blob/v2.079.0/src/vcbuild/msvc-dmc.d#L19 You could open a command prompt with the batch file running

Re: Setting up DMD on windows

2018-02-04 Thread Rubn via Digitalmars-d-learn
On Sunday, 4 February 2018 at 01:33:05 UTC, Seb wrote: On Sunday, 4 February 2018 at 01:23:50 UTC, Rubn wrote: On Saturday, 3 February 2018 at 23:42:28 UTC, welkam wrote: [...] I think you have to build with an old version of MSVC, 2010 maybe? It's been a while since I built it I don't

Re: Setting up DMD on windows

2018-02-03 Thread Rubn via Digitalmars-d-learn
On Saturday, 3 February 2018 at 23:42:28 UTC, welkam wrote: Tried to use DMD compiler that I built from source by following these instructions https://wiki.dlang.org/Building_under_Windows They are outdated but I managed to compile it but I get this error when I tried to compile some code.

Union Initialization

2018-01-30 Thread Rubn via Digitalmars-d-learn
Is there any way to initialize an array of unions with more than just the first union type? struct A { float a; } struct B { uint b; } union Test { A a; B b; } Test[2] test = [ Test(A(1.0f)), Test(B(10)), // ERROR ]; AFAIK there's no way to specify to use D with an

Re: New integer promotion rules

2018-01-17 Thread Rubn via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 22:30:11 UTC, rumbu wrote: code like "m = n < 0 ? -n : n" doesn't worth a wrapper That code is worth a wrapper, it's called "abs"... m = abs(n);

Re: New integer promotion rules

2018-01-17 Thread Rubn via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 20:30:07 UTC, rumbu wrote: And here is why is bothering me: auto max = isNegative ? cast(Unsigned!T)(-T.min) : cast(Unsigned!T)T.max); The generic code above (which worked for all signed integral types T in 2.077) must be rewritten like this in 2.078: