How to selectively include boost headers depending on boost version

Viewed 1078

This change in Boost caused some header file locations to change: https://github.com/boostorg/property_tree/commit/ea940990691de91e9b22255d9b450fcdac237646

I am working on a codebase where some users build with an older version of boost, with the old header locations, e.g. #include <boost/property_tree/detail/json_parser_error.hpp> instead of the newer #include <boost/property_tree/json_parser/error.hpp>. I want to retain compatibility with both older (pre-1.61) and newer boosts.

Is there a way to instruct the compiler to check for the boost version and use the new header include if the version >= 1.61?

1 Answers

I think you are looking for BOOST_VERSION preprocessor. It is defined in boost\version.hpp

// Caution, this is the only boost header that is guarenteed
// to change with every boost release, including this header
// will cause a recompile every time a new boost version is
// released.
//
// BOOST_VERSION % 100 is the patch level
// BOOST_VERSION / 100 % 1000 is the minor version
// BOOST_VERSION / 100000 is the major version

Simple usage would be:

#if BOOST_VERSION >= 106100
#include <this.hpp>
#else
#include <that.hpp> 
#endif
Related