Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::floating_point

      From cppreference.com
      <cpp‎ |concepts
       
       
      Concepts library
       
      Defined in header<concepts>
      template<class T>
      concept floating_point=std::is_floating_point_v<T>;
      (since C++20)

      The conceptfloating_point<T> is satisfied if and only ifT is a floating-point type.

      [edit]Example

      Run this code
      #include <concepts>#include <iostream>#include <type_traits> constexpr std::floating_pointauto x2(std::floating_pointauto x){return x+ x;} constexprstd::integralauto x2(std::integralauto x){return x<<1;} int main(){constexprauto d= x2(1.1);    static_assert(std::is_same_v<doubleconst, decltype(d)>);std::cout<< d<<'\n'; constexprauto f= x2(2.2f);    static_assert(std::is_same_v<floatconst, decltype(f)>);std::cout<< f<<'\n'; constexprauto i= x2(444);    static_assert(std::is_same_v<intconst, decltype(i)>);std::cout<< i<<'\n';}

      Output:

      2.24.4888

      [edit]References

      • C++23 standard (ISO/IEC 14882:2024):
      • 18.4.7 Arithmetic concepts [concepts.arithmetic]
      • C++20 standard (ISO/IEC 14882:2020):
      • 18.4.7 Arithmetic concepts [concepts.arithmetic]

      [edit]See also

      checks if a type is a floating-point type
      (class template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/concepts/floating_point&oldid=177886"

      [8]ページ先頭

      ©2009-2025 Movatter.jp