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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:02:38+00:00 2026-05-11T06:02:38+00:00

Is there any way that you can combine predicates? Lets say I have something

  • 0

Is there any way that you can combine predicates?

Lets say I have something like this:

class MatchBeginning : public binary_function<CStdString, CStdString, bool> {   public:           bool operator()(const CStdString &inputOne, const CStdString &inputTwo) const     {   return inputOne.substr(0, inputTwo.length()).compare(inputTwo) == 0;    } };  int main(int argc, char* argv[]) {     CStdString myString('foo -b ar -t az');       vector<CStdString> tokens;      // splits the string every time it encounters a '-'     split(myString, tokens, '-', true, true);         vector<CStdString>::iterator searchResult = find_if(tokens.begin(), tokens.end(), not1(bind2nd(MatchBeginning(), '-')));              return 0; } 

This works, but now I’d like to do something like:

searchResult = find_if(tokens.begin(), tokens.end(), bind2nd(MatchBeginning(), '-b') || not1(bind2nd(MatchBeginning(), '-'))); 

So I’d like to find the first string that starts with ‘-b’ or the first string that does not start with ‘-‘. However, this gives me an error (binary ‘||’ undefined).

Is there any way to do this?

  • 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. 2026-05-11T06:02:38+00:00Added an answer on May 11, 2026 at 6:02 am

    I can recommend boost.lambda for combining function-objects for such tasks. Although it is a bit heavyweight for such a simple problem. (edit) See the community wiki answer started by xhantt for a good example using STL.

    (old, deprecated, answer) You can write your own utility for this, similar:

    // here we define the combiner... template<class Left, class Right> class lazy_or_impl {   Left m_left;   Right m_right; public:   lazy_or_impl(Left const& left, Right const& right) : m_left(left), m_right(right) {}   typename Left::result_type operator()(typename Left::argument_type const& a) const {     return m_left(a) || m_right(a);   } };  // and a helper function which deduces the template arguments // (thx to xtofl to point this out) template<class Left, class Right> lazy_or_impl<Left, Right> lazy_or(Left const& left, Right const& right) {   return lazy_or_impl<Left, Right>(left, right); } 

    and then use it: ... lazy_or(bind1st(...), bind1st(...)) ...

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

Sidebar

Related Questions

Is there any way to have something that looks just like a file on
In many browsers you can do something like this: javascript: alert(...); Is there any
Is there any way that I can programmatically create (and I guess access) hidden
Is there any way that I can change how a Literal of a code
Is there any way that I can find the container pointed to by an
Is there any way so that i can echo password when asked for in
Is there any way to list all the files that have changed between two
Is there any way to have a dropdown in excel that will show a
I am wondering if there is any way that I can call a template
Is there any way that I could get the source of a website (as

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.