| 1 | // Copyright 2023 Matt Borland |
| 2 | // Distributed under the Boost Software License, Version 1.0. |
| 3 | // https://www.boost.org/LICENSE_1_0.txt |
| 4 | |
| 5 | #ifndef BOOST_CHARCONV_DETAIL_APPLY_SIGN_HPP |
| 6 | #define BOOST_CHARCONV_DETAIL_APPLY_SIGN_HPP |
| 7 | |
| 8 | #include <boost/config.hpp> |
| 9 | #include <boost/charconv/detail/emulated128.hpp> |
| 10 | #include <boost/charconv/detail/type_traits.hpp> |
| 11 | #include <type_traits> |
| 12 | |
| 13 | // We are purposefully converting values here |
| 14 | #ifdef BOOST_MSVC |
| 15 | # pragma warning(push) |
| 16 | # pragma warning(disable: 4146) |
| 17 | #elif defined(__GNUC__) && __GNUC__ >= 5 |
| 18 | # pragma GCC diagnostic push |
| 19 | # pragma GCC diagnostic ignored "-Wconversion" |
| 20 | #elif defined(__clang__) |
| 21 | # pragma clang diagnostic push |
| 22 | # pragma clang diagnostic ignored "-Wconversion" |
| 23 | #endif |
| 24 | |
| 25 | namespace boost { namespace charconv { namespace detail { |
| 26 | |
| 27 | template <typename Integer, typename Unsigned_Integer = detail::make_unsigned_t<Integer>, |
| 28 | typename std::enable_if<detail::is_signed<Integer>::value, bool>::type = true> |
| 29 | constexpr Unsigned_Integer apply_sign(Integer val) noexcept |
| 30 | { |
| 31 | return -(static_cast<Unsigned_Integer>(val)); |
| 32 | } |
| 33 | |
| 34 | template <typename Unsigned_Integer, typename std::enable_if<!detail::is_signed<Unsigned_Integer>::value, bool>::type = true> |
| 35 | constexpr Unsigned_Integer apply_sign(Unsigned_Integer val) noexcept |
| 36 | { |
| 37 | return val; |
| 38 | } |
| 39 | |
| 40 | }}} // Namespaces |
| 41 | |
| 42 | #ifdef BOOST_MSVC |
| 43 | # pragma warning(pop) |
| 44 | #elif defined(__GNUC__) && __GNUC__ >= 5 |
| 45 | # pragma GCC diagnostic pop |
| 46 | #elif defined(__clang__) |
| 47 | # pragma clang diagnostic pop |
| 48 | #endif |
| 49 | |
| 50 | #endif // BOOST_CHARCONV_DETAIL_APPLY_SIGN_HPP |
| 51 | |