我如何使用boost的特征检测和其他有用的宏?示例:BOOST_OVERRIDE

huangapple go评论67阅读模式
英文:

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 &lt;boost/config.hpp&gt;

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.

huangapple
  • 本文由 发表于 2023年4月17日 18:37:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76034242.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定