Consequently to a previous question about const/non-const with ternary operator, is the following test
function ok regarding to the C++11 standard :
template<bool UseConst> class MyClass
{
public:
constexpr bool test()
{
return (UseConst) ? (_constvar) : (_var);
}
protected:
int _var;
static const int _constvar;
}
The whole problem, is that _constvar
is const, and _var
is non-const. I would have to access these 2 data depending on the template parameter through the same function, and I would like to have a compile-time function when I use const.
Do the test()
function satisfy my requirements ?
UseConst
and go from there? – Xeo Sep 26 '12 at 12:56test()
return anint
? And what is the problem in making this test functionconstexpr
? It compiles for me. – KennyTM Sep 27 '12 at 17:55