What is std::ref? -- Sandor Dargo
When working with C++ standard containers and functions, handling references can sometimes lead to unexpected behavior, particularly with copy semantics. This is where
std::ref and std::cref come into play, allowing you to store references in containers and pass them safely to template functions like std::bind or std::thread.
What is std::ref?
by Sandor Dargo
From the article:
Have you heard about
std::refandstd::cref? The helper functions that generate objects of typestd::reference_wrapper? The answer is probably yes. In that case, this article is probably not for you. But if you haven’t heard about them, or the only usage ofstd::reference_wrapperyou faced was storing references in a vector, then probably it’s worth reading on.This article is inspired by some failing tests that needed me to use
std::refin order to pass them.What does
reference_wrapperdo?A reference of an object
T(T&) is not copy assignable. On the other hand,std::reference_wrapper<T>which emulatesT&it both copy-constructible and copy-assignable. It’s even trivially copyable, so copying can take place on a byte level which makes it very efficient.So when should we use such a wrapper?

When designing a circular doubly-linked list, the initial challenge is determining how to manage the construction of new nodes in relation to existing ones. While constructors seem like a natural fit for placing nodes before or after a given node, overloading them can lead to ambiguity and poor design choices. Instead, using distinct tag types or factory methods provides clearer intent, ensuring flexibility while respecting the constraints of guaranteed copy elision for node addresses.
Previously, I tried to answer the question:
C++ On Sea took place in Folkestone again in February this year. Sandor Dargo shares an overview of his favourite talks and some emergent ideas.
JSON is a widely-used format for data exchange, but in C++, handling JSON efficiently can be challenging. While current solutions like simdjson offer high-speed processing, upcoming features in C++26, such as powerful reflection, promise to simplify and accelerate the serialization and deserialization of JSON, making it both faster and more convenient for developers.