
Niels Dekker - mail address until 2008-12-31 wrote:
Michael Marcin wrote:
I think the only real way to get it right in every case is to have the author of the type specify the proper traits.
Okay, I give up. A generic way to tweak MSVC's "Swaptimization" just doesn't seem feasable without adding a /lot/ of template specializations.
See also the reply by Stephan T. Lavavej on my questions at http://blogs.msdn.com/vcblog/archive/2008/08/11/tr1-fixes-in-vc9-sp1.aspx
So any type for which default-construction + swap outperforms copy-construction should preferably have "Swaptimization" enabled. Let's call such a type "Swaptimizable". So should we add a specialization of std::_Move_operation_category to each Boost HPP file that defines a "Swaptimizable" type? Or would it be preferable to have a single header file, containing std::_Move_operation_category specializations of for all "Swaptimizable" Boost types?
Note that for some templates whether an instantiation is "Swaptimizable" depends upon its template argument. For example, "Swaptimization" should be applied to boost::array<std::string>, but not to boost::array<int>.
I think that each library including the proper specializations makes the most sense and supports the weakest coupling. Some utility, maybe in config, should probably be created so that libraries can easily enable these swaptimzations for their types. If it is not easy and clean people won't do it and that would be a shame because the VC team has provided us with a customization point to easily achieve some large performance gains.