Skip to content

Latest commit

 

History

History
84 lines (66 loc) · 1.75 KB

integral.md

File metadata and controls

84 lines (66 loc) · 1.75 KB

integral

  • concepts[meta header]
  • std[meta namespace]
  • concept[meta id-type]
  • cpp20[meta cpp]
namespace std {
  template<class T>
  concept integral = is_integral_v<T>;
}
  • is_integral_v[link /reference/type_traits/is_integral.md]

概要

integralは、任意の型Tが整数型であることを表すコンセプトである。

#include <iostream>
#include <concepts>
#include <cstdint>
#include <type_traits>

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

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


int main() {
  f<bool>("bool");
  f<int>("int");
  f<std::size_t>("std::size_t");
  f<std::uint32_t>("std::uint32_t");
  f<char>("char");
  f<char8_t>("char8_t");

  std::cout << "\n";

  f<int*>("int*");
  f<int&>("int&");
  f<std::integral_constant<int, 1>>("std::integral_constant<int, 1>");
}
  • std::integral[color ff0000]

出力

bool is integral
int is integral
std::size_t is integral
std::uint32_t is integral
char is integral
char8_t is integral

int* is not integral
int& is not integral
std::integral_constant<int, 1> is not integral

バージョン

言語

  • C++20

処理系

関連項目

参照