Re: Is it possible to avoid call to destructor for structs?

2017-09-27 Thread Elronnd via Digitalmars-d-learn
Here's a simple solution. Just make Bar a pointer and free it before it can be destructed! import std.stdio; struct Bar { ~this() { writeln("~bar"); } } struct Foo { Bar *bar; this(int why_the_fuck_dont_structs_have_default_constructors) { bar = new Bar;

Re: Is it possible to avoid call to destructor for structs?

2017-09-27 Thread Elronnd via Digitalmars-d-learn
Here's a simple solution. Just make Bar a pointer and free it before it can be destructed! import std.stdio; struct Bar { ~this() { writeln("~bar"); } } struct Foo { Bar *bar; this(int why_the_fuck_dont_structs_have_default_constructors) { bar = new Bar;

Re: Is it possible to specify the address returned by the address of operator?

2017-09-27 Thread DreadKyller via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 23:24:58 UTC, user1234 wrote: On Wednesday, 27 September 2017 at 21:01:36 UTC, Jesse Phillips wrote: On Wednesday, 27 September 2017 at 16:35:54 UTC, DreadKyller wrote: My question is about overloading, several operators can be overloaded in D, one of the

Re: Is it possible to specify the address returned by the address of operator?

2017-09-27 Thread user1234 via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 21:01:36 UTC, Jesse Phillips wrote: On Wednesday, 27 September 2017 at 16:35:54 UTC, DreadKyller wrote: My question is about overloading, several operators can be overloaded in D, one of the ones that can't apparently is the address of operator (). My

Re: What does ! mean?

2017-09-27 Thread Arun Chandrasekaran via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 14:34:06 UTC, Eugene Wissner wrote: On Wednesday, 27 September 2017 at 14:23:01 UTC, Ky-Anh Huynh wrote: See also the following chapter in Ali's book: http://ddili.org/ders/d.en/templates.html This chapter is what hooked me with D. Naming that chapter as

Re: What does ! mean?

2017-09-27 Thread Mengu via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 17:58:27 UTC, Ali Çehreli wrote: On 09/27/2017 08:33 AM, Ky-Anh Huynh wrote: > [...] Wissner wrote: > [...] The fact that such an important operator is explained so late in the book is due to the book's strong desire to have a linear flow. [...] ustad,

Re: What does ! mean?

2017-09-27 Thread Ali Çehreli via Digitalmars-d-learn
On 09/27/2017 03:06 PM, Mengu wrote: ustad, guess you can still write the new ed. :-) Since you're still around, one of these days... :) Ali

Re: Is it possible to specify the address returned by the address of operator?

2017-09-27 Thread DreadKyller via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 21:18:50 UTC, nkm1 wrote: On Wednesday, 27 September 2017 at 20:24:24 UTC, DreadKyller wrote: The attitude of "some people use this feature incorrectly, so let's ban it's use entirely" is honestly ridiculous to me, but oh well, that's apparently the modern

Re: Allocating byte aligned array

2017-09-27 Thread timvol via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 21:44:48 UTC, Ali Çehreli wrote: On 09/27/2017 02:39 PM, timvol wrote: [...] void main() { auto mem = new ubyte[1024+15]; auto ptr = cast(ubyte*)(cast(ulong)(mem.ptr + 15) & ~0x0FUL); auto arr = ptr[0..1024]; } Ali Works perfect. Thank you!

Re: Allocating byte aligned array

2017-09-27 Thread Ali Çehreli via Digitalmars-d-learn
On 09/27/2017 02:39 PM, timvol wrote: Hi guys, how can I allocate an (e.g. 16) byte aligned array? In C I can do the following: void *mem = malloc(1024+15); void *ptr = ((uintptr_t)mem+15) & ~ (uintptr_t)0x0F; memset_16aligned(ptr, 0, 1024); free(mem); I think in D it looks

Allocating byte aligned array

2017-09-27 Thread timvol via Digitalmars-d-learn
Hi guys, how can I allocate an (e.g. 16) byte aligned array? In C I can do the following: void *mem = malloc(1024+15); void *ptr = ((uintptr_t)mem+15) & ~ (uintptr_t)0x0F; memset_16aligned(ptr, 0, 1024); free(mem); I think in D it looks similar to this: auto mem = new

Re: Is it possible to specify the address returned by the address of operator?

2017-09-27 Thread nkm1 via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 20:24:24 UTC, DreadKyller wrote: The attitude of "some people use this feature incorrectly, so let's ban it's use entirely" is honestly ridiculous to me, but oh well, that's apparently the modern philosophy. Not even modern, see Java :) ("I left out operator

Re: Is it possible to specify the address returned by the address of operator?

2017-09-27 Thread DreadKyller via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 21:01:36 UTC, Jesse Phillips wrote: For example, if you store your Matrix in a custom container it could try to store pointer rather than the struct itself, if & is overloaded the generic implementation would be broken because it would no longer be a pointer

Re: Is it possible to specify the address returned by the address of operator?

2017-09-27 Thread Jesse Phillips via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 16:35:54 UTC, DreadKyller wrote: My question is about overloading, several operators can be overloaded in D, one of the ones that can't apparently is the address of operator (). My question is have I simply missed it or does it actually not exist, and if it's

Re: Is it possible to specify the address returned by the address of operator?

2017-09-27 Thread DreadKyller via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 19:55:07 UTC, nkm1 wrote: On Wednesday, 27 September 2017 at 16:35:54 UTC, DreadKyller wrote: Been using D for a couple years now, however one problem I've had, more so recently since I've been dealing a lot with OpenGL is related to pointers. I have a

Re: Is it possible to specify the address returned by the address of operator?

2017-09-27 Thread nkm1 via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 16:35:54 UTC, DreadKyller wrote: Been using D for a couple years now, however one problem I've had, more so recently since I've been dealing a lot with OpenGL is related to pointers. I have a matrix object to aid with the matrix math required for working

Inter-module symbol resolution error of template type-parameter when using mixins

2017-09-27 Thread Nordlöw via Digitalmars-d-learn
At https://github.com/nordlow/phobos-next/blob/03b4736fdd65ef84c6fc583eddee4196629cea81/src/variant_arrays.d I've implemented a lightweight-polymorphic array container I call `VariantArrays(Types...)` indexed by a corresponding polymorphic index I call `VariantIndex(Types...)`. It uses

Re: What does ! mean?

2017-09-27 Thread Ali Çehreli via Digitalmars-d-learn
On 09/27/2017 08:33 AM, Ky-Anh Huynh wrote: > On Wednesday, 27 September 2017 at 14:34:06 UTC, Eugene Wissner wrote: >> >> See also the following chapter in Ali's book: >> http://ddili.org/ders/d.en/templates.html > > Thanks a lot. I will keep reading :) The fact that such an important operator

Is it possible to specify the address returned by the address of operator?

2017-09-27 Thread DreadKyller via Digitalmars-d-learn
Been using D for a couple years now, however one problem I've had, more so recently since I've been dealing a lot with OpenGL is related to pointers. I have a matrix object to aid with the matrix math required for working with 3D transforms. However OpenGL (I'm using DerelictGL3 bindings)

Re: Can I skip sub directories with file.dirEntries() ?

2017-09-27 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 10:05:34 UTC, Nicholas Wilson wrote: I'd just use dirEntries with SpanMode.shallow in combination with filter either in a loop or a recursive function like below. void foo(string path = "path") { foreach(e;

Re: What does ! mean?

2017-09-27 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 14:23:01 UTC, Ky-Anh Huynh wrote: Can you please explain and give any link where I can learn more about these things? Thanks a lot. http://nomad.so/2013/07/templates-in-d-explained/

Re: What does ! mean?

2017-09-27 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 14:34:06 UTC, Eugene Wissner wrote: See also the following chapter in Ali's book: http://ddili.org/ders/d.en/templates.html Thanks a lot. I will keep reading :)

Re: What does ! mean?

2017-09-27 Thread Eugene Wissner via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 14:23:01 UTC, Ky-Anh Huynh wrote: Hi, I am from Ruby world where I can have `!` (or `?`) in method names: `!` indicates that a method would modify its object (`foo.upcase!` means `foo = foo.upcase`). ( I don't know if there is any official Ruby

Re: What does ! mean?

2017-09-27 Thread rikki cattermole via Digitalmars-d-learn
There are two types of arguments in D. The runtime one (which you are well aware of) and the compile time one. A compile time argument is a constant passed in during construction of a symbol. But here is the thing, it isn't just limited to functions, you can have it on classes as well. ---

What does ! mean?

2017-09-27 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hi, I am from Ruby world where I can have `!` (or `?`) in method names: `!` indicates that a method would modify its object (`foo.upcase!` means `foo = foo.upcase`). ( I don't know if there is any official Ruby documentation on this convention though. ) In D I see `!` quite a lot. I have

Sectioned variables?

2017-09-27 Thread Arav Ka via Digitalmars-d-learn
GCC supports a `__attribute((section("...")))` for variables to put them in specific sections in the final assembly. Is there any way this can be achieved in D? Does GDC support this?

Re: Can I skip sub directories with file.dirEntries() ?

2017-09-27 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 09:00:55 UTC, Ky-Anh Huynh wrote: Hi, Can I have a `break` option when using `dirEntries()` (similar to `break` in a loop)? I want to study sub-directories but if any sub-directory matches my criteria I don't to look further into their subdirectories ```

Can I skip sub directories with file.dirEntries() ?

2017-09-27 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hi, Can I have a `break` option when using `dirEntries()` (similar to `break` in a loop)? I want to study sub-directories but if any sub-directory matches my criteria I don't to look further into their subdirectories ``` A/ -> matches criteria, stop here, go to next directory (B)