std::experi...k_ptr::load(3)

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

πŸ’… NAME

std::experimental::atomic_weak_ptr::load β€” ok so this is the std::experimental::atomic_weak_ptr::load page, bestie, and it's literally the glow-up your weak_ptr needed ✨ (this is a cppreference.com joint, and yeah the title up top is the std::experi...k_ptr::load(3) one, we're not typing that whole thing out again πŸŽ€)


🌸 Synopsis

weak_ptr<T> load( std::memory_order order = std::memory_order_seq_cst ) const
noexcept;

So what does it do? It atomically loads and returns the current value of the atomic_weak_ptr. That's the whole vibe. Memory is affected according to the value of order β€” like, the order you pass in decides how the memory party gets synced πŸͺ©

⚠️ Okay so this is the important part, do not skip: order must be one of std::memory_order_relaxed, std::memory_order_consume, std::memory_order_acquire or std::memory_order_seq_cst. Anything else? Behavior is undefined. Not "kinda weird", not "probably fine" β€” undefined, fr fr, so don't be cute with it πŸ’€

🧚 Parameters

  • order β€” the memory order constraints to enforce πŸ‘‘ (like, which rules the memory ops have to play by)

πŸ¦‹ Remarks

All associated use_count increments are guaranteed to be performed as part of the atomic operation. Iconic. No half-done counter business, it's all one atomic package deal 🫢

⭐ Return value

The current value of the atomic_weak_ptr. That's it, that's the tea πŸ’–

πŸ‘‘ See also

  • operator weak_ptr<T> β€” loads a value from an atomic object (public member function)
  • std::atomic_is_lock_free(std::shared_ptr)
  • std::atomic_load(std::shared_ptr)
  • std::atomic_load_explicit(std::shared_ptr)
  • std::atomic_store(std::shared_ptr)
  • std::atomic_store_explicit(std::shared_ptr)
  • std::atomic_exchange(std::shared_ptr)
  • std::atomic_exchange_explicit(std::shared_ptr)
  • std::atomic_compare_exchange_weak(std::shared_ptr)
  • std::atomic_compare_exchange_strong(std::shared_ptr)
  • std::atomic_compare_exchange_weak_explicit(std::shared_ptr)
  • std::atomic_compare_exchange_strong_explicit(std::shared_ptr)

That whole lineup above β€” that's the gang that specializes atomic operations for std::shared_ptr (function template) ✨ and heads up, some of that set is (deprecated in C++20) and (removed in C++26), so πŸ‘€ check your standard version before you commit, iykyk.


kisses bestie!! 😘 this whole thing is brought to you by http://cppreference.com and it's dated 2024.06.10 β€” go forth and lock-free responsibly, mwah πŸ’œπŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from