I have seen usage of #ifdef macros ( example Eigen library ) to manage platform specific, but haven't seen any one use "inline namespace"s to manage platform specific code.
The github repo belows gives specific code and example usage. https://github.com/dchichkov/curious-namespace-trick/wiki/Curious-Namespace-Trick
I am wondering if it is a viable technique to use or if there are any gotchas that I am not able to see. Below is the code snippet :
#include <stdio.h>
namespace project {
// arm/math.h
namespace arm {
inline void add_() {printf("arm add\n");} // try comment out
}
// math.h
inline void add_() {
//
printf("common add\n");
//
} inline namespace platform {inline void add() {add_();}}
inline void dot_() {
//
add();
//
} inline namespace platform {inline void dot() {dot_();}}
}
int main() {
project::dot();
return 1;
}
Output :
$g++ func.cpp -Dplatform=common ; ./a.out common add
$ g++ func.cpp -Dplatform=arm ; ./a.out arm add