1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00
Sprout/sprout/cstdlib/abs.hpp
2015-04-05 01:32:49 +09:00

68 lines
1.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*=============================================================================
Copyright (c) 2011 RiSK (sscrisk)
https://github.com/sscrisk/CEL---ConstExpr-Library
Copyright (c) 2011-2015 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#ifndef SPROUT_CSTDLIB_ABS_HPP
#define SPROUT_CSTDLIB_ABS_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/type_traits/is_signed.hpp>
#include <sprout/type_traits/is_unsigned.hpp>
namespace sprout {
// 7.20.6.1 abs<62>Clabs<62>CyÑ llabs ŠÖ<C5A0>
inline SPROUT_CONSTEXPR int
abs(int j) {
return j < 0 ? -j : j;
}
inline SPROUT_CONSTEXPR long
labs(long j) {
return j < 0 ? -j : j;
}
inline SPROUT_CONSTEXPR long long
llabs(long long j) {
return j < 0 ? -j : j;
}
inline SPROUT_CONSTEXPR long
abs(long j) {
return sprout::labs(j);
}
inline SPROUT_CONSTEXPR long long
abs(long long j) {
return sprout::llabs(j);
}
namespace {
template<typename IntType>
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_integral<IntType>::value && sprout::is_signed<IntType>::value,
IntType
>::type
abs(IntType j) {
return j < 0 ? -j : j;
}
template<typename IntType>
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_integral<IntType>::value && sprout::is_unsigned<IntType>::value,
IntType
>::type
abs(IntType j) {
return j;
}
} // anonymous-namespace
} // namespace sprout
#endif // #ifndef SPROUT_CSTDLIB_ABS_HPP