From b0311f9cd41cfbc141ebbf4b02cc1ffdea8c2575 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sat, 15 Dec 2018 15:35:27 +1100 Subject: [PATCH] endian: remove templates from bswap It's too hard to trace problems with callers if we use templates here (most of the callgraph gets truncated so we can't even tell who's calling us). --- endian.hpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/endian.hpp b/endian.hpp index d23319d4..a61ca2d8 100644 --- a/endian.hpp +++ b/endian.hpp @@ -17,15 +17,10 @@ namespace cruft { //------------------------------------------------------------------------- - template - constexpr T - bswap (T) noexcept; - // CXX: Update using "if constexpr" when available. It doesn't seem to be // worth the dicking about to use enable_if_t to differentiate the // signed/unsigned cases. #define SIGNED_BSWAP(S) \ - template <> \ constexpr \ int##S##_t \ bswap (int##S##_t v) noexcept { \ @@ -41,12 +36,12 @@ namespace cruft { SIGNED_BSWAP(32) SIGNED_BSWAP(64) - template <> constexpr int8_t bswap ( int8_t v) noexcept { return v; } - template <> constexpr uint8_t bswap (uint8_t v) noexcept { return v; } + constexpr int8_t bswap ( int8_t v) noexcept { return v; } + constexpr uint8_t bswap (uint8_t v) noexcept { return v; } - template <> constexpr uint16_t bswap (uint16_t v) noexcept { return __builtin_bswap16 (v); } - template <> constexpr uint32_t bswap (uint32_t v) noexcept { return __builtin_bswap32 (v); } - template <> constexpr uint64_t bswap (uint64_t v) noexcept { return __builtin_bswap64 (v); } + constexpr uint16_t bswap (uint16_t v) noexcept { return __builtin_bswap16 (v); } + constexpr uint32_t bswap (uint32_t v) noexcept { return __builtin_bswap32 (v); } + constexpr uint64_t bswap (uint64_t v) noexcept { return __builtin_bswap64 (v); } // use a type-punning union to punt the byte swapping operation to the @@ -54,7 +49,6 @@ namespace cruft { // // this is debatably safe under production compilers like gcc + clang // despite what the standard may say about unions. - template <> constexpr float bswap (float v) noexcept {