Re: Type-Safer Modern High-Level Performant OpenGL

2014-03-06 Thread Mike Parker
On 3/7/2014 8:16 AM, "Nordlöw" wrote: GFM (my own, PLEASE, PLEASE CHOOSE ME) I'm trying to build your package using dub but I get the error θ61° [per:~/justd/gfm] master ± dub Error executing command run: Main package must have a binary target type, not none. Cannot build. I'm using a

Re: Best way to reference an array in a child class...

2014-03-06 Thread captain_fid
On Friday, 7 March 2014 at 00:10:20 UTC, bearophile wrote: captain_fid: struct S { int a; string b; } class A { S[] items; abstract void doit(); } class B: A { this() {items = [ {10, "first"}, {20, "second"}];}// line 21 override void doit() { } } (21): Error: found '}' when

Re: Best way to reference an array in a child class...

2014-03-06 Thread bearophile
captain_fid: struct S { int a; string b; } class A { S[] items; abstract void doit(); } class B: A { this() {items = [ {10, "first"}, {20, "second"}];}// line 21 override void doit() { } } (21): Error: found '}' when expecting ';' following statement (21): Error: found '

Re: Best way to reference an array in a child class...

2014-03-06 Thread captain_fid
Well, actually... take it back. When I did try this syntax, I receive(d) the following error. I then went and created this test which I thought couldn't go wrong. with both dmd and gdc ... struct S { int a; string b; } class A { S[] items; abstract void doit(); } class B: A {

Re: Type-Safer Modern High-Level Performant OpenGL

2014-03-06 Thread Nordlöw
GFM (my own, PLEASE, PLEASE CHOOSE ME) I'm trying to build your package using dub but I get the error θ61° [per:~/justd/gfm] master ± dub Error executing command run: Main package must have a binary target type, not none. Cannot build. I'm using a recent build of dub from git master.

Re: Type-Safer Modern High-Level Performant OpenGL

2014-03-06 Thread Nordlöw
On thing though...why did you choose SDL2 of GLFW3? I of course mean SDL2 *over* GLFW3.

Re: Type-Safer Modern High-Level Performant OpenGL

2014-03-06 Thread Nordlöw
GFM (my own, PLEASE, PLEASE CHOOSE ME) From what I've seen so far I like the structure of GFM the most :) On thing though...why did you choose SDL2 of GLFW3?

Re: Best way to reference an array in a child class...

2014-03-06 Thread captain_fid
this() {items = [ {10, "first"}, {20, "second"}];} strangely enough, when modeling this the first time (using items as a class) and 'new item() syntax) there was no real issue. I thought using a static array of structs in the children would be more efficient when instantiating the objec

Re: Best way to reference an array in a child class...

2014-03-06 Thread captain_fid
On Thursday, 6 March 2014 at 22:16:50 UTC, Steven Schveighoffer wrote: On Thu, 06 Mar 2014 17:05:12 -0500, captain_fid wrote: On Thursday, 6 March 2014 at 21:26:11 UTC, Ali Çehreli wrote: On 03/06/2014 12:02 PM, Steven Schveighoffer wrote: > The best way > to reference an array in a child c

Re: Best way to reference an array in a child class...

2014-03-06 Thread Ali Çehreli
On 03/06/2014 02:05 PM, captain_fid wrote: > Your suggestion Ali (of not accessing the base member in the child was > great) and it works properly. > > Believe if I understand what you are suggesting above is never to have > the array in base? simply retrieve slice through the child member funct

Re: Type-Safer Modern High-Level Performant OpenGL

2014-03-06 Thread ponce
On Thursday, 6 March 2014 at 21:30:01 UTC, Nordlöw wrote: Does anybody have some sample code (example or project) lying around that shows modern use of OpenGL (3 or 4) using some or all of the following libraries: - DerelictGL3 (Org) - DerelictGLFW3 (Org) - Glamour - gl3n I'm planning a graph

Re: Best way to reference an array in a child class...

2014-03-06 Thread Steven Schveighoffer
On Thu, 06 Mar 2014 17:05:12 -0500, captain_fid wrote: On Thursday, 6 March 2014 at 21:26:11 UTC, Ali Çehreli wrote: On 03/06/2014 12:02 PM, Steven Schveighoffer wrote: > The best way > to reference an array in a child class, especially one of a static type, > is to not have another copy in t

Re: Best way to reference an array in a child class...

2014-03-06 Thread captain_fid
On Thursday, 6 March 2014 at 21:26:11 UTC, Ali Çehreli wrote: On 03/06/2014 12:02 PM, Steven Schveighoffer wrote: > The best way > to reference an array in a child class, especially one of a static type, > is to not have another copy in the child class :) Agreed. Alternatively, a member functio

Re: fix struct API with an interface

2014-03-06 Thread Xavier Bigand
Le 06/03/2014 19:08, Dicebot a écrit : On Thursday, 6 March 2014 at 14:28:13 UTC, Flamaros wrote: Ok, it's like I though final class and struct are equivalent when calling a method (except the pointer deference, but it's minor I think). I don't think there is a real performance problem for us,

Re: Type-Safer Modern High-Level Performant OpenGL

2014-03-06 Thread Namespace
Dgame use VBO's and VBA's for the TileMap: http://dgame-dev.de/?package=System&module=VertexBufferObject http://dgame-dev.de/?package=System&module=VertexArrayObject http://dgame-dev.de/?package=System&module=VertexRenderer http://dgame-dev.de/?package=Graphics&module=TileMap and it has a FrameBu

Type-Safer Modern High-Level Performant OpenGL

2014-03-06 Thread Nordlöw
Does anybody have some sample code (example or project) lying around that shows modern use of OpenGL (3 or 4) using some or all of the following libraries: - DerelictGL3 (Org) - DerelictGLFW3 (Org) - Glamour - gl3n I'm planning a graph visualization engine in D and I would like to use as high

Re: Best way to reference an array in a child class...

2014-03-06 Thread Ali Çehreli
On 03/06/2014 12:02 PM, Steven Schveighoffer wrote: > The best way > to reference an array in a child class, especially one of a static type, > is to not have another copy in the child class :) Agreed. Alternatively, a member function in the child class could return a slice. Ali

Re: Forwarding or merging 'this' into a child class to aid chaining methods?

2014-03-06 Thread Gary Willoughby
On Thursday, 6 March 2014 at 19:16:07 UTC, anonymous wrote: public auto foo(this T)() { return cast(T) this; } http://dlang.org/template.html#TemplateThisParameter Nice! This seems to be what i was after and it works well.

Re: Best way to reference an array in a child class...

2014-03-06 Thread captain_fid
Steve and Ali, Thanks for the quick helpful suggestions. In this case I probably don't need the expansion (but certainly look forward to understanding either way). I'll certainly hit that reference (Special thanks Ali for your book. I've enjoyed it over the past few months)

Re: Best way to reference an array in a child class...

2014-03-06 Thread Steven Schveighoffer
On Thu, 06 Mar 2014 15:02:14 -0500, Steven Schveighoffer wrote: Second, it's very difficult to get an array, just by itself, in the heap. And you don't want to store a reference to a stack-frame slice. Sorry, I meant an array *reference*, not an array. Clearly allocating an array in the

Re: Best way to reference an array in a child class...

2014-03-06 Thread Steven Schveighoffer
On Thu, 06 Mar 2014 14:47:49 -0500, Ali Çehreli wrote: On 03/06/2014 11:40 AM, Steven Schveighoffer wrote: >> class A >> { >>S[]* pointer_to_list; >>abstract... >> } > I would highly suggest to just use S[] and not S[]*. A slice is already > a reference (coupled with a lengt

Re: Forwarding or merging 'this' into a child class to aid chaining methods?

2014-03-06 Thread anonymous
On Thursday, 6 March 2014 at 19:30:25 UTC, Ali Çehreli wrote: On 03/06/2014 11:16 AM, anonymous wrote: [...] > http://dlang.org/template.html#TemplateThisParameter [...] "type of the this reference" does not explain that it is about the type of the most derived object. Well, it isn't. It wo

Re: Best way to reference an array in a child class...

2014-03-06 Thread Ali Çehreli
On 03/06/2014 11:40 AM, Steven Schveighoffer wrote: >> class A >> { >>S[]* pointer_to_list; >>abstract... >> } > I would highly suggest to just use S[] and not S[]*. A slice is already > a reference (coupled with a length). But what if there are elements added to B.items later on? I ass

Re: Best way to reference an array in a child class...

2014-03-06 Thread Steven Schveighoffer
On Thu, 06 Mar 2014 14:31:52 -0500, captain_fid wrote: On Thursday, 6 March 2014 at 19:19:29 UTC, captain_fid wrote: Sorry for the very basic question. Much still alludes me with this language. I appreciate the forum. struct S { Wow sorry for that. I'm a moron... don't press ... struct

Re: Best way to reference an array in a child class...

2014-03-06 Thread Ali Çehreli
On 03/06/2014 11:31 AM, captain_fid wrote: On Thursday, 6 March 2014 at 19:19:29 UTC, captain_fid wrote: Sorry for the very basic question. Much still alludes me with this language. I appreciate the forum. struct S { Wow sorry for that. I'm a moron... don't press ... struct S { int a;

Re: Forwarding or merging 'this' into a child class to aid chaining methods?

2014-03-06 Thread Steven Schveighoffer
On Thu, 06 Mar 2014 14:04:48 -0500, Gary Willoughby wrote: I'm trying to create methods across class hierarchies that can be chained nicely but i'm running into the problem that 'this' declared in a parent class only refers to that type. Is there a way i can get the following code to perfo

Re: Best way to reference an array in a child class...

2014-03-06 Thread captain_fid
On Thursday, 6 March 2014 at 19:19:29 UTC, captain_fid wrote: Sorry for the very basic question. Much still alludes me with this language. I appreciate the forum. struct S { Wow sorry for that. I'm a moron... don't press ... struct S { int a; string b; } class A { S[]* pointer_to_lis

Re: Forwarding or merging 'this' into a child class to aid chaining methods?

2014-03-06 Thread Ali Çehreli
On 03/06/2014 11:16 AM, anonymous wrote: > public auto foo(this T)() > { > return cast(T) this; > } > > http://dlang.org/template.html#TemplateThisParameter Sweet! :) Unfortunately, it has a somewhat obfuscated definition: "TemplateThisParameters are used in member funct

Best way to reference an array in a child class...

2014-03-06 Thread captain_fid
Sorry for the very basic question. Much still alludes me with this language. I appreciate the forum. struct S {

Re: Forwarding or merging 'this' into a child class to aid chaining methods?

2014-03-06 Thread anonymous
On Thursday, 6 March 2014 at 19:04:50 UTC, Gary Willoughby wrote: I'm trying to create methods across class hierarchies that can be chained nicely but i'm running into the problem that 'this' declared in a parent class only refers to that type. Is there a way i can get the following code to per

Re: Forwarding or merging 'this' into a child class to aid chaining methods?

2014-03-06 Thread Ali Çehreli
On 03/06/2014 11:04 AM, Gary Willoughby wrote: I'm trying to create methods across class hierarchies that can be chained nicely but i'm running into the problem that 'this' declared in a parent class only refers to that type. Is there a way i can get the following code to perform in the way i exp

Re: mutable reference to const object

2014-03-06 Thread FreeSlave
Yes, in some cases C++ const does not provide const-guarantees, it's more like convention. For example, you can write this: class Class { public: Class() : ptr(new int()) {} ~Class() { delete ptr; } void setData(int data) const { *ptr = data; } private: int *ptr; };

Forwarding or merging 'this' into a child class to aid chaining methods?

2014-03-06 Thread Gary Willoughby
I'm trying to create methods across class hierarchies that can be chained nicely but i'm running into the problem that 'this' declared in a parent class only refers to that type. Is there a way i can get the following code to perform in the way i expect? import std.stdio; class Foo {

Re: Template mixins - why only declarations

2014-03-06 Thread Dejan Lekic
Template mixins can't contain statements, only declarations, because they (template mixins) are a way to inject code into the context. Therefore it makes sense to forbid statements, as they can't appear in ANY context. -- http://dejan.lekic.org

Re: Template mixins - why only declarations

2014-03-06 Thread Frustrated
On Thursday, 6 March 2014 at 17:27:35 UTC, Steve Teale wrote: Pretty much what the subject says. Why can't template mixins include statements ans so on? Is it just too hard, or is it just too much like C macros? Steve template mixins mix in directly into the code as if you typed them. If th

Re: Mutexes and locking

2014-03-06 Thread Kagamin
We use non-recursive locks too. The pattern is: --- bool wasMyLock=obj.isMyLock(); if(!wasMyLock)obj.lock(); ...code... if(!wasMyLock)obj.unlock(); ---

Re: fix struct API with an interface

2014-03-06 Thread Dicebot
On Thursday, 6 March 2014 at 14:28:13 UTC, Flamaros wrote: Ok, it's like I though final class and struct are equivalent when calling a method (except the pointer deference, but it's minor I think). I don't think there is a real performance problem for us, it's more about to learn how to have

Re: mutable reference to const object

2014-03-06 Thread Vadim Lopatin
On Thursday, 6 March 2014 at 17:47:34 UTC, bearophile wrote: There was a very long discussion on this. I think the short answer is to keep the syntax and semantics composed of a sufficiently low number of parts (in D you don't have syntax to tell apart objects from their references). Thank yo

Re: mutable reference to const object

2014-03-06 Thread Vadim Lopatin
On Thursday, 6 March 2014 at 15:54:13 UTC, FreeSlave wrote: You probably need Rebindable template from std.typecons. Thank you! Rebindable does exactly what I need. I'm just curious why there is no some syntax to describe the same. E.g. const(Foo) foo; // mutable ref to const object cons

Re: mutable reference to const object

2014-03-06 Thread bearophile
Vadim Lopatin: Const sub-tree is object itself and its data. Reference to object is outside of tree. Why references to const object should be const? There was a very long discussion on this. I think the short answer is to keep the syntax and semantics composed of a sufficiently low number of

Re: mutable reference to const object

2014-03-06 Thread Vadim Lopatin
On Thursday, 6 March 2014 at 15:59:12 UTC, bearophile wrote: Vadim Lopatin: In C++, following code works as I'm expecting: Different language, different (hopefully better) semantics. In D const and immutable are transitive, this means they make const/immutable the whole sub-tree of data the

Template mixins - why only declarations

2014-03-06 Thread Steve Teale
Pretty much what the subject says. Why can't template mixins include statements ans so on? Is it just too hard, or is it just too much like C macros? Steve

Re: xvalue and std::move in D

2014-03-06 Thread Ali Çehreli
On 03/06/2014 03:21 AM, Edwin van Leeuwen wrote: > Lately in C++ I have become a fan of the type of functional programming > discussed here: > http://blog.knatten.org/2012/11/02/efficient-pure-functional-programming-in-c-using-move-semantics/ I haven't read that yet but I have always returne

Re: mutable reference to const object

2014-03-06 Thread bearophile
Vadim Lopatin: In C++, following code works as I'm expecting: Different language, different (hopefully better) semantics. In D const and immutable are transitive, this means they make const/immutable the whole sub-tree of data they refer to: http://dlang.org/const3.html Bye, bearophile

Re: mutable reference to const object

2014-03-06 Thread FreeSlave
You probably need Rebindable template from std.typecons.

Re: xvalue and std::move in D

2014-03-06 Thread Mike Parker
On 3/6/2014 9:38 PM, Edwin van Leeuwen wrote: I guess what I am trying to do is allow code that looks like this: v = add_to_vector( x, v ); while enforcing that v is never copied. I know there are other ways to do this, i.e. void add_to_vector( x, ref v ); but for me the earlier pattern is mo

Re: fix struct API with an interface

2014-03-06 Thread Flamaros
On Thursday, 6 March 2014 at 13:35:13 UTC, John Colvin wrote: On Thursday, 6 March 2014 at 13:26:27 UTC, Flamaros wrote: I add directx 9 support on DQuick and as some of renderer objects are declared as struct, it seems it can make them derives from an interface. Need I use final class instea

Re: fix struct API with an interface

2014-03-06 Thread John Colvin
On Thursday, 6 March 2014 at 13:26:27 UTC, Flamaros wrote: I add directx 9 support on DQuick and as some of renderer objects are declared as struct, it seems it can make them derives from an interface. Need I use final class instead to avoid virtual methods? PS: I am not planning to support r

fix struct API with an interface

2014-03-06 Thread Flamaros
I add directx 9 support on DQuick and as some of renderer objects are declared as struct, it seems it can make them derives from an interface. Need I use final class instead to avoid virtual methods? PS: I am not planning to support run-time switch between OpenGL and directX renderers.

mutable reference to const object

2014-03-06 Thread Vadim Lopatin
Hello, Is there a possibility to define mutable reference to const object? I need variable which can be used to iterate through const objects. But it seems like const(Foo)p makes constant reference to constant object instead of mutable reference to const object. class Bar { } unittest { B

Re: xvalue and std::move in D

2014-03-06 Thread Edwin van Leeuwen
On Thursday, 6 March 2014 at 12:08:35 UTC, Nicolas Sicard wrote: On Thursday, 6 March 2014 at 11:49:51 UTC, Edwin van Leeuwen wrote: On Thursday, 6 March 2014 at 11:28:21 UTC, Mike Parker wrote: See std.algorithm.move Thank you, can't believe I missed that. How do I specify that the functi

Re: xvalue and std::move in D

2014-03-06 Thread Edwin van Leeuwen
On Thursday, 6 March 2014 at 12:10:40 UTC, Mike Parker wrote: On 3/6/2014 8:49 PM, Edwin van Leeuwen wrote: On Thursday, 6 March 2014 at 11:28:21 UTC, Mike Parker wrote: See std.algorithm.move Thank you, can't believe I missed that. How do I specify that the function expects a temporary/x

Re: xvalue and std::move in D

2014-03-06 Thread Mike Parker
On 3/6/2014 8:49 PM, Edwin van Leeuwen wrote: On Thursday, 6 March 2014 at 11:28:21 UTC, Mike Parker wrote: See std.algorithm.move Thank you, can't believe I missed that. How do I specify that the function expects a temporary/xvalue (&&) parameter though? D doesn't have anything like that.

Re: xvalue and std::move in D

2014-03-06 Thread Remo
On Thursday, 6 March 2014 at 12:01:25 UTC, bearophile wrote: Edwin van Leeuwen: Thank you, can't believe I missed that. How do I specify that the function expects a temporary/xvalue (&&) parameter though? Thankfully D lacks the && operator. Bye, bearophile But is also locks r-value referen

Re: enum return type

2014-03-06 Thread John Colvin
On Wednesday, 5 March 2014 at 23:17:45 UTC, Frustrated wrote: how does an enum return type work? enum foo(string s) { return s; } is it a purely compile time construct? That is, we can guarantee that foo, as a function, won't exist at runtime? e.g., it is a true ctfe instead of a function tha

Re: xvalue and std::move in D

2014-03-06 Thread Nicolas Sicard
On Thursday, 6 March 2014 at 11:49:51 UTC, Edwin van Leeuwen wrote: On Thursday, 6 March 2014 at 11:28:21 UTC, Mike Parker wrote: See std.algorithm.move Thank you, can't believe I missed that. How do I specify that the function expects a temporary/xvalue (&&) parameter though? What are yo

Re: xvalue and std::move in D

2014-03-06 Thread bearophile
Edwin van Leeuwen: Thank you, can't believe I missed that. How do I specify that the function expects a temporary/xvalue (&&) parameter though? Thankfully D lacks the && operator. Bye, bearophile

Re: xvalue and std::move in D

2014-03-06 Thread Edwin van Leeuwen
On Thursday, 6 March 2014 at 11:28:21 UTC, Mike Parker wrote: See std.algorithm.move Thank you, can't believe I missed that. How do I specify that the function expects a temporary/xvalue (&&) parameter though?

Re: xvalue and std::move in D

2014-03-06 Thread Mike Parker
On 3/6/2014 8:21 PM, Edwin van Leeuwen wrote: and call it as follows: std::vector v; v = add_to_vector( 1.2, std::move( v ) ); I know I could do the same by passing a reference value, but this makes it explicit that I am changing v, while being as efficient as passing a reference (since it ju

xvalue and std::move in D

2014-03-06 Thread Edwin van Leeuwen
I am trying to learn D and (partly) replace my C++ projects with D. Lately in C++ I have become a fan of the type of functional programming discussed here: http://blog.knatten.org/2012/11/02/efficient-pure-functional-programming-in-c-using-move-semantics/ and was wondering if something similar i