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

  • Home
  • SEARCH
  • 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 8832659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:35:04+00:00 2026-06-14T08:35:04+00:00

my code are having some problems on my Visual Studio 2010 but not on

  • 0

my code are having some problems on my Visual Studio 2010 but not on DevCPP. Heres the situation, I used C++ STL set in my code to insert pair<string, double> but then I want my set to sort them using the value instead of the key, so I used a custom comparator to achieve this.

struct sortPairSecond
{
   bool operator()(const pair<string, double> &lhs, const pair<string, double> &rhs)
   {
    return lhs.second >= rhs.second;
   }
};

The code works fine in DevCPP but encountered the Debug Assertion Failed on the xtree using VS2010. I did some debugging and I realize the error is caused by the use of >= in the custom comparator, eliminating the = make the code works but incorrect results as duplicate value should be allowed in my program. Therefore anyone can help me on this matter?

  • 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-06-14T08:35:05+00:00Added an answer on June 14, 2026 at 8:35 am

    Your using >= and not > may be invalid because it needs to be a strict ordering thus op(a,b) and op(b,a) cannot both be true (but they would be if they were equal).

    It is just an assertion error but a set cannot contain duplicate values. Just use a sorted vector or you can use multiset (and use ‘>’)

    Of course as we know the first values are unique, we can extend the predicate when the second value is equal to compare the first. That will guarantee you unique values and then you can still use std::set.

    struct sortPairSecond
    {
       bool operator()(const pair<string, double> &lhs, const pair<string, double> &rhs) const
       {
        return (lhs.second > rhs.second) || (lhs.second == rhs.second && lhs.first > rhs.first) ;
       }
    };
    

    Essentially, don’t try to “break” what std::set is intended to be used for by trying to manipulate your predicate.

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

Sidebar

Related Questions

I'm having some problems with Edit and Continue when using Visual Studio 2010 on
We are trying to upgrade our code base to use Visual Studio 2010 but
I've been having some serious issues with Visual Studio 2010 as of late. It's
Maybe its a stupid question, but i'm having this issue in Visual Studio 2010:
I'm having some problems trying to get the code below to output the data
I'm having some problems with this piece of code. I've included a class declaration
I'm having problems with some code to create a CDialog based window. The code
I'm having a problem with some code that used to work in PHP 4.X
(I'm using Visual Studio 2008, though I remember having similar problems with older versions
I am working through some C++ exercises in Visual Studio 2010, and I keep

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.