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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:13:33+00:00 2026-05-23T18:13:33+00:00

I have a class that is created from an enum that can be tested

  • 0

I have a class that is created from an enum that can be tested at any point in the future returning a bool whether it passes, for example:

ConditionObject cnd(CondIsTuesday);
door.setOpenCondition(cnd);

Then the door has a condition that it can use to determine its state.

However I wish to now overload the && and || operators for this condition class such that they can be chained together and work in the way expected with normal boolean logic. For example, making the following possible:

ConditionObject cnd(ConditionObject(CondIsTuesday) || (ConditionObject(CondIsThursday) && ConditionObject(CondIsAfterEight)));
door.openCondition(cnd);

Now the the door will be open on tuesdays or thursdays after eight.

I wasn’t sure of the correct way to describe the problem which also made it hard to search for a solution if one already existed. Thanks for any help with the problem!

[Edit]
I don’t think I explained it well enough, I don’t want the ConditionObject to be evaluated at the time of the creation of the object but instead to store the entire logic into the final ConditionObject such that it can be evaulated lazily.

Using the second example above, If I created the cnd object on a monday and never give the door anouther condition, it will open come tuesday because the condition it was given started returning true.

  • 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-23T18:13:34+00:00Added an answer on May 23, 2026 at 6:13 pm

    “Expression Templates” might be of use to you. This seems to be a reasonably thorough take on the subject, but there are others. I’m not overly familiar with the subject, but that should be a good googling point.

    The basic idea is that you want a tree, with the leafs being an actual condition, and the branches between them the operators that define how they interact. The expresion template is this tree, and you overload operators to build the tree.

    Then, when you actually want to know if your door needs to open, you walk the tree, checking each condition in turn until you have your answer. Short-circuit evaluation [like Tony mentioned] should come naturally, since you ultimately fall back on the built in operators.

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

Sidebar

Related Questions

I have a collection of classes that inherit from an abstract class I created.
Example: I have an class that inherits from UIImageView. An object creates an instance
I have a binary tree class that is created with a root node and
I have created a button CSS class that uses background images with different positions
Currently I have created a ABCFactory class that has a single method creating ABC
I have a control that is created like so: public partial class MYControl :
I have an ExpenseType object that I have created with the following migration: class
I have created a non-form c# program that uses the NotifyIcon class. The text
I have a class that creates several IDisposable objects, all of these objects are
I have a PHP class that creates a PNG image on the fly and

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.