call to non-constexpr function in constexpr

I know it is a error, to call to non-constexpr function in constexpr.
But it is still possible to do that? We are not allowed to use plenty of functions in constexpt?

Reason: I want to use the std::bitset to do some bit checking in constexpr. But these functions are non constexpr.

Additional: Without std::bitset. Do you have some ideas to convert decimal to binary in compile time?
Last edited on
I don't think so. The point of constexpr is that it evaluates to a constant at compile time.
Why don't you use a template function?
Hi Grime. Hmm I am not good with constexpr, could you give me a hint or example about that?
convert decimal to binary

What do you mean by that, exactly?
what checking are you trying to do?
I mean, you can have any number of lookups... bool validbits[size] = {true, false, true, true, false, ....} and your answer is simply validbits[input]. But doing the logic operation is nearly as fast: doing a lookup involves some pointer math that is pretty much equal work to a simple logic statement (eg input& 0xFFDDAA) or similar simple logic.

It seems like you should be able to just do the bit twiddles in code. You computer can do around a billion of those per second single threaded.
But if that is not the case, and you do need some sort of lookup, what is it that you are having trouble with that can't be resolved with what was shown in the 2 threads? Can you give a really simple example of what you want to do, but do not know how to do?

Decimal IS binary at compile time. The computer prints base 10 or base 16 for HUMAN use. All integers are stored in binary. You can use logic on them directly (& | ~ are the 3 primary bitwise functions in c++) and if you did not know it hex and binary have a direct relationship at the nibble level. eg the byte 0F can be split into nibbles 0 and F, 0 is 0000 and F is 1111 so the full result is just 00001111 ... this is not generally efficient because you end up going through strings to get there which is wasteful, but it may help you when checking your values by hand.
Last edited on
Topic archived. No new replies allowed.