Linux中的<ncurses.h>
头文件定义了函数meta
,而C++元编程库meta
将其所有代码放在全局命名空间meta
中。
我该如何在同一个C++程序中使用两者(不一定是同一个TU但这会很好)?有没有办法解决名称冲突?
我能想到两种易碎的解决方法,但它们很容易破坏:
Workaround A:
namespace linux { #include <ncurses.h> } // namespace linux using linux::max_align_t; // ncurses assumes it is in the global namespace #include <meta/meta.hpp>
compiles but will probably fail to link since the
ncurses
symbols are expected in the global namespace.Workaround B:
#include <ncurses.h> namespace cpp { #include <meta/meta.hpp> } // namespace cpp
is very brittle since it will only work as long as the
meta
library doesn't assume that any of its symbols are in the global namespace. That is, if the library needs to disambiguate internally a symbol and uses::meta::symbol_name
for that, this approach will break.