
Noah Stein wrote:
Your Create() function in AllocateUsingNew isn't guaranteed to work for all classes. The type of the singleton class might have alignment restrictions. char has no alignment restrictions; therefore, the program may crash when trying to initialize the singleton. I believe boost::aligned_storage is your friend in this situation.
I looked into aligned storage, and discovered that it is interwoven deep into boost, and includes many dependencies. Although I think it would be great if this library became a part of boost, I don't want to make it dependent upon becoming a part of boost just to solve the aligned storage issue. Perhaps I could add extension headers, which would contain the extra policies that require specific platforms or libraries. Then my singleton header would only include them if a corresponding tag (BOOST_AVAILABLE) has been defined or something of that nature. Of course, such action would be a last resort... if aligned_storage is a simple enough device, I would prefer to just inline it as an implementation detail of the static allocation policy. How dependent upon the compiler being used is the implementation of aligned_storage? Is implementing a bare-bones version myself feasible? -Jason