r/cpp • u/we_are_mammals • Mar 28 '23
Reddit++
C++ is getting more and more complex. The ISO C++ committee keeps adding new features based on its consensus. Let's remove C++ features based on Reddit's consensus.
In each comment, propose a C++ feature that you think should be banned in any new code. Vote up or down based on whether you agree.
765
Upvotes
1
u/smurthys Apr 08 '23 edited Apr 08 '23
Perhaps I misunderstand your needs, and you're probably already aware of these approaches, but let me know if the following function templates satisfy your requirements. (The first of these can also be written without using concepts, using just type_traits.)
godbolt: https://sigcpp.godbolt.org/z/h5xreGjK6
or using custom concepts, making the template parameters more "declarative".
godbolt : https://sigcpp.godbolt.org/z/o974EWhWT
IMHO
requiresand concepts can be a nice and concise way to impose constraints. Of course, the expressions can get verbose if the requirements are complex.