Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7411413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:22:58+00:00 2026-05-29T06:22:58+00:00

What benefits has using std::reference_wrapper as template parameter of containers instead of raw pointers?

  • 0

What benefits has using std::reference_wrapper as template parameter of containers instead of raw pointers? That is std::vector<std::reference_wrapper<MyClass> > vs. std::vector<MyClass*>

I like forgetting about nulls and not having to use pointer syntax, but the verbosity of the types (i.e. vector<reference_wrapper<MyClass> >) plus having the call site use std::ref to wrap the actual reference makes me think it is not worth it.

I am referring to cases in which using std::shared_ptr or any other smart pointer is not an option.

Are there other benefits of using reference_wrapper or any other factors I am currently not taking into account? (I think my question applies to both C++11’s reference_wrapper and boost’s)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:22:59+00:00Added an answer on May 29, 2026 at 6:22 am

    I don’t think there is any technical difference. Reference wrapper provides basic pointer functionality, including the ability to change the target dynamically.

    One benefit is that it demonstrates intent. It tells people who read the code that “whoever” has the variable, isn’t actually controlling its lifespan. The user hasn’t forgotten to delete or new anything, which some people may start to look for when they see pointer semantics.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I'm using an ORM like JPA2 - where I have my entities that
I would like to build a website that has some elements of a social
Has anyone used apc_define_constants or hidef vs using define. Any true benefits or possible
Much have been written about the benefits of using PDO::prepare , but little has
I have a method that has a few pointers as parameters. This method can
One of my C++ classes derives from std::vector so that it can act as
I wonder who has programmed using avaloq script. What are its benefits? What is
Switching from JVM 1.4 to 1.5 has performance benefits as per release notes. http://java.sun.com/j2se/1.5.0/docs/relnotes/features.html#performance
It looks like GetObjectKey has the benefit of searching for existing, instantiated objects, and
What are the benefits and drawbacks with using Centralized versus Distributed Version Control Systems

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.