Skip to main content
added 22 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

#define#define it, and optionally #undefing#undefing it is ugly. Use an elseelse block with parallel #defines#defines instead.

valuevalue will be empty when the object is constructed, so there is no need to clear it.

Converting to a charchar by ignoring everything but one element strikes me as ill-advised.

You make unneccesaryunnecessary copies of the data here.

The && operator is very similiar,similar; they should be refactored to eliminate duplicate code.

ii and jj are not very helpful names.

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.

#define it, and optionally #undefing it is ugly. Use an else block with parallel #defines instead

value will be empty when the object is constructed, there is no need to clear it.

Converting to a char by ignoring everything but one element strikes me as ill-advised.

You make unneccesary copies of the data here

The & operator is very similiar, they should be refactored to eliminate duplicate code.

i and j are not very helpful names

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.

#define it, and optionally #undefing it is ugly. Use an else block with parallel #defines instead.

value will be empty when the object is constructed, so there is no need to clear it.

Converting to a char by ignoring everything but one element strikes me as ill-advised.

You make unnecessary copies of the data here.

The & operator is very similar; they should be refactored to eliminate duplicate code.

i and j are not very helpful names.

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.

Source Link
Winston Ewert
  • 30.7k
  • 4
  • 52
  • 79

#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.