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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:36:13+00:00 2026-05-21T21:36:13+00:00

Question 1> I would like to know why in case I we have to

  • 0

Question 1>

I would like to know why in case I we have to use not2(ptr_fun(ciCharCompare)), while in case II, we just need to use ciCharLess. Why not use ptr_fun(ciCharLess) instead?

Question 2>

Is there a general rule that I can follow when to use which form?

Thank you

case I:

int ciCharCompare(char c1, char c2)
{
// case-insensitively compare chars c1 and c2
// return -1 if c1 < c2
// return 0  if c1 == c2
// return 1  if c1 > c2
}

string s1("Test 1");
string s2("test 2222222222222222");

pair<string::const_iterator, string::const_iterator>
    p = mismatch(s1.begin(), s1.end(),
                 s2.begin(),
                 not2(ptr_fun(ciCharCompare))));

http://www.cplusplus.com/reference/algorithm/mismatch/

template <class InputIterator1, class InputIterator2, class BinaryPredicate>
pair<InputIterator1, InputIterator2>
mismatch (InputIterator1 first1, InputIterator1 last1,
          InputIterator2 first2, BinaryPredicate pred );

pred:
Binary predicate taking two elements as argument

Case II:    
bool ciCharLess(char c1, char c2)
{
    // return true if c1 precedes c2 in a case insensitive comparison
}

lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(),
                         ciCharLess);

http://www.cplusplus.com/reference/algorithm/lexicographical_compare/

comp:
Comparison function object that, taking two values of the same type than those contained in the range, returns true if the first argument is to be considered less than the second argument.

  • 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-21T21:36:14+00:00Added an answer on May 21, 2026 at 9:36 pm

    Why not use ptr_fun(ciCharLess) instead?

    You could use ptr_fun(ciCharLess) if you wanted. All ptr_fun does is convert your function pointer into a functor, which contains some typedefs such as result_type. Most algorithms don’t need it, but some (particularly binders such as not2) do need it.

    Generally speaking, because you’re never going to be wrong by using ptr_fun on a function pointer type (note: applying it to a type which is already a functor is wrong), I just use it everywhere. The worst thing that can happen then is someone raising their eyebrows a bit as to why the wrapper is there if it need not be. If you don’t use it and it needs it the compiler is going to complain quite loudly at you.

    For more information on the specific bits that ptr_fun is for, see Scott Meyers’ Effective STL Item 41: Understand the reasons for ptr_fun, mem_fun, and mem_fun_ref.

    (Long story short, these binder adapters are required to make up for some syntactic inconsistencies in the language; e.g. functors and function pointers are called like identifier(args), member functions called via a pointer are object->identifier(args), and member functions called via a reference are object.identifier(args).)

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

Sidebar

Related Questions

Refering to a previously asked question , I would like to know how to
Just like Carl's question over here I would like to ask you (because I
I would like to apologize at first instant for asking some stupid question(well not
This question would probably apply equally as well to other languages with C-like multi-line
This seems like a silly question but I would really like your comments and
I saw this question asked about C# I would like an answer for PHP.
This is a bit of an open question but I would really like to
I found a question here about blogs on software development, but I would like
This is the sequel to this question . I would like to combine three
Once again a very beginner-ish question, but here I go: I would like to

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.