1074 | | |
| 1074 | As mentioned earlier, the libraries reviewed overwhelmingly chose to use STL11 over any equivalent Boost libraries, so `std::thread` instead of `boost::thread`, `std::shared_ptr` over `boost::shared_ptr` and so on. This makes sense right now as STL11 and Boost are still fairly close, however in the medium term there will be significant divergence between Boost and the STL as Boost "gets ahead" of the STL in terms of features. Indeed, one may find oneself needing to "swap in" Boost to test one's code with some future STL pattern not yet standardised. |
| 1075 | |
| 1076 | Let me put this another way: imagine a near future where Boost.Thread has been rewritten atop of the STL11 enhancing the STL11 threading facilities very substantially indeed with features which may not enter the standard until the 2020s. If your library is bound to only use the STL, you may lose out on substantial performance or feature improvements. Your users may clamour to be able to use Boost.Thread with your library. You will then have to duplicate an additional code path for Boost.Thread which replicates the STL11 threading path. But you still may not be done - what if Boost.Chrono also adds significant new features? Or Boost.Regex? Or any of the Boost libraries now standardised into the STL? |
| 1077 | |
| 1078 | Sometimes multiple code paths are unavoidable, specifically when you make use of Boost enhancements over the STL. However a large amount of the time one can treat the STL11 and the Boost implementation as being ''substitutable'' for one another, so now all you need is a method for your library's users to: |
| 1079 | |
| 1080 | 1. ''Dependency inject'' whether your library is to use a Boost implementation or the STL11 implementation for all those STL library facilities which also have equivalents in Boost. For reference, the substitutable implementations are the following STL headers: |
| 1081 | |
| 1082 | `array, atomic, chrono, condition_variable, functional, future, mutex, random, ratio, regex, system_error, thread, tuple, type_traits, typeindex` |
| 1083 | |
| 1084 | 2. Enable your library when configured with (for example) Boost.Thread to coexist with your library when configured with STL11 thread in the same executable. |
| 1085 | |
| 1086 | 3. Ideally enable your library when configured with Boost.Thread to coexist with your library when configured with STL11 thread in the same translation unit (i.e. header only library A can include your header only library configured one way, and header only library B can include your library configured the other way). |
| 1087 | |
| 1088 | TODO |