ericniebler / range-v3

Range library for C++14/17/20, basis for C++20's std::ranges
Other
4.05k stars 437 forks source link

C++20 #1792

Closed matheusdiogenesandrade closed 10 months ago

matheusdiogenesandrade commented 10 months ago

Hello everyone.

I am trying to setup a C++20 project along with Range-v3. But I am having some problems. In the code below,

#include <range/v3/all.hpp> // get everything

using namespace std;
using namespace ranges;

int main (int argc, const char *argv[])
{
    return 0;
}

I am obtaining the following message:

src/main.cpp:7:17: error: reference to ‘ranges’ is ambiguous
    7 | using namespace ranges;
      |                 ^~~~~~
compilation terminated due to -Wfatal-errors.
make[2]: *** [CMakeFiles/main.dir/build.make:76: CMakeFiles/main.dir/src/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/main.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

It seems that C++20 and range-V3 namespaces are incompatible in a same scope. Thus, I decided to "wrap" ranges-V3 in a custom namespace:

#include <rangev3.hpp> // get everything

using namespace std;
using namespace rangesv3;

int main (int argc, const char *argv[])
{
    return 0;
}

Where my rangev3.hpp script is given below:

namespace rangesv3 {
    #include <range/v3/all.hpp> // get everything
    using namespace ranges;
}

But, I also obtained another error:

In file included from ~/.conan/data/range-v3/0.12.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/meta/meta.hpp:18,
   from ~/.conan/data/range-v3/0.12.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/range/v3/action/action.hpp:19,                                         from ~/.conan/data/range-v3/0.12.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/range/v3/action.hpp:17,
   from ~/.conan/data/range-v3/0.12.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/range/v3/all.hpp:17,                                                   from includes/rangev3.hpp:2,
   from src/main.cpp:4:                                                                                                                                                   /usr/include/c++/11/cstddef:58:11: error: ‘max_align_t’ has not been declared in ‘::’
   58 |   using ::max_align_t;                                                                                                                                            |           ^~~~~~~~~~~
   compilation terminated due to -Wfatal-errors.                                                                                                                          make[2]: *** [CMakeFiles/main.dir/build.make:76: CMakeFiles/main.dir/src/main.cpp.o] Error 1
   make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/main.dir/all] Error 2                                                                                                make: *** [Makefile:91: all] Error 2

For the entire project (link).

I would like to know if someone found a way oc conciliating C++ with rangesV3.

Thanks and regards.

JohelEGP commented 10 months ago

This is related: #1271.

namespace rangesv3 {
    #include <range/v3/all.hpp> // get everything
    using namespace ranges;
}

I think this is what you want: namespace rangesv3 = ::ranges;.

matheusdiogenesandrade commented 10 months ago

Thank you very much.