New answers tagged

1

It's a neat piece of engineering but it's not that much different from a std::vector of unique_ptrs to the base class. The following accomplishes the same thing with a tad more typing. std::vector<std::unique_ptr<base>> pv; pv.push_back(std::make_unique<derived_a>(derived_a{ "abc" })); pv.push_back(std::make_unique<derived_b>(...


9

Names All-caps names are typically reserved for macros. They don't seem to me to make much sense for const variables. In fact, they only make minimal sense for object-like macros--they were originally used for function-like macros as kind of a warning that you should be cautious about passing an argument with side-effects, because they might happen more ...


1

One idea for simplification is to count frequencies directly instead of putting all the values in an array that you only use for counting frequencies. You can then remove the getFrequencyCounts function and the whole thing gets a little more efficient. This works well when you have a set of values in a dense range like [80,85]. If you have a lot of values ...


4

If you go for modern C++ the static variables should be marked as constexpr instead of plain old const. As was said in the other question, it should be beneficial to create an array of length MAXLEGALVALUE - MINLEGALVALUE and directly index into that array. That way there is probably less memory consumed and we count automatically. Personally I would use ...


2

Here are some suggestions. __DYNAMICS_H__ is a reserved identifier because it contains consecutive underscores. Use a non-reserved identifier like DYNAMICS_H_. Also, this name is too common and may introduce name clashes. One solution is to append a sequence of random characters. I see no reason to make Clonables a friend of Clonable. The latter doesn't ...


Top 50 recent answers are included