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 7553551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:05:31+00:00 2026-05-30T11:05:31+00:00

the whole point of const_string is avoiding make a unnecesary copy when the string

  • 0

the whole point of const_string is avoiding make a unnecesary copy when the string is not supposed to change.

However, there are circumstances where you cannot guarantee the lifetime of the const char* source to outlive the const_string, for instance, if using const_string as keys of the map, if some of the const char* become reclaimed, you’ll have very amusing segmentation faults to debug ahead of you.

Is there a way to tell const_string, hey pal, please keep a private copy of this const char*? or std::string?

I’ll refer to a previous question so you understand what i’m after.

  • 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-30T11:05:32+00:00Added an answer on May 30, 2026 at 11:05 am

    And what doesn’t work? By looking at the code (the documentation is mediocre at best), I can see that const_string(charp) (as opposed to const_string(boost::cref(charp)) with charp being char* should make a copy of the data. Another possibility is using the const_string(Iterator begin, Iterator end) constructor. (See the two-argument constructor of const_string_storage in storage.hpp, line 153)

    They even use a temporary std::basic_string to initialize const_string in their test (I haven’t run it to be honest), so it should work normally.

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

Sidebar

Related Questions

I wrote this string copy routine for C strings. It is supposed to behave
The whole point of rvm is to be able to install multiple rubies and
I'm just wondering, what is the whole point of separating classes into an .h
I'm trying to run jetty without building the whole project, but simply point jetty
I want to print my whole file compilation options on make in my console
By default it will not print out anything until the whole page has finished
I need to print last 20 characters of string, but only whole words. Delimiter
At the following first line of code I get this error: cannot convert ‘std::string’
I have a project in mind whose main selling point would be very good
I am not yet very experienced with the TVirtualStringTree component, therefore maybe I overlooked

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.