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.
In Chapter 19.8.4 of the book "C++ Templates - The Complete Guide - Second Edition", the authors show how one can determine if a type is a class type in compile-time:
In my TClass<T>::foo() function, I'd like to invoke a T instance if and only if T is a function type.