最終更新日時(UTC):
が更新

履歴 編集

concept
<concepts>

std::semiregular(C++20)

namespace std {
  template<class T>
  concept semiregular = copyable<T> && default_initializable<T>;
}

概要

semiregularは、任意の型Tcopyableコンセプトを満たし、それに加えてデフォルト構築可能であることを表すコンセプトである。

半正則(semiregular)な型とはint型などの基本型の様に扱うことができる型を表しているが、==による等値比較が必ずしも可能ではない。

#include <iostream>
#include <concepts>

template<std::semiregular T>
void f(const char* name) {
  std::cout << name << " is semiregular" << std::endl;
}

template<typename T>
void f(const char* name) {
  std::cout << name << " is not semiregular" << std::endl;
}


struct semiregular {
  semiregular() = default;
  semiregular(const semiregular&) = default;
  semiregular& operator=(const semiregular&) = default;
};

struct copyable {
  copyable(const copyable&) = default;
  copyable& operator=(const copyable&) = default;
};

int main() {
  f<int>("int");
  f<double>("double");
  f<std::nullptr_t>("std::nullptr_t");
  f<std::size_t>("std::size_t");
  f<semiregular>("semiregular");

  std::cout << "\n";
  f<void>("void");
  f<copyable>("copyable");
}

出力

int is semiregular
double is semiregular
std::nullptr_t is semiregular
std::size_t is semiregular
semiregular is semiregular

void is not semiregular
copyable is not semiregular

バージョン

言語

  • C++20

処理系

関連項目

参照