Skip to content

Commit f6096d2

Browse files
authored
Merge pull request #1230 from RicoAntonioFelix/dev
net: Constrain function net::getbits to integral types
2 parents 2f9ce27 + f12634a commit f6096d2

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

api/net/util.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is a part of the IncludeOS unikernel - www.includeos.org
22
//
3-
// Copyright 2015 Oslo and Akershus University College of Applied Sciences
3+
// Copyright 2015-2017 Oslo and Akershus University College of Applied Sciences
44
// and Alfred Bratterud
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,6 +19,7 @@
1919
#define NET_UTIL_HPP
2020

2121
#include <cstdint>
22+
#include <type_traits>
2223

2324
namespace net {
2425

@@ -28,8 +29,12 @@ namespace net {
2829
* e.g., getbits(x, 31, 8) -- highest byte
2930
* getbits(x, 7, 8) -- lowest byte
3031
*/
31-
template<typename T>
32-
constexpr inline auto getbits(T&& x, T&& p, T&& n) noexcept {
32+
template
33+
<
34+
typename T,
35+
typename = std::enable_if_t<std::is_integral<T>::value>
36+
>
37+
constexpr inline auto getbits(const T x, const T p, const T n) noexcept {
3338
return (x >> ((p + 1) - n)) & ~(~0 << n);
3439
}
3540

0 commit comments

Comments
 (0)