audiofile
audiofile copied to clipboard
Unary_function is deprecated since c++11
Unary_function is deprecated since c++11 and is being removed from current compilers e.g. clang17, so that compilation falls.
I see this using llvm-16 on MacOS. Is there a fix?
In file included from /Users/cary/projects/xsimall-dev1/builds/trilinos-14.0.0/packages/tpetra/core/src/Epetra_TsqrMessenger.cpp:55: In file included from /Users/cary/projects/xsimall-dev1/builds/trilinos-14.0.0/packages/tpetra/core/src/Epetra_TsqrMessenger.hpp:58: /Users/cary/projects/xsimall-dev1/builds/trilinos-14.0.0/packages/tpetra/core/src/Tpetra_ConfigDefs.hpp:153:34: error: no template named 'binary_function' in namespace 'std'; did you mean '__binary_function'? class project1st : public std::binary_function<Arg1, Arg2, Arg1> { ~~~~~^~~~~~~~~~~~~~~ __binary_function /opt/homebrew/Cellar/llvm/16.0.6/bin/../include/c++/v1/__functional/binary_function.h:49:1: note: '__binary_function' declared here using __binary_function = __binary_function_keep_layout_base<_Arg1, _Arg2, _Result>;
I encountered this error with a gentoo clang profile using libcxx. Unfortunately this library seems to be unmaintained 😕
I see this using llvm-16 on MacOS. Is there a fix?
Probably the most pragmatic solution is to explicitly set a lower C++ standard with -std
.
Alternatively, applying the following patch resolves the Clang deprecation errors:
--- a/libaudiofile/modules/SimpleModule.h
+++ b/libaudiofile/modules/SimpleModule.h
@@ -125,13 +125,17 @@ struct signConverter
static const int kScaleBits = (Format + 1) * CHAR_BIT - 1;
static const int kMinSignedValue = 0-(1U<<kScaleBits);
- struct signedToUnsigned : public std::unary_function<SignedType, UnsignedType>
+ struct signedToUnsigned
{
+ typedef SignedType argument_type;
+ typedef UnsignedType result_type;
UnsignedType operator()(SignedType x) { return x - kMinSignedValue; }
};
- struct unsignedToSigned : public std::unary_function<SignedType, UnsignedType>
+ struct unsignedToSigned
{
+ typedef SignedType argument_type;
+ typedef UnsignedType result_type;
SignedType operator()(UnsignedType x) { return x + kMinSignedValue; }
};
};
@@ -323,8 +327,10 @@ private:
};
template <typename Arg, typename Result>
-struct intToFloat : public std::unary_function<Arg, Result>
+struct intToFloat
{
+ typedef Arg argument_type;
+ typedef Result result_type;
Result operator()(Arg x) const { return x; }
};
@@ -389,14 +395,18 @@ private:
};
template <typename Arg, typename Result, unsigned shift>
-struct lshift : public std::unary_function<Arg, Result>
+struct lshift
{
+ typedef Arg argument_type;
+ typedef Result result_type;
Result operator()(const Arg &x) const { return x << shift; }
};
template <typename Arg, typename Result, unsigned shift>
-struct rshift : public std::unary_function<Arg, Result>
+struct rshift
{
+ typedef Arg argument_type;
+ typedef Result result_type;
Result operator()(const Arg &x) const { return x >> shift; }
};
@@ -491,8 +501,10 @@ private:
};
template <typename Arg, typename Result>
-struct floatToFloat : public std::unary_function<Arg, Result>
+struct floatToFloat
{
+ typedef Arg argument_type;
+ typedef Result result_type;
Result operator()(Arg x) const { return x; }
};
@LinuxUserGD Thank you so much for sharing your patch! With it, the Gentoo audiofile package finally builds for me when using libc++ 17 instead of libstdc++.
Edit
@orbea I've tried setting -std=c++11
, but then configuration fails, at least on Linux, at the checking whether the C compiler works
step because CXXFLAGS
seem to be in use instead of CFLAGS
, leading to the following error:
error: invalid argument '-std=c++11' not allowed with 'C'
Looks like mpruett hasn't been active on GitHub for the past seven years and some change, so locally carrying this patch is probably as good as it's going to get 😔