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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:21:08+00:00 2026-05-18T20:21:08+00:00

I have created a set of C-strings, supplying my own comparator function because I

  • 0

I have created a set of C-strings, supplying my own comparator function because I wanted it to only take take the first three characters into account. Here’s its definition:

struct set_object {
 bool operator()(const char* first, const char* second) {
        return strncmp(first, second, 3) > 0;
 }
};
std::set<const char*, set_object> c_string_set;

It works as I wanted it to, sorting the strings as I add them the way I outlined in the set_object class. But the interesting part begins when I try to add a string that compares equal to one already added. For example, if I try to add “aaab” when there is already “aaa” in the set, it doesn’t add it into the set. If I add “aaab” first, then try to add “aaa”, it only lists “aaab”. But how does it know when they are equal if I only provided a function that returns true when one of the strings is greater? It should return false when it’s either equal or smaller!

To clarify, it’s not a problem, just trying to figure out how C++ works.

  • 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-18T20:21:09+00:00Added an answer on May 18, 2026 at 8:21 pm

    You’re right that set_object(x, y) returning false doesn’t say whether x is less than y or they are equal. So set then calls set_object(y, x) to find out.

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

Sidebar

Related Questions

I have created a set of C-strings, supplying my own comparator function because I
I have created a the following strings: set l_project_name = concat(UPPER(a.project_name) like UPPER ('%,projectName,%'));
I have created a set of default project templates and development framework libraries. I
I have created below bat file to run my RMI server @echo Off set
I have created a wpf vb.net project and am trying to set a simple
I have created an MS Access 2003 application, set up as a split front-end/back-end
I have a set of stylesheets with different colour options. I have created a
I have created a dynamic web project in Eclipse, but when I set up
I have created a divider in JSplitPane . I am unable to set the
I have created a button in my Android application & I tried to set

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.