Need a std::numeric_limits<T>::lowest() equivalent
Xavier Bigand via Digitalmars-d
digitalmars-d at puremagic.com
Fri Jan 20 15:45:38 PST 2017
Hi,
I am creating an AABB struct that should be initialized in an invalid
state. Here is my actual code :
> struct AABB(type, int dimensions)
> {
> static assert(dimensions == 2 || dimensions == 3);
>
> VectorType min = Vector!(type, 3)(type.max, type.max, type.max);
> VectorType max = Vector!(type, 3)(-type.max, -type.max, -type.max);
>
> bool isValid() const
> {
> return max >= min;
> }
>
> private alias VectorType = Vector!(type, dimensions);
>
> unittest
> {
> AABB2i aabbInt;
> AABB2f aabbFloat;
>
> assert(aabbInt.isValid == false);
> assert(aabbFloat.isValid == false);
> }
> }
Using -type.max is close to what I want but for integer int.min is
different than -int.max.
In c++11 there is std::numeric_limits<T>::lowest() that works perfectly.
Can an equivalent property added to integer and floating types?
PS: I prefer to use border values to be sure that the AABB stay invalid
with a partial initialization, else using -1 and 1 give the same result ;-)
More information about the Digitalmars-d
mailing list