| 1 |
#ifndef BITFUNCTIONAL__ |
| 2 |
#define BITFUNCTIONAL__ |
| 3 |
|
| 4 |
#include <functional> |
| 5 |
|
| 6 |
/* |
| 7 |
Frank B. Brokken, july 19, 2001. |
| 8 |
[email protected] |
| 9 |
|
| 10 |
This file predefines function-objects that are non-standard. |
| 11 |
|
| 12 |
The following function objects are defined: |
| 13 |
|
| 14 |
name operator |
| 15 |
---------------------------- |
| 16 |
shift_left << |
| 17 |
shift_right >> |
| 18 |
bit_not ~ |
| 19 |
bit_and & |
| 20 |
bit_or | |
| 21 |
bit_xor ^ |
| 22 |
---------------------------- |
| 23 |
|
| 24 |
In order to make these objects available, install this file in a directory |
| 25 |
where your compiler finds it, and let sources do: |
| 26 |
|
| 27 |
#include <bitfunctional> |
| 28 |
|
| 29 |
This include directive implies #include <functional> |
| 30 |
*/ |
| 31 |
|
| 32 |
template <typename _Tp> |
| 33 |
struct shift_left : public binary_function<_Tp,_Tp,_Tp> { |
| 34 |
_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x << __y; } |
| 35 |
}; |
| 36 |
|
| 37 |
template <typename _Tp> |
| 38 |
struct shift_right : public binary_function<_Tp,_Tp,_Tp> { |
| 39 |
_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x >> __y; } |
| 40 |
}; |
| 41 |
|
| 42 |
template <typename _Tp> |
| 43 |
struct bit_not : public unary_function<_Tp,_Tp> { |
| 44 |
_Tp operator()(const _Tp& __x) const { return ~__x; } |
| 45 |
}; |
| 46 |
|
| 47 |
template <typename _Tp> |
| 48 |
struct bit_and : public binary_function<_Tp,_Tp,_Tp> { |
| 49 |
_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x & __y; } |
| 50 |
}; |
| 51 |
|
| 52 |
template <typename _Tp> |
| 53 |
struct bit_or : public binary_function<_Tp,_Tp,_Tp> { |
| 54 |
_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x | __y; } |
| 55 |
}; |
| 56 |
|
| 57 |
template <typename _Tp> |
| 58 |
struct bit_xor : public binary_function<_Tp,_Tp,_Tp> { |
| 59 |
_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x ^ __y; } |
| 60 |
}; |
| 61 |
|
| 62 |
#endif |
| 63 |
|