Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::function_ref::function_ref

      From cppreference.com
      <cpp‎ |utility‎ |functional‎ |function ref
       
       
      Utilities library
       
      Function objects
      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*)
       
       
      template<class F>
      function_ref( F* f)noexcept;
      (1)(since C++26)
      template<class F>
      function_ref( F&& f)noexcept;
      (2)(since C++26)
      template<auto f>
      function_ref(std::nontype_t<f>)noexcept;
      (3)(since C++26)
      template<auto f,class U>
      function_ref(std::nontype_t<f>, U&& obj)noexcept;
      (4)(since C++26)
      template<auto f,class T>
      function_ref(std::nontype_t<f>,/*cv*/ T* obj)noexcept;
      (5)(since C++26)
      function_ref(const function_ref& other)=default;
      (6)(since C++26)

      Creates a newstd::function_ref.

      1) Initializesbound-entity withf, andthunk-ptr with the address of a functionthunk. The behavior is undefined iff is a null pointer.
      • This overload participates in overload resolution only if bothstd::is_function_v<F> and/*is-invocable-using*/<F> aretrue.
      2) Initializesbound-entity withstd::addressof(f), andthunk-ptr with the address of a functionthunk.
      3) Initializesbound-entity with a pointer to an unspecified object or null pointer value, andthunk-ptr with the address of a functionthunk.
      • LetF bedecltype(f). This overload participates in overload resolution only if/*is-invocable-using*/<F> istrue.
      • The program is ill-formed iff!= nullptr isfalse whenstd::is_pointer_v<F>||std::is_member_pointer_v<F> istrue.
      4) Initializesbound-entity withstd::addressof(obj), andthunk-ptr with the address of a functionthunk.
      5) Initializesbound-entity withobj, andthunk-ptr with the address of a functionthunk. The behavior is undefined ifobj is a null pointer whenstd::is_member_pointer_v<F> istrue.
      • LetF bedecltype(f). This overload participates in overload resolution only if/*is-invocable-using*/<F,/*cv*/ T*> istrue.
      • The program is ill-formed iff!= nullptr isfalse whenstd::is_pointer_v<F>||std::is_member_pointer_v<F> istrue.
      6) Defaulted copy constructor copies thebound-entity andthunk-ptr ofother.

      The address of a functionthunk is used to initializethunk-ptr such that a call tothunk(bound-entity, call-args...) isexpression-equivalent to:

      OverloadsExpression-equivalence
      (1,3)std::invoke_r<R>(f, call-args...)
      (2)std::invoke_r<R>(static_cast<cv T&>(f), call-args...)
      (4)std::invoke_r<R>(f,static_cast<cv T&>(obj), call-args...)
      (5)std::invoke_r<R>(f, obj, call-args...)

      /*is-invocable-using*/<T...> istrue if and only if:

      [edit]Parameters

      other - anotherfunction_ref to copy from
      f - a function or aCallable object to wrap
      obj - an object or pointer to bound

      [edit]Example

      This section is incomplete
      Reason: no example

      [edit]See also

      constructs a newstd::move_only_function object
      (public member function ofstd::move_only_function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/functional/function_ref/function_ref&oldid=178019"

      [8]ページ先頭

      ©2009-2025 Movatter.jp