8

Usage of "fat" templates I would try to avoid using full-blown class templates when there's an elegant alternative solution with alias templates or constexpr functions. Note that I didn't measure this, so take it with a grain of salt: lightweight constexpr functions and alias template can be faster to instantiate. Using constexpr functions might reduce the ...


3

I've also been messing around with making everything constexpr, then using static_asserts in addition to regular unit tests to find problems before even running the tests. I haven't really gone as deep into it as you have, though. I'm going to focus specifically on the elements you say you're struggling with. The problem with needing exceptions What you ...


3

You actually hint at the primary concern with your note about std::make_tuple(), std::tuple_cat() and gradually building up the result. The point is that you have much copying with a plethora of temporaries going on. Also, quite a bit of recursion. Use index_sequences, the power of template parameter pack expansion, and forwarding using std::...


2

You have to compare values char by char, or even simpler change const char* to std::string_view make your code work. Thanks to the deduction guides, you can just write std::array = ... and template parameters will be automatically deduced. Also, you can simplify your loop using a "range-based for". If we generalize for other types of compile-time array, ...


2

What I thought is I could call an overloaded function from Callable::Invoke, which resolves to the correct implementation. I would overload a private Callable::Invoke__ function, and use SFINAE or enable_if to choose at compile time. But since my functions would have the same signature, the compiler complains that one of them cannot be overloaded. It's ...


2

The biggest readability concern, in my opinion, is squashing everything on one line. Compare: int main () { for (std::size_t i = 0; i < 6; ++i) { std::cout << flatArray[i] << " "; } std::cout << std::endl; } to int main() { for (std::size_t i = 0; i < 6; ++i) { std::cout << flatArray[i] << " "; } ...


2

After some searching I found that my ring buffer is broken if its capacity isn't power of 2, because once the counter reaches its maximum (on 64-bit : 2^64 - 1) it will begin from zero the next increment so if the modulus of the counter by n isn't n-1 when it reaches the maximum unsigned integer of the architecture then the counter will misbehave because at ...


1

Given that the result can be computed as simply as this: #include <array> template <std::size_t MN> constexpr int maximum_sum(std::array<int, MN> array, int M, int N, int current_row, int skip) { int max = 0; for (int x = 0; x < N; ++x) { if (x == skip) continue; int value = array[current_row * N + x]; ...


Only top voted, non community-wiki answers of a minimum length are eligible