/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #pragma once #include #include #include #include #include #include #include namespace o3tl { // An approximation of C++20 std::strong_order that should work at least for IEC559 float // and double on platforms that have correspondingly-sized std::int32_t and std::int64_t: #if HAVE_CPP_STRONG_ORDER inline constexpr auto strong_order = std::strong_order; #else namespace detail { template To bit_cast(From val) requires (sizeof (To) == sizeof (From)) { char buf alignas(To)[sizeof (From)]; std::memcpy(buf, &val, sizeof (From)); return *reinterpret_cast(buf); } struct strong_order { template auto operator ()(T x, T y) const requires std::same_as && std::numeric_limits::is_iec559 { return bit_cast(x) <=> bit_cast(y); } template auto operator ()(T x, T y) const requires std::same_as && std::numeric_limits::is_iec559 { return bit_cast(x) <=> bit_cast(y); } }; } inline constexpr auto strong_order = detail::strong_order(); #endif } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */