Skip to main content
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,770
15 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,715
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

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
  • 69.5k
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
  • 16.6k
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
  • 88.7k
8 votes
Accepted

Partial application in C++

Looks like you are trying to re-invent std::bind. ...
Loki Astari's user avatar
  • 97.7k
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,715
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.6k
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
  • 69.5k
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: ...
Loki Astari's user avatar
  • 97.7k
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
  • 2,486
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,582
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.7k
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
  • 67.2k
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.7k
7 votes
Accepted

Member detection within a class

Pre C++20 concepts I know you are using C++20 (as everyone should; C++23 is the current version, and C++26 already has its first major features), but just for completeness I thought I’d give a pre-C++...
indi's user avatar
  • 16.6k
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.7k
6 votes
Accepted

Generic implementation of an array view

Constructors The second constructor: ...
Loki Astari's user avatar
  • 97.7k
6 votes
Accepted

An overloaded random number function template using modern C++

The constructor of uniform_int_distribution has default arguments: ...
Toby Speight's user avatar
  • 88.7k
6 votes
Accepted

Transaction manager, supporting undo/redo, using C++ templates

If you want to implement the command manager pattern, you can do something so very much simpler that I don't really understand what you're aiming for. As you know, the design pattern has a ...
papagaga's user avatar
  • 5,817
6 votes
Accepted

Finding the common iterator category in C++

If you have a typelist of iterator tag types, then std::common_type will find the common base type. ...
Snowhawk's user avatar
  • 6,770
6 votes
Accepted

C++17 <span> implementation

Well, it looks quite nice. But now let's try to find all the corners which can still be improved: I'm not quite sure why you list a few members of each include you added. But, at least it simplifies ...
Deduplicator's user avatar
  • 19.9k
6 votes
Accepted

Implementing apply_each for tuple c++

I see two main issues with the design. That you need to use std::ref to operate on the tuples themselves and not their copies. This isn't good. It is used this way ...
ALX23z's user avatar
  • 2,539
6 votes
Accepted

Function composition in the context of data processing pipelines

Issues: There's a technical issue in the implementation is the design of the type trait InvokeResult. The problem lies in the usage of ...
ALX23z's user avatar
  • 2,539
6 votes

A generic function that reads a line of numeric values from a file

Naming things I would avoid using exactly the same name as the function from the standard library. Yours does a bit more. Maybe get_values_from_line() or ...
G. Sliepen's user avatar
  • 69.5k
5 votes
Accepted

Generic implementation of an HeapArray and StackArray

Personally I would implement those as this: ...
Incomputable's user avatar
  • 9,722
5 votes

Alternative to integer_sequence trick

Looks good to me! I mean, I'm not likely to convert to it because of its heavyweightness — you noted its use of std::apply, but it also pulls in all of ...
Quuxplusone's user avatar
  • 19.7k
5 votes

Compile-time Lagrange polynomials in C++

struct evaluate ⋯ Compile-time computation is much easier today using constexpr! Rather than going for a pre-2014 TMP library,...
JDługosz's user avatar
  • 11.7k

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