「MaxAlign トリック」と呼ばれるものを示すLoki シングルトン実装のコード スニペットに従います。私はそれがアラインメントと関係があると思いますが(当たり前!)、ユニオン内で言及されているすべてのタイプとアラインしようとする目的は何ですか? それがないと中の新しい配置はCreate()壊れますか?
template <class T> struct CreateStatic
{
union MaxAlign
{
char t_[sizeof(T)];
short int shortInt_;
int int_;
long int longInt_;
float float_;
double double_;
long double longDouble_;
struct Test;
int Test::* pMember_;
int (Test::*pMemberFn_)(int);
};
static T* Create()
{
static MaxAlign staticMemory_;
return new(&staticMemory_) T;
}
// other code...
}