-
Notifications
You must be signed in to change notification settings - Fork 0
/
swap_sign.hpp
26 lines (21 loc) · 1.15 KB
/
swap_sign.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#ifndef VT_SWAP_SIGN_HPP
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ swap_sign.hpp: ┃
// ┃ Copyright (c) 2020 viraltaco_ (viraltaco@gmx.com) ┃
// ┃ https://github.com/ViralTaco ┃
// ┃ SPDX-License-Identifier: MIT ┃
// ┃ <http://www.opensource.org/licenses/MIT> ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
#define VT_SWAP_SIGN_HPP "1.0.1"
#include <type_traits>
namespace argumentative {
template <class T> [[nodiscard, maybe_unused]]
constexpr auto swap_sign(const T integral) noexcept {
if constexpr (std::is_unsigned_v<T>) { // unsigned --> signed
return static_cast< std::make_signed_t<T> > (integral);
} else { // signed --> unsigned
return static_cast< std::make_unsigned_t<T> > (integral);
}
}
} namespace ive = argumentative;
#endif