My question is this:
Suppose type T
is trivially copyable....can "create" an instance of this type without calling a constructor....like so:
#include <type_traits>
#include <cstring>
using T = int; // T can be any trivially copyable type
T create(const T& other)
{
std::aligned_storage_t<sizeof(T),alignof(T)> my_T;
std::memcpy(&my_T,&other,sizeof(T));
return *reinterpret_cast<T*>(&my_T);
}
Is this defined behavior, or can I only copy into an existing object of type T?