Templates & STL Stefan Roiser, Lorenzo Moneta CERN PH/SFT.
-
Upload
luke-roberts -
Category
Documents
-
view
215 -
download
0
Transcript of Templates & STL Stefan Roiser, Lorenzo Moneta CERN PH/SFT.
![Page 1: Templates & STL Stefan Roiser, Lorenzo Moneta CERN PH/SFT.](https://reader036.fdocuments.in/reader036/viewer/2022082821/5697bf721a28abf838c7ec40/html5/thumbnails/1.jpg)
Templates & STL
Stefan Roiser, Lorenzo Moneta
CERN
PH/SFT
![Page 2: Templates & STL Stefan Roiser, Lorenzo Moneta CERN PH/SFT.](https://reader036.fdocuments.in/reader036/viewer/2022082821/5697bf721a28abf838c7ec40/html5/thumbnails/2.jpg)
Templates & STL 2
Current Usage
• Template types are highly used in HEP– Via STL– Libraries provided by external parties
• E.g. Boost
– Libraries provided by CERN developers• E.g. SMatrix, a library for linear algebra
– Uses expression templates
2009-09-03
![Page 3: Templates & STL Stefan Roiser, Lorenzo Moneta CERN PH/SFT.](https://reader036.fdocuments.in/reader036/viewer/2022082821/5697bf721a28abf838c7ec40/html5/thumbnails/3.jpg)
Templates & STL 3
Symbols
Generic vector<T*> ?
• Problems– Length of symbols
• Source code typetypedef std::map<std::string, std::pair<int,int> > MyMap;
• Mangled symbol (constructor)
__ZNSt3mapISsSt4pairIiiESt4lessISsESaIS0_IKSsS1_EEEC1Ev• Demangled symbol
std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<int, int>, std::less<std::basic_string<char, std::char_traits<char>, std:: allocator<char> > >, std::allocator<std::pair<std::basic_string<char, std::char_ traits<char>, std::allocator<char> > const, std::pair<int, int> > > >::map()
– Number of symbols• Symbols for member functions of class<T> for every instantiation
• Results in – Code bloat
• Many of these symbols are not even used
– Increased library sizes and load time• E.g. literal type names are stored in reflection libraries
– Lengthy compiler error messages
2009-09-03
![Page 4: Templates & STL Stefan Roiser, Lorenzo Moneta CERN PH/SFT.](https://reader036.fdocuments.in/reader036/viewer/2022082821/5697bf721a28abf838c7ec40/html5/thumbnails/4.jpg)
Templates & STL 4
Concepts
• Narrowing template types a la “concepts”ROOT::Math::LorentzVector<CoordSystem<T> >
float or double
Must provide functions x(), y(), z()
• Currently a wrong instantiation producesLorentzVector.h: In member function 'typename CoordSystem::Scalar LorentzVector<CoordSystem>::x() const [with CoordSystem = Foo]':testMessage.cxx:13: instantiated from here LorentzVector.h:616: error: 'const struct Foo' has no member named 'Px'
2009-09-03
![Page 5: Templates & STL Stefan Roiser, Lorenzo Moneta CERN PH/SFT.](https://reader036.fdocuments.in/reader036/viewer/2022082821/5697bf721a28abf838c7ec40/html5/thumbnails/5.jpg)
Templates & STL 5
Other Issues
• Thread safety for STL?– E.g. “Intel Threading Building Blocks”
• Provides implementations for hash_map, queue, vector
• Enhancements for iterator programming– Simplifications for the coding itself
• E.g. using lambda functions
2009-09-03