configlib: Remove deprecated std::binary_function inheritance
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Tue, 30 Dec 2025 20:32:14 +0000 (21:32 +0100)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Wed, 31 Dec 2025 11:11:25 +0000 (12:11 +0100)
Original warnings:
configlib/i2n_global_config.hpp:261:15: error: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Werror=deprecated-declarations]
configlib/i2n_global_config.hpp:278:15: error: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Werror=deprecated-declarations]
configlib/i2n_global_config.hpp:299:15: error: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Werror=deprecated-declarations]
configlib/i2n_global_config.hpp:350:18: error: 'template<class _Arg1, class _Arg2, class _Result> 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<ValueType>
- DefaultConverter<std::string>
- AutoIntConverter<ValueType>

Also added conditional BOOST_STATIC_ASSERT in Var class to check
binary_function inheritance only for GCC < 4.8.

configlib/i2n_global_config.hpp

index a1bfaa8..ac5d243 100644 (file)
@@ -62,6 +62,15 @@ using namespace boost::placeholders;
 #endif
 #include <boost/foreach.hpp>
 
+/*
+ * 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,