Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::mem_fun_ref

      From cppreference.com
      <cpp‎ |utility‎ |functional
       
       
      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*)

      mem_fun_ref
      (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 Res,class T>
      std::mem_fun_ref_t<Res,T> mem_fun_ref( Res(T::*f)());
      (1)(deprecated in C++11)
      (removed in C++17)
      template<class Res,class T>
      std::const_mem_fun_ref_t<Res,T> mem_fun_ref( Res(T::*f)()const);
      (1)(deprecated in C++11)
      (removed in C++17)
      template<class Res,class T,class Arg>
      std::mem_fun1_ref_t<Res,T,Arg> mem_fun_ref( Res(T::*f)(Arg));
      (2)(deprecated in C++11)
      (removed in C++17)
      template<class Res,class T,class Arg>
      std::const_mem_fun1_ref_t<Res,T,Arg> mem_fun_ref( Res(T::*f)(Arg)const);
      (2)(deprecated in C++11)
      (removed in C++17)

      Creates a member function wrapper object, deducing the target type from the template arguments. The wrapper object expects a reference to an object of typeT as the first parameter to itsoperator().

      1) Effectively callsstd::mem_fun_ref_t<S,T>(f) orstd::const_mem_fun_ref_t<S,T>(f).
      2) Effectively callsstd::mem_fun1_ref_t<S,T>(f) orstd::const_mem_fun1_ref_t<S,T>(f).

      This function and the related types were deprecated in C++11 and removed in C++17 in favor of the more generalstd::mem_fn andstd::bind, both of which create callable adaptor-compatible function objects from member functions.

      Contents

      [edit]Parameters

      f - pointer to a member function to create a wrapper for

      [edit]Return value

      A function object wrappingf.

      [edit]Exceptions

      May throw implementation-defined exceptions.

      [edit]Notes

      The difference betweenstd::mem_fun andstd::mem_fun_ref is that the former produces a function wrapper that expects a pointer to an object, whereas the latter — a reference.

      [edit]Example

      Usesstd::mem_fun_ref to bindstd::string's member functionsize().

      Run this code
      #include <algorithm>#include <functional>#include <iostream>#include <iterator>#include <string>#include <vector> int main(){std::vector<std::string> v={"once","upon","a","time"};std::transform(v.cbegin(), v.cend(),std::ostream_iterator<std::size_t>(std::cout," "),                   std::mem_fun_ref(&std::string::size));}

      Output:

      4 4 1 4

      [edit]See also

      (deprecated in C++11)(removed in C++17)
      creates a wrapper from a pointer to member function, callable with a pointer to object
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/functional/mem_fun_ref&oldid=152262"

      [8]ページ先頭

      ©2009-2025 Movatter.jp