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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:14:00+00:00 2026-05-21T18:14:00+00:00

I admit I had difficulties coming up with a reasonable description for this. I

  • 0

I admit I had difficulties coming up with a reasonable description for this. I cannot think of a good term that would describe precisely what I’m looking for. Perhaps this could be called a slicing iterator.

Let’s say I have something like this:

struct S
{
    int i;
    char *s;
    float f;
};

std::vector<S> v(10);

What I’m looking for is a way to construct an iterator, that would point to a member of S. I’d like to be able to pass it to something like std::min_element without creating a predicate in each case. Something that might look like this:

std::min_element(slicing_iterator(v.begin(), S::f), slicing_iterator(v.end(), S::f));

Is there any template trick that I could use to achieve this? Or perhaps it’s already done somewhere in Boost or some other library?

  • 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-21T18:14:00+00:00Added an answer on May 21, 2026 at 6:14 pm

    If you’re looking for an iterator that converts S into its S::f, this could certainly be done using boost (what can’t be?):

    std::cout << *std::min_element(
                   boost::make_transform_iterator(v.begin(), boost::bind(&S::f, _1)),
                   boost::make_transform_iterator(v.end(), boost::bind(&S::f, _1))
                  ) << '\n';
    

    test: https://ideone.com/jgcHr

    But if you’re looking for the S whose S::f is the smallest in the vector, the predicate is the most reasonable approach.

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

Sidebar

Related Questions

I'll be the first to admit that this is cut and past programming. I've
More times than I'd like to admit I've had people new to a project
I admit this is not strictly a programming question, although I do use my
First of all I have to admit that my programming skills are pretty limited
This might seem like a stupid question I admit. But I'm in a small
I have to admit I never had to worry about Firefox versions before when
First, I have to admit I screwed up a little with CVS. I had
I had until recently been under the impression that the CDbl(x) operation in VB.NET
I have had this problem for a while, still trying to work on a
I gotta admit that's a first-timer bug for me. I've never seen that... I

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.