std::signed_integral
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Concepts library
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
signed_integral
(C++20)
(C++20)
(C++20)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
Exposition-only concepts
(C++20)
Defined in header
<concepts>
template< class T >
concept signed_integral = std::integral <T> && std::is_signed_v <T>;
(since C++20)
concept signed_integral = std::integral <T> && std::is_signed_v <T>;
The concept signed_integral<T>
is satisfied if and only if T
is an integral type and std::is_signed_v <T> is true.
Contents
[edit] Notes
signed_integral<T>
may be satisfied by a type that is not a signed integer type, for example, char (on a system where char is signed).
[edit] Example
Run this code
#include <concepts> #include <iostream> #include <string_view> void test(std::signed_integral auto x, std::string_view text = "") { std::cout << text << " (" + (text == "") << x << ") is a signed integral\n"; } void test(std::unsigned_integral auto x, std::string_view text = "") { std::cout << text << " (" + (text == "") << x << ") is an unsigned integral\n"; } void test(auto x, std::string_view text = "") { std::cout << text << " (" + (text == "") << x << ") is non-integral\n"; } int main() { test(42); // signed test(0xFULL, "0xFULL"); // unsigned test('A'); // platform-dependent test(true, "true"); // unsigned test(4e-2, "4e-2"); // non-integral (hex-float) test("∫∫"); // non-integral }
Possible output:
(42) is a signed integral 0xFULL (15) is an unsigned integral (A) is a signed integral true (1) is an unsigned integral 4e-2 (0.04) is non-integral (∫∫) is non-integral
[edit] References
- C++23 standard (ISO/IEC 14882:2024):
- 18.4.7 Arithmetic concepts [concepts.arithmetic]
- C++20 standard (ISO/IEC 14882:2020):
- 18.4.7 Arithmetic concepts [concepts.arithmetic]