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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:54:40+00:00 2026-06-17T12:54:40+00:00

I am trying to create vector<Wrap> with same values as in v . I

  • 0

I am trying to create vector<Wrap> with same values as in v. I tried the below combinations, didn’t work!

using namespace std;

struct Wrap
{
  int data;
  //Other members
};

int main()
{
  int a[10] = {2345,6345,3,243,24,234};
  vector<int> v(&a[0],&a[10]);
  Wrap w;
  //Populate other members of w
  vector<Wrap> vw;
  using namespace boost::lambda;
  //transform(v.begin(),v.end(), back_inserter(vw), (bind(&Wrap::data,&w,_1), boost::lambda::constant(w)));
  //transform(v.begin(),v.end(), back_inserter(vw), bind(&Wrap::data,&w,_1), boost::lambda::constant(w));
  //transform(v.begin(),v.end(), back_inserter(vw), ((w.data = _1), boost::lambda::constant(w)));
  //transform(v.begin(),v.end(), back_inserter(vw), ((w.data = _1), w));
  cout << vw.size() << endl;
  BOOST_FOREACH(Wrap w, vw)
  {
    cout << w.data << endl;
  }
}

Note: Can’t use C++11 yet

Update Any clean solution which works in C++03 is fine. Need not use boost lambda

  • 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-17T12:54:41+00:00Added an answer on June 17, 2026 at 12:54 pm

    Use std::transform() and specify a binary operation function. For example:

    #include <iostream>
    #include <vector>
    #include <algorithm>
    
    struct Wrap
    {
        int data;
    };
    
    Wrap set_data(int a_new_data, Wrap a_wrap)
    {
        a_wrap.data = a_new_data;
        return a_wrap;
    }
    
    int main()
    {
        int a[10] = { 2345, 6345, 3, 243, 24, 234 };
        const size_t A_SIZE = sizeof(a) / sizeof(a[0]);
        std::vector<Wrap> vw(A_SIZE);
    
        std::transform(a, a + A_SIZE, vw.begin(), vw.begin(), set_data);
    
        std::cout << vw[0].data << ','
                  << vw[1].data << ','
                  << vw[5].data << ','
                  << vw[9].data << '\n';
        return 0;
    }
    

    See demo at http://ideone.com/DHAXWs .

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

Sidebar

Related Questions

I'm trying to create a vector of System::String ^, I tried using the straight
So, im trying to create a 3 dimensional 5x3x2 vector, using the vector lib
I'm trying to create a generic function that removes duplicates from an std::vector. Since
I am trying to create a class managing a shared-memory vector of (std)strings. typedef
I am simply trying to create some simple vector graphics using the Javascript Library
I'm trying to create an array of classes using a vector, but I think
I'm trying to create a vector of std::functions in my logger class. When I
I'm trying to create a Vector class using templates to store 3D positions of
I'm trying to create a sparse vector class in C++, like so: template<typename V,
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can

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.