std::mem_fu..._fun_ref_t,(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

🌸 NAME 🌸

Okay bestie, manual-name check near the top: this is the C++ Standard Libary manual page for std::mem_fu..._fun_ref_t,(3). (The header really does spell it Libary β€” preserving the exact text, no notes.) The NAME line says std::mem_fun_ref_t,std::mem_fun1_ref_t,std::const_mem_fun_ref_t, - and then repeats std::mem_fun_ref_t,std::mem_fun1_ref_t,std::const_mem_fun_ref_t,. The synopsis below also brings in const_mem_fun1_ref_t, so yes, four wrapper class templates are in the group chat. ✨

✨ Synopsis ✨

Defined in header <functional> β€” and here's the synopsis, copied exactly so the compiler gremlins don't come for us:

          Defined in header <functional>
          template< class S, class T >

          class mem_fun_ref_t : public unary_function<T,S> {
          public:                                                    (1)
       (deprecated in C++11)
              explicit mem_fun_ref_t(S (T::*p)());
       (removed in C++17)
              S operator()(T& p) const;

          };
          template< class S, class T >

          class const_mem_fun_ref_t : public unary_function<T,S> {
          public:                                                    (2)
       (deprecated in C++11)
              explicit const_mem_fun_ref_t(S (T::*p)() const);
       (removed in C++17)
              S operator()(const T& p) const;

          };
          template< class S, class T, class A >

          class mem_fun1_ref_t : public binary_function<T,A,S> {
          public:                                                    (3)
       (deprecated in C++11)
              explicit mem_fun1_ref_t(S (T::*p)(A));
       (removed in C++17)
              S operator()(T& p, A x) const;

          };
          template< class S, class T, class A >

          class const_mem_fun1_ref_t : public binary_function<T,A,S>
          {
       (deprecated in C++11)
          public:                                                    (4)
       (removed in C++17)
              explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
              S operator()(const T& p, A x) const;

          };

Okay so the plot: this whole family is a wrapper around a member function pointer. The class instance whose member function you're calling gets passed as a reference to operator(). That's the main character energy. The numbered versions map like this:

  1. Wraps a non-const member function with no parameters.
  2. Wraps a const member function with no parameters.
  3. Wraps a non-const member function with a single parameter.
  4. Wraps a const member function with a single parameter.
Heads up, bestie: the synopsis itself marks these (deprecated in C++11) and (removed in C++17). That is a real technical caveat, not just a vibe check. πŸ’€

🫢 See also 🫢

  • mem_fun_ref β€” creates a wrapper from a pointer to member function, callable with a reference to object (function template). (deprecated in C++11) (removed in C++17)
  • mem_fun_t, mem_fun1_t, const_mem_fun_t, const_mem_fun1_t β€” wrapper for a pointer to nullary or unary member function, callable with a pointer to object (class template). (deprecated in C++11) (removed in C++17)

Source/version/date sign-off, straight from the footer: http://cppreference.com Β· 2024.06.10 Β· std::mem_fu..._fun_ref_t,(3) πŸ’–βœ¨πŸ«Ά

πŸ“¦ where this page comes from