##Style and other issues
Equality comparisons with boolean constants are usually redundant:
if (sorted_distinct_numbers[i] == true)
can be simply if (sorted_distinct_numbers[i])
gen_random_range()
doesn't need an lvalue RndGen
, so we can simplify a lot:
template<typename T>
std::vector<T> gen_random_range(std::size_t count, T start, T end) {
std::vector<T> vec(count);
std::generate(vec.begin(), vec.end(), RndGen<T>{start, end});
std::sort(vec.begin(), vec.end());
return vec;
}
The RndGen
doesn't need to store a random device:
template<typename T>
class RndGen {
public:
RndGen(T start, T end)
: mersenne_engine{std::random_device{}()},
dist{start, end}
{
}
T operator()()
{
return dist(mersenne_engine);
}
private:
std::mt19937 mersenne_engine;
std::uniform_int_distribution<T> dist;
};
If we make reversed()
accept argument by value, that means we don't need to explicitly copy it:
template<typename T>
std::vector<T> reversed(std::vector<T> v) {
std::reverse(v.begin(), v.end());
return v;
}