03.12.2012 Views

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

7.6. BEST OF BOTH WORLDS 221<br />

7.6 Best of Both Worlds<br />

The object-oriented programming paradigm offers mechanisms to write libraries that are open<br />

<strong>for</strong> extension, but it tends to impose intrusive interface requirements on the types that will be<br />

supplied to the library. The generic programming paradigm has seen much success in <strong>C++</strong>,<br />

partly due to the fact that libraries remain open to extension without imposing the need to<br />

intrusively inherit from particular abstract base classes. However, the static polymorphism that<br />

is a staple of programming with templates and overloads in <strong>C++</strong>, limits generic programming<br />

applicability in application domains where more dynamic polymorphism is required.<br />

In combining elements of object-oriented programming with those of generic programming, we<br />

take generic programming as the starting point, retaining its central ideas. In particular, generic<br />

programming is built upon the notion of value types that are assignable, copy constructible,<br />

The behavior expected from value types reflects that of <strong>C++</strong> built-in types, like int, double,<br />

and so <strong>for</strong>th. This generally assumes that types encapsulate their memory and resource management<br />

into their constructors, copy-constructors, assignment operators, and destructors, so<br />

that objects can be copied, and passed as parameters by copy, etc., without worrying about<br />

references to their resources becoming aliased or becoming dangling. Value types simplify local<br />

reasoning about programs. Explicitly managing objects on the heap and using pass-by-reference<br />

as the parameter passing mode makes <strong>for</strong> complex object ownership management (and object<br />

lifetime management in languages that are not garbage collected). Instead, explicitly visible<br />

mechanisms thin wrapper types like reference wrapper in the (draft) <strong>C++</strong> standard library ae<br />

used when sharing is desired.<br />

.. more to come..<br />

7.6.1 Compile Time Container<br />

7.6.2 Meta-Functions<br />

7.6.3 Run-Time concepts

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!