Converting a number to complex

Artur Skawina art.08.09 at gmail.com
Sat Nov 24 02:30:40 PST 2012


On 11/24/12 08:27, Philippe Sigaud wrote:
> What's even nicer with an is() expr is that the introspection info is accessible when used inside a static if. So with Artur's code, CT can be seen inside the true branch of the static if.

Actually, static-ifs do not create a scope, so 'CT' leaks and is accessible
after it's defined, not just inside the static-if branch:

   void main() {
      Complex!double c;
      static if (is(typeof(c) _ == Complex!CT, CT))
         {}
      writeln(CT.stringof);
   }

It has to work like that, as otherwise it would be impossible (well, harder)
to conditionally compile /declarations/.


Unfortunately the is-expressions don't handle aliases properly, at least
with my old compiler here. So this does not work:

   template isTempInst(alias TEMPL, T) {
      static if (is(T _ == TEMPL!CT, CT))
         enum isTempInst = true;
      else
         enum isTempInst = false;
   }

artur


More information about the Digitalmars-d-learn mailing list