Re: Do array literals still always allocate?

2017-05-14 Thread Namespace via Digitalmars-d-learn
On Sunday, 14 May 2017 at 01:15:03 UTC, Lewis wrote: On Saturday, 13 May 2017 at 19:22:09 UTC, Steven Schveighoffer wrote: It's just out of date. Can't remember the version, but this did use to allocate. It doesn't any more. But only for this case. In most cases it does allocate. Okay cool,

Re: C++-style mutable members

2017-01-17 Thread Namespace via Digitalmars-d-learn
On Tuesday, 17 January 2017 at 20:21:34 UTC, Nordlöw wrote: Is there a way to mimic C++-style `mutable` members in D? You could store a ptr to the member outside: import std.stdio; private int* _pid; struct A { int id; this(int id) {

Re: Use class template as a type

2016-11-28 Thread Namespace via Digitalmars-d-learn
We have a handy dandy syntax for this: if (MyClassInt subclass = cast(MyClassInt)value) { writeln(subclass.value); } If it doesn't cast to said type (it will be null) that branch won't execute. Just out of interest: it looks like a dynamic_cast in C++ which is considered as slow

Re: Instantiating a class with different types at runtime

2016-11-27 Thread Namespace via Digitalmars-d-learn
On Sunday, 27 November 2016 at 20:52:06 UTC, Marduk wrote: Dear all, I would like to have a kind of template class like the following: class Example { this(Type_left x, Type_right y) { this.left = x; this.right = y; } Type_left left; Type_right right; }

Re: A simplification of the RvalueRef idiom

2016-11-22 Thread Namespace via Digitalmars-d-learn
On Tuesday, 22 November 2016 at 13:06:27 UTC, Nordlöw wrote: On Monday, 21 November 2016 at 20:04:51 UTC, Ali Çehreli wrote: mixin template RvalueRef()// <-- DOES NOT TAKE A PARAMETER ANY MORE { alias T = typeof(this); static assert (is(T == struct)); @nogc @safe ref

Re: the best language I have ever met(?)

2016-11-21 Thread Namespace via Digitalmars-d-learn
On Monday, 21 November 2016 at 12:44:47 UTC, Jonathan M Davis wrote: On Monday, November 21, 2016 12:08:30 Patric Dexheimer via Digitalmars-d- learn wrote: No. D doesn't have that, though it's easy enough to do the same thing with a helper template. However, Ketmar seems to like to use his own

Re: inferred size for static array initialization

2016-10-18 Thread Namespace via Digitalmars-d-learn
On Tuesday, 18 October 2016 at 10:35:44 UTC, Nordlöw wrote: On Monday, 2 May 2016 at 17:43:56 UTC, Namespace wrote: immutable auto a = [1,2,3].s; Will that have zero run-time overhead compared to: immutable int[3] a = [1,2,3]; ? I'm not quite sure if pragma(inline, true) would result

Re: Explicit casting of enum -- intentional restriction?

2016-10-01 Thread Namespace via Digitalmars-d-learn
The Code below still works, so I guess it's some problem with the constraint of "exists". import std.stdio; enum Foo { A = "B" } void test(string a) { } void main() { test(Foo.A); Foo.A.test(); }

Re: how to access struct member using [] operator?

2016-09-25 Thread Namespace via Digitalmars-d-learn
On Sunday, 25 September 2016 at 04:54:31 UTC, grampus wrote: Dear all For example, I have a struct struct point{int x;int y} point a; Is there an easy way to access x and y by using a["x"] and a["y"] I guess I need to overload [], but can't figure out how. Someone can help? Thank you very

Re: Get class name of C++ class at runtime

2016-07-07 Thread Namespace via Digitalmars-d-learn
On Thursday, 7 July 2016 at 09:59:23 UTC, Jacob Carlborg wrote: Is it possible to get the name of a C++ class, "extern(C++) class Foo {}", at runtime just as it's possible to do the same for a D class, like "object.classinfo.name"? Maybe with a template? void class_name(T)(T obj) if

Re: Passing structs to functions

2016-07-02 Thread Namespace via Digitalmars-d-learn
Just for you, a slightly adapted version: import std.stdio; struct A { public int id = 0; this(int id) { this.id = id; } ref A byRef() { return this; } } void foo(ref const A a) {

Re: Passing structs to functions

2016-07-02 Thread Namespace via Digitalmars-d-learn
On Saturday, 2 July 2016 at 21:19:04 UTC, ketmar wrote: On Saturday, 2 July 2016 at 21:17:33 UTC, Namespace wrote: On Saturday, 2 July 2016 at 21:15:29 UTC, ketmar wrote: On Saturday, 2 July 2016 at 21:05:18 UTC, Namespace wrote: Try this little trick: or don't. such pointers to structs are

Re: Passing structs to functions

2016-07-02 Thread Namespace via Digitalmars-d-learn
On Saturday, 2 July 2016 at 21:15:29 UTC, ketmar wrote: On Saturday, 2 July 2016 at 21:05:18 UTC, Namespace wrote: Try this little trick: or don't. such pointers to structs are *dangerous*. Either that "dangerous" thing or 2^N template bloat.

Re: Passing structs to functions

2016-07-02 Thread Namespace via Digitalmars-d-learn
On Saturday, 2 July 2016 at 19:40:53 UTC, phant0m wrote: On Saturday, 2 July 2016 at 19:25:37 UTC, ketmar wrote: note the first "()", though: this is effectively a template function, which compiler will instantiate either with "ref" or without it. Yeah, I've noticed it. Always using function

Re: Default initialization of structs?

2016-06-17 Thread Namespace via Digitalmars-d-learn
The Factory-Pattern would be a good idea.

Re: mutable keyword

2016-05-20 Thread Namespace via Digitalmars-d-learn
On Friday, 20 May 2016 at 18:42:44 UTC, Ali Çehreli wrote: On 05/20/2016 10:28 AM, Namespace wrote: > On Thursday, 19 May 2016 at 23:21:14 UTC, Jonathan M Davis wrote: >> On Thursday, May 19, 2016 20:44:54 ciechowoj via Digitalmars-d-learn >> wrote: >>> Is there D equivalent of C++'s mutable

Re: mutable keyword

2016-05-20 Thread Namespace via Digitalmars-d-learn
On Thursday, 19 May 2016 at 23:21:14 UTC, Jonathan M Davis wrote: On Thursday, May 19, 2016 20:44:54 ciechowoj via Digitalmars-d-learn wrote: Is there D equivalent of C++'s mutable keyword? Like the one that allows to modify a field of struct from constant method. Or some alternative solution?

Re: inferred size for static array initialization

2016-05-02 Thread Namespace via Digitalmars-d-learn
On Monday, 2 May 2016 at 20:05:15 UTC, Steven Schveighoffer wrote: On 5/2/16 3:38 PM, Namespace wrote: The assembler might be safe in some instances, but that doesn't reflect the original internal representation in the compiler. Some other configuration of calls may allow the compiler to reuse

Re: inferred size for static array initialization

2016-05-02 Thread Namespace via Digitalmars-d-learn
The assembler might be safe in some instances, but that doesn't reflect the original internal representation in the compiler. Some other configuration of calls may allow the compiler to reuse that memory, and then you run into problems. I'm wondering if you used my rewrite if it would

Re: inferred size for static array initialization

2016-05-02 Thread Namespace via Digitalmars-d-learn
On Monday, 2 May 2016 at 19:08:52 UTC, Steven Schveighoffer wrote: On 5/2/16 3:02 PM, Namespace wrote: On Monday, 2 May 2016 at 18:57:49 UTC, Namespace wrote: A slice of a no-longer-existing temporary! Admittedly, this is not an issue with your code, but a deeper issue of allowing slicing of

Re: inferred size for static array initialization

2016-05-02 Thread Namespace via Digitalmars-d-learn
A slice of a no-longer-existing temporary! Admittedly, this is not an issue with your code, but a deeper issue of allowing slicing of rvalues. This works: int[] as = [1, 2, 3].s; writeln(as[2]); Bug or feature? Or did I may misunderstood you? You can drop auto. It's just a

Re: inferred size for static array initialization

2016-05-02 Thread Namespace via Digitalmars-d-learn
On Monday, 2 May 2016 at 18:57:49 UTC, Namespace wrote: A slice of a no-longer-existing temporary! Admittedly, this is not an issue with your code, but a deeper issue of allowing slicing of rvalues. This works: int[] as = [1, 2, 3].s; writeln(as[2]); Of course this slice is only valid

Re: inferred size for static array initialization

2016-05-02 Thread Namespace via Digitalmars-d-learn
On Monday, 2 May 2016 at 13:00:27 UTC, Erik Smith wrote: Is there a way to initialize a static array and have it's size inferred (and that works for arrays of structs using braced literals)? This would make it easier to maintain longer static array definitions. The code below doesn't work

Re: Garbage Collector : Ignoring a reference

2016-04-30 Thread Namespace via Digitalmars-d-learn
On Tuesday, 26 April 2016 at 09:07:59 UTC, Begah wrote: I am trying to create an asset manager for my textures. I had the idea ( it may be a wrong idea ) to create a hashmap of my textures with a string as the key. When the program request a texture, it firts check if it is in the hashmap and

Re: Const vs Non const method

2016-03-07 Thread Namespace via Digitalmars-d-learn
On Monday, 7 March 2016 at 18:17:18 UTC, Ola Fosheim Grøstad wrote: On Monday, 7 March 2016 at 16:30:48 UTC, Namespace wrote: Thanks to the wildcard modifier inout. Is there any possible way to do the same in C++? In this specific case you could do it with a macro if you don't mind dirty

Re: Const vs Non const method

2016-03-07 Thread Namespace via Digitalmars-d-learn
Let's use an example: import std.stdio; class Visitor { public: void visit(inout A) { writeln("visit A"); } void visit(inout B) { writeln("visit B"); } } class A { public: void accept(Visitor v) inout { v.visit(this); } } class B : A {

Re: Const vs Non const method

2016-03-06 Thread Namespace via Digitalmars-d-learn
On Thursday, 25 February 2016 at 10:59:43 UTC, Rene Zwanenburg wrote: On Thursday, 25 February 2016 at 10:44:49 UTC, Andrea Fontana wrote: Check this simple code: http://dpaste.dzfl.pl/2772c9144f1c I can't understand how to minimize code duplication for function like get(). Of course on real

Re: Const vs Non const method

2016-02-25 Thread Namespace via Digitalmars-d-learn
Try inout: import std.stdio; struct Inner { int field = 3; } struct Test { auto get() inout { return inner; } private Inner inner; } void main() { { Test test; test.get.field = 4; }

Re: [Dgame] Is there Multiple Window support?

2015-12-13 Thread Namespace via Digitalmars-d-learn
On Sunday, 13 December 2015 at 06:33:55 UTC, Jack wrote: Hello, so I've been experimenting with the framework and I tried to implement a game that has more than two windows. The first window is the main game and the second window is a smaller one with the various commands you can select. So

Re: How to make a transparent wrapper type?

2015-12-07 Thread Namespace via Digitalmars-d-learn
This seems to work: struct RefVal(T) { private T* ptr; this(T* val) { ptr = val; } ref auto opAssign(U)(auto ref U value) { *ptr = value; return *ptr; } auto

Re: [Dtiled] Unfamiliar terms and trouble using it for Dgame

2015-11-28 Thread Namespace via Digitalmars-d-learn
Well to start, I just copied the code for loading the map and tried to build it, substituting the variables like Rect and others. Then it went crazy all of a sudden: http://dpaste.com/2D59A2B The whole thing went mad, and I was sure I had my imports correct: import dtiled.data; import

Re: [Dtiled] Unfamiliar terms and trouble using it for Dgame

2015-11-27 Thread Namespace via Digitalmars-d-learn
On Friday, 27 November 2015 at 13:00:16 UTC, Jack wrote: Greetings! I've been using Dgame for quite a while now and I have been learning quite a lot from using playing with it. Then I found Tiled that's a tool to draw tilemaps, and DTiled to implement it. Link [

Re: OT: why do people use python when it is slow?

2015-10-18 Thread Namespace via Digitalmars-d-learn
On Tuesday, 13 October 2015 at 23:26:14 UTC, Laeeth Isharc wrote: https://www.quora.com/Why-is-Python-so-popular-despite-being-so-slow Andrei suggested posting more widely. Maybe also interesting:

Re: OT: why do people use python when it is slow?

2015-10-18 Thread Namespace via Digitalmars-d-learn
On Sunday, 18 October 2015 at 13:29:50 UTC, Ola Fosheim Grøstad wrote: On Sunday, 18 October 2015 at 12:50:43 UTC, Namespace wrote: On Tuesday, 13 October 2015 at 23:26:14 UTC, Laeeth Isharc wrote: https://www.quora.com/Why-is-Python-so-popular-despite-being-so-slow Andrei suggested posting

Re: Chaining struct method invocations

2015-09-07 Thread Namespace via Digitalmars-d-learn
On Monday, 7 September 2015 at 14:12:25 UTC, Bahman Movaqar wrote: I need some help understand the behaviour of my code[1]. Specifically I have trouble with `add` method on line 79. My impression is that since it returns `this`, multiple invocations can be chained like

Re: [Dgame] Sprite loading and setting position in another class

2015-08-25 Thread Namespace via Digitalmars-d-learn
Thank you for answering so quickly. If you don't mind me asking when will v0.7 be out? Not so soon. But maybe I'll release v0.6.5 with this feature at the end of september. For now you need to store your Texture in e.g. a Texture manager.

Re: [Dgame] Sprite loading and setting position in another class

2015-08-25 Thread Namespace via Digitalmars-d-learn
Edit: Basically my code is: //Texman.d// Class TextureManager { //variables void addSprite(string sprite_file, string name) { Surface wiki_img = Surface(sprite_file); Texture wiki_tex =

Re: [Dgame] Sprite loading and setting position in another class

2015-08-25 Thread Namespace via Digitalmars-d-learn
Note that Texture is (in constrast to Sprite) a struct and not a class, so it is a value type. Dgame tries to use as many value types as possible to reduce the amount of garbage.

Re: How disruptive is the GC?

2015-07-29 Thread Namespace via Digitalmars-d-learn
On Wednesday, 29 July 2015 at 09:25:50 UTC, Snape wrote: I'm in the early stages of building a little game with OpenGL (in D) and I just want to know the facts about the GC before I decide to either use it or work around it. Lots of people have said lots of things about it, but some of that

Re: Yes or No Options

2015-07-27 Thread Namespace via Digitalmars-d-learn
Look at my example: import std.stdio; import std.string; import std.conv : to; void main() { while (true) { write(Roll the dice: Enter a number: ); int dieNumber = readln.strip.to!int; if (dieNumber 4) { writeln(You won!); } else if

Re: pass by value elide dtor + post-blit

2015-06-21 Thread Namespace via Digitalmars-d-learn
Dear Ali, thank you for helping! Problem happens when passing by value as in param. Change 'foo' to this: ref S foo(ref S s) { s.val+=1; return s; }

Re: Base type for arrays

2015-06-17 Thread Namespace via Digitalmars-d-learn
On Wednesday, 17 June 2015 at 20:58:10 UTC, jmh530 wrote: On Wednesday, 17 June 2015 at 20:33:11 UTC, Namespace wrote: import std.stdio; template BaseTypeOf(T) { static if (is(T : U[], U)) alias BaseTypeOf = BaseTypeOf!(U); else alias BaseTypeOf = T; } void foo(T

Re: Base type for arrays

2015-06-17 Thread Namespace via Digitalmars-d-learn
import std.stdio; template BaseTypeOf(T) { static if (is(T : U[], U)) alias BaseTypeOf = BaseTypeOf!(U); else alias BaseTypeOf = T; } void foo(T : U[], U)(T arr) if (is(BaseTypeOf!(U) == real)) { } void main() { //real _x; real[2] x;

Re: Regex-Fu

2015-05-25 Thread Namespace via Digitalmars-d-learn
On Monday, 25 May 2015 at 11:11:50 UTC, Chris wrote: I'm a bit at a loss here. I cannot get the longest possible match. I tried several versions with eager operators and stuff, but D's regex engine(s) always seem to return the shortest match. Is there something embarrassingly simple I'm

Re: Template type deduction and specialization

2015-05-20 Thread Namespace via Digitalmars-d-learn
On Wednesday, 20 May 2015 at 06:31:13 UTC, Mike Parker wrote: I don't understand why this behaves as it does. Given the following two templates: ``` void printVal(T)(T t) { writeln(t); } void printVal(T : T*)(T* t) { writeln(*t); } ``` I find that I actually have to explicitly

Re: -vgc Info ok?

2015-05-19 Thread Namespace via Digitalmars-d-learn
On Monday, 18 May 2015 at 14:30:43 UTC, Chris wrote: The following string[string] myarray = [key:value]; string entry; entry = myarray[key]; // = vgc: indexing an associative array may cause GC allocation Why is _accessing_ an assoc treated as indexing it? No error if you use

Re: -vgc Info ok?

2015-05-19 Thread Namespace via Digitalmars-d-learn
On Tuesday, 19 May 2015 at 09:43:06 UTC, Chris wrote: On Tuesday, 19 May 2015 at 09:10:50 UTC, Namespace wrote: On Monday, 18 May 2015 at 14:30:43 UTC, Chris wrote: The following string[string] myarray = [key:value]; string entry; entry = myarray[key]; // = vgc: indexing an associative array

Re: GC Destruction Order

2015-05-19 Thread Namespace via Digitalmars-d-learn
On Tuesday, 19 May 2015 at 19:36:23 UTC, rsw0x wrote: On Tuesday, 19 May 2015 at 18:37:31 UTC, bitwise wrote: On Tue, 19 May 2015 14:19:30 -0400, Adam D. Ruppe destructiona...@gmail.com wrote: On Tuesday, 19 May 2015 at 18:15:06 UTC, bitwise wrote: Is this also true for D? Yes. The GC

Re: GC Destruction Order

2015-05-19 Thread Namespace via Digitalmars-d-learn
On Tuesday, 19 May 2015 at 20:02:07 UTC, rsw0x wrote: On Tuesday, 19 May 2015 at 19:45:38 UTC, Namespace wrote: On Tuesday, 19 May 2015 at 19:36:23 UTC, rsw0x wrote: On Tuesday, 19 May 2015 at 18:37:31 UTC, bitwise wrote: On Tue, 19 May 2015 14:19:30 -0400, Adam D. Ruppe

Re: overloading evaluation (treating objects as functions)

2015-05-18 Thread Namespace via Digitalmars-d-learn
On Sunday, 17 May 2015 at 18:49:40 UTC, dan wrote: Is it possible to define a class F so that auto f=new F(); writeln(The value of f at 7 is ,f(7)); compiles and works as expected? So the idea would be to be able to use notation like f(7) instead of f.eval(7) or something along

ICE?

2015-05-17 Thread Namespace via Digitalmars-d-learn
Is this error an ICE? I think so, because I see the internal filename, but I'm not sure. Error: e2ir: cannot cast malloc(length * 8u) of type void* to type char[]

Re: ICE?

2015-05-17 Thread Namespace via Digitalmars-d-learn
On Sunday, 17 May 2015 at 09:30:16 UTC, Gary Willoughby wrote: On Sunday, 17 May 2015 at 09:25:33 UTC, Namespace wrote: Is this error an ICE? I think so, because I see the internal filename, but I'm not sure. Error: e2ir: cannot cast malloc(length * 8u) of type void* to type char[] Have

Re: ICE?

2015-05-17 Thread Namespace via Digitalmars-d-learn
On Sunday, 17 May 2015 at 09:59:41 UTC, Daniel Kozak wrote: On Sun, 17 May 2015 09:33:27 + Namespace via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Sunday, 17 May 2015 at 09:30:16 UTC, Gary Willoughby wrote: On Sunday, 17 May 2015 at 09:25:33 UTC, Namespace wrote

Re: Dynamic / resizable array type, and a crash problem

2015-05-14 Thread Namespace via Digitalmars-d-learn
On Thursday, 14 May 2015 at 13:26:27 UTC, ivoras wrote: On Thursday, 14 May 2015 at 12:46:48 UTC, Adam D. Ruppe wrote: I would just use a regular `string[]` array... Is it resizable? Somehow I didn't get that impression from the docs. Apparently it doesn't even have an insert method:

Re: Efficiently passing structs

2015-05-05 Thread Namespace via Digitalmars-d-learn
On Tuesday, 5 May 2015 at 21:58:57 UTC, bitwise wrote: On Tue, 05 May 2015 17:33:09 -0400, Namespace rswhi...@gmail.com wrote: I've discussed that so many times... just search for auto / scope ref... ;) It will never happen. See:

Re: Efficiently passing structs

2015-05-05 Thread Namespace via Digitalmars-d-learn
I've discussed that so many times... just search for auto / scope ref... ;) It will never happen. See: http://forum.dlang.org/thread/ntsyfhesnywfxvzbe...@forum.dlang.org?page=1 http://forum.dlang.org/thread/ylebrhjnrrcajnvtt...@forum.dlang.org?page=1

Re: Factory pattern in D

2015-05-01 Thread Namespace via Digitalmars-d-learn
How about this: struct A { int x = 42; } struct B { int x = 7; } T factory(T)() { return T(); } void main() { auto a = factory!(A); }

Re: Factory pattern in D

2015-05-01 Thread Namespace via Digitalmars-d-learn
On Friday, 1 May 2015 at 10:04:46 UTC, Namespace wrote: How about this: struct A { int x = 42; } struct B { int x = 7; } T factory(T)() { return T(); } void main() { auto a = factory!(A); } Of course, you can restrict the type to A or B, or both: T factory(T)() if

Re: Example from d-idioms is incorrect

2015-04-30 Thread Namespace via Digitalmars-d-learn
On Thursday, 30 April 2015 at 21:30:36 UTC, TheGag96 wrote: I was looking at the d-idioms website today and saw this code example: http://p0nce.github.io/d-idioms/#Adding-or-removing-an-element-from-arrays And I was kind of irked. I just recently working with removing an element from an

Re: Example from d-idioms is incorrect

2015-04-30 Thread Namespace via Digitalmars-d-learn
Same output: [1, 10] true [1] false with dmd 2.067.1

Re: Reuse object memory?

2015-04-20 Thread Namespace via Digitalmars-d-learn
Thank you. Do you mean this is worth a PR, to add this functionality to Phobos? My current code looks like this: http://dpaste.dzfl.pl/19b78a600b6c

Re: Reuse object memory?

2015-04-20 Thread Namespace via Digitalmars-d-learn
On Monday, 20 April 2015 at 21:58:59 UTC, Ali Çehreli wrote: On 04/20/2015 02:44 PM, Namespace wrote: Thank you. Do you mean this is worth a PR, to add this functionality to Phobos? I am not familiar with such a need so I don't have a strong opinion. However, if an object needs to be

Re: Reuse object memory?

2015-04-20 Thread Namespace via Digitalmars-d-learn
On Sunday, 19 April 2015 at 21:17:18 UTC, Ali Çehreli wrote: On 04/19/2015 09:04 AM, Namespace wrote: Is it somehow possible to reuse the memory of an object? Yes, when you cast a class variable to void*, you get the address of the object. @nogc T emplace(T, Args...)(ref T obj, auto ref

Re: Reuse object memory?

2015-04-19 Thread Namespace via Digitalmars-d-learn
It seems that D has currently no direct support to reuse object memory. D should add a new-placement syntax: Foo f = new Foo(42); new (f) Foo(23); and/or should add an emplace overload which takes an object: T emplace(T, Args...)(ref T obj, auto ref Args args) if (is(T == class))

Re: Reuse object memory?

2015-04-19 Thread Namespace via Digitalmars-d-learn
And if I have an already instantiated object? Foo f = new Foo(); // reuse f's memory Is there an nicer way to override the memory instead of: void[] buf = (cast(void*) f)[0 .. __traits(classInstanceSize, Foo)]; buf = typeid(Foo).init[]; // or: buf = f.classinfo.init[]; ?

Reuse object memory?

2015-04-19 Thread Namespace via Digitalmars-d-learn
Is it somehow possible to reuse the memory of an object? My current idea is: @nogc T emplace(T, Args...)(ref T obj, auto ref Args args) nothrow if (is(T == class)) { if (obj is null) return null; enum size_t SIZE = __traits(classInstanceSize, T); void[] buf =

Re: [DerelictOrg] Forum down ?

2015-04-07 Thread Namespace via Digitalmars-d-learn
On Tuesday, 7 April 2015 at 10:48:38 UTC, ParticlePeter wrote: Hi, I think I have a bug report for DerelictGL3, but cannot find the related Forum ( http://dblog.aldacron.net/forum/index.php ), is it still in the process of being moved ? Regards, ParticlePeter Post it there:

Re: alias this of non-public member

2015-04-07 Thread Namespace via Digitalmars-d-learn
On Tuesday, 7 April 2015 at 17:21:09 UTC, Daniel Kozak wrote: On Tue, 07 Apr 2015 16:40:29 + via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Hi! Excuse me if this is obvious, but I can't recall coming across anything similar and a quick search returns nothing

Re: Conditional compilation for debug/release

2015-04-06 Thread Namespace via Digitalmars-d-learn
On Monday, 6 April 2015 at 14:50:29 UTC, Johan Engelen wrote: How do conditionally compile code for either release (-release) or debug (-debug)? Something like this: version(Debug) { pragma(lib, libcmtd.lib); } else { pragma(lib, libcmt.lib); } In the documentation [1], I don't see

Re: Conditional compilation for debug/release

2015-04-06 Thread Namespace via Digitalmars-d-learn
On Monday, 6 April 2015 at 15:15:48 UTC, Johan Engelen wrote: On Monday, 6 April 2015 at 14:55:58 UTC, Namespace wrote: debug { pragma(lib, libcmtd.lib); } else { pragma(lib, libcmt.lib); } Thanks for the quick reply! Worth adding an example like that to http://dlang.org/version.html

Re: Issue with free() for linked list implementation

2015-04-06 Thread Namespace via Digitalmars-d-learn
2. When you malloc, you use 'two.sizeof' and 'ten.sizeof'. Integers are 4 bytes, so you were allocating 4 bytes for each of these (not 2 or 10 bytes as is alluded to above). Yeah, my mistake. I saw the mistake but could not describe it correctly. :)

Re: Issue with free() for linked list implementation

2015-04-04 Thread Namespace via Digitalmars-d-learn
On Saturday, 4 April 2015 at 09:05:03 UTC, bearophile wrote: Namespace: I've written a straight forward linked list implementation here: https://github.com/nomad-software/etcetera/blob/master/source/etcetera/collection/linkedlist.d Even though I'm using the GC to manage memory, maybe it

Re: Issue with free() for linked list implementation

2015-04-03 Thread Namespace via Digitalmars-d-learn
On Friday, 3 April 2015 at 22:02:13 UTC, Kitt wrote: Hello. I’m trying to write my own version of a list that doesn’t rely on the garbage collector. I’m working on a very bare bones implementation using malloc and free, but I’m running into an exception when I attempt to call free. Here is a

Re: Issue with free() for linked list implementation

2015-04-03 Thread Namespace via Digitalmars-d-learn
Wow, I can't even begin to explain how red my cheeks are right now. You're completely right; I have no idea what my head was thinking. Sure enough, call malloc with the correct type, and the error goes away =P Thanks for the help =) I guess I've been in C# land at work for way too long now,

Re: Issue with free() for linked list implementation

2015-04-03 Thread Namespace via Digitalmars-d-learn
On Friday, 3 April 2015 at 22:38:00 UTC, Gary Willoughby wrote: On Friday, 3 April 2015 at 22:08:52 UTC, Kitt wrote: Thanks for the help =) I guess I've been in C# land at work for way too long now, my low level C skills are evaporating! I've written a straight forward linked list

Re: reinterpret_cast float to uint

2015-03-29 Thread Namespace via Digitalmars-d-learn
On Sunday, 29 March 2015 at 16:29:40 UTC, ketmar wrote: On Sun, 29 Mar 2015 16:00:05 +, matovitch wrote: On Sunday, 29 March 2015 at 14:50:24 UTC, ketmar wrote: On Sun, 29 Mar 2015 13:45:10 +, matovitch wrote: you can also use unions. Good idea ! In my case I think it was better to

Re: PrimitiveRef ?

2015-03-23 Thread Namespace via Digitalmars-d-learn
Something like that? struct PrimitiveRef(T) { private T* _value; @property ref inout(T) get() inout pure nothrow { assert(_value); return *_value; } alias get this; this(T val) {

Re: ref for (const) variables

2015-03-17 Thread Namespace via Digitalmars-d-learn
On Tuesday, 17 March 2015 at 09:56:09 UTC, Jonathan M Davis wrote: On Monday, March 16, 2015 18:46:59 Namespace via Digitalmars-d-learn wrote: May this be worth of an enhancement request? Or was this already rejected? And, no, I want no mutable references such as C++. Walter has been

Re: ref for (const) variables

2015-03-16 Thread Namespace via Digitalmars-d-learn
On Monday, 16 March 2015 at 19:20:09 UTC, anonymous wrote: On Monday, 16 March 2015 at 18:47:00 UTC, Namespace wrote: const(Matrix)* m = t.getCurrentModelViewMatrix(); // currently } But IMO it would be a lot nicer if I could store the reference like this: ref const(Matrix) m =

ref for (const) variables

2015-03-16 Thread Namespace via Digitalmars-d-learn
Currently, if you want to store a long getter into a variable without copying it (because it may be a big struct), your only way is to store it as a pointer: struct Matrix { float[16] values= [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]; }

Re: 'strong types' a la boost

2015-03-14 Thread Namespace via Digitalmars-d-learn
You can do it this way: struct dollars_t { uint _dollar; this(uint d) { _dollar = d; } alias _dollar this; } struct cents_t { uint _cent; this(uint c) { _cent = c; } alias _cent this; } void do_something_with_dollars(dollars_t d) {

Re: 'strong types' a la boost

2015-03-14 Thread Namespace via Digitalmars-d-learn
On Saturday, 14 March 2015 at 16:55:09 UTC, Charles Cooper wrote: Interesting. I think in the second example there are pathological cases where one has similar declarations in two modules at the same line. Yes, that right, I've kept it simple, but of course it is not complete safe. :)

Re: Bypass the protection level

2015-03-12 Thread Namespace via Digitalmars-d-learn
On Wednesday, 11 March 2015 at 15:22:43 UTC, Ali Çehreli wrote: On 03/11/2015 04:40 AM, Namespace wrote: I can call draw on Drawable, because it is declared public and I cannot call draw on Sprite because it is declared protected (this is already a bit weird, why can I redeclare the

Re: moving from c++ to D is easy?

2015-03-12 Thread Namespace via Digitalmars-d-learn
On Thursday, 12 March 2015 at 18:57:51 UTC, Ali Çehreli wrote: On 03/12/2015 06:01 AM, ayush wrote: Is D a lot like c++ ? I came to D from C++. I remember the following being notable differences: - In D, classes have reference semantics. I quickly realized that this is not an issue

Re: moving from c++ to D is easy?

2015-03-12 Thread Namespace via Digitalmars-d-learn
On Thursday, 12 March 2015 at 21:41:07 UTC, Ali Çehreli wrote: On 03/12/2015 01:19 PM, Namespace wrote: On Thursday, 12 March 2015 at 18:57:51 UTC, Ali Çehreli wrote: On 03/12/2015 06:01 AM, ayush wrote: Is D a lot like c++ ? I came to D from C++. I remember the following being notable

Re: enum and static if

2015-03-11 Thread Namespace via Digitalmars-d-learn
On Wednesday, 11 March 2015 at 14:34:32 UTC, ketmar wrote: On Wed, 11 Mar 2015 13:48:45 +, Namespace wrote: This code does not work: enum Test { Foo, static if (__VERSION__ = 2067) Bar, } Quatz } Any chance that this could work? nope. `static if` is statement,

Re: Bypass the protection level

2015-03-11 Thread Namespace via Digitalmars-d-learn
Could it be that this is intentional and has always worked?

Bypass the protection level

2015-03-11 Thread Namespace via Digitalmars-d-learn
Let's say we have these files: module Foo.Graphic.Drawable; interface Drawable { void draw(bool); } module Foo.Graphic.Sprite; import Foo.Graphic.Drawable; class Sprite : Drawable { protected: void draw(bool enable) { import core.stdc.stdio :

Re: Template. C++ to D

2015-03-11 Thread Namespace via Digitalmars-d-learn
Or even shorter: import std.stdio; T foo(T, Args...)(auto ref const T val, auto ref const Args u) { static if (Args.length 0) { static if (is(T == string)) return val ~ foo(u); else return val + foo(u); } else { return val; } } void

Re: Template. C++ to D

2015-03-11 Thread Namespace via Digitalmars-d-learn
import std.stdio; T foo(T)(auto ref const T val) { return val; } T foo(T, Args...)(auto ref const T val, auto ref const Args u) { static if (is(T == string)) return val ~ foo(u); else return val + foo(u); } void main() { writeln(foo(some , test)); // prints

enum and static if

2015-03-11 Thread Namespace via Digitalmars-d-learn
This code does not work: enum Test { Foo, static if (__VERSION__ = 2067) Bar, } Quatz } Any chance that this could work?

New package behaviour in 2.067

2015-03-10 Thread Namespace via Digitalmars-d-learn
I'm unsure, but I think this code should work: module A.B.Foo; import core.stdc.stdio : printf; struct Foo { package(A) void foo() { printf(Hallo\n); } } package(A) void bar() { printf(Hallo\n); } and module A.C.Bar; import A.B.Foo; void main() { Foo f;

Re: Will D have a serious dedicated well supported IDE like Visual Studio or Eclipse?

2015-02-26 Thread Namespace via Digitalmars-d-learn
On Thursday, 26 February 2015 at 20:55:52 UTC, Rinzler wrote: Thanks! Actually I had already seen that page, but I was asking for other open-source projects. If there's someone working on a D dedicated IDE or not. You could search on dub: http://code.dlang.org/

How can I do that in @nogc?

2015-02-25 Thread Namespace via Digitalmars-d-learn
void glCheck(lazy void func, string file = __FILE__, uint line = __LINE__) { func(); glCheckError(file, line); } How can I specify that 'func' is @nogc? Or can define the function otherwise?

Re: How can I do that in @nogc?

2015-02-25 Thread Namespace via Digitalmars-d-learn
On Wednesday, 25 February 2015 at 19:53:16 UTC, Ivan Timokhin wrote: On Wed, Feb 25, 2015 at 07:32:48PM +, Namespace wrote: void glCheck(lazy void func, string file = __FILE__, uint line = __LINE__) { func(); glCheckError(file, line); } How can I specify that

Re: How can I do that in @nogc?

2015-02-25 Thread Namespace via Digitalmars-d-learn
On Wednesday, 25 February 2015 at 20:15:10 UTC, anonymous wrote: On Wednesday, 25 February 2015 at 19:32:50 UTC, Namespace wrote: void glCheck(lazy void func, string file = __FILE__, uint line = __LINE__) { func(); glCheckError(file, line); } How can I specify that

Re: How can I do that in @nogc?

2015-02-25 Thread Namespace via Digitalmars-d-learn
On Wednesday, 25 February 2015 at 20:46:32 UTC, ketmar wrote: On Wed, 25 Feb 2015 20:36:32 +, Namespace wrote: That last thing works. But I have no clue why. o.O Anyway, thanks a lot! this is a smart hack. that should be NEVER used in production code. anyway, it's good that you don't

Re: Better native D 2D graphics library?

2015-02-09 Thread Namespace via Digitalmars-d-learn
On Monday, 9 February 2015 at 05:50:00 UTC, uri wrote: On Saturday, 7 February 2015 at 23:29:01 UTC, Namespace wrote: On Saturday, 7 February 2015 at 22:09:03 UTC, Gan wrote: Is there a better D graphics library in the works? I'm using SFML(which is very easy and has lots of features) but it

Re: Better native D 2D graphics library?

2015-02-08 Thread Namespace via Digitalmars-d-learn
On Sunday, 8 February 2015 at 01:39:19 UTC, Gan wrote: On Saturday, 7 February 2015 at 23:29:01 UTC, Namespace wrote: On Saturday, 7 February 2015 at 22:09:03 UTC, Gan wrote: Is there a better D graphics library in the works? I'm using SFML(which is very easy and has lots of features) but it

Re: Better native D 2D graphics library?

2015-02-08 Thread Namespace via Digitalmars-d-learn
Let me hear what comes out. ;)

  1   2   >