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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:35:27+00:00 2026-05-17T23:35:27+00:00

I want a partial_sum of my elements in a vector, where each element is

  • 0

I want a partial_sum of my elements in a vector, where each element is a pair<double, unsinged int>. The partial_sum should incrementally add the double values (first of each pair).

Example:

vector<pair<double, unsigned int> > temp_vec;
temp_vec.push_back(make_pair(0.5, 0));
temp_vec.push_back(make_pair(0.2, 1));
temp_vec.push_back(make_pair(0.3, 2));
partial_sum(temp_vec.begin(), temp_vec.end(), temp_vec.begin(), ???);   // in place

should give me a vector containing: [(0.5, 0), (0.7, 1), (1.0, 2)]

How to implement the necessary functor to use the partial_sum function?

I was able to use my pair in a stl lower_bound search with a custom-functor, but in the case above, I don’t know how to declare the binary operation.

  • 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-17T23:35:28+00:00Added an answer on May 17, 2026 at 11:35 pm
    struct pair_sum {
        pair<double, unsigned int> operator()(const pair<double, unsigned int> & sum, const pair<double, unsigned int> & i) {
            return pair<double, unsigned int>(sum.first + i.first, i.second);
        }
    };
    

    This will add up the firsts and return the seconds unchanged.

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

Sidebar

Related Questions

Belong to this article Jquery Partial View What should i do when i want
I have dbml with single table users i want add partial class for User
I want to provide for partial matching, so I am tacking on * to
I have a partial that I want to display in a layout only when
I have a partial view that I want to basically take care of itself
I want to graph from one date to another date and i only partial
Here's what I want the resulting class declaration to look like: public sealed partial
I want to program something in both C# and F#. I have partial classes
I have a partial view the returns an HTML5 video tag. I want to
Is it possible to do a partial update through linq2sql? If I want to

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.