Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::same_as

      From cppreference.com
      <cpp‎ |concepts
       
       
      Concepts library
       
      Defined in header<concepts>
      template<class T,class U>
      concept same_as=/* see below */;
      (since C++20)

      The conceptsame_as<T, U> is satisfied if and only ifT andU denote the same type.

      std::same_as<T, U>subsumesstd::same_as<U, T> and vice versa.

      Contents

      [edit]Possible implementation

      namespace detail{template<class T,class U>    concept SameHelper=std::is_same_v<T, U>;} template<class T,class U>concept same_as= detail::SameHelper<T, U>&& detail::SameHelper<U, T>;

      [edit]Example

      Run this code
      #include <concepts>#include <iostream> template<typename T,typename ...U>concept either=(std::same_as<T, U>|| ...); template<typename T>concept is_printable=std::integral<T>||std::floating_point<T>||    either<std::remove_cvref_t<std::remove_pointer_t<std::decay_t<T>>>,char,wchar_t>; void println(is_printableautoconst ...arguments){(std::wcout<< ...<< arguments)<<'\n';} int main(){    println("Example: ",3.14," : ",42," : [",'a', L'-', L"Z]");}

      Output:

      Example: 3.14 : 42 : [a-Z]

      [edit]References

      • C++23 standard (ISO/IEC 14882:2024):
      • 18.4.2 Conceptsame_as [concept.same]
      • C++20 standard (ISO/IEC 14882:2020):
      • 18.4.2 Conceptsame_as [concept.same]

      [edit]See also

      (C++11)
      checks if two types are the same
      (class template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/concepts/same_as&oldid=182044"

      [8]ページ先頭

      ©2009-2025 Movatter.jp