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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:07:38+00:00 2026-05-25T14:07:38+00:00

C++11 introduces semantics to avoid unnecessarily copying objects, and std::move to apply those semantics

  • 0

C++11 introduces semantics to avoid unnecessarily copying objects, and std::move to apply those semantics when otherwise a copy would occur. However, there are now also some cases where a copy is required, but not the default.

Consider this naive implementation of reverse, for example. Because range-based for uses perfect forwarding, modification to the container within the loop amounts to corruption.

auto out_iter = container.rbegin();
for ( auto value : container ) {
    * out_iter ++ = value;
}

The goal is to fix this using

for ( auto value : copy( container ) ) {

It seems simple enough… accept any argument, get the underlying type and return a temporary copy.

  • 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-25T14:07:39+00:00Added an answer on May 25, 2026 at 2:07 pm

    The return type you’re computing is better known as typename std::decay<T>::type. Other than that, use std::forward in the body to reap the full benefits of perfect forwarding:

    template<typename T>
    typename std::decay<T>::type
    val(T&& t)
    { return std::forward<T>(t); }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Oracle 11g version of ODP.Net introduces the provider model objects (session state provider, identity
I have read that SL4 introduces the ability to data bind properties on objects
The code below introduces a class C. The class has constructor, copy constructor, operator=
The dynamic keyword in C# 4 introduces new ways to work with objects that
I'm wondering which Linux distribution would be best (i.e. introduces the least dependencies) when
C++0x introduces concepts , that let you define, basically, a type of a type.
For example this article introduces them. What is the benefit? Static analysis seems cool
.NET framework 3.5 introduces Action and Func<> predefined delegate types that are very handy.
UPDATE : GWT 2.3 introduces a better mechanism to fight XSRF attacks. See http://code.google.com/webtoolkit/doc/latest/DevGuideSecurityRpcXsrf.html
As you know the dash introduces a comment how can I make this valid?

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.