Search code examples
c++boost

How do I use boost's feature detection and other useful macros? Example: BOOST_OVERRIDE


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


Solution

  • 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.