2

What was once known as std::experimental::optional is now known as std::optional in C++17.

But some libraries -- such as libpqxx -- haven't yet been updated to drop the experimental namespace.

So now with the new version of Ubuntu 18.10 which comes with g++ v8.2.0, attempting to compile projects that use libpqxx results in errors like this:

/usr/include/pqxx/internal/statement_parameters.hxx:213:13: error: ‘experimental’ in namespace ‘std’ does not name a type const std::experimental::optional<Arg> &arg) ^~~~~~~~~~~~ /usr/include/pqxx/internal/statement_parameters.hxx:213:35: error: expected unqualified-id before ‘<’ token const std::experimental::optional<Arg> &arg) ^ /usr/include/pqxx/internal/statement_parameters.hxx:213:35: error: expected ‘)’ before ‘<’ token const std::experimental::optional<Arg> &arg) ^ ) 

Is there some sort of flag I can pass in to g++ so it defines that old experimental namespace?

These are the relevant version numbers in Ubuntu 18.10:

> dpkg -l | egrep "libpqxx|g\+\+" ii g++ 4:8.2.0-1ubuntu1 amd64 GNU C++ compiler ii g++-8 8.2.0-7ubuntu1 amd64 GNU C++ compiler ii libpqxx-6.2 6.2.4-4 amd64 C++ library to connect to PostgreSQL ii libpqxx-dev 6.2.4-4 amd64 C++ library to connect to PostgreSQL (development files) 
2
  • 2
    experimental::optional still exists in libstdc++, and is still in the <experimental/optional> header. Is that include just missing? Commented Oct 22, 2018 at 15:41
  • 3
    Looking at the source code it seems that libpqxx does try to use std::optional when possible, but apparently its build system misdetects this feature. The release note says you can fix the error by defining PQXX_HIDE_EXP_OPTIONAL. Commented Oct 22, 2018 at 16:53

1 Answer 1

3

As @cpplearner pointed out in a comment above, libpqxx has a macro (PQXX_HIDE_EXP_OPTIONAL) you can define prior to including the pqxx header files. More of a temporary workaround than a solution, but in my case it allowed me to get past the error and working on the code I needed.

This is the definition I added to my cmake file:

ADD_DEFINITIONS ( -DPQXX_HIDE_EXP_OPTIONAL ) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.