Rainer Deyke wrote:
Denis Koroskin wrote:
Arrays in D are reference types. Besides, it's best to avoid hidden
allocations.
Arrays in D are reference types except when they're not.
int[] a = [5];
int[] b = a;
a[0] = 4;
assert(b[0] == 4);
a.length = 2;
assert(b.length == 1);
a[0] = 3;
// Is b[0
On Tue, Jan 20, 2009 at 7:42 PM, Christopher Wright wrote:
> Naturally, __traits and foreach don't mix, so you'll have to use template
> recursion. This is pretty damn ugly.
I never understood why __traits likes returning arrays so much. Why not tuples?
> Note that getVirtualFunctions returns
Jarrett Billingsley wrote:
On Tue, Jan 20, 2009 at 10:29 AM, Trass3r wrote:
It seems like there is no way to automatically get the class methods in D1
currently?!
__traits isn't supported, std.traits doesn't give anything usable, .tupleof
only gets the fields (plus only giving an ExpressionTupl
Sergey Gromov wrote:
Comment out the traits and it compiles. Traits are supposed to be
compile-time. How's that possible for them to prevent compile-time
evaluation?
It's the amazing powers of the DMD CTFE engine! And it's why I don't use
d2 these days.
I think I'll dust off some old code
On Wed, Jan 21, 2009 at 8:25 AM, Trass3r wrote:
> Trass3r schrieb:
>>
>> This works:
>>
>> string foo(const string[] members)
>> {
>>string result;
>>foreach(m; members)
>>result ~= m ~ " ";
>>return result;
>> }
>>
>
> Furthermore there seems to be no way to use these member n
Trass3r schrieb:
This works:
string foo(const string[] members)
{
string result;
foreach(m; members)
result ~= m ~ " ";
return result;
}
Furthermore there seems to be no way to use these member names in a
__traits(getMember, class, m) call.
This is driving me crazy.
This works:
template classMixin()
{
static this()
{
const string[] members = __traits(allMembers, typeof(this));
pragma(msg, foo(members));
}
}
string foo(const string[] members)
{
string result;
foreach(m; members)
result ~= m ~ " ";
retur
Tue, 20 Jan 2009 21:12:18 + (UTC), BCS wrote:
> Reply to Trass3r,
>
>> Sergey Gromov schrieb:
>>
>>> auto members = __traits(allMembers, Cls);
>>
>> Seeing this really simple example crashing makes me think that this
>> has to be a bug.
>>
>
> that auto might be mucking it up (if so it wou
Reply to Trass3r,
Sergey Gromov schrieb:
auto members = __traits(allMembers, Cls);
Seeing this really simple example crashing makes me think that this
has to be a bug.
that auto might be mucking it up (if so it would be a bug).
Reply to Trass3r,
auto members = __traits(allMembers, typeof(this));
try switching that to
const[][] members = __traits(allMembers, typeof(this));
if that doesn't fix it try dropping this part (it might make it clearer what's
going on)
static if (is (typeof(__traits(getMember, this, m
Sergey Gromov schrieb:
> class Cls
{
int bar;
char[] baz;
}
string foo()
{
auto members = __traits(allMembers, Cls);
return "";
}
pragma(msg, foo());
dmd -c test.d
test.d(11): Error: cannot evaluate foo() at compile time
test.d(11): pragma msg string expected for message, not 'foo()'
BCS schrieb:
template Tpl(T...)
{
alias T Tpl;
}
template Range(int l, int u)
{
static if(l foreach(str; Range!(0,set.length-1)) // compile time foreach over the
numbers from 0 to set.length-1
pragma(msg, set[str]);
}
Still doesn't work for this code (used with a mixin):
template class
Tue, 20 Jan 2009 16:36:09 +0100, Trass3r wrote:
> Is there any way to output information at compile time other than
> pragma(msg?
> pragma is driving me crazy, the following doesn't work:
>
> auto members = __traits(allMembers, typeof(this));
> foreach(m; members)
> {
> pragma(msg, m);
> }
Reply to Trass3r,
BCS schrieb:
I don't do 2.0 but it looks to me like your mixing runtime and
compile time stuff. A foreach over an array is a runtime foreach.
Do you know how I could make it run at compile-time?
template Tpl(T...)
{
alias T Tpl;
}
template Range(int l, int u)
{
static
BCS schrieb:
I don't do 2.0 but it looks to me like your mixing runtime and compile
time stuff. A foreach over an array is a runtime foreach.
Do you know how I could make it run at compile-time?
Jarrett Billingsley schrieb:
On Tue, Jan 20, 2009 at 2:13 PM, Trass3r wrote:
Yeah, __traits works quite well to get the function names, but I still can't
manage to get the corresponding function object to pass it to
ParameterTypeTuple (for checking the parameters for correctness).
Ah, that's
On Tue, Jan 20, 2009 at 2:13 PM, Trass3r wrote:
> Yeah, __traits works quite well to get the function names, but I still can't
> manage to get the corresponding function object to pass it to
> ParameterTypeTuple (for checking the parameters for correctness).
Ah, that's what __traits(getMember) is
Jarrett Billingsley schrieb:
On Tue, Jan 20, 2009 at 10:29 AM, Trass3r wrote:
It seems like there is no way to automatically get the class methods in D1
currently?!
__traits isn't supported, std.traits doesn't give anything usable, .tupleof
only gets the fields (plus only giving an ExpressionTu
Jarrett Billingsley Wrote:
> On Tue, Jan 20, 2009 at 12:21 PM, Steven Schveighoffer
> wrote:
> > So it appears it returns 0 unless you return something else (!)
>
> Ha!
Yes (but not always), even though specs clearly say that void functions
evaluate return values and discard them.
IIRC, this
Reply to Trass3r,
Is there any way to output information at compile time other than
pragma(msg?
pragma is driving me crazy, the following doesn't work:
auto members = __traits(allMembers, typeof(this));
foreach(m; members)
{
pragma(msg, m);
}
-> Error: string expected for message, not 'm'
Thoug
Bill Baxter schrieb:
try indexing explicitly or using ref:
foreach(i,m; members)
{
pragma(msg, members[i]);
}
foreach(ref m; members)
{
pragma(msg, m);
}
Latter one may not be useful. I can't recall.
Neither one works for me :(
On Tue, Jan 20, 2009 at 12:21 PM, Steven Schveighoffer
wrote:
> So it appears it returns 0 unless you return something else (!)
Ha!
"bearophile" wrote
>I post this here, but if later I see it fit I may post something in the
>main D group too.
>
> D allows to have the main() function of type void too. In such case I'd
> like the program return 0 by default. If people agrees, this can become a
> feature request.
A test:
[ste.
Trass3r wrote:
Is there any way to output information at compile time other than
pragma(msg?
pragma is driving me crazy, the following doesn't work:
auto members = __traits(allMembers, typeof(this));
Kind of offtopic, but I tried this (with typeof(Foo) and Foo is defined
in the same module)
On Tue, Jan 20, 2009 at 10:29 AM, Trass3r wrote:
> It seems like there is no way to automatically get the class methods in D1
> currently?!
> __traits isn't supported, std.traits doesn't give anything usable, .tupleof
> only gets the fields (plus only giving an ExpressionTuple for classes).
You'r
On Tue, Jan 20, 2009 at 10:25 AM, bearophile wrote:
> Bill Baxter:
>
>> What does it return now?
>
> A random int, I presume.
>
>
>>I always assumed returned zero for void main.<
>
> Me too.
I've only ever seen void mains return 0. I think they used to return
random ints but that was fixed long
On Wed, Jan 21, 2009 at 12:36 AM, Trass3r wrote:
> Is there any way to output information at compile time other than
> pragma(msg?
> pragma is driving me crazy, the following doesn't work:
>
> auto members = __traits(allMembers, typeof(this));
> foreach(m; members)
> {
>pragma(msg, m);
> }
Is there any way to output information at compile time other than
pragma(msg?
pragma is driving me crazy, the following doesn't work:
auto members = __traits(allMembers, typeof(this));
foreach(m; members)
{
pragma(msg, m);
}
-> Error: string expected for message, not 'm'
Though the doc
It seems like there is no way to automatically get the class methods in
D1 currently?!
__traits isn't supported, std.traits doesn't give anything usable,
.tupleof only gets the fields (plus only giving an ExpressionTuple for
classes).
Bill Baxter:
> What does it return now?
A random int, I presume.
>I always assumed returned zero for void main.<
Me too.
Bye,
bearophile
BCS schrieb:
you can get the names even in D1.0. Not exactly clean but...
http://codepad.org/Eu16XqFu
Yeah but only works for structs. When used with classes returns an
ExpressionTuple. Furthermore you only get the fields, I need the methods ;)
On Tue, Jan 20, 2009 at 11:15 PM, bearophile wrote:
> I post this here, but if later I see it fit I may post something in the main
> D group too.
>
> D allows to have the main() function of type void too. In such case I'd like
> the program return 0 by default. If people agrees, this can become
I post this here, but if later I see it fit I may post something in the main D
group too.
D allows to have the main() function of type void too. In such case I'd like
the program return 0 by default. If people agrees, this can become a feature
request.
A question: when D automatically adds som
%u schrieb:
is there a script engine for D 2.x
You might try lua. See announce section, I just released a new revision
aiming at compatibility with D2.
Is it possible to compile D source code to object files without first
saving the source to the filesystem. I kind of would like to generate the
code within the program and use a static or dynamicly linked program to
compile it. Not like interpreting script language.
35 matches
Mail list logo