std::regular
From 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 standard (ISO/IEC 14882:2020)
- 18.6 オブジェクトコンセプツ [concepts.object]
[編集] 関連項目
| (C++20) |
その型のオブジェクトがコピー、ムーブ、交換、およびデフォルト構築可能であることを規定する (コンセプト) |