std::mem_fun_ref(3)
β¨ std::mem_fun_ref(3) β¨
okay bestie, this one is from the C++ Standard Library manual, and itβs giving vintage C++ chaos: a template that wraps member functions, expects a reference, got deprecated in C++11, and then got yeeted in C++17. π
π NAME π
std::mem_fun_ref - std::mem_fun_ref
πΈ Synopsis πΈ
Defined in header <functional>
template< class Res, class T > (1)
(deprecated in C++11)
(removed in C++17)
std::mem_fun_ref_t<Res,T> mem_fun_ref( Res (T::*f)() );
template< class Res, class T >
(deprecated in C++11)
(removed in C++17)
std::const_mem_fun_ref_t<Res,T> mem_fun_ref( Res (T::*f)() const );
template< class Res, class T, class Arg >
(deprecated in C++11)
(removed in C++17)
std::mem_fun1_ref_t<Res,T,Arg> mem_fun_ref( Res (T::*f)(Arg) );
template< class Res, class T, class Arg >
(deprecated in C++11)
(removed in C++17)
std::const_mem_fun1_ref_t<Res,T,Arg> mem_fun_ref( Res (T::*f)(Arg) const );
Creates a member function wrapper object, deducing the target type from the template arguments. The wrapper object expects a reference to an object of type T as the first parameter to its operator(). β¨
- Effectively calls
std::mem_fun_ref_t<S,T>(f)orstd::const_mem_fun_ref_t<S,T>(f). - Effectively calls
std::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 general std::mem_fn and std::bind, both of which create callable adaptor-compatible function objects from member functions. π«Ά
π Parameters π
fβ pointer to a member function to create a wrapper for.
π¦ Return value π¦
A function object wrapping f.
π Exceptions π
May throw implementation-defined exceptions.
π Notes π
The difference between std::mem_fun and std::mem_fun_ref is that the former produces a function wrapper that expects a pointer to an object, whereas the latter β a reference. no cap, thatβs the whole vibe check π
π₯ Example π₯
Uses std::mem_fun_ref to bind std::stringβs member function size().
// 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
π See also π
mem_funβ creates a wrapper from a pointer to member function, callable with a pointer to object (deprecated in C++11) (removed in C++17) (function template).
mwah π β this page came from the C++ Standard Library manual, sourced from http://cppreference.com, version/date 2024.06.10. bye bestie, go wrap responsibly π«Ά
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms