Hi all,
I am wondering if there is any Phobos functionality for indexing into a list using a type. What I mean is something like:

assert( somethingie!(float, float, double, real)(1, 22, 333) == 1 ); assert( somethingie!(double, float, double, real)(1, 22, 333) == 22 ); assert( somethingie!(real, float, double, real)(1, 22, 333) == 333 );

It would help with unittest definitions, such as:

foreach (F; TypeTuple!(float, double, real))
{
  Tuple!(F, int)[] vals =     // x, ilogb(x)
  [
    tuple(  2.0001    , 1           ),
    tuple(  1.9999    , 0           ),
    // ...
tuple(-F.min_normal, somethingie!(F, float, double, real)(-126, -1022, -16382),
  ];

  foreach(elem; vals)
  {
    assert(ilogb(elem[0]) == elem[1]);
  }
}

Thanks!

(on IRC, I was advised to move the special case of min_normal outside of the loop. Perhaps more people like that better, but still I am interested in knowing if my "somethingie" exists, or whether you think it is useful too. (what if there are 10 such special cases?))

Reply via email to