bool equation

T

thomas

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
 
J

joseph cook

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<typename A>
class Answer {
private:
Answer(){}
};

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

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

Ian Collins

thomas said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,170
Messages
2,570,927
Members
47,469
Latest member
benny001

Latest Threads

Top