Guest User

Untitled

a guest
Oct 23rd, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.80 KB | None | 0 0
  1.  
  2. import std.stdio;
  3. import std.traits;
  4.  
  5. template pointerTargetRecursive(T : T*) {
  6.   static if (!isPointer!T)
  7.     alias T pointerTargetRecursive;
  8.   else
  9.     alias pointerTargetRecursive!T pointerTargetRecursive;
  10. }
  11.  
  12. pointerTargetRecursive!T concreteValue (T) (T pointer) if (isPointer!T) {
  13.   return  concreteValue(*pointer);
  14. }
  15.  
  16. T concreteValue (T) (T value) if (!isPointer!T) {
  17.   return value;
  18. }
  19.  
  20. void main () {
  21.   writeln("start");
  22.  
  23.   int i = 5;
  24.   int* p = &i;
  25.   int** pp = &p;
  26.   int*** ppp = &pp;
  27.   int**** pppp = &ppp;
  28.   int***** ppppp = &pppp;
  29.  
  30.   writeln(concreteValue(i)); // 5
  31.   writeln(concreteValue(p)); // 5
  32.   writeln(concreteValue(pp)); // 5
  33.   writeln(concreteValue(ppp)); // 5
  34.   writeln(concreteValue(pppp)); // 5
  35.   writeln(concreteValue(ppppp)); // 5
  36.  
  37.   writeln("end");
  38. }
Add Comment
Please, Sign In to add comment