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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:48:51+00:00 2026-05-27T22:48:51+00:00

Originally I had a member that was a std::vector<Point> with a method that did

  • 0

Originally I had a member that was a std::vector<Point> with a method that did this:

bool Spline::Intersects(const Point& point) const {
    return std::find(this->_result_points.begin(), _result_points.end(), point) != _result_points.end();
}

The design changed and std::vector<Point> became std::vector<Point*> and the previous method no longer worked and I had to change it to:

bool Spline::Intersects(const Point& point) const {
    for(std::vector<Point*>::const_iterator _iter = _result_points.begin(); _iter != _result_points.end(); ++_iter) {
        if(*(*_iter) == point) return true;
    }
    return false;
}

Does std::find perform the same linear search? If so, is there a faster/better/less gross way to do this (especially the double de-reference of the iterator)?

There are other places in the code that the std::find(this->_result_points.begin(), _result_points.end(), point) != _result_points.end(); (or similar, but opposite results) is performed and I would rather not have to use that slow linear for loop.

  • 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-27T22:48:52+00:00Added an answer on May 27, 2026 at 10:48 pm

    Yes, find does the same linear search.

    You could hide the loop and the double indirection by using find_if with a suitable predicate: bool operator()(Point* ptr) { return *ptr == point; }

    If you want to avoid linear searches, you need to change the way the data is stored. For example keeping the vector sorted would allow std::binary_search, which is faster than std::find. That’s sorted by the value pointed to, not sorted by pointer value, so you’d need to pass a comparator to std::sort etc. Or you could use an entirely different container: perhaps one of (unordered_)(multi)set.

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

Sidebar

Related Questions

A co-worker asked about some code like this that originally had templates in it.
I'm not sure how to do this. So I originally had a ViewController that
I originally had a submit button like this <form action=<?php $self ?> method=post >
I originally had an array[1..1000] that was defined as a global variable. But now
Ok, So I have the following situation. I originally had some code like this:
I originally had this code which I mistakenly thought would do what I wanted
I originally had this code written as a series of if statements, but after
Problem: I originally had a query that was working great but I'm now having
All, I originally had my setup like this and everything worked as expected. WEB-INF
NOTE: Originally had this listed as a memory leak. After looking into this deeper,

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.