jeudi 30 juin 2016

Using constexpr together with getenv (or alternative)

I'm trying to capture environment variables from a build server as compile time constants that can be used within the build library. I have a static class that can be queried for these constants and would like to use constexpr with std::getenv, but I get the errors that constexpr variable must be initialised from a constant expression due to the fact that getenv returns a non-const char*, due to the fact it is a little long in the tooth.

I'd like to avoid bloating the build scripts by injecting all of the env vars as -DMY_ENV_VAR if possible. If the answer is simply "no, you must add each as a definition like that", and there are no modern alternatives to getenv or tricks I can use then so be it, but then there are 2 spots to maintain, which is not ideal.

Aucun commentaire:

Enregistrer un commentaire