pineapplemachine

Dlang static foreach syntax ideas

Sep 30th, 2016
513
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// allSatisfy-equivalent template from mach
  2. template All(alias predicate, T...){
  3.     static if(T.length == 0){
  4.         enum bool All = true;
  5.     }else static if(T.length == 1){
  6.         enum bool All = predicate!(T[0]);
  7.     }else{
  8.         enum bool All = (
  9.             All!(predicate, T[0]) &&
  10.             All!(predicate, T[1 .. $])
  11.         );
  12.     }
  13. }
  14.  
  15. /// static foreach syntax suggestion
  16. template All(alias predicate, Tx...){
  17.     foreach(T; Tx){
  18.         static if(!predicate!T){
  19.             enum bool All = false;
  20.             // Some way to not evaluate after-loop `enum bool All = true;`
  21.             // is required. `return` may be the best option for this?
  22.             return;
  23.         }
  24.     }
  25.     enum bool All = true;
  26. }
  27.  
  28. /// another suggestion
  29. template All(alias predicate, Tx...){
  30.     enum bool All = true;
  31.     foreach(T; Tx){
  32.         static if(!predicate!T){
  33.             enum bool All = false;
  34.         }
  35.     }
  36. }
  37.  
  38.  
  39.  
  40. // In mach currently
  41. template Map(alias transform, T...){
  42.     static if(T.length == 0){
  43.         alias Map = Aliases!();
  44.     }else static if(T.length == 1){
  45.         alias Map = Aliases!(transform!(T[0]));
  46.     }else{
  47.         alias Map = Aliases!(
  48.             Map!(transform, T[0]),
  49.             Map!(transform, T[1 .. $])
  50.         );
  51.     }
  52. }
  53.  
  54. // static foreach suggestion
  55. template Map(alias transform, Tx...){
  56.     alias Map = Aliases!() // Aliases ~= AliasSeq
  57.     foreach(T; Tx){
  58.         alias Map = Aliases!(Map, transform!T);
  59.     }
  60. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×