Re: Having "in" for arrays

2017-11-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, November 22, 2017 08:03:50 Fra Mecca via Digitalmars-d-learn wrote: > Why doesn't D have a in keyword for arrays? > > The docs explains that you can use in only for associative arrays > but I don't see the reasons for such decision. > > > Example code: > > void main() > { > auto v

Re: Having "in" for arrays

2017-11-22 Thread lobo via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 09:36:43 UTC, Dukc wrote: On Wednesday, 22 November 2017 at 08:03:50 UTC, Fra Mecca wrote: void main() { auto v = ["r", "i", "o"]; assert ("r" in v); } Also note that even if it wereimplemented, you search for 'r' instead of "r". "r" is a

Re: interfacing c++

2017-11-22 Thread MGW via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 08:29:26 UTC, MGW wrote: Possibly it will be interesting https://pp.userapi.com/c639524/v639524332/60240/uH3jnxrchik.jpg

Re: interfacing c++

2017-11-22 Thread MGW via Digitalmars-d-learn
On Tuesday, 21 November 2017 at 23:12:33 UTC, Markus wrote: hi, im trying to interface a cpp class. I'd like to interface a bigger library and I'm trying to figure out the minimum effort. Possibly it will be interesting https://www.youtube.com/watch?v=HTgJaRRfLPk

Re: interfacing c++

2017-11-22 Thread drug via Digitalmars-d-learn
22.11.2017 02:12, Markus пишет: snip I could do the instancing/destruction by functions and write a custom d class that calls these methods in this()/~this(). This is what I used to do as special members like ctor/dtor did not supported in D before, but your example of using ctor is

Re: Having "in" for arrays

2017-11-22 Thread Dukc via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 08:03:50 UTC, Fra Mecca wrote: void main() { auto v = ["r", "i", "o"]; assert ("r" in v); } Also note that even if it wereimplemented, you search for 'r' instead of "r". "r" is a string, but you would want to search for a char.

Re: Error: 'this' is only defined in non-static member functions

2017-11-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/22/17 5:19 PM, A Guy With a Question wrote: I have an interface where I have a classes embedded in it's scope (trying to create something for the classes that implement the interface can use for unittesting).     interface IExample     {     // stuff ...     class Tester    

Re: Can I count the of enum's fields at compile time?

2017-11-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, November 23, 2017 00:58:21 Marc via Digitalmars-d-learn wrote: > for example: > > enum A { a = -10, b = -11, c = -12, d = -13, e = -34} > > enum int countOfA = coutOfFields(A); // 5 fields import std.traits; enum countOfA = EnumMembers!A.length; - Jonathna M Davis

Re: Error: 'this' is only defined in non-static member functions

2017-11-22 Thread A Guy With a Question via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 22:45:53 UTC, A Guy With a Question wrote: On Wednesday, 22 November 2017 at 22:37:46 UTC, Steven Schveighoffer wrote: On 11/22/17 5:36 PM, Steven Schveighoffer wrote: This allows access to the outer class's members. So you need an instance to instantiate. I

Re: Can I count the of enum's fields at compile time?

2017-11-22 Thread Michael V. Franklin via Digitalmars-d-learn
On Thursday, 23 November 2017 at 00:58:21 UTC, Marc wrote: for example: enum A { a = -10, b = -11, c = -12, d = -13, e = -34} enum int countOfA = coutOfFields(A); // 5 fields https://dlang.org/spec/traits.html#allMembers enum A { a = -10, b = -11, c = -12, d = -13, e = -34} enum int

Re: Error: 'this' is only defined in non-static member functions

2017-11-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, November 23, 2017 00:49:33 Mike Parker via Digitalmars-d-learn wrote: > On Wednesday, 22 November 2017 at 22:45:53 UTC, A Guy With a > > Question wrote: > > Out of curiosity, what does static mean in that context? When I > > think of a static class I think of them in the context of

Error: 'this' is only defined in non-static member functions

2017-11-22 Thread A Guy With a Question via Digitalmars-d-learn
I have an interface where I have a classes embedded in it's scope (trying to create something for the classes that implement the interface can use for unittesting). interface IExample { // stuff ... class Tester { } } I'm trying to make an instance

Re: Error: 'this' is only defined in non-static member functions

2017-11-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/22/17 5:36 PM, Steven Schveighoffer wrote: This allows access to the outer class's members. So you need an instance to instantiate. I bet it's the same for interfaces. All that being said, the error message is quite lousy. -Steve

Re: Error: 'this' is only defined in non-static member functions

2017-11-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, November 22, 2017 22:45:53 A Guy With a Question via Digitalmars-d-learn wrote: > On Wednesday, 22 November 2017 at 22:37:46 UTC, Steven > > Schveighoffer wrote: > > On 11/22/17 5:36 PM, Steven Schveighoffer wrote: > >> This allows access to the outer class's members. So you need >

Re: Error: 'this' is only defined in non-static member functions

2017-11-22 Thread A Guy With a Question via Digitalmars-d-learn
here as non-static, nested class is associated with a specific instance of the class and has access to that class instance via its outer member. - Jonathan M Davis Hmmm...now you have me very intrigued. What is a use-case where you'd want to use a non-static embedded class? Sorry if I'm

Re: Error: 'this' is only defined in non-static member functions

2017-11-22 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 22:45:53 UTC, A Guy With a Question wrote: Out of curiosity, what does static mean in that context? When I think of a static class I think of them in the context of Java or C# where they can't be instantiated and where they are more like namespaces that you

Re: Error: 'this' is only defined in non-static member functions

2017-11-22 Thread A Guy With a Question via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 22:37:46 UTC, Steven Schveighoffer wrote: On 11/22/17 5:36 PM, Steven Schveighoffer wrote: This allows access to the outer class's members. So you need an instance to instantiate. I bet it's the same for interfaces. All that being said, the error message is

Re: Error: 'this' is only defined in non-static member functions

2017-11-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, November 23, 2017 00:17:46 A Guy With a Question via Digitalmars-d-learn wrote: > > here as non-static, nested class is associated with a specific > > instance of the class and has access to that class instance via > > its outer member. > > > > - Jonathan M Davis > > Hmmm...now you

Can I count the of enum's fields at compile time?

2017-11-22 Thread Marc via Digitalmars-d-learn
for example: enum A { a = -10, b = -11, c = -12, d = -13, e = -34} enum int countOfA = coutOfFields(A); // 5 fields

Re: Can I count the of enum's fields at compile time?

2017-11-22 Thread Marc via Digitalmars-d-learn
On Thursday, 23 November 2017 at 01:04:29 UTC, Jonathan M Davis wrote: On Thursday, November 23, 2017 00:58:21 Marc via Digitalmars-d-learn wrote: for example: enum A { a = -10, b = -11, c = -12, d = -13, e = -34} enum int countOfA = coutOfFields(A); // 5 fields import std.traits; enum

Re: Can I count the of enum's fields at compile time?

2017-11-22 Thread Ali Çehreli via Digitalmars-d-learn
On 11/22/2017 05:21 PM, Marc wrote: On Thursday, 23 November 2017 at 01:04:29 UTC, Jonathan M Davis wrote: On Thursday, November 23, 2017 00:58:21 Marc via Digitalmars-d-learn wrote: for example: enum A { a = -10, b = -11, c = -12, d = -13, e = -34} enum int countOfA = coutOfFields(A); // 5

Re: Having "in" for arrays

2017-11-22 Thread Dukc via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 10:32:48 UTC, lobo wrote: On Wednesday, 22 November 2017 at 09:36:43 UTC, Dukc wrote: On Wednesday, 22 November 2017 at 08:03:50 UTC, Fra Mecca wrote: void main() { auto v = ["r", "i", "o"]; assert ("r" in v); } Also note that even if it

Re: writeln, alias this and dynamic arrays.

2017-11-22 Thread matthewh via Digitalmars-d-learn
Thank you all for the helpful responses. I will read more about ranges.

Re: Can I count the of enum's fields at compile time?

2017-11-22 Thread Marc via Digitalmars-d-learn
On Thursday, 23 November 2017 at 01:01:42 UTC, Michael V. Franklin wrote: On Thursday, 23 November 2017 at 00:58:21 UTC, Marc wrote: for example: enum A { a = -10, b = -11, c = -12, d = -13, e = -34} enum int countOfA = coutOfFields(A); // 5 fields

Re: Can I count the of enum's fields at compile time?

2017-11-22 Thread Marc via Digitalmars-d-learn
On Thursday, 23 November 2017 at 01:34:54 UTC, Ali Çehreli wrote: On 11/22/2017 05:21 PM, Marc wrote: On Thursday, 23 November 2017 at 01:04:29 UTC, Jonathan M Davis wrote: On Thursday, November 23, 2017 00:58:21 Marc via Digitalmars-d-learn wrote: [...] import std.traits; enum countOfA =

reduce condition nesting

2017-11-22 Thread Andrey via Digitalmars-d-learn
Hello, is there way to reduce this condition: if (c1) { foo(); } else { if (c2) { bar(); } else { if (c3) { ... } } } for instance in kotlin it can be replace with this: when { c1 -> foo(), c2 -> bar(), c3 -> ... else ->

Re: reduce condition nesting

2017-11-22 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 23 November 2017 at 05:19:27 UTC, Andrey wrote: Hello, is there way to reduce this condition: if (c1) { foo(); } else { if (c2) { bar(); } else { if (c3) { ... } } } for instance in kotlin it can be replace with this: when { c1

glfwSetDropCallback undefined symbol

2017-11-22 Thread Tim Hsu via Digitalmars-d-learn
DCD and DMD says that the symbol is undefined! However, I look into derelichtGLFW3. It has this symbol defined! It looks like a bug for me!

Re: Passing this to void *

2017-11-22 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:07:08 UTC, Tim Hsu wrote: I am a C++ game developer and I want to give it a try. It seems "this" in Dlang is a reference instead of pointer. How can I pass it as void *? void foo(void *); class Pizza { public: this() { Pizza newone = this;

Is d-apt.sourceforge.net functional?

2017-11-22 Thread Kai via Digitalmars-d-learn
I couldn't find the d-apt-keyring package anywhere root@d9:~# cat /etc/apt/sources.list.d/d-apt.list deb http://master.dl.sourceforge.net/project/d-apt/ d-apt main #APT repository for D root@d9:~# LANG=C apt-get -y --allow-unauthenticated install --reinstall d-apt-keyring Reading package

Re: betterC and noboundscheck

2017-11-22 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 16:57:10 UTC, Joakim wrote: On Wednesday, 22 November 2017 at 15:10:40 UTC, Oleg B wrote: [...] betterC is a new feature that's still being worked on and still has holes in it: https://github.com/dlang/dmd/pull/7151 I suggest you open an issue for it on

Re: Passing this to void *

2017-11-22 Thread Tim Hsu via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:14:32 UTC, Stefan Koch wrote: On Wednesday, 22 November 2017 at 15:11:08 UTC, Tim Hsu wrote: On Wednesday, 22 November 2017 at 15:07:54 UTC, Stefan Koch will do. I've tried it in the first place. ... Error: this is not an lvalue In that case casting

Re: Passing this to void *

2017-11-22 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:23:58 UTC, Tim Hsu wrote: I am afraid what will happen when casting this reference to void * a ref is a ptr. The cast will produce a ptr which is valid as long as the ref is valid.

Passing this to void *

2017-11-22 Thread Tim Hsu via Digitalmars-d-learn
I am a C++ game developer and I want to give it a try. It seems "this" in Dlang is a reference instead of pointer. How can I pass it as void *? void foo(void *); class Pizza { public: this() { Pizza newone = this; // works but newone is actually not this pizza.

Re: Passing this to void *

2017-11-22 Thread Tim Hsu via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:27:27 UTC, Dukc wrote: On Wednesday, 22 November 2017 at 15:17:33 UTC, Adam D. Ruppe wrote: On Wednesday, 22 November 2017 at 15:07:54 UTC, Stefan Koch wrote: will do. Even if it were an lvalue, that would be the address of a local. You should basically

Re: dmd/ldc failed with exit code -11

2017-11-22 Thread Anonymouse via Digitalmars-d-learn
On Tuesday, 21 November 2017 at 19:22:47 UTC, Anonymouse wrote: Compiling a debug dmd and running the build command in gdb, it seems to be a stack overflow at ddmd/dtemplate.d:6241, TemplateInstance::needsCodegen(). After a lot of trial and error I managed to find /a/ line which lets it

Re: Passing this to void *

2017-11-22 Thread Tim Hsu via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:07:54 UTC, Stefan Koch wrote: On Wednesday, 22 November 2017 at 15:07:08 UTC, Tim Hsu wrote: I am a C++ game developer and I want to give it a try. It seems "this" in Dlang is a reference instead of pointer. How can I pass it as void *? void foo(void *);

Re: Passing this to void *

2017-11-22 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:11:08 UTC, Tim Hsu wrote: On Wednesday, 22 November 2017 at 15:07:54 UTC, Stefan Koch will do. I've tried it in the first place. ... Error: this is not an lvalue In that case casting to void* should be fine.

Re: betterC and noboundscheck

2017-11-22 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:10:40 UTC, Oleg B wrote: Why -betterC flag not 'include' -noboundscheck flag? -noboundscheck is extremely harmful. If -betterC implied that, it would no longer be a better C, it would just be the same buggy C. The compiler should perhaps inline the

Re: Passing this to void *

2017-11-22 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:07:54 UTC, Stefan Koch wrote: will do. Even if it were an lvalue, that would be the address of a local. You should basically NEVER do that with D classes. Just `cast(void*) this` if you must pass it to such a function.

Re: Passing this to void *

2017-11-22 Thread Tim Hsu via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:17:33 UTC, Adam D. Ruppe wrote: On Wednesday, 22 November 2017 at 15:07:54 UTC, Stefan Koch wrote: will do. Even if it were an lvalue, that would be the address of a local. You should basically NEVER do that with D classes. Just `cast(void*) this` if

Re: Passing this to void *

2017-11-22 Thread Dukc via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:17:33 UTC, Adam D. Ruppe wrote: On Wednesday, 22 November 2017 at 15:07:54 UTC, Stefan Koch wrote: will do. Even if it were an lvalue, that would be the address of a local. You should basically NEVER do that with D classes. Just `cast(void*) this` if

Re: Passing this to void *

2017-11-22 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:07:08 UTC, Tim Hsu wrote: I am a C++ game developer and I want to give it a try. It seems "this" in Dlang is a reference instead of pointer. How can I pass it as void *? void foo(void *); class Pizza { public: this() { Pizza newone = this;

betterC and noboundscheck

2017-11-22 Thread Oleg B via Digitalmars-d-learn
Hello. I try compile simple example: import core.stdc.stdio; import std.algorithm : min; extern (C) void main() { char[256] buf; buf[] = '\0'; auto str = "hello world"; auto ln = min(buf.length, str.length); buf[0..ln] = str[0..ln]; printf("%s\n", buf.ptr); } rdmd

Re: Passing this to void *

2017-11-22 Thread Tim Hsu via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:36:22 UTC, Adam D. Ruppe wrote: On Wednesday, 22 November 2017 at 15:31:36 UTC, Tim Hsu wrote: It seems in D, reference has its own address, am I right? unlike c++ The local variable does have its own address. Do not take its address - avoid or Just

Re: Passing this to void *

2017-11-22 Thread Dukc via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:31:36 UTC, Tim Hsu wrote: It seems in D, reference has its own address, am I right? unlike c++ In case of classes, yes. But I think function parameter references do not (or rather, of course they have since they exist in memory but it's hidden). Not sure

Re: ESR on post-C landscape

2017-11-22 Thread Kagamin via Digitalmars-d-learn
Also http://ithare.com/chapter-vb-modular-architecture-client-side-programming-languages-for-games-including-resilience-to-reverse-engineering-and-portability/ scroll to the part about language choice.

Re: Passing this to void *

2017-11-22 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:27:27 UTC, Dukc wrote: It's worth noting that you will still be passing different addresses to foo(void*) because classes are reference types in D (structs are not). In the constructor you're passing the address of the class object itself, but in the main

Re: Passing this to void *

2017-11-22 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:23:58 UTC, Tim Hsu wrote: m_window = glfwCreateWindow(); glfwSetWindowUserPointer(m_window, cast(void *)()); That that & out of there! glfwSetWindowUserPointer(m_window, cast(void *)(this)); without the &, you are fine. Then, on the other side,

Re: interfacing c++

2017-11-22 Thread Markus via Digitalmars-d-learn
another indicator (as documented) that GC destructor won't work // extern(C++) classes don't have a classinfo pointer in their vtable so the GC can't finalize them https://github.com/dlang/druntime/blob/3d8d4a45c01832fb657c16a656b6e1566d77fb21/src/rt/lifetime.d#L90 annoying :( Markus

Re: Passing this to void *

2017-11-22 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:31:36 UTC, Tim Hsu wrote: It seems in D, reference has its own address, am I right? unlike c++ The local variable does have its own address. Do not take its address - avoid or Just cast the ref itself. In D, a class this or Object variable is already

Re: Passing this to void *

2017-11-22 Thread Dukc via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:34:53 UTC, Adam D. Ruppe wrote: No, in both cases, if you do as I say, you will be passing the same address. I was referring to his version of the main function that used &. But yes, if you do a cast instead it works just as you say.

Re: dmd/ldc failed with exit code -11

2017-11-22 Thread Petar via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:33:46 UTC, Anonymouse wrote: On Tuesday, 21 November 2017 at 19:22:47 UTC, Anonymouse wrote: Compiling a debug dmd and running the build command in gdb, it seems to be a stack overflow at ddmd/dtemplate.d:6241, TemplateInstance::needsCodegen(). After a

Re: interfacing c++

2017-11-22 Thread Markus via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 08:43:54 UTC, drug wrote: 22.11.2017 02:12, Markus пишет: What about dtor - you allocate class using D GC but try to destroy it manually - namely this I guess gives you an error in rt_finalize2 because it tries to destroy object that has been destroyed.

Re: interfacing c++

2017-11-22 Thread drug via Digitalmars-d-learn
22.11.2017 19:06, Markus пишет: another indicator (as documented) that GC destructor won't work // extern(C++) classes don't have a classinfo pointer in their vtable so the GC can't finalize them

Re: betterC and noboundscheck

2017-11-22 Thread Joakim via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:10:40 UTC, Oleg B wrote: Hello. I try compile simple example: import core.stdc.stdio; import std.algorithm : min; extern (C) void main() { char[256] buf; buf[] = '\0'; auto str = "hello world"; auto ln = min(buf.length, str.length);