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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:47:25+00:00 2026-05-29T10:47:25+00:00

I created a function which, given a list of some type T, and a

  • 0

I created a function which, given a list of some type T, and a predicate (a pointer to a specified function), counts how many elements in the list return true.

This works with atomic predicates (isEven,isOdd,is_less_than_42), but what should I do if I want to use it with N-ary predicates? Is there any way to pass an optional list of N-1 arguments needed by the N-ary predicate?

template<typename T, class Pred>
int evaluate(listofelements<T> &sm, Pred pred){
    typename listofelements<T>:: iterator begin, end;
    int count=0;
    begin=sm.begin();
    end=sm.end();
    while(begin!=end){
        if(pred(*(begin->data))) count++;
        begin++;
    }
    return count;
}
  • 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-29T10:47:25+00:00Added an answer on May 29, 2026 at 10:47 am

    You could use std::bind to convert an N-ary function to a unary function object.

    using std::placeholders::_1;
    
    evaluate(sm, std::bind(some_function, _1, other, arguments));
    

    std::bind is in C++11, but in older compilers it is likely that TR1 is included where you could use std::tr1::bind, and lastly there is still Boost.Bind.

    Or you could make up the function object yourself:

    struct SomeFunctor
    {
        SecondType arg2;
        ThirdType arg3;
        SomeFunctor(cosnt SecondType& arg2, const ThirdType& arg3)
          : arg2(arg2), arg3(arg3)
        {}
    
        ResultType operator()(const FirstType& arg1) const
        {
            return some_function(arg1, arg2, arg3);
        }
    };
    
    evaluate(sm, SomeFunctor(other, arguments));
    //           ^ construct SomeFunctor with arg2=other, arg3=arguments
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a JS function which executes fine when it's included an the
I created webservice which contain Add function as 'webmethod' when we want to deploy
I created a sample webservice which contain default 'HelloWorld' function as 'webmethod' when tried
Given a function zipdistance(zipfrom,zipto) which calculates the distance (in miles) between two zip codes
$(document).ready(function() { $('#somebutton').click(function() { $.get('List', function(responseJson) { $.each(responseJson, function(index, item) { var elem=$('<input type=checkbox
I am trying to create a function which will give me alphabet position when
I want to create a function which grabs every users latest tweet from a
I'm trying to create a function which takes an array as an argument, adds
I am currently trying to create a function which will allow me to pass
I'm trying to create a simple function which returns me a date with a

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.