ericniebler / range-v3

Range library for C++14/17/20, basis for C++20's std::ranges
Other
4.05k stars 437 forks source link

`diffmax_t` type does not satisfy the standards's "integer-class" requirements #1774

Open gnaggnoyil opened 1 year ago

gnaggnoyil commented 1 year ago

[iterator.concept.winc]#3 requires an integer-class type to be able to represent values either from $−2^{N−1}$ to $2^{N−1}−1$ or from 0 to $2^N-1$:

The range of representable values of an integer-class type is the continuous set of values over which it is defined. For any integer-class type, its range of representable values is either $−2^{N−1}$ to $2^{N−1}−1$ (inclusive) for some integer N, in which case it is a signed-integer-class type, or 0 to $2^N-1$ (inclusive) for some integer N, in which case it is an unsigned-integer-class type.

However, the following code:

#include <limits>
#include <iostream>
#include <cstdint>
#include <range/v3/all.hpp>

int main(){
    auto r = ranges::cpp20::views::iota(std::uintmax_t(0), std::uintmax_t(1));
    using t = ranges::cpp20::range_difference_t<decltype(r)>;
    std::cout << std::numeric_limits<t>::min() << ' ';
    std::cout << std::numeric_limits<t>::max() << std::endl;
    return 0;
}

gives the output -18446744073709551615 18446744073709551615 on compiler explorer, which doesn't fit the above requirements.