bool equation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • thomas

    bool equation

    for c++ stl, is there any container or algorithm that can help
    calculate result of a bool expression?

    e.g.
    input: 1&&~0&&0||1
    output: 1
  • joseph  cook

    #2
    Re: bool equation

    On Aug 9, 8:45 pm, thomas <FreshTho...@gm ail.comwrote:
    for c++ stl, is there any container or algorithm that can help
    calculate result of a bool expression?
    >
    e.g.
    input:  1&&~0&&0||1
    output: 1
    Did you try just that?

    int main()
    {
    bool answer = 1&&~0&&0||1; // Ta Da!
    // that's it.
    }

    you could be cute and even get this answer printed to your screen at
    compile time. (i.e. you don't even have to run the program).

    something like:

    template<typena me A>
    class Answer {
    private:
    Answer(){}
    };

    int main()
    {
    const bool answer = 1&&~0&&0||1;
    Answer<answeris ;
    }

    The answer will appear in the error message you receive trying to
    compile the program.
    Joe Cook

    Comment

    • Ian Collins

      #3
      Re: bool equation

      thomas wrote:
      for c++ stl, is there any container or algorithm that can help
      calculate result of a bool expression?
      >
      e.g.
      input: 1&&~0&&0||1
      output: 1
      No, not in standard C++. You'd have to write a simple parser.

      --
      Ian Collins.

      Comment

      Working...