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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:59:04+00:00 2026-05-24T20:59:04+00:00

I have a std::vector<std::pair<int,std::pair<Bone,std::string> > > I’m trying to sort it with std sort,

  • 0

I have a std::vector<std::pair<int,std::pair<Bone,std::string> > >

I’m trying to sort it with std sort, with the expectation that it is sorted by int, but instead I get 21 errors related to the sort call.

What could be wrong?

Code:

std::vector<std::pair<int,std::pair<Bone,std::string> > > tempBones;
std::sort(tempBones.begin(),tempBones.end());

Errors:

Error 1 error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const skl::Bone' c:\Program Files\Microsoft Visual Studio 9.0\VC\include\utility 102

Error 2 error C2784: 'bool std::operator <(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const _Elem *' from 'const skl::Bone' c:\Program Files\Microsoft Visual Studio 9.0\VC\include\utility 102

Error 3 error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const skl::Bone' c:\Program Files\Microsoft Visual Studio 9.0\VC\include\utility 102

Error 4 error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const skl::Bone' c:\Program Files\Microsoft Visual Studio 9.0\VC\include\utility 102

Error 5 error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const skl::Bone' c:\Program Files\Microsoft Visual Studio 9.0\VC\include\utility 102

Error 6 error C2784: 'bool std::operator <(const std::list<_Ty,_Ax> &,const std::list<_Ty,_Ax> &)' : could not deduce template argument for 'const std::list<_Ty,_Ax> &' from 'const skl::Bone' c:\Program Files\Microsoft Visual Studio 9.0\VC\include\utility 102

Error 7 error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const skl::Bone' c:\Program Files\Microsoft Visual Studio 9.0\VC\include\utility 102

Error 8 error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const skl::Bone' c:\Program Files\Microsoft Visual Studio 9.0\VC\include\utility 102

Error 9 error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const skl::Bone' c:\Program Files\Microsoft Visual Studio 9.0\VC\include\utility 102

Error 10 error C2676: binary '<' : 'const skl::Bone' does not define this operator or a conversion to a type acceptable to the predefined operator c:\Program Files\Microsoft Visual Studio 9.0\VC\include\utility 10

Error 11 error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const skl::Bone' c:\Program Files\Microsoft Visual Studio 9.0\VC\include\utility 103

Error 12 error C2784: 'bool std::operator <(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const _Elem *' from 'const skl::Bone' c:\Program Files\Microsoft Visual Studio 9.0\VC\include\utility 103

Error 13 error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const skl::Bone' c:\Program Files\Microsoft Visual Studio 9.0\VC\include\utility 103

Error 14 error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const skl::Bone' c:\Program Files\Microsoft Visual Studio 9.0\VC\include\utility 103

Error 15 error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const skl::Bone' c:\Program Files\Microsoft Visual Studio 9.0\VC\include\utility 103

Error 16 error C2784: 'bool std::operator <(const std::list<_Ty,_Ax> &,const std::list<_Ty,_Ax> &)' : could not deduce template argument for 'const std::list<_Ty,_Ax> &' from 'const skl::Bone' c:\Program Files\Microsoft Visual Studio 9.0\VC\include\utility 103

Error 17 error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const skl::Bone' c:\Program Files\Microsoft Visual Studio 9.0\VC\include\utility 103

Error 18 error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const skl::Bone' c:\Program Files\Microsoft Visual Studio 9.0\VC\include\utility 103

Error 19 error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const skl::Bone' c:\Program Files\Microsoft Visual Studio 9.0\VC\include\utility 103

Error 20 error C2676: binary '<' : 'const skl::Bone' does not define this operator or a conversion to a type acceptable to the predefined operator c:\Program Files\Microsoft Visual Studio 9.0\VC\include\utility 103

  • 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-24T20:59:05+00:00Added an answer on May 24, 2026 at 8:59 pm

    Why would you expect it to be sorted by int? Any container<T> is sorted by T, and sorting requires that there be a less-than comparison for T. Now for pair<S,T>, there is an operator<, defined as lexicographic ordering, but this requires comparability of both S and T:

    // lexicographic compare:
    bool operator<(pair<S,T> a, pair<S,T> b)
    {
      return a.first < b. first || (!(b.first < a.first) && (a.second < b.second));
      //                                                    ^^^^^^^^^^^^^^^^^^^^^^^
    } //                                                     compare second type!
    

    Moving down recursively, you need Bone to be less-than comparable. Do check, any bet that you didn’t implement a comparison operator for that type!

    Edit: According to your update that is precisely your problem.

    Remark: You might wonder why lexicographic compare is the default: It’s the only sensible comparison for which !(x < y) && !(y < x) is identical to x == y, provided the same holds for both sub-types individually.

    Update: If you only want ordering by the first member, you should write a custom comparator predicate, or use a multi-map instead.

    Custom comparator:

    template <typename S, typename T>
    bool PairCompareOnlyFirst(const std::pair<S,T> & a, const std::pair<S,T> & b)
    {
      return a.first < b.first;
    }
    
    std::sort(v.begin(), v.end(), PairCompareOnlyFirst);
    

    Note that sort may rearrange elements with the same key. If you want those to maintain their relative ordering, use stable_sort instead.

    Multimap:

    typedef std::multimap<int, std::pair<Bone,std::string> > myMapType;
    

    The multimap is a more complicated structure than the vector, and its elements are always kept in sorted order by key value, i.e. your int. Which one is preferable depends on what you’re doing.

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

Sidebar

Related Questions

It seems that I can sort a std::vector<std::pair<int, std::string>> , and it will sort
If I have a vector of pairs: std::vector<std::pair<int, int> > vec; Is there and
I have this map<string, vector <pair<int, int> > > variable and I'm pushing back
I have several std::vector , all of the same length. I want to sort
I have a std::vector<int> , and I want to delete the n th element.
I have a std::vector. I want to create iterators representing a slice of that
I have a std::vector<uint8_t> that contains strings at specific offsets. Here's a shortened dump:
I have a std::vector<std::string> m_vPaths; I iterate over this vector and call ::DeleteFile(strPath) as
I have a multimap defined by typedef std::pair<int, int> au_pair; //vertices typedef std::pair<int, int>
suppose I have a std::vector of pair. How can I use, efficiently, method std::find

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.