Skip to content
Snippets Groups Projects
Commit af0ccf0e authored by Dennis Gläser's avatar Dennis Gläser
Browse files

Merge branch 'cleanup/property-slides-minor-fixes' into 'master'

[slides][props] minor improvements

See merge request !159
parents 250cab51 ff12c9b5
No related branches found
No related tags found
1 merge request!159[slides][props] minor improvements
Pipeline #30349 passed
slides/img/template_example.png

187 KiB

......@@ -40,6 +40,13 @@ class vector;
std::vector<int> v;
```
## Template parameters
An example - `std::vector`
<img src="./img/template_example.png" width="800"/>
## Template specializations
Template implementations can be specialized for concrete types
......@@ -52,7 +59,7 @@ class MyVector
};
template<>
class MyClass<int>
class MyVector<int>
{
// specialized implementation for `int`
};
......@@ -111,7 +118,7 @@ typename MyDoubleTraits::vector v{1.14142, 1.73205};
Based on template specialization
```cpp
// Trait class template declaration
// Type trait template declaration
template<typename T> struct ValueType;
// Specialization for vectors of T
......@@ -143,7 +150,7 @@ void someFunction(const Container& c) {
- Based on __C++ template specialization__ (_type traits_)
- From a __type tag__, one can extract __properties__ defined for it
- A __property tag__ is a trait class definition (or default implementation)
- A __property tag__ is a type trait declaration (or default implementation)
- A __property__ is exported from a __property tag__ specialization for a __type tag__
- (The property system also supports definitions of traits classes - see later)
......@@ -154,9 +161,8 @@ A simplified example to illustrate the idea
```cpp
// myproperties.hh
namespace TTag { struct MyTypeTag {}; }
namespace Properties {
namespace TTag { struct MyTypeTag {}; }
// some property tag
template<typename TypeTag> struct SomeTag;
......@@ -165,7 +171,6 @@ template<typename TypeTag> struct SomeTag;
template<>
struct SomeTag<MyTypeTag>
{ using type = /*the actual property*/; };
} // namespace Properties
```
......@@ -208,7 +213,7 @@ Issues with this simplified example
Let's implement the `Vector` example using the property system
```cpp
namespace TTag { struct BaseTag; }
namespace TTag { struct BaseTag {}; }
// specialization of the Scalar property for BaseTag
template<class TypeTag>
......@@ -274,7 +279,6 @@ class InjectionProblemTwoP
using VolumeVariables = GetPropType<
TypeTag, Properties::VolumeVariables
>;
constexpr auto useIFS = getPropValue<
TypeTag, Properties::EnableBoxInterfaceSolver
>();
......@@ -303,7 +307,7 @@ Creating new <span style="color:blue">TypeTag</span> nodes
```cpp
namespace Dumux::Properties::TTag {
struct MyTypeTag;
struct MyTypeTag {};
struct MyOtherTypeTag
{ using InheritsFrom = std::tuple<MyTypeTag>; }
......@@ -344,7 +348,7 @@ namespace Properties::TTag {
struct MyTypeTag {
...
template<class TypeTag>
using Problem = Dumux::MyProblem<TypeTag>;
using Problem = Dumux::MyProblem<TypeTag>;
...
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment