on-internet
← Community

C++ has pointers, smart pointers and references for indirect access, so what is std::indirect?

Stack Overflow ·

C++26 apparently introduces a new type template named std::indirect<T>. If it's an "indirect T", then it's some sort of reference to a T, or pointer to a T, right? Well - why do we need those? C++ already has not just raw pointers and references, but also smart pointers with ownership semantics - std::unique_ptr, std::shared_ptr etc.; as well as std::reference_wrapper if you want fancier references. So why yet another one of these reference-types? What's so special about it?

Comments

Sign in or sign up to comment and upvote.

No comments yet.