Re: Get specific functions of unknown type at runtime?

2012-12-16 Thread F i L

@Adam D. Ruppe

Damn, I was afraid you where going to say to do something like 
that. It doesn't really work for what I'm thinking about, but 
thanks for confirming that my original code can't work.


I have an alternative in mind, but first, is there a possible way 
for a Super class to ask about a derivative's members during 
constructions? (I'm guessing not). Something like:


import std.stdio, std.traits;

class A
{
this() {
alias typeof(this) type;
static if (hasMember!(type, "foo")) {
auto top = cast(type) this;
top.foo();
}
}
}

class B : A
{
void foo() { writeln("foobar"); }
}

void main() {
auto b = new B(); // prints: 'foobar'
}

I assume there's no way (I can't get it to work), but I've heard 
odd things about 'typeof(this)' before, I just can't remember 
exactly what, so I figure it's worth asking about.


If not, I have an alternative way to accomplish what I want. It's 
just not as ideal. I really wish D has partial classes, that 
would be awesome.





@Jacob Carlborg

Thanks for the link.


error Nomber 55 in zlib1.dll did not founded

2012-12-16 Thread Suliman

I am writing some simple downloader App.
After it's compiles ok, but when I run it's I got error 55 in 
zlib1.dll

I had put zlib1.dll into my apps folder, but without success

http://www.everfall.com/paste/id.php?68zzu6x37k6z


Re: Derelict SFML destructor crashes

2012-12-16 Thread Jacob Carlborg

On 2012-12-17 07:45, Nekroze wrote:


So what i am getting here is that either A: having it in the destructor
will work solong as the GC cleanup is called before the end of main
because that is when sfml is unloaded OR B: I just have to have a manual
destroy method in my class too to release the sfml objects?


You cannot trust that the GC will collect at all. Although if the 
function pointers in the bindings are still active and you don't need to 
rely on the order of destruction you should be pretty safe, since your 
not destroying GC memory.


The safest is to either:

A. Manually call a destroy/delete function
B. Call a destroy/delete function in a scope(exit) block (basically the 
same as A)

C. Use a struct and call a destroy/delete function in its destructor.

--
/Jacob Carlborg


Re: Get specific functions of unknown type at runtime?

2012-12-16 Thread Jacob Carlborg

On 2012-12-17 02:39, F i L wrote:

My goal is this, to have an XML file:

 
 
 
 

and a D file:

 module person;

 import std.stdio;

 class Person
 {
 void greet() {
 writeln("hello");
 }
 }

and then another D file:

 module main;

 import person;
 import std.xml;
 import std.file;

 static class Engine
 {
 static void delegate() event;
 static void callEvent() { event(); }
 }

 void main() {
 auto doc = new Document(read("scene.xml"));
 auto className = /* find class name in xml file */;
 auto eventName = /* find event name in xml file */;
 auto obj = Object.factory(className);

 Engine.event = /* get 'eventName' void in 'obj' */;

 for (/* some loop */) { Engine.callEvent(); }
 }

So yeah, basically is is possible to create a general object, then look
at it's members at runtime? Through maybe a .classinfo or something? Or
is this level of runtime reflection simply not supported in D (yet)? If
so, what are my best alternative options here?


For the serialization part you could have a look at Orange:

https://github.com/jacob-carlborg/orange

It won't handle the dynamic methods though.

--
/Jacob Carlborg


Re: Derelict SFML destructor crashes

2012-12-16 Thread Nekroze

On Monday, 17 December 2012 at 04:42:49 UTC, Mike Parker wrote:

On Monday, 17 December 2012 at 04:40:39 UTC, Mike Parker wrote:
First, please take all Derelict trouble-shooting problems to 
the Derelict forums[1]. I never check the sfml forums. I do 
check the newsgroups regularly, but these newsgroups are not 
generally the place to look for help with Derelict problems. 
Plus, by posting in other places, you are making it more 
unlikely that future users with the same problem will find an 
answer.




[1]http://dblog.aldacron.net/forum/index.ph


Sorry about not posting on the derelict forums, i cant remember 
exactly what happened but i made an account and it said i have to 
wait for authentication or something so i couldn't post... may 
have it confused with another forum but yeah will do in the 
future when i can post there.


Anyways so if i understand right the sfml objects wont delete 
themselves until the process exits right but what if i am in the 
middle of the process say in a game and i want to load another 
level i need to destroy the resources from the last level with 
the sfml destroy functions right. I just wanted that to be done 
automatically rather then having to have a destroy method that i 
must manually call from my class.


So what i am getting here is that either A: having it in the 
destructor will work solong as the GC cleanup is called before 
the end of main because that is when sfml is unloaded OR B: I 
just have to have a manual destroy method in my class too to 
release the sfml objects?


Re: phobos by ref or by value

2012-12-16 Thread Jonathan M Davis
On Monday, December 17, 2012 04:06:52 Dan wrote:
> > They'll use ref when it's required for
> > the semantics of what they're doing, but auto ref on function
> > parameters is
> > rare.
> 
> When would ref be required for semantics? I am asking this to
> learn the D way - so any guidelines are helpful. We have language
> spec and TDPL. Maybe we need another book or three in the vein of
> Meyers "50 Effective Ways".

ref is required when you want the argument you're passing in to be altered 
rather than the copy being altered. That's the same as in C++.

Ranges in general don't do deep copies when they're passed around for 
basically the same reasons that pointers don't. If you want to know more about 
ranges, this is probably the best resource at this point:

http://ddili.org/ders/d.en/ranges.html

There are probably plenty of cases in D where the equivalent of C++'s const& 
would be desirable, but D doesn't really have that at this point. The closest 
is auto ref, which only works with templated functions, and it doesn't prevent 
the argument from being mutated (though auto ref const would). Also, const in 
D is far more restrictive than it is in C++, making it so that forcing const 
on function parameters can be highly restrictive and annoying. It's an ongoing 
debate on how to solve that, as emulating C++'s const& and having const ref 
take rvalues has been rejected. So, in most cases, the issue is completely 
ignored at this point in Phobos. And since most functions in Phobos take 
either ranges or built-in types (where passing by value is not a problem), so 
in most cases, it's not an issue at all. Long term, it's something that should 
probably be addressed, but until the const ref situation is sorted out, it 
probably won't be.

Functions which take the element of a range rather than a range probably 
should do something to avoid unnecessary copies, and auto ref may be the 
solution to that at the moment, but it's not clear how that's going to be 
sorted out in the long run.

- Jonathan M Davis


Re: Derelict SFML destructor crashes

2012-12-16 Thread Mike Parker

On Monday, 17 December 2012 at 04:40:39 UTC, Mike Parker wrote:
First, please take all Derelict trouble-shooting problems to 
the Derelict forums[1]. I never check the sfml forums. I do 
check the newsgroups regularly, but these newsgroups are not 
generally the place to look for help with Derelict problems. 
Plus, by posting in other places, you are making it more 
unlikely that future users with the same problem will find an 
answer.




[1]http://dblog.aldacron.net/forum/index.ph


Re: Derelict SFML destructor crashes

2012-12-16 Thread Mike Parker
First, please take all Derelict trouble-shooting problems to the 
Derelict forums[1]. I never check the sfml forums. I do check the 
newsgroups regularly, but these newsgroups are not generally the 
place to look for help with Derelict problems. Plus, by posting 
in other places, you are making it more unlikely that future 
users with the same problem will find an answer.



On Sunday, 16 December 2012 at 17:20:55 UTC, Nekroze wrote:
I am sorry if i am being dim but i thought that the sfml 
objects are not GC objects so it will exist forever until i 
call its destroy function so why cant this be done in the 
destructor? Unless you mean the pointer is being destroyed 
before the destructor is being called?


You are correct in that the sfImage instance is not GCed and will 
continue to stay resident in memory. But *your* Image class *is* 
GCed. You cannot, ever, rely on D destructors to clean up 
external resources. This is because you have no idea when, if, or 
in what order they will be called during runtime. They *will* be 
called when the program exits and the GC cleans up, but that is 
where you are running into your problem. See below.



sfImage_destroy is purely a binding to a c function in a dll. 
It has no knowledge of the GC or anything which is why the 
image will live forever unless i call that function.


SFML is a c++ OO based graphics library, in order to provide a 
c binding they made a C wrapper around all the OO stuff so the 
object, its all handled using C functions, needs to have its 
destructor called manually with the C destroy functions. With 
the D wrapper for this (Derelict3) there is no actual function 
for these its just some kind of pass through binding to the dll 
so the above, as far as i can understand, still holds true.


This is why i have come to the belief that i should be 
perfectly able to call this destroy function in the destructor 
because what i am calling destroy on is an object that is 
created in C++ but accessed through C functions which have just 
been imported and bound to D names.


You have to understand that Derelict is a dynamic binding and not 
a static one. In this sort of binding, all of the functions you 
call are actually function pointers. When you call 
DerelictSFML2.load, Derelict is loading the shared library for 
you and making sure the function pointers are pointing to the 
write places. In a static binding where you would link with a 
static library, a Windows DLL import library, or directly with an 
shared object file on Posix systems, the shared library is loaded 
automatically and you call the functions normally rather than 
through pointers ("bound to D names", in other words).


Any call to load a library into memory should generally be 
matched by a call to unload it. All Derelict bindings include a 
module destructor that automatically unloads its shared library 
at program exit. So here's what's happening to you. When your 
main function exits, the runtime starts the cleanup process. It 
runs the module destructors *before* cleaning up the GC. So 
DerelictSFML2's module destructor is run, the CSFML2 library is 
unloaded from memory, then after that the GC's cleanup begins 
and, at some point, the destructor on your Image class instance 
is called. Only now, when you call sfImage_destroy the library 
was already unloaded by the module destructor so the function 
pointer is no longer valid. Boom! You have a crash.


Perhaps it would be ok for me to remove the module destructors 
and let the OS just free up the libraries when the process exits, 
but I'm not going to do that. Regardless, it doesn't change the 
fact that you should never, ever, ever rely on D class 
destructors for this sort of thing.


Re: phobos by ref or by value

2012-12-16 Thread Dan

On Monday, 17 December 2012 at 03:23:13 UTC, bearophile wrote:
Then I suggest you to not study std.random because it currently 
contains know flaws regarding what you are saying.


Fine, thanks. But which would be recommended to study?


Re: phobos by ref or by value

2012-12-16 Thread bearophile

Dan:

Usually the best place to learn the way of a language is 
studying its standard libraries,


Then I suggest you to not study std.random because it currently 
contains know flaws regarding what you are saying.


Bye,
bearophile


Re: phobos by ref or by value

2012-12-16 Thread Dan
On Sunday, 16 December 2012 at 23:02:30 UTC, Jonathan M Davis 
wrote:


You _don't_ take ranges by ref unless you want to alter the 
original, which is
almost never the case. Functions like popFrontN are the 
exception. And since
you _are_ going to mutate the parameter (since ranges iterate 
via mutation),
something like const ref would never make sense, even if it had 
C++'s
semantics. I'm not sure if auto ref screams at you if you try 
and mutate the
original, but if it doesn't, then you get problems when passing 
it lvalue
ranges, because they'd be being passed by ref and mutated, 
which you don't
want. So, auto ref makes no sense either. You pretty much 
always pass ranges
by value. And a range which does a deep copy when it's copied 
is a
fundamentally broken range anyway. It has the wrong semantics 
and won't
function correctly with many range-based functions. Ranges are 
supposed to be
a view into a range of values (possibly in a container), and 
copying the view
shouldn't copy the actual elements. Otherwise, you'd be doing 
the equivalent
of passing around a container by value, which is almost always 
a horrible

idea.

As for types which aren't ranges, they're almost a non-issue in 
Phobos. Most
functions in Phobos take either a range or a primitive type. 
There aren't very
many user-defined types in Phobos which aren't ranges (e.g. the 
types in
std.datetime), but those that aren't ranges are generally 
either small enough
that trying to pass by const ref or auto ref doesn't buy you 
much (if
anything), or they're classes, in which case, it's a non-issue. 
And almost
every generic function in Phobos takes a range. So, functions 
in Phobos almost

always take their arguments by value.


I assume you are talking about functions other than lowerBound, 
upperBound, trisect.



They'll use ref when it's required for
the semantics of what they're doing, but auto ref on function 
parameters is

rare.


When would ref be required for semantics? I am asking this to 
learn the D way - so any guidelines are helpful. We have language 
spec and TDPL. Maybe we need another book or three in the vein of 
Meyers "50 Effective Ways".



Sorry, but I don't understand the focus on ranges. I know ranges 
are involved because lowerBound is a method on SortedRange. But I 
am asking why a member function of a range (i.e. lowerBound) 
takes its argument by value. I don't mind copies of ranges being 
made when needed - as I think they are "light copies" of 
pointers. But by value of type V in lowerBound performs 
unnecessary copy of the element of unknown size/complexity. The 
library can not know the cost of that *and* it can be avoided (I 
think). I thought ranges were a refinement or improvement on pair 
of iterators. So I have a range of items already existing in 
memory and I want to find all elements in the range less than 
some value of type V. I don't understand the choice of the V as 
opposed to 'ref const(V)'. What this does is cause the fire of 
postblits again and again on a non-phobos user defined struct - 
and I think they are needless. *find* or *lower_bound* in C++, 
for example, take the element to be found as 'const &' so copies 
are not made. Why is that not done here? If it is not an 
oversight, I have more to learn on how things work in D and 
therefore want a broader set of guidelines. I would think a 
guideline like: "In generic code always take generic types that 
are not known to be primitives or very small collections of 
pointers (like dynamic array, associative array) by reference 
since you can not know the cost of copying".


Usually the best place to learn the way of a language is studying 
its standard libraries, so that is what I am after - the why's of 
it.



Thanks
Dan


Re: Get specific functions of unknown type at runtime?

2012-12-16 Thread Adam D. Ruppe
The way I'd do it is to make an interface with a generic call 
method. The classes themselves fill this out using __traits.



interface SceneObject {
   void _callFunction(string name);
}

mixin template SceneObjectReflection() {
 override void _callFunction(string name) {
   foreach(funcname; __traits(derivedMembers, 
typeof(this))) {
static if(funcname[0] != '_') // just to skip 
stuff like _ctor

if(funcname == name) {
__traits(getMember, this, funcname)();
return;
}
   }
   throw new Exception("no such method");
 }
}

class Person : SceneObject {
mixin SceneObjectReflection!();
void greet() { writeln("hello"); }
}




Then you can use it like:

void main() {
   auto obj = cast(SceneObject) Object.factory("test6.Person") ;
   if(obj is null) throw new Exception("no such class");
   obj._callFunction("greet");
}



Where of course the class name and the function name are runtime 
strings.



It will still be a bumpy ride to make this work in a real world 
situation, but this is how I would get started.


Get specific functions of unknown type at runtime?

2012-12-16 Thread F i L

My goal is this, to have an XML file:






and a D file:

module person;

import std.stdio;

class Person
{
void greet() {
writeln("hello");
}
}

and then another D file:

module main;

import person;
import std.xml;
import std.file;

static class Engine
{
static void delegate() event;
static void callEvent() { event(); }
}

void main() {
auto doc = new Document(read("scene.xml"));
auto className = /* find class name in xml file */;
auto eventName = /* find event name in xml file */;
auto obj = Object.factory(className);

Engine.event = /* get 'eventName' void in 'obj' */;

for (/* some loop */) { Engine.callEvent(); }
}

So yeah, basically is is possible to create a general object, 
then look at it's members at runtime? Through maybe a .classinfo 
or something? Or is this level of runtime reflection simply not 
supported in D (yet)? If so, what are my best alternative options 
here?


Re: Get class type parameters at compile time

2012-12-16 Thread js.mdnq
I see now why it was returning a bool as that is the type of the 
template argument passed.


class A(bool x = true)

then your TemplateArgs returns `tuple(bool)`. What I'm looking 
for is something that returns `(x)`. For class A(T1, T2, bool x = 
true) I would like `(T1, T2, x)`.


To see why this will help, in my Nested structs code, I have to 
do the following:


class _A(, bool _NestedLevel = true) {
enum string __ClassNameFix = "_A!(";
...}

Using what you said about typeof(this), I can now remove the 
class name dependency, so I have this:


enum string __ClassNameFix = __traits(identifier, 
typeof(this))~"!(";


Now I want to remove the type argument list dependency(the 
`!(...` part).


Once that is done, I can completely remove the __ClassNameFix 
since I can get the class name and template arg names without 
user intervention. The whole point of __ClassNameFix was to 
provide a way for the user to specify the class name and args. I 
had to use strings so I could parse them. (since in my mixins 
I'll set _NestedLevel to false and such, using strings, which is 
easy)


If I could go the next step and get the template argument names 
it will drastically reduce the code in my template mixins.


Re: Get class type parameters at compile time

2012-12-16 Thread js.mdnq
On Saturday, 15 December 2012 at 21:49:51 UTC, Philippe Sigaud 
wrote:


Oops ;/ How do I get the number of type arguments if I don't 
know them
yet? I know this sort of seems wrong but somehow, to know how 
to alias the
class I need to know it's number of arguments. (I don't think 
it makes too
much sense with the type system but not sure how to solve the 
following

problem without it:

http://forum.dlang.org/thread/**wacupbnlqgrfhaebdssd@forum.**
dlang.org#post-**yhhtuojlsgiykyrfhngl:40forum.**dlang.org
)



I saw your other post. I'll try to understand what you're 
trying to do in

the dpaste you posted.

I'm not sure I get your question, though. If a type is not 
known in the
current scope, you cannot determine its number of arguments, 
because, well,

it's not known.



I would like to be able to get the template args of a class 
inside the class:


class A(T1, T2)
{
   this() { pragma(msg, TemplateArgs!(typeof(this)).stringof); }
}

should print (T1, T2) or something similar.

When I run your code I get

tuple(true).

I'd also sort of like to setup an alias outside the class to 
refer to the class from inside without knowing the arguments 
explicitly


e.g.,


class A(T1, T2)
{
   this() { outer alias ... AB; } // ... is something like A!(T1, 
int) where T1 is inferred from being inside the class and int is 
explicit.

}

would be equivalent to something like

template A(T1,T2) { alias .A!(T1, int) A(T1); }

(this isn't suppose to be valid D code but pseudo-D code)

The idea is simply to reduce what the user outside the class has 
to know and type. If I were to parameterize a class:


class A(uT1, uT2, a,b,c,d,e,f,g,q,x,z,y) { }

and only uT1, uT2 were meant for the user and the rest were all 
statically known then I wouldn't want the user to have to type 
that stuff in... which is were aliases come in. Aliases don't 
seem to let you specify only a partial template list though, 
which, I think, is why you use templates?


But if I can create all the code inside the class that does this 
grunt work it would make it easier on the user and make it as 
transparent as possible. The goal is to make it feel like they 
are just using class A(uT1, uT2) rather than the other one. Since 
they are actually creating the class, the technique I use must 
work with any number of "user" template arguments.


In any case, being able to get the string name of a class, 
including the template arguments, would be very helpful in this.


Alternatively, having the ability to combine classes, even with 
different template arguments, would be useful(ah'la the other 
thread):


class Master(a,b,c,d,e,f,g,q,x,z,y) { xxx }
class User(uT1, uT2) { yyy }

Master(a,b,c,d,e,f,g,q,x,z,y) + User(uT1,uT2)
= struct MasterpUser(uT1,uT2,a,b,c,d,e,f,g,q,x,z,y) { xxx yyy }

which, if all of the master template arguments have default 
arguments then it should be easy to treat MasterpUser as if it 
were a User class and the user would not really know the 
difference between the two. (since MasterpUser contains all the 
functionality of User and the user does not know about the 
master's template args)


I, of course, provide the Master class, and the user(the 
programmer wanting the additional functionality, creates the User 
class.


It is very similar to inheritance except sort of static(no 
virtual functions, etc...). User, can, of course, also access 
data in Master(yyy could access Master's data) since they are 
actually the same class when combined.


It would be better to have a compile time inheritance construct 
as that is essentially what I'm trying to do:


class Master(a = 1,b = 2,c = 3,d = 4) { xxx }
class User(uT1, uT2) + Master!() { yyy [xxx is implicit] }

note that a class like

class User2(uT1, uT2) + Master!() { yyy [xxx is implicit] }

has no relationship to User(uT1, uT2) + Master!(). (well, it does 
but it at run time there is no common parent Master because there 
is no vtable. One could subtract the two classes to recover 
Master!() which would be non-empty and hence have overlap. This 
could only be carried out at compile time unless the 
functionality was added to the dynamic type system)


Anyways, I'm not sure if any of this is making sense but 
ultimately I'm trying to achieve something sort of like the above 
since I think D does not support such constructs. To do that, I 
need to be able to get the class name with it's type argument 
list without actually knowing them. typeof(this).stringof gets 
only the name... I need the other part.


I have seen someone mention a codeof trait, which is something I 
was also hoping for. This would make it easier to get what I want 
and also even implement an static algebra of classes and structs.













Re: alias type reduction

2012-12-16 Thread js.mdnq

On Sunday, 16 December 2012 at 15:21:17 UTC, Philippe Sigaud
wrote:



The real issue I'm having now is not having to mangle the 
names and hide

the `_NestLevel` and `_Offset` dependencies.

alias works for the case of one template argument to _A. 
Simply `alias
_A!(true) A`. But when I have more than one such as `class 
_A(T1, bool)` I
can't do `alias _A!(T1, true) A(T1)` analogous to the first 
case.




Because A(T1) would itself be a template, hence our proposal:

template A(T1) { ... }


You could also use overloads, as for functions:

class A ( 3 args version) { ... }
class A (2 args version) { ... }
class A (1 arg ) { ... }





You should try to use templated factory functions:

auto makeA(..., bool _NestLevel = true)
{
return new A!(..., _NestLevel)();
}




Ok, I'm not familiar with these, I've seen a lot of "weird" 
notation
dealing with a variable number of template args(I think it's 
`T...`?)


and such. I'll play around with it and hopefully get somewhere 
;)




Yes, Symbol... (three dots) is the template tuple parameter 
syntax. They
are heavily used and are one of the most useful parts of D 
templates. Docs

are here:

http://dlang.org/template.html#TemplateTupleParameter
http://dlang.org/tuple.html
http://dlang.org/variadic-function-templates.html
http://dlang.org/templates-revisited.html

They are a bit old (they were already there in 2008 when I 
began with D),

but still useful.

Also, I wrote a tutorial on templates with other people being 
kind enough

to put example code in it. You'll find it here:


https://github.com/PhilippeSigaud/D-templates-tutorial/blob/master/dtemplates.pdf?raw=true


Thanks, I'll look into these. It's nice D has such features but
it's a pain to find all the documentation to help get a grip on
how to use it ;)


Re: static code generation

2012-12-16 Thread js.mdnq

On Sunday, 16 December 2012 at 20:29:19 UTC, r_m_r wrote:

On 12/16/2012 02:03 PM, js.mdnq wrote:
That looks like it might be pretty close. I was also thinking 
that one
could just use mixin templates of trying to do it with structs 
directly.


i dunno if this is what u want, but have a look: 
http://dpaste.dzfl.pl/f5616d77


cheers,
r_m_r


Well, it a slightly another way and close. Let me see if I can 
come up with something that expresses better what I'm after. It 
will be a week or two though till I get around to it probably.


Re: phobos by ref or by value

2012-12-16 Thread Jonathan M Davis
On Sunday, December 16, 2012 16:09:45 Dan wrote:
> Is there a general philosophy in D phobos on when to pass by
> value or
> reference?  For instance, to find a slice using lowerBound many
> copies
> of the target item, as well as copies of items in the collection
> are
> made (see code example below). This seems unnecessary - why not
> have
> functions like:
> 
>  auto lowerBound(...)(V value)
> 
> be:
> 
>  auto lowerBound(...)(ref V value)
> 
> or:
> 
>  auto lowerBound(...)(auto ref V value)
> 
> Is this a source for desire for no postblits, shallow semantics on
> copy/assignment with additional logic for copy on write
> semantics. If
> libraries in general are coded to make many copies of parameters
> it
> might be a big improvement to not have postblits. A general
> purpose
> library accessing ranges will not know the semantics of V (deep or
> shallow), so why incur the cost of copies? Certainly finding a
> lowerBound on a range of V can be done with 0 copies of elements?
> 
> Is there an established philosophy?

You _don't_ take ranges by ref unless you want to alter the original, which is 
almost never the case. Functions like popFrontN are the exception. And since 
you _are_ going to mutate the parameter (since ranges iterate via mutation), 
something like const ref would never make sense, even if it had C++'s 
semantics. I'm not sure if auto ref screams at you if you try and mutate the 
original, but if it doesn't, then you get problems when passing it lvalue 
ranges, because they'd be being passed by ref and mutated, which you don't 
want. So, auto ref makes no sense either. You pretty much always pass ranges 
by value. And a range which does a deep copy when it's copied is a 
fundamentally broken range anyway. It has the wrong semantics and won't 
function correctly with many range-based functions. Ranges are supposed to be 
a view into a range of values (possibly in a container), and copying the view 
shouldn't copy the actual elements. Otherwise, you'd be doing the equivalent 
of passing around a container by value, which is almost always a horrible 
idea.

As for types which aren't ranges, they're almost a non-issue in Phobos. Most 
functions in Phobos take either a range or a primitive type. There aren't very 
many user-defined types in Phobos which aren't ranges (e.g. the types in 
std.datetime), but those that aren't ranges are generally either small enough 
that trying to pass by const ref or auto ref doesn't buy you much (if 
anything), or they're classes, in which case, it's a non-issue. And almost 
every generic function in Phobos takes a range. So, functions in Phobos almost 
always take their arguments by value. They'll use ref when it's required for 
the semantics of what they're doing, but auto ref on function parameters is 
rare.

- Jonathan M Davis


Re: static code generation

2012-12-16 Thread js.mdnq
On Sunday, 16 December 2012 at 15:34:34 UTC, Philippe Sigaud 
wrote:

One could also think of it as an algebra of structs.

It would be nice to be able to do stuff like

A + B, A - B(possibly useless), A*B(possibly useless), etc...

A + B would just combine the members, A - B could remove the 
members that

overlap, A*B could qualify overlapping members.



Usually, given types A and B, A+B means `A or B` (in D,
std.typecons.Algebraic!(A,B) ) and A*B means the tuple 
containing A and B

(in D, std.typecons.Tuple!(A,B) ).


What you're trying to do is doable in D, but you'd have to 
define it a bit

more:

if we have

struct A { int a; int b}
struct B { int b; int a} // just a and b swapped.

What is `A+B`? `A-B`?




(Thanks for the typeof(this) works great!)


Yes, A+B = A or B. Or is inclusive though.. and "overlap" and 
order is immaterial.


So `A+B` is equivalent to

struct ApB { int a; int b; }

Since order ultimately matters(the layout of the struct in 
memory) we could define


`B+A` =
struct BpA { int b; int a; }

`A-B` = `B-A` = (only in this case)
struct AmB { } = struct BmA { }


So A*B = std.typecons.Algebraic!(A,B) which is what I initially 
said * should be. That should take care of that operation. How do 
you do the other ops?






Re: static code generation

2012-12-16 Thread r_m_r

On 12/16/2012 02:03 PM, js.mdnq wrote:

That looks like it might be pretty close. I was also thinking that one
could just use mixin templates of trying to do it with structs directly.


i dunno if this is what u want, but have a look: 
http://dpaste.dzfl.pl/f5616d77


cheers,
r_m_r


Re: recursive function call at compile time

2012-12-16 Thread Philippe Sigaud
>
>
> When you instantiate MyStruct!5, it tries to define ret, so it
> instantiates MyStruct!4, MyStruct!3, ... and so on. You have to put a
> static if or something else to stop that.
>

Like this:

import std.stdio;

struct MyStruct(uint K) if (K > 0) // Only to disable direct creation for
K==0
{
real[K] data;

static if (K > 1) // getSmaller only exists for K > 1
MyStruct!(K-1) getSmaller()
{
MyStruct!(K-1) ret;
foreach( no, ref d; ret.data )
d = data[no];
return ret;
}

real recursionAlgo()
{
static if( K == 1 ) return data[0];
else
{
real sum = 0;
foreach( i; 1 .. K )
sum += getSmaller().recursionAlgo();
return sum;
}
}
}

void main()
{
MyStruct!(5) a;
a.data = [ 1, 2, 3, 4, 5 ];
writeln( a.recursionAlgo() ); // 24
}


Re: Unittest

2012-12-16 Thread Jacob Carlborg

On 2012-12-16 19:39, bioinfornatics wrote:

Dear,

I would like to understand if to have an empty main file ils need to use
unittest.

I explain i have a library with some unittest section

-- foo.d--

void doFoo(){ ... }
unittest{
   scope(success) writeln( "ok" );
   scope(failure) writeln( "no" );
   doFoo();
}
--


to use unittest i need to have main file which import each library
module as

--- main.d- --
import foo1, foo2, foo3;

void main(){}
---

why they are not a dflag to do this?

Maybe that is me where is use badly d unittest


You don't necessarily need to import the other files. As long as all 
files are compiled it should run the unit tests for all files.


You do need a main function.

--
/Jacob Carlborg


Re: Unittest

2012-12-16 Thread Dan

On Sunday, 16 December 2012 at 18:39:30 UTC, bioinfornatics wrote:

Dear,

I would like to understand if to have an empty main file ils 
need to use

unittest.

I explain i have a library with some unittest section

-- foo.d--

void doFoo(){ ... }
unittest{
  scope(success) writeln( "ok" );
  scope(failure) writeln( "no" );
  doFoo();
}
--


to use unittest i need to have main file which import each 
library

module as

--- main.d- --
import foo1, foo2, foo3;

void main(){}
---

why they are not a dflag to do this?

Maybe that is me where is use badly d unittest

thanks


A simpler way is to use rdmd. Suppose you have a file called 
history.d with a one or more unittest sections. You could just 
run:

rdmd --force  -g -w  --main -unittest history.d

This would provide a simple main and run the unittests in one go. 
The --force is not needed, but if you have added an import 
statement anywhere it will ensure everything is rebuilt. If you 
have just recently run this command, you can run again without 
--force.


One thing to be aware of, I think when using unittest sections, 
not only are your unittests run, but unittests of all your 
imports.


Thanks
Dan


Unittest

2012-12-16 Thread bioinfornatics
Dear,

I would like to understand if to have an empty main file ils need to use
unittest.

I explain i have a library with some unittest section

-- foo.d--

void doFoo(){ ... }
unittest{
  scope(success) writeln( "ok" );
  scope(failure) writeln( "no" );
  doFoo();
}
--


to use unittest i need to have main file which import each library
module as

--- main.d- --
import foo1, foo2, foo3;

void main(){}
---

why they are not a dflag to do this?

Maybe that is me where is use badly d unittest

thanks



Re: recursive function call at compile time

2012-12-16 Thread bearophile

Oleg:


at compile time i have errors
./recursion.d(7): Error: index 4294967295 overflow for static 
array
./recursion.d(7): Error: index 4294967294 overflow for static 
array

 etc


It prints a little too many of those...



call 'recursionAlgo()' where it should not be ( K == 1 )


The first problem to fix in your code is visible here, it's not a 
CTFE problem:



struct MyStruct(uint K) {
real[K] data;

auto getSmaller() {
MyStruct!(K - 1) ret;
}
}

void main() {
MyStruct!5 a;
}


When you instantiate MyStruct!5, it tries to define ret, so it 
instantiates MyStruct!4, MyStruct!3, ... and so on. You have to 
put a static if or something else to stop that.


Bye,
bearophile


recursive function call at compile time

2012-12-16 Thread Oleg

Hello.
I want use recursion, but in my situation compiler doesn't 
correct work.


import std.stdio;

struct MyStruct(uint K)
{
real[K] data;

auto getSmaller()
{
MyStruct!(K-1) ret;
foreach( no, ref d; ret.data )
d = data[no];
return ret;
}

real recursionAlgo()
{
static if( K == 1 ) return data[0];
else
{
real sum = 0;
foreach( i; 1 .. K )
sum += getSmaller().recursionAlgo();
return sum;
}
}
}

void main()
{
MyStruct!(5) a;
a.data = [ 1, 2, 3, 4, 5 ];
writeln( a.recursionAlgo() );
}

at compile time i have errors
./recursion.d(7): Error: index 4294967295 overflow for static 
array
./recursion.d(7): Error: index 4294967294 overflow for static 
array

 etc

i think it's happens because compiler call 'recursionAlgo()' 
where it should not be ( K == 1 )


how to turn off compile time calculation in this part of code?


Re: Derelict SFML destructor crashes

2012-12-16 Thread Nekroze

On Sunday, 16 December 2012 at 17:14:55 UTC, Maxim Fomin wrote:

On Sunday, 16 December 2012 at 15:21:46 UTC, Nekroze wrote:

On Sunday, 16 December 2012 at 14:59:32 UTC, Maxim Fomin wrote:

On Sunday, 16 December 2012 at 14:42:57 UTC, Nekroze wrote:
I am trying to do some wrapping of the CSFML derelict 
bindings to classes however when i use the CSFML methods to 
destroy the objects it causes a crash.


I have made a post in the SFML>D forum because they have 
syntax highlighting for D so this kind of post looks nicer 
but the link is here:


http://en.sfml-dev.org/forums/index.php?topic=10005.0

There is a minimal code example there and a better 
explanation.


Can anyone help me with why this is happening?


Why would you call a destroy() on a this object inside 
~this()? And accessing allocated by GC objects inside 
destructor is not safe, because they may be collected before 
running the destructor.


I am sorry if i am being dim but i thought that the sfml 
objects are not GC objects so it will exist forever until i 
call its destroy function so why cant this be done in the 
destructor? Unless you mean the pointer is being destroyed 
before the destructor is being called?


I do not know this library, but if you get 
InvalidMemoryOperationError it likely mean that you call in 
class dtor some function, which causes GC allocation. In your 
case it seems that you call sfImage_destroy(image) which might 
do such things.


sfImage_destroy is purely a binding to a c function in a dll. It 
has no knowledge of the GC or anything which is why the image 
will live forever unless i call that function.


SFML is a c++ OO based graphics library, in order to provide a c 
binding they made a C wrapper around all the OO stuff so the 
object, its all handled using C functions, needs to have its 
destructor called manually with the C destroy functions. With the 
D wrapper for this (Derelict3) there is no actual function for 
these its just some kind of pass through binding to the dll so 
the above, as far as i can understand, still holds true.


This is why i have come to the belief that i should be perfectly 
able to call this destroy function in the destructor because what 
i am calling destroy on is an object that is created in C++ but 
accessed through C functions which have just been imported and 
bound to D names.


Re: Derelict SFML destructor crashes

2012-12-16 Thread Maxim Fomin

On Sunday, 16 December 2012 at 15:21:46 UTC, Nekroze wrote:

On Sunday, 16 December 2012 at 14:59:32 UTC, Maxim Fomin wrote:

On Sunday, 16 December 2012 at 14:42:57 UTC, Nekroze wrote:
I am trying to do some wrapping of the CSFML derelict 
bindings to classes however when i use the CSFML methods to 
destroy the objects it causes a crash.


I have made a post in the SFML>D forum because they have 
syntax highlighting for D so this kind of post looks nicer 
but the link is here:


http://en.sfml-dev.org/forums/index.php?topic=10005.0

There is a minimal code example there and a better 
explanation.


Can anyone help me with why this is happening?


Why would you call a destroy() on a this object inside 
~this()? And accessing allocated by GC objects inside 
destructor is not safe, because they may be collected before 
running the destructor.


I am sorry if i am being dim but i thought that the sfml 
objects are not GC objects so it will exist forever until i 
call its destroy function so why cant this be done in the 
destructor? Unless you mean the pointer is being destroyed 
before the destructor is being called?


I do not know this library, but if you get 
InvalidMemoryOperationError it likely mean that you call in class 
dtor some function, which causes GC allocation. In your case it 
seems that you call sfImage_destroy(image) which might do such 
things.


Re: Derelict SFML destructor crashes

2012-12-16 Thread Nekroze

On Sunday, 16 December 2012 at 15:21:46 UTC, Nekroze wrote:

On Sunday, 16 December 2012 at 14:59:32 UTC, Maxim Fomin wrote:

On Sunday, 16 December 2012 at 14:42:57 UTC, Nekroze wrote:
I am trying to do some wrapping of the CSFML derelict 
bindings to classes however when i use the CSFML methods to 
destroy the objects it causes a crash.


I have made a post in the SFML>D forum because they have 
syntax highlighting for D so this kind of post looks nicer 
but the link is here:


http://en.sfml-dev.org/forums/index.php?topic=10005.0

There is a minimal code example there and a better 
explanation.


Can anyone help me with why this is happening?


Why would you call a destroy() on a this object inside 
~this()? And accessing allocated by GC objects inside 
destructor is not safe, because they may be collected before 
running the destructor.


I am sorry if i am being dim but i thought that the sfml 
objects are not GC objects so it will exist forever until i 
call its destroy function so why cant this be done in the 
destructor? Unless you mean the pointer is being destroyed 
before the destructor is being called?


To me it makes sense to use the sfml objects destroy function 
when the my object gets destroyed regardless of when it happens.


It cant be that i have to have a separate destroy method for my 
class that i must manually use each time. kind of kills the point 
of having a GC then doesn't it?


Like i said sorry if i am being dim that just makes sense to me.


Re: bio parser

2012-12-16 Thread Simen Kjaeraas
On 2012-09-16 17:12, bioinfornatics   
wrote:



Dear,
I wrote a fasta format parser and fastq format parser. These parser used
MmFile and do not load all file these will save memory.

Fastq http://dpaste.dzfl.pl/9b23574d
Fasta http://dpaste.dzfl.pl/228dba11

The way to iterate over it is really close and i search a way to have
one struct bySection one template doIndex for both file format.

If you have any suggestion to improve this, please tell to me.


As this is something that might be useful to others, you should probably
post it to digitalmars.D.announce. I'd also advice setting up a github rep
for it and placing a link on wiki.dlang.org.

--
Simen


bio parser

2012-12-16 Thread bioinfornatics
Dear,
I wrote a fasta format parser and fastq format parser. These parser used
MmFile and do not load all file these will save memory.

Fastq http://dpaste.dzfl.pl/9b23574d
Fasta http://dpaste.dzfl.pl/228dba11

The way to iterate over it is really close and i search a way to have
one struct bySection one template doIndex for both file format.

If you have any suggestion to improve this, please tell to me.

thanks



Re: static code generation

2012-12-16 Thread Philippe Sigaud
> it would be real nice if I there was a compile time construct for this.
> like "me" or something that would return type info inside the current
scope.

>
> class A(T) { this() { writeln(me.typeinfo.name); }
>
> would print "A(T)".
>
> (of course me is probably a bad name but just an example :)
>


You could use `typeof(this)`. It returns the static type of `this`.


Re: Derelict SFML destructor crashes

2012-12-16 Thread Nekroze

On Sunday, 16 December 2012 at 14:59:32 UTC, Maxim Fomin wrote:

On Sunday, 16 December 2012 at 14:42:57 UTC, Nekroze wrote:
I am trying to do some wrapping of the CSFML derelict bindings 
to classes however when i use the CSFML methods to destroy the 
objects it causes a crash.


I have made a post in the SFML>D forum because they have 
syntax highlighting for D so this kind of post looks nicer but 
the link is here:


http://en.sfml-dev.org/forums/index.php?topic=10005.0

There is a minimal code example there and a better explanation.

Can anyone help me with why this is happening?


Why would you call a destroy() on a this object inside ~this()? 
And accessing allocated by GC objects inside destructor is not 
safe, because they may be collected before running the 
destructor.


I am sorry if i am being dim but i thought that the sfml objects 
are not GC objects so it will exist forever until i call its 
destroy function so why cant this be done in the destructor? 
Unless you mean the pointer is being destroyed before the 
destructor is being called?


Re: alias type reduction

2012-12-16 Thread Philippe Sigaud
>
>
> The real issue I'm having now is not having to mangle the names and hide
> the `_NestLevel` and `_Offset` dependencies.
>
> alias works for the case of one template argument to _A. Simply `alias
> _A!(true) A`. But when I have more than one such as `class _A(T1, bool)` I
> can't do `alias _A!(T1, true) A(T1)` analogous to the first case.
>

Because A(T1) would itself be a template, hence our proposal:

template A(T1) { ... }


You could also use overloads, as for functions:

class A ( 3 args version) { ... }
class A (2 args version) { ... }
class A (1 arg ) { ... }


>
>> You should try to use templated factory functions:
>>
>> auto makeA(..., bool _NestLevel = true)
>> {
>> return new A!(..., _NestLevel)();
>> }
>>
>
>
> Ok, I'm not familiar with these, I've seen a lot of "weird" notation
> dealing with a variable number of template args(I think it's `T...`?)

and such. I'll play around with it and hopefully get somewhere ;)
>

Yes, Symbol... (three dots) is the template tuple parameter syntax. They
are heavily used and are one of the most useful parts of D templates. Docs
are here:

http://dlang.org/template.html#TemplateTupleParameter
http://dlang.org/tuple.html
http://dlang.org/variadic-function-templates.html
http://dlang.org/templates-revisited.html

They are a bit old (they were already there in 2008 when I began with D),
but still useful.

Also, I wrote a tutorial on templates with other people being kind enough
to put example code in it. You'll find it here:


https://github.com/PhilippeSigaud/D-templates-tutorial/blob/master/dtemplates.pdf?raw=true


phobos by ref or by value

2012-12-16 Thread Dan
Is there a general philosophy in D phobos on when to pass by 
value or
reference?  For instance, to find a slice using lowerBound many 
copies
of the target item, as well as copies of items in the collection 
are
made (see code example below). This seems unnecessary - why not 
have

functions like:

auto lowerBound(...)(V value)

be:

auto lowerBound(...)(ref V value)

or:

auto lowerBound(...)(auto ref V value)

Is this a source for desire for no postblits, shallow semantics on
copy/assignment with additional logic for copy on write 
semantics. If
libraries in general are coded to make many copies of parameters 
it
might be a big improvement to not have postblits. A general 
purpose

library accessing ranges will not know the semantics of V (deep or
shallow), so why incur the cost of copies? Certainly finding a
lowerBound on a range of V can be done with 0 copies of elements?

Is there an established philosophy?

Thanks
Dan
---
  struct S {
DateTime date;
double val;
this(this) { writeln("copying S ", &this, ' ', date, ',', 
val); }

  }
---
  auto before(ref const(ValueType) vt) const {
auto ass = assumeSorted!orderingPred(_history[]);
writeln("Before lb");
auto lb = ass.lowerBound(vt);
writeln("After lb");
return History!(V, orderingPred)(_history[0 .. lb.length]);
  }

---
Before lb
copying S 7FFF622CE110 2001-Nov-01 00:00:00,0
copying S 7FFF622CE090 2001-Nov-01 00:00:00,0
copying S 7FFF622CE020 2001-Jan-01 00:00:00,100
copying S 7FFF622CE030 2001-Nov-01 00:00:00,0
copying S 7FFF622CDF90 2001-Jan-01 00:00:00,100
copying S 7FFF622CDFA0 2001-Nov-01 00:00:00,0
copying S 7FFF622CE020 2002-Jan-01 00:00:00,200
copying S 7FFF622CE030 2001-Nov-01 00:00:00,0
copying S 7FFF622CDF90 2002-Jan-01 00:00:00,200
copying S 7FFF622CDFA0 2001-Nov-01 00:00:00,0
copying S 7FFF622CE020 2001-Jan-01 00:00:00,200
copying S 7FFF622CE030 2001-Nov-01 00:00:00,0
copying S 7FFF622CDF90 2001-Jan-01 00:00:00,200
copying S 7FFF622CDFA0 2001-Nov-01 00:00:00,0
After lb


Re: Derelict SFML destructor crashes

2012-12-16 Thread Maxim Fomin

On Sunday, 16 December 2012 at 14:42:57 UTC, Nekroze wrote:
I am trying to do some wrapping of the CSFML derelict bindings 
to classes however when i use the CSFML methods to destroy the 
objects it causes a crash.


I have made a post in the SFML>D forum because they have syntax 
highlighting for D so this kind of post looks nicer but the 
link is here:


http://en.sfml-dev.org/forums/index.php?topic=10005.0

There is a minimal code example there and a better explanation.

Can anyone help me with why this is happening?


Why would you call a destroy() on a this object inside ~this()? 
And accessing allocated by GC objects inside destructor is not 
safe, because they may be collected before running the destructor.


Re: static code generation

2012-12-16 Thread anonymous

On Sunday, 16 December 2012 at 08:49:10 UTC, js.mdnq wrote:

On Sunday, 16 December 2012 at 06:38:13 UTC, anonymous wrote:

On Saturday, 15 December 2012 at 16:32:27 UTC, r_m_r wrote:

On 12/15/2012 08:57 PM, anonymous wrote:

Note that here s1alpha and s2alpha are distinct types.


what about this: http://dpaste.dzfl.pl/95f7a74d


Consider

struct Foo {mixin (genStruct!("s1"));}
struct Bar {mixin (genStruct!("s1"));}

Foo.s1alpha and Bar.s1alpha are the same type. In my version 
they are not.



Yes, they should be the same type. If you are inserting an 
actual struct with the same name("s1") then you would expect 
them to be identical.


I would not, actually. I'd expect it to behave like this:

struct Foo {struct s1 {}}
struct Bar {struct s1 {}}

and not like this:

struct s1 {}
struct Foo {alias .s1 s1;}
struct Bar {alias .s1 s1;}

However, if the alias version makes more sense in your case, by 
all means, use that one.


Re: Cross Compiler Lniux to Win32

2012-12-16 Thread Johannes Pfau
Am Sun, 16 Dec 2012 04:02:41 +0100
schrieb "Nekroze" :

>This would be fine i guess 
> so long as i could get away with being able to compile without 
> using the llvm-config tool that gives you the library and include 
> paths based on command line input because i am assuming i cant do 
> something like that from a visualD or some such project.

Well gdc's windows support is certainly not as good as dmds and dmd
doesn't support cross compilation...

I guess the simplest solution is to somehow extract the needed compiler
flags from llvm-config.


Re: std.math.approxEqual, 'maxRelDiff' parameter?

2012-12-16 Thread js.mdnq

On Saturday, 15 December 2012 at 19:01:23 UTC, ref2401 wrote:

What does means 'maxRelDiff' parameter?
I looked at the source code of this method and I still didn't 
get it.


return fabs((lhs - rhs) / rhs) <= maxRelDiff
|| maxAbsDiff != 0 && fabs(lhs - rhs) <= maxAbsDiff;

In what cases can I use this parameter?



basically floating point types are not accuracy. Is 0.01 = 
0.0001?


It all depends! floating point calculations can accumulate 
rounding errors which result in comparisons that should be valid 
are not.


Hence, it is not technically correct to compare two floating 
point types. Hence, the calculation above simply compares how 
close the two are and accepts them as == if they are within some 
distance of each other.




Re: static code generation

2012-12-16 Thread js.mdnq

On Sunday, 16 December 2012 at 06:38:13 UTC, anonymous wrote:

On Saturday, 15 December 2012 at 16:32:27 UTC, r_m_r wrote:

On 12/15/2012 08:57 PM, anonymous wrote:

Note that here s1alpha and s2alpha are distinct types.


what about this: http://dpaste.dzfl.pl/95f7a74d


Consider

struct Foo {mixin (genStruct!("s1"));}
struct Bar {mixin (genStruct!("s1"));}

Foo.s1alpha and Bar.s1alpha are the same type. In my version 
they are not.



Yes, they should be the same type. If you are inserting an actual 
struct with the same name("s1") then you would expect them to be 
identical. (else you could just do something like 
mixin(genStruct!("_1", "s1")); to get a different copy of the 
struct.


But we are not talking about inserting a field but "combining" 
structs.


I think the updated answer is more pertinent:

http://dpaste.dzfl.pl/d9f001db

Here we are "inserting" a struct(well, now it is simply a 
template) into another(not a struct field, different things).


struct B { int x; }
struct A { Insert(B); }

should be indentical to

struct A { int x; }

r_rm_r has parameterized it so that it's really A!(B) which is 
better so we can combine them in many ways.


What all this is analogous to is multiple inheritance at compile 
time. A inherits B, so to speak. It is helpful in breaking down 
larges structs into smaller ones and being able to mix and match.


One could also think of it as an algebra of structs.

It would be nice to be able to do stuff like

A + B, A - B(possibly useless), A*B(possibly useless), etc...

A + B would just combine the members, A - B could remove the 
members that overlap, A*B could qualify overlapping members.


struct A
{
  int x;
  int y;
}

struct B
{
  int x;
  int z;
}

A + B <==>

struct ApB {
  int x;   // Possible error because of overlap
  int y;
  int z;
}

A - B <==>
struct AmB {
   int y;
   int z;
}

A*B <==>
struct AtB {
   int x.A;
   int x.B;
   int y;
   int z;
}

or whatever. The usefulness is mainly that you can decompose a 
struct into pieces then recombine them into something possibly 
different. I'm not interested in the algebra aspect, just the 
ability to break down into two pieces, one I supply, one the user 
of the struct supplies. A simple A + B type of operation. The 
point, is, a lot of possible with such a feature. Possibly no one 
will use it but it could be quite powerful if it was designed 
appropriately.







Re: static code generation

2012-12-16 Thread js.mdnq

On Sunday, 16 December 2012 at 01:32:44 UTC, r_m_r wrote:

On 12/16/2012 06:36 AM, r_m_r wrote:

this is the closest I can get: http://dpaste.dzfl.pl/9d11d060


Cleaned up a bit: http://dpaste.dzfl.pl/d9f001db

regards,
r_m_r


That looks like it might be pretty close. I was also thinking 
that one could just use mixin templates of trying to do it with 
structs directly.


I think it is the right approach but the code as is will not work 
with additional type parameters from MasterStruct and UserStruct. 
I ran into the same issues in my nested struct code:


http://dpaste.dzfl.pl/64025e0a

Where I had to pass the types as strings and then append the 
hidden parameter.


Possibly you could try to figure out how to solve this problem? 
Maybe there is a better way then doing it with strings. (it would 
be real nice if I there was a compile time construct for this. 
like "me" or something that would return type info inside the 
current scope.


class A(T) { this() { writeln(me.typeinfo.name); }

would print "A(T)".

(of course me is probably a bad name but just an example :)

I'll be using your code soon once it works with multiple template 
parameters. (I'll make the changes if you don't)


Thanks.