www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - a couple of questions.. (mixins and inout)

↑ ↓ ← "Ivan Senji" <ivan.senji public.srce.hr> writes:
class A
{
 void func(){}
 template funcdecl(Type)
 {
  void func(Type t){writefln(t);}
 }
 mixin funcdecl!(int) ;
 mixin funcdecl!(float) ;
}

We all know this doesn't work but it can be fixed by adding aliases:
 mixin funcdecl!(int) a1;
 mixin funcdecl!(float) a2;
 alias a1.func func;
 alias a2.func func;

And now the name overloading works, but:
what if i want to mixin constructors, how can i do that?

 template funcdecl(Type)
 {
  this(Type t){}
 }
 mixin funcdecl!(int) a1;
 mixin funcdecl!(float) a2;
 alias a1.this this;
 alias a2.this this;

This doesn't work!

And another question:

class A{}
 void func(inout A a){}
 func(new A);
--> this doesn't work why? (new A  is not an lvalue)
If C++ can do it why not D?

It is a lot more complicated to assign temporary objects
to variables and then pass it as an inout param then to pass
it directly.
Sep 07 2004
↑ ↓ → "Ivan Senji" <ivan.senji public.srce.hr> writes:
Sorry! Wrong NG :)

"Ivan Senji" <ivan.senji public.srce.hr> wrote in message
news:chjmjn$268h$1 digitaldaemon.com...
 class A
 {
  void func(){}
  template funcdecl(Type)
  {
   void func(Type t){writefln(t);}
  }
  mixin funcdecl!(int) ;
  mixin funcdecl!(float) ;
 }

 We all know this doesn't work but it can be fixed by adding aliases:
  mixin funcdecl!(int) a1;
  mixin funcdecl!(float) a2;
  alias a1.func func;
  alias a2.func func;

 And now the name overloading works, but:
 what if i want to mixin constructors, how can i do that?

  template funcdecl(Type)
  {
   this(Type t){}
  }
  mixin funcdecl!(int) a1;
  mixin funcdecl!(float) a2;
  alias a1.this this;
  alias a2.this this;

 This doesn't work!

 And another question:

 class A{}
  void func(inout A a){}
  func(new A);
 --> this doesn't work why? (new A  is not an lvalue)
 If C++ can do it why not D?

 It is a lot more complicated to assign temporary objects
 to variables and then pass it as an inout param then to pass
 it directly.

Sep 07 2004