Regarding the bound-checks... You have underestimated our code... ;)

If I understand correctly here:

https://github.com/cms-sw/cmssw/blob/HEAD/DetectorDescription/Parser/src/DDLDivision.cc#L52

we read those enums from xml, unless I misunderstand something, so you are not guaranteed that they are in bound.

I do have seen the compiler being extremely smart with bisections and so on with this kind of recursive constexpr, thanks to the fact a constexpr has to be only one single statement, and it allows for quite optimizable AST... I think also that the fact you cannot throw in constexpr plays a role in how aggressive it can be in optimizing.

In this particular case, however, I checked and the code in question it effectively does a linear search, so I can actually update it with something which uses your suggestion (in other cases I could not guarantee the compactness of the range hence the generic code which I cut & pasted, in this case your suggestion is obviously fine) +  the boundary checks.