diff --git a/slides/properties.md b/slides/properties.md index b21ab24587cc5b337d1e89a9c15a6fe3086166a7..bab6a8aed2b3cbd6e7da192995b0b043579c86c0 100644 --- a/slides/properties.md +++ b/slides/properties.md @@ -85,7 +85,8 @@ DGGO2 dggo2(gfs, cd, gfs, cf, lop, mbe); A usual way to group template parameters ```cpp -struct MyGridOperatorTraits{ +struct MyGridOperatorTraits +{ using FromGFS = ...; // ... }; @@ -110,7 +111,7 @@ struct MyDoubleTraits : public MyBaseTraits }; // this is a vector of ints! -typename MyDoubleTraits::vector v{1.14142, 1.73205}; +typename MyDoubleTraits::Vector v{1.14142, 1.73205}; ``` ## Type traits @@ -135,7 +136,19 @@ struct ValueType<Dune::FieldVector<T, size>> { using type = T; }; A usage example + +```cpp +// expecting Container to export value_type +template<typename Container> +void someFunction(const Container& c) { + using V = typename Container::value_type; + // do something with V + // ... +} +``` + ```cpp +// using type traits template<typename Container> void someFunction(const Container& c) { using V = typename ValueType<Container>::type; @@ -161,7 +174,7 @@ A simplified example to illustrate the idea ```cpp // myproperties.hh -namespace Properties { +namespace Dumux::Properties { namespace TTag { struct MyTypeTag {}; } // some property tag @@ -171,7 +184,7 @@ template<typename TypeTag> struct SomeTag; template<> struct SomeTag<MyTypeTag> { using type = /*the actual property*/; }; -} // namespace Properties +} // namespace Dumux::Properties ``` @@ -194,10 +207,10 @@ class GenericClass ## Property System Design -Issues with this simplified example -- Composition of __type tags__ via inheritance bears the same issue as in the previous example (with traits classes) -- We would like to define properties in base __type tags__ dependent on property definitions in derived ones +__Issue__: Inheritance not (easily) possible. All type traits need to be specialized for `MyTypeTag`. + +__Goal__: We would like __type tags__ to be composable via inheritance, while providing a mechanism for customizing any property defined in the hierarchy. ## Actual Design @@ -213,6 +226,7 @@ Issues with this simplified example Let's implement the `Vector` example using the property system ```cpp +namespace Properties { namespace TTag { struct BaseTag {}; } // specialization of the Scalar property for BaseTag @@ -221,11 +235,9 @@ struct Scalar<TypeTag, TTag::BaseTag> { using type = int; }; // specialization of the Vector property for BaseTag template<class TypeTag> -struct Vector<TypeTag, TTag::BaseTag> -{ - using type = std::vector< - GetPropType<TypeTag, Properties::Scalar> - >; +struct Vector<TypeTag, TTag::BaseTag> { + private: using Scalar = GetPropType<TypeTag, Properties::Scalar>; + public: using type = std::vector<Scalar>; }; ``` @@ -235,7 +247,10 @@ struct Vector<TypeTag, TTag::BaseTag> Let's implement the `Vector` example using the property system ```cpp +namespace Properties { +namespace TTag { struct DoubleTag { using InheritsFrom = std::tuple<BaseTag>; }; +} // namespace TTag // Specialization of the Scalar property for DoubleTag template<class TypeTag>