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

The Archive Base Latest Questions

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

A program I’m working on contains this predicate struct: struct Unlike { Unlike(const Vertex&

  • 0

A program I’m working on contains this predicate struct:

struct Unlike {
    Unlike(const Vertex& in) : a(in) {}
    bool operator()(const Vertex& b) {
        return !(a==b);
    }
    const Vertex& a;
};

Vertices are structs with (among other members) a struct coord with members X, Y, Z. Comparison is done with these functions:

bool operator==(const Vertex& a, const Vertex& b) {
    bool res =  a.coord.X == b.coord.X &&
        a.coord.Y == b.coord.Y &&
        a.coord.Z == b.coord.Z;
    return res;
}
inline bool operator!=(const Vertex& a, const Vertex& b) {
    bool res = !(a==b);
    return res;
}

Which is used like this:

std::vector<Vertex> vertices;
// Fill and sort vertices
std::vector<Vertex>::iterator vcur, vnext;
vcur = vertices.begin();
while(vcur != vertices.end()) {
    vnext = std::find_if(vcur, vertices.end(), Unlike(*vcur));
    // Loop over [vcur, vnext]
    vcur = vnext;
}

So we perform some calculations on all vertices which compare equal.

I’m doing some cleaning in the code, and would like to get rid of the Unlike struct. I tried to do it like this, which to my mind is clearer in intent:

vnext = std::adjacent_find(vcur, vertices.end(), std::not_equal_to<Vertex>());

but that did not retain the same behavior, but rather goes into an infinite loop. Why? Have I misinterpreted adjacent_find or not_equal_to?

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

    std::adjacent_find looking ahead for one item and returns iterator if predicate is true.

    (1) For example, if you use not_equal_to for the list of two letters
    [‘a’,’b’] and your current iterator points to ‘a’ then predicate
    will be positive because ‘a’ not equal to the next ‘b’ and std::adjacent_find
    returns an iterator which is a reference to ‘a’.

    (2) in your first version find_if first iterate to ‘b’ and only then compare ‘b’ with
    ‘a’. And as result we have an iterator which is a reference to ‘b’.

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

Sidebar

Related Questions

Most program languages have some kind of exception handling; some languages have return codes,
Strange program hang, what does this mean in debug? After attaching windbg I found
This program is really getting on my nerves: I am trying to read a
My program is intended for multiple projects (clients) use. I am working w/ PHP
My program goes through a loop like this: ... while(1){ read(sockfd,buf,sizeof(buf)); ... } The
Program followed by output. Someone please explain to me why 10,000,000 milliseconds from Jan
My program generates relatively simple PDF documents on request, but I'm having trouble with
A program receives a list of Messages (base type). Each message in the list
My Program overrides public void paint(Graphics g, int x, int y); in order to
What program can I use to decompile a class file? Will I actually get

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.