std::shared...::operator<<(3)

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

🌸 NAME 🌸

std::shared_ptr::operator<< β€” std::shared_ptr::operator<< πŸ’…

okay so this is the C++ Standard Libary manual page for the stream-insertion operator that works with std::shared_ptr, and it's literally here to help you understand what happens when you send one into an output stream ✨


✨ Synopsis ✨

bestie, here's the signature β€” keep it exact, no cap:

template< class T, class U, class V >
std::basic_ostream<U, V>& operator<<( std::basic_ostream<U, V>& os,
const
std::shared_ptr<T>& ptr );

what it does: it inserts the value of the pointer stored in ptr into the output stream os 🫢

it's equivalent to os << ptr.get() β€” periodt 🌟


πŸŽ€ Parameters πŸŽ€

  • os β€” a std::basic_ostream to insert ptr into
  • ptr β€” the data to be inserted into os

πŸ’– Return value πŸ’–

it returns os πŸ’–


πŸ¦‹ Example πŸ¦‹

run this code, it's giving shared-pointer-in-a-stream realness:

// Run this code

#include <iostream>
#include <memory>

class Foo {};

int main()
{
    auto sp = std::make_shared<Foo>();
    std::cout << sp << '\n';
    std::cout << sp.get() << '\n';
}

🌟 Possible output 🌟

0x6d9028
0x6d9028

πŸ‘‘ See also πŸ‘‘

  • get β€” returns the stored pointer (public member function)

source/version + date check bestie: http://cppreference.com Β· 2024.06.10 Β· std::shared...::operator<<(3) β€” periodt, mwah πŸ’‹πŸ’…

πŸ“¦ where this page comes from