|
|
Defined in header <utility> | ||
template<class R,class T> constexprbool in_range( T t)noexcept; | (since C++20) | |
Returnstrue if the value oft is in the range of values that can be represented inR
, that is, ift can be converted toR
in a value-preserving manner.
It is a compile-time error if eitherT
orU
is a non-integer type, a character type, orbool.
Contents |
t | - | value to test |
true if the value oft is representable inR
,false otherwise.
template<class R,class T>constexprbool in_range(T t)noexcept{returnstd::cmp_greater_equal(t,std::numeric_limits<R>::min())&&std::cmp_less_equal(t,std::numeric_limits<R>::max());} |
This function cannot be used withenums (includingstd::byte),char,char8_t,char16_t,char32_t,wchar_t andbool.
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_integer_comparison_functions | 202002L | (C++20) | Integer comparison functions |
#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';}
Output:
falsetrue
(C++20) | returns the smaller of the given values (algorithm function object)[edit] |
(C++20) | returns the greater of the given values (algorithm function object)[edit] |
(C++20) | clamps a value between a pair of boundary values (algorithm function object)[edit] |
(C++20) | linear interpolation function (function)[edit] |