I would like to provide different implementations of a function dependant on if it is a pointer, a reference or a regular type. This is my code so far:
I have many EnableIf traits that basically check whether the input type satisfies an interface. I was trying to create a generic Resolve trait that can be used to transform those into a boolean trait.
https://www.godbolt.org/z/_4aqsF:gcc, clang and msvc apparently agree that this cannot compile because find_if would return an array.
Let's say I have defined a zero_initialize() function:Calling zero_initialize() for some types would lead to undefined behavior1, 2. I'm currently enforcing T to verify std::is_pod. With that trait being deprecated in C++20 and the coming of concepts, I'm curious how zero_initialize() should evolve.
For performance reasons, I'm using a templated class with an enum instead of relay on inheritance (It is not an option).
I have a Container class that holds objects whose type may be derived from any combination of some base classes (TypeA, TypeB, etc.). The base class of Container has virtual methods that return a pointer to the contained object; these should return nullptr if the contained object isn't derived from...
I was playing around with this answer to investigate how it handles functions with default parameters. To my surprise, the results are different for free functions and operator():
I would like to detect if a class has member variables and fail a static assert if they do. Something like:
Suppose we have some SFINAE member function:If we declared it as above, then how can we define them? Both of their function signatures would look like:
I have just discovered the following technique. It looks very close to one of proposed concepts syntax, works perfectly on Clang, GCC and MSVC.