18 votes
Accepted

Min function accepting varying number of arguments in C++17

template <typename Less, typename T, typename... Ts> constexpr const T& min(Less less, const T& a, const T& b, const Ts&... rems) { This ...
Snowhawk's user avatar
  • 6,148
13 votes
Accepted

Implementation of std::any

Your implementation is excellent! I can hardly find any problems. I was amazed how simple a conforming implementation of any can be. And I wholeheartedly agree with ...
L. F.'s user avatar
  • 9,456
12 votes

Min function accepting varying number of arguments in C++17

This looks nice! Two issues I see here, When compiling your template with clang, it refuses the if constexpr dispatch for every ...
lubgr's user avatar
  • 956
11 votes
Accepted

Filtering variadic template arguments

One reason you think you require a lot of helper metafunctions is that you haven't clearly separated the code for solving the problem (filtering a list) from the code for testing the solution (e.g. <...
Quuxplusone's user avatar
  • 19.3k
11 votes

Fixed array with configurable bounds

Write Less Code The main problem I see with this solution is that you're writing so much more code than you need to to accomplish the task at hand. First of all, your copy constructor is broken ...
Barry's user avatar
  • 18.4k
11 votes
Accepted

Fixed array with configurable bounds

It looks pretty clean to me. The copy constructor doesn't have to be explicitly declared, you could = default it or just omit. You shouldn't ...
glampert's user avatar
  • 17.1k
11 votes
Accepted

C++17 : Typelist manipulation

Overall, your code looks very good. No need to overload for empty template parameter packs A typename... parameter pack also matches zero elements, so the following ...
G. Sliepen's user avatar
  • 50.4k
10 votes

The real std::apply

I think there are two flaws with this function; the first is in conception, and the second is in implementation. The conception problem is this: What does ...
ruds's user avatar
  • 3,271
10 votes

FlagSet with C++ templates

IndexOf can probably be a nested type of FlagSet, unless you intend for that to be part of the public interface. ...
indi's user avatar
  • 10.2k
9 votes

Min function accepting varying number of arguments in C++17

It works well, according to my simple test program: #include <functional> int main() { return min(std::less<int>(), 2, 0, 3); } I suggest that when ...
Toby Speight's user avatar
8 votes
Accepted

Concatenate two containers, e.g. vector or strings

Your current strategy will cause more reallocations than you need to, which is not efficient. You already have all of your vector parameters, so you simply need to get their size, and reserve that ...
user2296177's user avatar
  • 3,533
8 votes
Accepted

Partial application in C++

Looks like you are trying to re-invent std::bind. ...
Martin York's user avatar
  • 94.3k
8 votes
Accepted

`printf` improvement with C++ variadic templates

General design Currently, your function is defined to have "undefined behavior" if the number of arguments is wrong. This is sub-optimal. Checking is trivial in this case, so report the problem in ...
L. F.'s user avatar
  • 9,456
8 votes

c++17 compatible std::bind_front alternative

Are there some cases in std::bind_front that I missed? There are several significant differences between std::bind_front's ...
Barry's user avatar
  • 18.4k
8 votes
Accepted

How to simplify this C++ CRTP example?

Avoid special cases A lot of problems come from the fact that you have slightly different ways to construct a 2D point and to get its elements than you have for an arbitrary dimensional point. You ...
G. Sliepen's user avatar
  • 50.4k
8 votes
Accepted

Generic test case templates

C++ 17 Why limit yourself to C functions? DynamicTest(OutputType (*testfunc)(InputType), OutputType (*trustedfunc)(InputType)) I would declare this as: ...
Martin York's user avatar
  • 94.3k
8 votes
Accepted

De-/Serialization of structs representing TCP messages

Your code produces no memory leaks since you're not manually allocating and deleting memory. Include all headers Always include all the headers. In this case, you need ...
Rish's user avatar
  • 1,751
7 votes

Template integer range, version 2

My main objection to your code is: Principle of Least Surprise I was pretty surprised that: make_index_range<15u, 0u, 3u> is the sequence ...
Barry's user avatar
  • 18.4k
7 votes
Accepted

Generic matrix type in C++

Use one vector instead of two vectors You can improve performance by using one vector instead of two vectors; you can calculate the 2nd dimension using a little math. This is actually how primitive ...
user2296177's user avatar
  • 3,533
7 votes

The perfect function alias

Is there a situation where the compiler will not optimize away the wrapper because the wrapper and the original function have different semantics? Yes to the first part and no to the second. Any ...
Rakete1111's user avatar
  • 2,562
7 votes
Accepted

Meta functions for sequences of exponents of 2

Certainly your definitions of printing_type and print could be shortened. You're currently doing ...
Quuxplusone's user avatar
  • 19.3k
7 votes

De-/Serialization of structs representing TCP messages

Here are some things that may help you improve your program. Use all required #includes Part of the interface is the #include ...
Edward's user avatar
  • 65.3k
7 votes
Accepted

Object to ignore unused function output parameters

What's wrong with just writing: int main() { X ignore; foo(ignore); return 0; } What benefit is gained by adding a wrapper around the unused argument? ...
JDługosz's user avatar
  • 11.3k
6 votes
Accepted

C++ template Partial Specialization Member Function; Am I doing right?

What you've written does work, and you seem to understand all the concepts (e.g., "you can't partially specialize function templates"), and your coding style (indentation and whatnot) seems fine. ...
Quuxplusone's user avatar
  • 19.3k
6 votes
Accepted

Typelist with extractor

Naming Templates depend on a consistent naming scheme for static polymorphism. We can observe such consistent naming throughout the type traits offered by the standard library (from ...
user2296177's user avatar
  • 3,533
6 votes

Selection sorting a type list (compile-time)

I recommend a naming style that uses CamelCase for template parameters and snake_case (only) for plain old variables and ...
Quuxplusone's user avatar
  • 19.3k
6 votes
Accepted

Selecting function overload based on a type match with return value of passed callable

Higher level overview: Personally I think the architecture has limited use cases. It was quite hard to implement, and even then doesn't match the specification. From what I understood, this is the ...
Incomputable's user avatar
  • 9,374
6 votes
Accepted

Set an order or precedence when calling functions that may or may not exist

Not a full review, just an answer on the SFINAE-mechanisms part: I'd say that your method is perfectly idiomatic. I recommend an approach exactly isomorphic to yours, based on some code I originally ...
Quuxplusone's user avatar
  • 19.3k
6 votes
Accepted

Event handling attempt using some of the c++ 17 features

I'm actually not the right person to properly review your code, since event handling is outside my particular experience, so the overall idea of even having this kind of observer-handler-emitter ...
einpoklum's user avatar
  • 1,995

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