Limiting range of value types in C++

前端 未结 9 775
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 10:33

Suppose I have a LimitedValue class which holds a value, and is parameterized on int types \'min\' and \'max\'. You\'d use it as a container for holding values which can on

9条回答
  •  渐次进展
    2020-11-28 11:22

    At the moment, that is impossible in a portable manner due to the C++ rules on how methods (and by extension, constructors) are called even with constant arguments.

    In the C++0x standard, you could have a const-expr that would allow such an error to be produced though.

    (This is assuming you want it to throw an error only if the actual value is illegal. If the ranges do not match, you can achieve this)

提交回复
热议问题