英文:
How do I use boost's feature detection and other useful macros? Example: BOOST_OVERRIDE
问题
我正在处理需要在较旧的C++版本下编译的代码(我不知道适用的所有版本)。具体来说,我想使用宏BOOST_OVERRIDE。还有其他几个。
我如何可靠地访问这些宏?我可以使用boost/config/detail/suffix.hpp,但这似乎不是正确的方法(深入研究boost内部)。
我们使用的是boost 1.78。
英文:
I am working on code that needs to compile under older C++ versions (I don't know all the versions applicable). Specifically, I would like to use the macro BOOST_OVERRIDE. There are several others.
How do I reliably access these macros? I can boost/config/detail/suffix.hpp but that doesn't seem to be the right approach (delving into boost internals).
We use boost 1.78
答案1
得分: 1
All feature detection macros defined by Boost.Config become available by including boost/config.hpp
. You should not need to include any other headers for feature detection, and certainly, you should never include anything from the detail
subdirectory.
#include <boost/config.hpp>
struct interface
{
virtual void foo() = 0;
};
struct impl :
public interface
{
void foo() BOOST_OVERRIDE
{
}
};
Boost.Config also defines a few other utilities that are defined in separate headers. For example, boost/config/auto_link.hpp
allows enabling automatic linting to libraries on compilers that support this feature, and boost/config/workaround.hpp
defines a few macros for testing compiler versions to apply workarounds. But for the purpose of feature detection, boost/config.hpp
should be the only include you need.
英文:
All feature detection macros defined by Boost.Config become available by including boost/config.hpp
. You should not need to include any other headers for feature detection, and certainly, you should never include anything from the detail
subdirectory.
#include <boost/config.hpp>
struct interface
{
virtual void foo() = 0;
};
struct impl :
public interface
{
void foo() BOOST_OVERRIDE
{
}
};
Boost.Config also defines a few other utilities that are defined in separate headers. For example, boost/config/auto_link.hpp
allows enabling automatic linting to libraries on compilers that support this feature, and boost/config/workaround.hpp
defines a few macros for testing compiler versions to apply workarounds. But for the purpose of feature detection, boost/config.hpp
should be the only include you need.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论