This code basically does what I may want
    
    
    type
      O[X] = object
        i: int
        x: X
    
    proc d[X](o: O[X]) =
      when type(o.x) is bool: echo "yes" else: echo "no"
    
    var h1: O[bool]
    var h2: O[int8]
    
    d(h1)
    d(h2)
    
    
    
    yes
    no

But of course it is strange to use an arbitrary data type field just to get a 
compile time decision.

The reason why I may want that is, that I have generic data types, which for 
special use cases allow optimizations. But I do not want to code all procs 
working on these data types twice, and I can not use "when (defined)" because 
decision is for individual instances. Indeed it is for a Robin-Hood Hash Table, 
where for some cases optimizations are possible. But the optimization is not 
really based on the key data type, but more on the used equality test, so 
something like "when type(key) is string" is not the best solution. Well, maybe 
I will find a solution in the manual...

[EDIT]

Well, I could delete this posting: 

>From manual: "The is operator checks for type equivalence at compile time." So 
>it is exactly what I need. I was confused, thought it is a runtime check.

Reply via email to