Trass3r:
> Of course this can be circumvented by using
> opBinary(string op, U:Vector2)(U v)
> opBinary(string op, U:int)(U v)
>
> But is this how it's supposed to be done? Couldn't the compiler detect
> that itself?
The compiler can probably do that by itself, but to do that I think templates
I stumbled across this while playing with operator overloading. Since they
are now function templates, this becomes an issue.
struct Vector2(T)
{
T x;
T y;
/// element-wise operations, +, -,
Vector2 opBinary(string op)(ref Vector2 v)
{
mixin("return Ve
Filed it, with some small changes:
http://d.puremagic.com/issues/show_bug.cgi?id=3934
Bye,
bearophile
On 03/11/2010 10:44 PM, bearophile wrote:
As far as I know, it's "enum" that has that purpose.
Oh, but they are not the same. enum declares a constant, whereas static
declares a variable. A static global is still mutable.
Thank you for your answers,
bearophile
Why thank you!
Pelle M.
> static does not apply to free functions, I would guess this means the
> same as auto.
As far as I know a global function like:
auto foo() {}
is correct in D2, it means the compiler will infer the return type, that here
is void. That's why I have not added this case to that list.
>s
On 03/11/2010 10:20 PM, bearophile wrote:
While looking for possible attribute problems to add to Bugzilla, I have seen
the following D2 program compiles and runs with no errors or warnings:
static foo1() {}
static does not apply to free functions, I would guess this means the
same as auto.
While looking for possible attribute problems to add to Bugzilla, I have seen
the following D2 program compiles and runs with no errors or warnings:
static foo1() {}
final foo2() {}
ref foo3() {}
enum void foo5() {}
nothrow foo4() {}
pure foo6() {}
static int x1 = 10;
static x2 = 10;
void main()
On 03/11/2010 06:22 PM, bearophile wrote:
While trying to create a safe int, I have found a problem, this is reduced code:
struct Foo {
int x;
static Foo opAssign(int value) { return Foo(value); }
}
void main() {
Foo y = 0;
}
The compiler prints:
test.d(6): Error: cannot implici
On Thu, Mar 11, 2010 at 21:03, BCS wrote:
>
>
>> i.e.
>>
>> static C create(Args...)(int foo, float bar, Args args)
>> {
>> auto c = new C(foo, bar);
>> c.t = T(args);
>> return c;
>> }
>>
>
> What about a static function instead of a constructor?
>
Two variations on the same theme:
storing (Ar
Hello Steven,
What about a static function instead of a constructor?
i.e.
static C create(Args...)(int foo, float bar, Args args)
{
auto c = new C(foo, bar);
c.t = T(args);
return c;
}
That's my fallback position.
It's a shame template constructors aren't allowed, they aren't even
virtual
Hello Lutger,
Workaround if T has a single constructor, perhaps it can be
generalized with some work:
this(int foo, float bar, std.traits.ParameterTypeTuple!(T.__ctor)
args)
{
t = T(args);
}
Not exactly ideal, but... :)
--
... <
On Thu, 11 Mar 2010 02:58:52 -0500, BCS wrote:
Using D2, I have a template class that looks something like this:
class C(T) { T t; }
(For simplicity, assume T is required to be a struct of some kind.) I
want to have a constructor that passes on some of it's args to a
constructor for t. Th
BCS wrote:
> Using D2, I have a template class that looks something like this:
>
> class C(T) { T t; }
>
> (For simplicity, assume T is required to be a struct of some kind.) I want
> to have a constructor that passes on some of it's args to a constructor for
> t. This is easy as long as I don't
Ellery Newcomer:
> define opCall in Foo
Thank you :-)
I need to practice more with operator overload.
Bye,
bearophile
On 03/11/2010 11:22 AM, bearophile wrote:
While trying to create a safe int, I have found a problem, this is reduced code:
struct Foo {
int x;
static Foo opAssign(int value) { return Foo(value); }
}
void main() {
Foo y = 0;
}
The compiler prints:
test.d(6): Error: cannot implici
On 03/11/2010 10:36 AM, Nick Sabalausky wrote:
"Ellery Newcomer" wrote in message
news:hn9qvi$qf...@digitalmars.com...
how do you get stacktracing to work under windows?
Have you seen this page?
http://www.dsource.org/projects/tango/wiki/TutStackTrace
No I haven't. Thanks.
"Windows
You n
While trying to create a safe int, I have found a problem, this is reduced code:
struct Foo {
int x;
static Foo opAssign(int value) { return Foo(value); }
}
void main() {
Foo y = 0;
}
The compiler prints:
test.d(6): Error: cannot implicitly convert expression (0) of type int to Foo
"Ellery Newcomer" wrote in message
news:hn9qvi$qf...@digitalmars.com...
> how do you get stacktracing to work under windows?
Have you seen this page?
http://www.dsource.org/projects/tango/wiki/TutStackTrace
"Windows
You need to compile without optimizations and with -g to get the stack
traces.
On Wed, 10 Mar 2010 08:28:16 -0500, bearophile wrote:
> Michal Minich:
>> is there way to decorate delegate type with any of these?
>
> Yes, you can do it, but this part of the language is new and I think it
> has some bugs.
>
> Bye,
> bearophile
I see that you also post a bug report about it.
On 3/11/10 08:58, BCS wrote:
Using D2, I have a template class that looks something like this:
class C(T) { T t; }
(For simplicity, assume T is required to be a struct of some kind.) I
want to have a constructor that passes on some of it's args to a
constructor for t. This is easy as long as I
Using D2, I have a template class that looks something like this:
class C(T) { T t; }
(For simplicity, assume T is required to be a struct of some kind.) I want
to have a constructor that passes on some of it's args to a constructor for
t. This is easy as long as I don't need it to work for ar
21 matches
Mail list logo