New answers tagged

6

Lots of good comments already given. I'll just point out that you should most likely not be writing your own math primitives. It's easy to get wrong, it takes time away from actually creating what you're trying to create, you'll tear your hair out fixing hard to spot bugs and your code (contrary to what most people who write their own math primitives seem ...


3

I see some things that I think could help you improve your code. Don't abuse using namespace std Putting using namespace std at the top of every program is a bad habit that you'd do well to avoid. Eliminate global variables where practical Having routines dependent on global variables makes it that much more difficult to understand the logic and ...


0

negative // and lower - upper = specified binwidth Wait a minute! Strike that, reverse it. Thank you. Also typo nit: "explaind" helper Please introduce a helper that maps from val to bin_id. I am skeptical that bin ids are compatible with edge counts currently, since binstart does not participate in computing a bin_id. This matters when binstart is not ...


5

General - it might be better to create a matrix class and your own vector class in a namespace. Allow The Tools to Help You Improve the Code There are compiler settings that can help you improve your code, these can be specific the the c++ compiler you are using or they can be common. A common c++ compiler switch is -Wall which indicates a errors and ...


5

Here are some suggestions. Non conformance Many of your functions are marked constexpr. This is non-conforming. Per [constexpr.functions]: This document explicitly requires that certain standard library functions are constexpr ([dcl.constexpr]). An implementation shall not declare any standard library function signature as constexpr except for ...


1

// buffer which should be faster than std::vector<uint8_t> when resizing a lot because it does not do byte initialization when resizing This comment line is really long. You should wrap the text so that there is no horizontal scrollbar anymore. class uint8_fast_buffer { public: uint8_fast_buffer(const size_t initial_size) Undeclared identifier ...


2

I prefer using the likely() macros over __builtin* directly.


1

Using this-> to refer to class members Ditch this. It's unnecessary unless you need to have to refer to inherited members or disambiguate any other variables or parameters.


1

First impressions: I like the comments that clearly specify preconditions and postconditions - very valuable in C! One thing that wasn't clear was the meaning of the return value from the insert/add/remove methods - is that the number of elements added/removed? It would be nice to have a list of all the functions at the top of the file (I was surprised to ...


8

- float float constants need the suffix f: static const float EXPANSION_POINT = 1.0f; if not, you're assigning a double constant implicitly converted to float. - functions that accept 0 parameters Functions that accept 0 parameters should always be defined as type foo(void) type foo() means different things depending on the context. It is different ...


3

static const int MIN_CAPACITY = 16; static const int GROWTH_FACTOR = 2; static const int SHRINK_FACTOR = 4; Global const variables automatically get internal linkage, thus making the statics redundant. Since you tagged your question c++11, the preferred way is to use constexpr variables: constexpr int MIN_CAPACITY = 16; constexpr int GROWTH_FACTOR = 2; ...


8

Several of the public member names differ needlessly from those of the standard containers. That can prevent use of this class in generic code. For instance, void push(int); int pop(); void prepend(int); bool isEmpty(); I would have expected: void push_back(int); void pop_back(); void push_front(int); bool empty() const; These ones, dealing with size ...


11

Your two constructors don't store a value into m_capacity, so if the initial capacity requested (passed in as a parameter) is larger than the default capacity you'll have things in an inconsistent state and likely run into problems later. Is there a reason you're not using std::make_unique<int[]>, instead of allocating memory with new and constructing ...


Top 50 recent answers are included