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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:01:12+00:00 2026-06-15T20:01:12+00:00

C++11 There should be a one-line version of the last two lines. typedef std::pair<T1,

  • 0

C++11

There should be a one-line version of the last two lines.

        typedef std::pair<T1, T2> impl_node;
        std::vector<impl_node> impl;
        /* do stuff with impl */
        std::vector<T1> retval(impl.size());
        std::transform(impl.cbegin(), impl.cend(), retval.begin(),
                         [](const impl_node& in) { return *in.first; });

I tried writing some sort of custom iterator adapter, and the types are getting hairy. What’s the “right” solution? (And it probably generalizes to all sorts of other adapters.)

  • 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-06-15T20:01:14+00:00Added an answer on June 15, 2026 at 8:01 pm

    This is still two lines, but less typing (in both senses):

    std::vector<T1> retval(impl.size());
    for (const auto& p : impl) retval.push_back(p.first); 
    

    Actually, now that I look at it, I’d prefer three lines:

    std::vector<T1> retval;
    retval.reserve(impl.size());
    for (const auto& p : impl) retval.push_back(p.first); 
    

    (Edited to remove move because there’s no evidence that it’s appropriate)

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

Sidebar

Related Questions

Is there any difference between the following two examples and should one be preferred
As we know to generate a class file there should be atleast one class
My app is expanding, but the reqs dictate that there should be only one
Are there any counterindications to fork under mod_perl2? Should one use another way to
My usecase is a one-page site. On the page, there should be three frames.
I'm trying to determine if there is a specific method of authentication one should
When should I choose one over the other? Are there any pointers that you
On the Eclipse site, there are several Eclipse downloads , which one I should
This should be and easy one for the LINQ gurus out there. I'm doing
Should I merge those tables into one table? Is there any tricky alternative? Table

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.