Missing introspection? "How exactly this type is actually used"

Ali Çehreli acehreli at yahoo.com
Fri May 20 17:45:01 UTC 2022


This is not really important and not possible at least due to separate 
compilation but I've just realized something.

Imagine there is a range type that uses DbI:

struct S(R) {
// ...
   static if (isRandomAccessRange!R) {
     // Potentially costly additional members
   }
}

What if the user never uses those costly members of that particular 
instantiation? What is missing is the ability to know whether the type 
is actually used that way. Since the compiler cannot know, I guess one 
option is to provide an additional template parameter to help the user 
opt out of certain DbI costs:

struct S(JustInputRangePlease justInputRangePlease /* ... */, R) {
// ...
   static if (justInputRangePlease) {
     // Nothing to add extra

   } else {
     static if (isRandomAccessRange!R) {
       // Potentially costly additional members
     }
   }
}

I don't think there is any real problem and this is not worth the 
complexity. I just wanted to tell you. :)

Ali


More information about the Digitalmars-d mailing list