diff --git a/slides/img/template_example.png b/slides/img/template_example.png new file mode 100644 index 0000000000000000000000000000000000000000..391154d66a485fc21856642e1712f8f2db8316fd Binary files /dev/null and b/slides/img/template_example.png differ diff --git a/slides/properties.md b/slides/properties.md index 471c040d50ecf2b74cf37f97aff6147c7bba2a55..b21ab24587cc5b337d1e89a9c15a6fe3086166a7 100644 --- a/slides/properties.md +++ b/slides/properties.md @@ -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>; ... };