0

I am new to C++ and I am trying to install the pybeesgrid package (https://github.com/berleon/pybeesgrid). In this specifc part of the pybeesgrid.cpp file:

void buildGridsFromNpArrWorkFn(
        PyArrayObject * bits_and_config_ptr,
        PyObject * maybe_grid_structure,
        const size_t offset,
        const size_t nb_todo,
        std::vector<GeneratedGrid> &grids)
{

    PyArrayObject * structure_arr = nullptr;
    if (maybe_grid_structure != Py_None) {
        structure_arr = reinterpret_cast<PyArrayObject*>(maybe_grid_structure);
    }

    for(size_t i = offset; i < offset + nb_todo; i++) {
        Grid::idarray_t id;
        size_t pos = 0;
        for(size_t c = 0; c < NUM_MIDDLE_CELLS; c++) {
            float cell = get_float(bits_and_config_ptr, i, pos);
            ++pos;
            if(cell == 1.) {
                id[c] = true;
            } else if(cell == 0) {
                id[c] = false;
            } else {
                id[c] = boost::tribool::indeterminate_value;
            }
        }

I am getting the error:

 error: enum constant in boolean context [-Werror=int-in-bool-context] 

236 |                 id[c] = boost::tribool::indeterminate_value;                                                                                

Does anyone knows how to fix it?

I tried to supress the warning but then my file doesn't compile. I also tried to change the line to

id[c] = static_cast<uint64_t>(boost::tribool::indeterminate_value);

But it didn't work.

Scheff's Cat
  • 19,528
  • 6
  • 28
  • 56
  • 1
    Why do you believe that the return value of `id[c]` is something that works with Boost's `tribool` type? – Nicol Bolas Dec 02 '22 at 16:58
  • @NicolBolas Looking at the linked code, it seems `Grid::idarray_t` is a typedef for an `std::array` of `tribool`. It's not clear to me why the code does not compile. – john Dec 02 '22 at 17:00
  • 1) What do you want to store in a `Grid::idarray_t`: a bool or a tribool? It seems you are storing a bool but want to store a tribool. 2) In case you really want to store a bool, what do you want to store when `cell` is neither `1.0`, nor `0`: true or false? – rturrado Dec 02 '22 at 18:52
  • Try using `boost::tribool::indeterminate` (which is a tribool) instead of `boost::tribool::indeterminate_value` (which appears to be an int). – Eljay Dec 02 '22 at 20:51

0 Answers0