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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:58:49+00:00 2026-06-14T21:58:49+00:00

Possible Duplicate: What is predicate in C++? When I read the C++ primer, there

  • 0

Possible Duplicate:
What is predicate in C++?

When I read the C++ primer, there is a defined term which is predicate.

The definition is this :

Functions that returns a type that can be converted to bool. Often used by the generic algorithms to test elements . predicates used by the library are either unary (taking one argument) or binary(taking two).

Anyone that returns a type that can be converted to bool can be predicate ! Right? Or there are some other restrictive conditions.

Thanks!

  • 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-14T21:58:50+00:00Added an answer on June 14, 2026 at 9:58 pm

    There’s no formal definition of a predicate in the context of C++ (that I know of anyway), but it generally means a function that can be used in a true/false context.

    Here’s a possible implementation of count_if from cppreference that illustrates what it’s talking about:

    template<class InputIt, class UnaryPredicate>
    typename iterator_traits<InputIt>::difference_type
        count_if(InputIt first, InputIt last, UnaryPredicate p)
    {
        typename iterator_traits<InputIt>::difference_type ret = 0;
        for (; first != last; ++first) {
            if (p(*first)) {
                ret++;
            }
        }
        return ret;
    }
    

    p must return something that can be used inside of an if statement is what it basically boils down to.

    For example:

    class T {};
    
    T f(int x)
    {
        return T();
    }
    

    This is not a valid predicate for count_if because T is not implicitly convertible to a bool.

    In other words:

    if (f(4)) { }
    

    Is uncompilable code.

    If, however, T could be implicitly converted to a bool, f would be an acceptable predicate (though very odd).

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

Sidebar

Related Questions

Possible Duplicate: Python: find first element in a sequence that matches a predicate Is
Possible Duplicate: Qt equivalent of PathAppend? Is there a class that handles file paths
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: Objective C for Windows iPhone development on Windows Is there any way
Possible Duplicate: Can a Bash script tell what directory it's stored in? Is there
Possible Duplicate: NAnt or MSBuild, which one to choose and when? What is the
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
Possible Duplicate: Difference Between Equals and == in which cases equals() works exactly like
Possible Duplicate: Transparent images with C# WinForms I am coding an app which will

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.