Search code examples
c++binarybitbitmask

'bit_ceil' was not declared in this scope


I am trying to use bit_ceil(), I included the <bit> header, and used the std namespace (I know that it is not a good practice, but I did it here for the sake of the question).

But when I try to use the function it just raises an error 'bit_ceil' was not declared in this scope.

The full code:

#include<iostream>
#include <bit>
using namespace std;
int main ()
{
    int x = 1;
    x = bit_ceil(x);

}

Weird, anyone got an idea?

The questions regarding this function are scarce around the internet.


Solution

  • It is something introduced in C++20 so you need to add in your command line (if using GCC) -std=c++20

    https://godbolt.org/z/chqaYG1bf