EllAlgo 1.6.13
Loading...
Searching...
No Matches
half_nonnegative.hpp
Go to the documentation of this file.
1
20#ifndef ALGO_HALF_NONNEGATIVE_H
21#define ALGO_HALF_NONNEGATIVE_H
22
23#include <type_traits>
24#include <utility>
25
26namespace algo {
27
43 template <typename N> auto half_nonnegative(N n) noexcept ->
44 typename std::enable_if_t<std::is_integral<N>::value, N> {
45 using UN = typename std::make_unsigned_t<N>;
46 return static_cast<N>(static_cast<UN>(n) / 2);
47 }
48
56 template <typename N> auto half_nonnegative(N n) noexcept ->
57 typename std::enable_if_t<!std::is_integral<N>::value, N> {
58 return std::move(n) / 2;
59 }
60
61} // namespace algo
62
63#endif // ALGO_HALF_NONNEGATIVE_H
auto invalid_value() -> T
Return an invalid/sentinel value for type T.
Definition cutting_plane.hpp:27
Definition half_nonnegative.hpp:26
auto half_nonnegative(N n) noexcept -> typename std::enable_if_t< std::is_integral< N >::value, N >
Compute half of a non-negative integral number.
Definition half_nonnegative.hpp:43