Sean Kelly wrote:
> Steven Schveighoffer Wrote:
>
>> On Thu, 05 Aug 2010 13:53:20 -0400, dcoder wrote:
>>
>> > Suppose I have a base class with many ctors().
>> >
>> > I want to inherit from the base class and make one slight alteration to
>> > it,
>> > but I don't want to write X times the fol
Rationale (http://digitalmars.com/d/2.0/rationale.html) says:
"""Why not use operator names like __add__ and __div__ instead of opAdd,
opDiv, etc.?
__ keywords should indicate a proprietary language extension, not a
basic part of the language. """
But traits is explained under the language
Are these equivalent?
S s;//struct
void f(ref S s){s.x++;}
f(s);
void f2(S* s){(*s).x++;}
f2(&s);
If so, why is it stated that ref is very rarely used?
It looks like something I would use a lot with structures.
On Fri, 06 Aug 2010 08:42:40 -0400, simendsjo
wrote:
Rationale (http://digitalmars.com/d/2.0/rationale.html) says:
"""Why not use operator names like __add__ and __div__ instead of opAdd,
opDiv, etc.?
__ keywords should indicate a proprietary language extension, not a
basic part of the
On Fri, 06 Aug 2010 08:51:31 -0400, Pluto wrote:
Are these equivalent?
S s;//struct
void f(ref S s){s.x++;}
f(s);
void f2(S* s){(*s).x++;}
f2(&s);
They are pretty much equivalent. I think the code generated actually will
be exactly the same. However, the compiler treats ref differently
== Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article
> On Fri, 06 Aug 2010 08:51:31 -0400, Pluto wrote:
> > Are these equivalent?
> >
> > S s;//struct
> >
> > void f(ref S s){s.x++;}
> > f(s);
> >
> > void f2(S* s){(*s).x++;}
> > f2(&s);
> They are pretty much equivalent. I think th
Hi,
I'm investigating if D would be useful to me as a numerical programming
language to replace my current mix of fortran and python.
I'm stuck with a problem which seems odd to me:
cdouble c1;
c1 = 2.0;
complains:
Error: cannot implicitly convert expression (2) of type double to c
== Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article
> On Fri, 06 Aug 2010 08:51:31 -0400, Pluto wrote:
> > Are these equivalent?
> >
> > S s;//struct
> >
> > void f(ref S s){s.x++;}
> > f(s);
> >
> > void f2(S* s){(*s).x++;}
> > f2(&s);
> They are pretty much equivalent. I think th
John Travers:
> c1 = cast(cdouble)2.0;
Casts are bad, better to avoid them when possible.
You can do this:
void main() {
cdouble c1;
c1 = 2.0 + 0i;
}
But complex numbers will be removed from D, they will become partially library
ones (imaginary ones will probably just removed). I think
On 2010-08-06 15:33, Pluto wrote:
== Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article
On Fri, 06 Aug 2010 08:51:31 -0400, Pluto wrote:
Are these equivalent?
S s;//struct
void f(ref S s){s.x++;}
f(s);
void f2(S* s){(*s).x++;}
f2(&s);
They are pretty much equivalent. I think
On Fri, Aug 6, 2010 at 11:43, Rory Mcguire wrote:
> I've been trying to make a template for this but it seems that dmd still
> won't allow me to get the parameters of the constructors. dmd Seems to
> think
> that I'm trying to use it as a property.
>
>
> void main() {
>foreach (m; __traits(
Philippe Sigaud:
> This is my new once-a-day bug :(
Add them all to Bugzilla :-)
Bye,
bearophile
On Fri, Aug 6, 2010 at 19:09, bearophile wrote:
> Philippe Sigaud:
> > This is my new once-a-day bug :(
>
> Add them all to Bugzilla :-)
>
I do, from time to time. But I'm never sure if it's a bug or not.
It's related to The Great And Neverending Property Debate (tm). So I don't
what to believe
Philippe Sigaud wrote:
> On Fri, Aug 6, 2010 at 11:43, Rory Mcguire
> wrote:
>
>
>> I've been trying to make a template for this but it seems that dmd still
>> won't allow me to get the parameters of the constructors. dmd Seems to
>> think
>> that I'm trying to use it as a property.
>>
>>
>
>>
== Quote from Jacob Carlborg (d...@me.com)'s article
> On 2010-08-06 15:33, Pluto wrote:
> > == Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article
> >> On Fri, 06 Aug 2010 08:51:31 -0400, Pluto wrote:
> >>> Are these equivalent?
> >>>
> >>> S s;//struct
> >>>
> >>> void f(ref S s){s.x
Rory Mcguire wrote:
> Philippe Sigaud wrote:
>
>> On Fri, Aug 6, 2010 at 11:43, Rory Mcguire
>> wrote:
>>
>>
>>> I've been trying to make a template for this but it seems that dmd still
>>> won't allow me to get the parameters of the constructors. dmd Seems to
>>> think
>>> that I'm trying to
Hello,
can someone help me with this?
struct Group {
int i1;
Group opBinary(string op)(int x) {
// do somehting
return this;
}
Group opBinary(string op)(Group g) {
// do something
return this;
}
}
Group g, h;
g.i1 = 1;
h = g+g;
On Friday, August 06, 2010 12:30:38 Blonder wrote:
> Hello,
>
> can someone help me with this?
>
> struct Group {
> int i1;
> Group opBinary(string op)(int x) {
> // do somehting
> return this;
> }
> Group opBinary(string op)(Group g) {
> // do something
>
dcoder wrote:
> Suppose I have a base class with many ctors().
>
> I want to inherit from the base class and make one slight alteration to
> it, but I don't want to write X times the following:
>
> this(args) {
> super(args);
> }
>
> Does D have an easy way for the derived class to 'inherit'
Hello, I am trying to understand how operator overloading works with D. I am a
C++
programmer and I am reading the book of Andrei Alexandrescu and try to
understand
D and it's language features.
My Group example don't compile, the error is:
Error: template instance opBinary!("+") matches more th
On 06/08/2010 21:08, Blonder wrote:
Hello, I am trying to understand how operator overloading works with D. I am a
C++
programmer and I am reading the book of Andrei Alexandrescu and try to
understand
D and it's language features.
My Group example don't compile, the error is:
Error: template i
On 06/08/2010 21:37, div0 wrote:
You need to add a second template parameter for the function arguments
and add a template constrait like so:
struct Group {
int i1;
Group opBinary(string op, U) (U x)
if(op == "+" && is(U: int))
{
// do somehting
return this;
On Fri, Aug 6, 2010 at 21:59, Rory Mcguire wrote:
>
> Here is a possible solution to your problem:
>
> -Rory
I believe you can get the type of A. Isn't it typeof(super) or
std.traits.BaseClassesTuple!B[0] ? B in the latter case being typeof(this)
That way, there is no need for the user to provi
On Fri, Aug 6, 2010 at 22:37, div0 wrote:
> Personally, I'm with you and I would expect that the compiler should
> example the function parameters after the template string parameter but it
> doesn't.
>
Yes :o(
You need to add a second template parameter for the function arguments and
add a temp
Hello,
this seems to work, but if I add the following
double opBinary(string op, U) (U rhs)
{
static if(op == "^" && is(U: Group))
{
// do something
return 42;
}
}
because I wa
On 06/08/2010 22:24, Blonder wrote:
Hello,
this seems to work, but if I add the following
double opBinary(string op, U) (U rhs)
{
static if(op == "^"&& is(U: Group))
{
// do something
return 42;
There is an AutoImplement class template in
http://www.digitalmars.com/d/2.0/phobos/std_typecons.html#AutoImplement , which
I've just been trying out. Apparently you can pass it 1: a Base class, 2: a
templated function to filter out which functions you want to inherit/overwrite
from the Base cl
Thanks, that is the solution.
> No programming language is intuitive; they all take time to learn.
> D is a big win over C++ though and well worth sticking with.
Yes, you are right, it takes time to learn.
@Philippe Sigaud
Thanks also.
Here's an example:
import std.stdio;
import std.traits;
import std.conv;
import std.typecons;
class C
{
int m_value;
int testMe()
{
return 1;
}
this(int x)
{
m_value = x;
}
this(int x, int z)
{
m_value = x + z;
}
}
29 matches
Mail list logo