std::in_range

Header: <utility>

Returns true if the value of t is in the range of values that can be represented in R, that is, if t can be converted to R in a value-preserving manner.

# Declarations

template< class R, class T >
constexpr bool in_range( T t ) noexcept;

(since C++20)

# Parameters

# Return value

true if the value of t is representable in R, false otherwise.

# Notes

This function cannot be used with enums (including std::byte), char, char8_t, char16_t, char32_t, wchar_t and bool.

# Example

#include <iostream>
#include <utility>
 
int main()
{
    std::cout << std::boolalpha;
 
    std::cout << std::in_range<std::size_t>(-1) << '\n';
    std::cout << std::in_range<std::size_t>(42) << '\n';
}

# See also