mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
add single and range bitwise operations
This commit is contained in:
parent
5bfb5087ac
commit
fd608b74e2
13 changed files with 318 additions and 2 deletions
28
sprout/bit/flipbit.hpp
Normal file
28
sprout/bit/flipbit.hpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2011-2014 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_BIT_FLIPBIT_HPP
|
||||||
|
#define SPROUT_BIT_FLIPBIT_HPP
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
//
|
||||||
|
// flipbit
|
||||||
|
//
|
||||||
|
template<typename Integral>
|
||||||
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||||
|
std::is_integral<Integral>::value,
|
||||||
|
Integral
|
||||||
|
>::type
|
||||||
|
flipbit(Integral x, int b) SPROUT_NOEXCEPT {
|
||||||
|
return x ^ (Integral(1) << b);
|
||||||
|
}
|
||||||
|
} // namespace sprout
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_BIT_FLIPBIT_HPP
|
28
sprout/bit/flipbitsge.hpp
Normal file
28
sprout/bit/flipbitsge.hpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2011-2014 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_BIT_FLIPBITSGE_HPP
|
||||||
|
#define SPROUT_BIT_FLIPBITSGE_HPP
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
//
|
||||||
|
// flipbitsge
|
||||||
|
//
|
||||||
|
template<typename Integral>
|
||||||
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||||
|
std::is_integral<Integral>::value,
|
||||||
|
Integral
|
||||||
|
>::type
|
||||||
|
flipbitsge(Integral x, int b) SPROUT_NOEXCEPT {
|
||||||
|
return x ^ ~((Integral(1) << b)-1);
|
||||||
|
}
|
||||||
|
} // namespace sprout
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_BIT_FLIPBITSGE_HPP
|
28
sprout/bit/flipbitsle.hpp
Normal file
28
sprout/bit/flipbitsle.hpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2011-2014 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_BIT_FLIPBITSLE_HPP
|
||||||
|
#define SPROUT_BIT_FLIPBITSLE_HPP
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
//
|
||||||
|
// flipbitsle
|
||||||
|
//
|
||||||
|
template<typename Integral>
|
||||||
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||||
|
std::is_integral<Integral>::value,
|
||||||
|
Integral
|
||||||
|
>::type
|
||||||
|
flipbitsle(Integral x, int b) SPROUT_NOEXCEPT {
|
||||||
|
return x ^ ((Integral(1) << (b+1))-1);
|
||||||
|
}
|
||||||
|
} // namespace sprout
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_BIT_FLIPBITSLE_HPP
|
|
@ -13,8 +13,8 @@
|
||||||
#include <sprout/bit/count.hpp>
|
#include <sprout/bit/count.hpp>
|
||||||
#include <sprout/bit/rightmost.hpp>
|
#include <sprout/bit/rightmost.hpp>
|
||||||
#include <sprout/bit/reverse.hpp>
|
#include <sprout/bit/reverse.hpp>
|
||||||
//#include <sprout/bit/single.hpp>
|
#include <sprout/bit/single.hpp>
|
||||||
//#include <sprout/bit/range.hpp>
|
#include <sprout/bit/range.hpp>
|
||||||
//#include <sprout/bit/pow2.hpp>
|
//#include <sprout/bit/pow2.hpp>
|
||||||
//#include <sprout/bit/saturated.hpp>
|
//#include <sprout/bit/saturated.hpp>
|
||||||
//#include <sprout/bit/align.hpp>
|
//#include <sprout/bit/align.hpp>
|
||||||
|
|
19
sprout/bit/range.hpp
Normal file
19
sprout/bit/range.hpp
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2011-2014 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_BIT_RANGE_HPP
|
||||||
|
#define SPROUT_BIT_RANGE_HPP
|
||||||
|
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
#include <sprout/bit/rstbitsge.hpp>
|
||||||
|
#include <sprout/bit/rstbitsle.hpp>
|
||||||
|
#include <sprout/bit/setbitsge.hpp>
|
||||||
|
#include <sprout/bit/setbitsle.hpp>
|
||||||
|
#include <sprout/bit/flipbitsge.hpp>
|
||||||
|
#include <sprout/bit/flipbitsle.hpp>
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_BIT_RANGE_HPP
|
28
sprout/bit/rstbit.hpp
Normal file
28
sprout/bit/rstbit.hpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2011-2014 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_BIT_RSTBIT_HPP
|
||||||
|
#define SPROUT_BIT_RSTBIT_HPP
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
//
|
||||||
|
// rstbit
|
||||||
|
//
|
||||||
|
template<typename Integral>
|
||||||
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||||
|
std::is_integral<Integral>::value,
|
||||||
|
Integral
|
||||||
|
>::type
|
||||||
|
rstbit(Integral x, int b) SPROUT_NOEXCEPT {
|
||||||
|
return x & ~(Integral(1) << b);
|
||||||
|
}
|
||||||
|
} // namespace sprout
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_BIT_RSTBIT_HPP
|
28
sprout/bit/rstbitsge.hpp
Normal file
28
sprout/bit/rstbitsge.hpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2011-2014 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_BIT_RSTBITSGE_HPP
|
||||||
|
#define SPROUT_BIT_RSTBITSGE_HPP
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
//
|
||||||
|
// rstbitsge
|
||||||
|
//
|
||||||
|
template<typename Integral>
|
||||||
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||||
|
std::is_integral<Integral>::value,
|
||||||
|
Integral
|
||||||
|
>::type
|
||||||
|
rstbitsge(Integral x, int b) SPROUT_NOEXCEPT {
|
||||||
|
return x & ((Integral(1) << b)-1);
|
||||||
|
}
|
||||||
|
} // namespace sprout
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_BIT_RSTBITSGE_HPP
|
28
sprout/bit/rstbitsle.hpp
Normal file
28
sprout/bit/rstbitsle.hpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2011-2014 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_BIT_SRSTBITSLE_HPP
|
||||||
|
#define SPROUT_BIT_SRSTBITSLE_HPP
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
//
|
||||||
|
// rstbitsle
|
||||||
|
//
|
||||||
|
template<typename Integral>
|
||||||
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||||
|
std::is_integral<Integral>::value,
|
||||||
|
Integral
|
||||||
|
>::type
|
||||||
|
rstbitsle(Integral x, int b) SPROUT_NOEXCEPT {
|
||||||
|
return x & ~((Integral(1) << (b+1))-1);
|
||||||
|
}
|
||||||
|
} // namespace sprout
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_BIT_SRSTBITSLE_HPP
|
28
sprout/bit/setbit.hpp
Normal file
28
sprout/bit/setbit.hpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2011-2014 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_BIT_SETBIT_HPP
|
||||||
|
#define SPROUT_BIT_SETBIT_HPP
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
//
|
||||||
|
// setbit
|
||||||
|
//
|
||||||
|
template<typename Integral>
|
||||||
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||||
|
std::is_integral<Integral>::value,
|
||||||
|
Integral
|
||||||
|
>::type
|
||||||
|
setbit(Integral x, int b) SPROUT_NOEXCEPT {
|
||||||
|
return x | (Integral(1) << b);
|
||||||
|
}
|
||||||
|
} // namespace sprout
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_BIT_SETBIT_HPP
|
28
sprout/bit/setbitsge.hpp
Normal file
28
sprout/bit/setbitsge.hpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2011-2014 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_BIT_SETBITSGE_HPP
|
||||||
|
#define SPROUT_BIT_SETBITSGE_HPP
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
//
|
||||||
|
// setbitsge
|
||||||
|
//
|
||||||
|
template<typename Integral>
|
||||||
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||||
|
std::is_integral<Integral>::value,
|
||||||
|
Integral
|
||||||
|
>::type
|
||||||
|
setbitsge(Integral x, int b) SPROUT_NOEXCEPT {
|
||||||
|
return x | ~((Integral(1) << b)-1);
|
||||||
|
}
|
||||||
|
} // namespace sprout
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_BIT_SETBITSGE_HPP
|
28
sprout/bit/setbitsle.hpp
Normal file
28
sprout/bit/setbitsle.hpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2011-2014 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_BIT_SETBITSLE_HPP
|
||||||
|
#define SPROUT_BIT_SETBITSLE_HPP
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
//
|
||||||
|
// setbitsle
|
||||||
|
//
|
||||||
|
template<typename Integral>
|
||||||
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||||
|
std::is_integral<Integral>::value,
|
||||||
|
Integral
|
||||||
|
>::type
|
||||||
|
setbitsle(Integral x, int b) SPROUT_NOEXCEPT {
|
||||||
|
return x | ((Integral(1) << (b+1))-1);
|
||||||
|
}
|
||||||
|
} // namespace sprout
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_BIT_SETBITSLE_HPP
|
17
sprout/bit/single.hpp
Normal file
17
sprout/bit/single.hpp
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2011-2014 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_BIT_SINGLE_HPP
|
||||||
|
#define SPROUT_BIT_SINGLE_HPP
|
||||||
|
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
#include <sprout/bit/setbit.hpp>
|
||||||
|
#include <sprout/bit/rstbit.hpp>
|
||||||
|
#include <sprout/bit/flipbit.hpp>
|
||||||
|
#include <sprout/bit/testbit.hpp>
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_BIT_SINGLE_HPP
|
28
sprout/bit/testbit.hpp
Normal file
28
sprout/bit/testbit.hpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2011-2014 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_BIT_TESTBIT_HPP
|
||||||
|
#define SPROUT_BIT_TESTBIT_HPP
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
//
|
||||||
|
// testbit
|
||||||
|
//
|
||||||
|
template<typename Integral>
|
||||||
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||||
|
std::is_integral<Integral>::value,
|
||||||
|
bool
|
||||||
|
>::type
|
||||||
|
testbit(Integral x, int b) SPROUT_NOEXCEPT {
|
||||||
|
return x & (Integral(1) << b);
|
||||||
|
}
|
||||||
|
} // namespace sprout
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_BIT_TESTBIT_HPP
|
Loading…
Reference in a new issue