#define BITS 32
#if INTPTR_MAX == INT64_MAX
#undef BITS
#define BITS 64
#endif
#define it, and optionally #undefing it is ugly. Use an else block with parallel #defines instead
integer(){
value.clear();
}
value will be empty when the object is constructed, there is no need to clear it.
operator char(){
return (char) value.back();
}
Converting to a char by ignoring everything but one element strikes me as ill-advised.
operator uint64_t(){
int out = 0, count = 0;
std::deque <uint8_t>::iterator i = value.end();
while ((*this > 0) && (count < 8))
out += *(i++);
return out;
}
Do you really need to convert to so many different integer types? You should probably assert/throw an error if the value cannot be stored in the output format type.
integer operator|(integer rhs){
std::deque <uint8_t> larger = value, smaller = rhs.value;
You make unneccesary copies of the data here
if (value.size() < rhs.value.size())
larger.swap(smaller);
while (smaller.size() < larger.size())
smaller.push_front(0);
for(std::deque <uint8_t>::reverse_iterator i = smaller.rbegin(), j = larger.rbegin(); i != smaller.rend(); i++, j++)
Why are you using a reverse iterator?
*j |= *i;
return integer(larger);
}
The & operator is very similiar, they should be refactored to eliminate duplicate code.
integer operator~(){
std::deque <uint8_t> out = value;
std::deque <uint8_t>::reverse_iterator i = out.rbegin(), j = out.rend();
j--;
i and j are not very helpful names
for(i = i; i != j; i++)
*i ^= 0xff;
// get highest bit
int8_t top = 8;
while (!((1 << top) & *i))
top--;
for(top = top; top > -1; top--)
*i ^= 1 << top;
return integer(out);
}
Can't you just apply ~ to all of the elements? At any rate some comments as to why you are doing what you are doing here would be useful.