I have code that should be compiled with gcc 4.7, which have not bad c++11 supports, but lacks c++14 and c++17.
And I want to use std::optional and std::variant in my code, with fallback for boost::optional and boost::variant for gcc 4.7
What the standard way to achieve this?
I see two variants:
- Wrapper around variant, it may be macro like:
#define VARIANT_TYPE boost::variantornamespace my_code { using variant = boost::variant } - extend
stdnamespace
The first one is not good, because of my code will use my_code::variant, instead of std::variant. The second one looks more clear for me.
The 2 may be UB in general case What are the reasons that extending the std namespace is considered undefined behavior?
But what about my specific case? I know what exactly version of gcc has variant/optional, I can check it on configure stage of build. For all other compilers/standard c++ library I can require c++17 support and not use my hack that convert boost::optional to std::optional.
Can I still catch some exotic problems?
Aucun commentaire:
Enregistrer un commentaire