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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:11:00+00:00 2026-05-30T07:11:00+00:00

Some operators such as && and || perform short-circuit evaluation. Also, when a function

  • 0

Some operators such as && and || perform short-circuit evaluation. Also, when a function is called with arguments, all arguments are constructed before calling the function.

For instance, take the following three functions

bool f1();
bool f2();
bool f3(bool, bool);

if I call

if( f3(f2(),f1()) )//Do something

Then the return value of both f2 and f1 are evaluated before f3 is called. But, if I had used (the regular) operator|| instead of f3, than the code above would be equivalent to

if( f2()||f1() )//Do something

and f1 won’t be evaluated if f2 evaluates to true.

My question is: is it possible to have f3 (a user defined function taking two booleans) behave the same way? If not, what makes the operator|| so special?

  • 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-30T07:11:01+00:00Added an answer on May 30, 2026 at 7:11 am

    Not if f3() takes the values of the result of the functions.

    But if it takes the address of the functions (or more generically treats its input as functors) rather than the results then f3() can decide if it needs to call the function.

    template<typename F1, typename F2>
    bool f3(F1 const& f1, F2 const& f2)
    {
        return f1() || f2();
    }
    
    bool f1();
    bool f2();
    
    int main()
    {
        f3(&f1, &f2);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there some drawbacks of such implementation of copy-constructor? Foo::Foo(const Foo& i_foo) { *this
In short: is there some way I can modify a class definition such that
I'm using boost python. I've exported some function which takes class CL_DomElement in arguments.
I've found this page about the Twitter search API and some operators : http://search.twitter.com/operators
In this question , Codygman gave an answer that some operators offer a way
There are some special operators in Prolog, one of them is is , however,
If I have have some overloaded ostream operators, defined for library local objects, is
Reading some questions here on SO about conversion operators and constructors got me thinking
Coming from a non-OO background in Matlab, I'm looking to perform some of the
Consider a class that is supposed to offer some (polymorphic) methods such as arithmetic

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.