www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Storing "auto" types in classes

reply Rob Adelberg <radelberg36 gmail.com> writes:
I'm sure this has come up before, but I want to store something like an
std.array appender in a class.  All of the examples use auto for the type but
you can't put that in a class definition, so what do you put?

Example:
class packet{...}

class A {

   packet []  packetlist;
   appender!(packet) packappender;   // wrong format

   this () {
      packetlist = new packet[0];
      packappender = appender(&packetlist);
   }
   :
}

What's the format to store the appender in the class?
Jul 02 2010
parent reply Jonathan M Davis <jmdavisprog gmail.com> writes:
On Friday, July 02, 2010 09:46:37 Rob Adelberg wrote:
 I'm sure this has come up before, but I want to store something like an
 std.array appender in a class.  All of the examples use auto for the type
 but you can't put that in a class definition, so what do you put?
 
 Example:
 class packet{...}
 
 class A {
 
    packet []  packetlist;
    appender!(packet) packappender;   // wrong format
 
    this () {
       packetlist = new packet[0];
       packappender = appender(&packetlist);
    }
 
 }
 
 What's the format to store the appender in the class?

In this case, the type would be Appender!(packet[]). However, if you ever want to know the exact type of something, one way to do it is something like this: writeln(typeid(appender(&packelist))); It will print out the type of the expression for you. - Jonathan M Davis
Jul 02 2010
parent BCS <none anon.com> writes:
Hello Jonathan,

 On Friday, July 02, 2010 09:46:37 Rob Adelberg wrote:
 
 I'm sure this has come up before, but I want to store something like
 an std.array appender in a class.  All of the examples use auto for
 the type but you can't put that in a class definition, so what do you
 put?
 
 Example:
 class packet{...}
 class A {
 
 packet []  packetlist;
 appender!(packet) packappender;   // wrong format
 this () {
 packetlist = new packet[0];
 packappender = appender(&packetlist);
 }
 }
 
 What's the format to store the appender in the class?
 

ever want to know the exact type of something, one way to do it is something like this: writeln(typeid(appender(&packelist))); It will print out the type of the expression for you.

or you can get it at compile time: pragma(msg, typeof(exp).stringof);
 - Jonathan M Davis
 

... <IXOYE><
Jul 02 2010