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

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


On 5/20/22 12:41, H. S. Teoh wrote:

 > Actually, there would not be any compile-time or runtime cost if the
 > user doesn't actually use a method that requires calling the expensive
 > member.

Agreed about functions.

DbI allows one to inject member variables:

   static if (something) {
     int[1000] big;
   }

That big member cannot be optimized away if 'something' is true. Even if 
the user never uses this type in a way that necessitates that big member...

This appeared as I was designing a range type that could support 
BidirectionalRange primitives, which could make me add a buffer for 
those back elements:

   static if (isBidirectionalRange!R) {
     ElementType!R[] backElements;
   }

As you can see, the type is going out of its way to be helpful. But it 
costs the user even if they don't use .back or .popBack().

Ali



More information about the Digitalmars-d mailing list