std::experi...al::function(3)

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

πŸ¦‹ NAME πŸ¦‹

okay bestie, meet std::experimental::function β€” yes that's the whole name section, it literally just says its own name back at you πŸ’…. This page lives in the C++ Standard Libary manual (section 3), and we're gonna get you comfy with it, fr fr.


✨ Synopsis ✨

So first things first, it's chillin' in this header:

Defined in header <experimental/functional>

and here's the shape of it β€” the primary template is lowkey undefined, which is giving "do not touch" energy:

template< class >
class function; /* undefined */

template< class R, class... Args >
class function<R(Args...)>

both of those are (library fundamentals TS) by the way 🫢

And what is it? Okay so β€” std::experimental::function is a modified version of std::function with support for type-erased allocators. That's the whole glow-up. Periodt. πŸ‘‘


πŸŽ€ Member types πŸŽ€

  • allocator_type β€” defined as std::experimental::erased_type (library fundamentals TS) β€” until library fundamentals TS v3
  • allocator_type β€” defined as std::pmr::polymorphic_allocator<> (library fundamentals TS v3) πŸ¦‹

(yes, allocator_type shows up twice β€” the definition switches over at TS v3, iykyk)


πŸ’– Member functions πŸ’–

  • constructor β€” constructs a new std::experimental::function instance (public member function)
  • operator= β€” assigns a new target (public member function)
  • swap β€” swaps the contents (public member function)
  • get_memory_resource β€” retrieves a pointer to the memory resource used by this object to allocate memory (public member function) β€” removed in library fundamentals TS v3 ⚰️
  • get_allocator β€” retrieves a type-erased std::pmr::polymorphic_allocator used by this object to allocate memory (public member function) β€” library fundamentals TS v3 ✨

🌸 Non-member functions 🌸

  • std::experimental::swap(std::experimental::function) β€” specializes the swap algorithm (function template)
  • operator== / operator!= β€” compares an std::experimental::function with nullptr (function template) β€” removed in library fundamentals TS v3 πŸ’€

🧚 Helper classes 🧚

  • std::uses_allocator<std::experimental::function> β€” specializes the std::uses_allocator type trait (class template specialization) β€” removed in library fundamentals TS v3 🌈

πŸ‘‘ Members identical to std::function πŸ‘‘

bestie, everything under here is the same as std::function β€” no cap, it's a straight carryover 🫢

⭐ Member types ⭐

  • result_type β€” R

πŸ“ Member types removed in Library Fundamental TS v3 πŸ“

  • argument_type β€” T if sizeof...(Args) == 1 and T is the first and only type in Args...
  • first_argument_type β€” T1 if sizeof...(Args) == 2 and T1 is the first of the two types in Args...
  • second_argument_type β€” T2 if sizeof...(Args) == 2 and T2 is the second of the two types in Args...
little note: member types argument_type, first_argument_type, and second_argument_type are removed, because the corresponding member types of std::function are removed in C++20. they're gone-gone, (library fundamentals TS v3) said so πŸ™ˆ

πŸ’œ Member functions πŸ’œ

  • destructor β€” destroys a std::function instance (public member function of std::function<R(Args...)>)
  • operator bool β€” checks if a target is contained (public member function of std::function<R(Args...)>)
  • operator() β€” invokes the target (public member function of std::function<R(Args...)>)

🌈 Target access 🌈

  • target_type β€” obtains the typeid of the stored target (public member function of std::function<R(Args...)>)
  • target β€” obtains a pointer to the stored target (public member function of std::function<R(Args...)>)

okay that's the whole page and you ate it up, I'm so proud πŸ˜­πŸ’– this came from cppreference.com, dated 2024.06.10, and it's the std::experi...al::function(3) page of the C++ Standard Libary manual β€” go forth and allocator-erase, bestie πŸŽ€πŸ¦‹βœ¨

πŸ“¦ where this page comes from