From 209fd4a2079d66a2d9b43d4b80b1e03b523c71d7 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Tue, 30 Dec 2025 21:32:14 +0100 Subject: [PATCH] configlib: Remove deprecated std::binary_function inheritance Original warnings: configlib/i2n_global_config.hpp:261:15: error: 'template struct std::binary_function' is deprecated [-Werror=deprecated-declarations] configlib/i2n_global_config.hpp:278:15: error: 'template struct std::binary_function' is deprecated [-Werror=deprecated-declarations] configlib/i2n_global_config.hpp:299:15: error: 'template struct std::binary_function' is deprecated [-Werror=deprecated-declarations] configlib/i2n_global_config.hpp:350:18: error: 'template struct std::binary_function' is deprecated [-Werror=deprecated-declarations] Keep std::binary_function inheritance for GCC < 4.8 only. GCC 4.8.1 was the first version with feature-complete C++11 support. Require C++11 when using GCC >= 4.8 to avoid ABI mismatch between the deprecated std::binary_function and modern C++ standard library. Applied to: - DefaultConverter - DefaultConverter - AutoIntConverter Also added conditional BOOST_STATIC_ASSERT in Var class to check binary_function inheritance only for GCC < 4.8. --- configlib/i2n_global_config.hpp | 21 ++++++++++++++++++--- 1 files changed, 18 insertions(+), 3 deletions(-) diff --git a/configlib/i2n_global_config.hpp b/configlib/i2n_global_config.hpp index a1bfaa8..ac5d243 100644 --- a/configlib/i2n_global_config.hpp +++ b/configlib/i2n_global_config.hpp @@ -62,6 +62,15 @@ using namespace boost::placeholders; #endif #include +/* + * Require C++11 when using GCC >= 4.8 to avoid ABI mismatch + * between the deprecated std::binary_function and modern C++ standard library. + */ +#if __cplusplus < 201103L && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) +#error "This header requires C++11 or higher when compiled with GCC >= 4.8. " \ + "Otherwise we get an ABI mismatch." +#endif + namespace I2n { @@ -263,7 +272,9 @@ template< typename ValueType > struct DefaultConverter +#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8) : public std::binary_function< std::string, ValueType&, bool > +#endif { bool operator () ( const std::string& str, ValueType& v ) @@ -280,7 +291,9 @@ struct DefaultConverter * just copies the input to the result var and returns true. */ template<> struct DefaultConverter< std::string > +#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8) : public std::binary_function< std::string, std::string&, bool > +#endif { bool operator () ( const std::string& str, std::string& v ) @@ -301,7 +314,9 @@ template< typename ValueType > struct AutoIntConverter +#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8) : public std::binary_function< std::string, ValueType&, bool > +#endif { bool operator () ( const std::string& str, ValueType& v ) @@ -328,9 +343,7 @@ struct AutoIntConverter * @brief represents a configuration variable with automatic update. * @tparam ValueType type of the value this variable should hold. * @tparam Converter a converter class which converts a string (from config file) to the desired - * type. - * Needs to be derived from std::binary_function (taking a string as first arg, a reference to the - * desired type as second and returning bool (@a true if conversion was succesful). + * type. Must have an operator() taking (const std::string&, ValueType&) and returning bool. * * Basic idea is to pass a point (section, key) in the config where the value for this * variable is stored. The config value (a string) should be converted to the desired value (type). @@ -351,6 +364,7 @@ class Var ValueType, Converter, Detail::is_list_container< ValueType >::value > { +#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8) BOOST_STATIC_ASSERT(( boost::is_base_of< std::binary_function< std::string, @@ -359,6 +373,7 @@ class Var >::type, bool >, Converter >::value )); +#endif typedef Detail::OuterSpace< ValueType, Converter, -- 1.7.1