I'm trying to use c++17 if constexpr for conditionally compilation but it does not behave the way I expect.
For example, with the code below, c++ still compiles the code defined by the macro X2,
#include <string>
#include <iostream>
#include <type_traits>
#define X1 pp("x")
#define X2 pp("x", "x")
void pp(const std::string str){
std::cout << str << std::endl;
}
int main(){
std::map<std::string, int> map;
if constexpr (std::is_null_pointer_v<decltype(map)>)
X2;
else
X1;
}
and spits this error messages:
1.c:6:23: error: too many arguments to function ‘void pp(std::__cxx11::string)’
#define X2 pp("x", "x")
^
1.c:18:3: note: in expansion of macro ‘X2’
X2;
^~
Any idea how to skip compilation of X2?
Thanks!
Aucun commentaire:
Enregistrer un commentaire