名稱空間
變體
操作

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 物件概念 [concepts.object]
  • C++20 標準 (ISO/IEC 14882:2020)
  • 18.6 物件概念 [concepts.object]

[編輯] 參閱

指定型別的物件可以被複制、移動、交換和預設構造
(概念) [編輯]