Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] A util for expression evaluation in CDT?

> We don't have a facility to evaluate expressions.

For integer-valued expressions, you can trick the editor
into doing it:

// Declare a constant whose value is your expression.
const int x = 1 + 2 * 3;

// Declare a template with an integer parameter.
template <int> class dummy;

// Construct an instance of your template with
// the constant as the argument.
auto a = dummy<x>();

// Hover over the 'auto'. The editor will show you
// "dummy<int7>", which tells you the simplified
// value.

(That it's "dummy<int7>" instead of "dummy<7>" is
a bug. We should fix that.)

Regards,
Nate

 		 	   		  

Back to the top