std::regular
從 cppreference.com
在標頭 <concepts> 定義
|
||
template <class T> concept regular = std::semiregular<T> && std::equality_comparable<T>; |
(C++20 起) | |
regular
概念指定類型為正則,即它可複製、可默認構造且可比較相等。它被表現與如 int 的內建類型類似,且能以 ==
進行比較的類型所滿足。
[編輯] 示例
運行此代碼
#include <concepts> #include <iostream> template<std::regular T> struct Single { T value; friend bool operator==(const Single&, const Single&) = default; }; int main() { Single<int> myInt1{4}; Single<int> myInt2; myInt2 = myInt1; if (myInt1 == myInt2) std::cout << "Equal\n"; std::cout << myInt1.value << ' ' << myInt2.value << '\n'; }
輸出:
Equal 4 4
[編輯] 引用
- C++23 標準(ISO/IEC 14882:2024):
- 18.6 Object concepts [concepts.object]
- C++20 標準(ISO/IEC 14882:2020):
- 18.6 Object concepts [concepts.object]
[編輯] 參閱
(C++20) |
指定能賦值、移動、交換及默認構造一個類型的對象 (概念) |