Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::is_placeholder

      From cppreference.com
      <cpp‎ |utility‎ |functional
       
       
      Utilities library
       
      Function objects
      Partial function application
      (C++20)(C++23)
      (C++11)
      is_placeholder
      (C++11)
      Function invocation
      (C++17)(C++23)
      Identity function object
      (C++20)
      Old binders and adaptors
      (until C++17*)
      (until C++17*)
      (until C++17*)
      (until C++17*)  
      (until C++17*)
      (until C++17*)(until C++17*)(until C++17*)(until C++17*)
      (until C++20*)
      (until C++20*)
      (until C++17*)(until C++17*)
      (until C++17*)(until C++17*)

      (until C++17*)
      (until C++17*)(until C++17*)(until C++17*)(until C++17*)
      (until C++20*)
      (until C++20*)
       
      Defined in header<functional>
      template<class T>
      struct is_placeholder;
      (since C++11)

      IfT is the type of a standard placeholder(_1, _2, _3, ...), then this template is derived fromstd::integral_constant<int,1>,std::integral_constant<int,2>,std::integral_constant<int,3>, respectively.

      IfT is not a standard placeholder type, this template is derived fromstd::integral_constant<int,0>.

      A program may specialize this template for aprogram-defined typeT to implementUnaryTypeTrait with base characteristic ofstd::integral_constant<int, N> with positiveN to indicate thatT should be treated asNth placeholder type.

      std::bind usesstd::is_placeholder to detect placeholders for unbound arguments.

      Contents

      [edit]Helper variable template

      template<class T>
      constexprint is_placeholder_v= is_placeholder<T>::value;
      (since C++17)

      Inherited fromstd::integral_constant

      Member constants

      value
      [static]
      placeholder value or0 for non-placeholder types
      (public static member constant)

      Member functions

      operator int
      converts the object toint, returnsvalue
      (public member function)
      operator()
      (C++14)
      returnsvalue
      (public member function)

      Member types

      Type Definition
      value_typeint
      typestd::integral_constant<int, value>

      [edit]Example

      Run this code
      #include <functional>#include <iostream>#include <type_traits> struct My_2{} my_2; namespace std{template<>struct is_placeholder<My_2>:public integral_constant<int,2>{};} int f(int n1,int n2){return n1+ n2;} int main(){std::cout<<"Standard placeholder _5 is for the argument number "<< std::is_placeholder_v<decltype(std::placeholders::_5)><<'\n'; auto b=std::bind(f, my_2,2);std::cout<<"Adding 2 to 11 selected with a custom placeholder gives "<< b(10,11)// the first argument, namely 10, is ignored<<'\n';}

      Output:

      Standard placeholder _5 is for the argument number 5Adding 2 to 11 selected with a custom placeholder gives 13

      [edit]See also

      (C++11)
      binds one or more arguments to a function object
      (function template)[edit]
      placeholders for the unbound arguments in astd::bind expression
      (constant)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/functional/is_placeholder&oldid=176455"

      [8]ページ先頭

      ©2009-2025 Movatter.jp