Answers for "c++ calling variable constructor"

C++
0

c++ calling variable constructor

#include <type_traits>

template <class T, typename... Args>
void Reconstruct(T& x, Args&&... args)
{
    static_assert(!std::has_virtual_destructor<T>::value, "Unsafe"); 
    x.~T();
    new (&x) T(std::forward<Args>(args)...);
}
Posted by: Guest on March-11-2022

Browse Popular Code Answers by Language