www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Suggesting an addition to std.traits for arrays and pointers

reply Markus Dangl <danglm in.tum.de> writes:
I think these two simple templates could be added to std.traits. Afaik
there is no way around defining templates for this:

/***
 * Get the referenced type of an array.
 * Example:
 * ---
 * import std.traits;
 * int[] foo;
 * ValueType!(foo) x;   // x is declared as int
 * ---
 */
template ValueType(T : T*)
{
    alias T ValueType;
}

/***
 * Get the referenced type of an pointer.
 * Example:
 * ---
 * import std.traits;
 * int* foo;
 * ValueType!(foo) x;   // x is declared as int
 * ---
 */
template ValueType(T : T[])
{
    alias T ValueType;
}
Aug 13 2007
next sibling parent Markus Dangl <danglm in.tum.de> writes:
Sorry wrong newsgroup. But - since ready-to-use code is included - this
might not be so totally wrong.
Aug 13 2007
prev sibling parent Benjamin Phillips <blackllotus gmail.com> writes:
Markus Dangl Wrote:

 I think these two simple templates could be added to std.traits. Afaik
 there is no way around defining templates for this:
 
 /***
  * Get the referenced type of an array.
  * Example:
  * ---
  * import std.traits;
  * int[] foo;
  * ValueType!(foo) x;   // x is declared as int
  * ---
  */
 template ValueType(T : T*)
 {
     alias T ValueType;
 }
 
 /***
  * Get the referenced type of an pointer.
  * Example:
  * ---
  * import std.traits;
  * int* foo;
  * ValueType!(foo) x;   // x is declared as int
  * ---
  */
 template ValueType(T : T[])
 {
     alias T ValueType;
 }

I think you mixed the comments up :)
Aug 14 2007