1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-12-11 15:16:27 +01:00

Make Audacity build in C++17 ...

... Fixing many conditional operators with explicit construction of wxString
instead of simple string literals;

And fixing allocation of more strictly aligned structures on Mac, without need
for 10.14 as the minimum SDK, by means of some class-specific operators new
and delete.
This commit is contained in:
Paul Licameli
2021-02-02 11:44:00 -05:00
committed by Dmitry Vedenko
parent e6e81399f7
commit 77dab158c3
19 changed files with 112 additions and 32 deletions

View File

@@ -4,6 +4,7 @@
// C++ standard header <memory> with a few extensions
#include <iterator>
#include <memory>
#include <new> // align_val_t and hardware_destructive_interference_size
#include <cstdlib> // Needed for free.
#ifndef safenew
#define safenew new
@@ -579,6 +580,36 @@ OutContainer transform_container( InContainer &inContainer, Function &&fn )
inContainer.begin(), inContainer.end(), fn );
}
//! Non-template helper for class template NonInterfering
/*!
If a structure contains any members with large alignment, this base class may also allow it to work in
macOS builds under current limitations of the C++17 standard implementation.
*/
struct UTILITY_API alignas(
#ifdef __WIN32__
std::hardware_destructive_interference_size
#else
// That constant isn't defined for the other builds yet
64 /* ? */
#endif
)
NonInterferingBase {
#ifdef __APPLE__
static void *operator new(std::size_t count, std::align_val_t al);
static void operator delete(void *ptr, std::align_val_t al);
#endif
};
/*! Given a structure type T, derive a structure with sufficient padding so that there is not false sharing of
cache lines between successive elements of an array of those structures.
*/
template< typename T > struct NonInterfering
: NonInterferingBase // Inherit operators; use empty base class optimization
, T
{
using T::T;
};
// These macros are used widely, so declared here.
#define QUANTIZED_TIME(time, rate) (floor(((double)(time) * (rate)) + 0.5) / (rate))
// dB - linear amplitude conversions