From 2ffc13e9c3a5c4b5671287951104f7fd9c0b6a9e Mon Sep 17 00:00:00 2001 From: Bernd Flemisch Date: Wed, 11 Mar 2020 13:17:08 +0100 Subject: [PATCH] [properties] splice mechanism almost working again --- opm/models/utils/propertysystem.hh | 132 ++++++++++++++++++----- opm/models/utils/propertysystemmacros.hh | 6 -- 2 files changed, 107 insertions(+), 31 deletions(-) diff --git a/opm/models/utils/propertysystem.hh b/opm/models/utils/propertysystem.hh index ea6febd0c..ec2a2cfd2 100644 --- a/opm/models/utils/propertysystem.hh +++ b/opm/models/utils/propertysystem.hh @@ -36,25 +36,12 @@ namespace Properties { //! a tag to mark properties as undefined struct UndefinedProperty {}; -template -struct SpatialDiscretizationSplice { using type = UndefinedProperty; }; - -namespace TTag { -struct MyTTag {}; -struct MySDTTag {}; -} - -template -struct SpatialDiscretizationSplice -{ using type = TTag::MySDTTag; }; - -template -struct VtkOutputFormat { using type = UndefinedProperty; }; - -template -struct VtkOutputFormat -{ static constexpr auto value = 2; }; - +template +struct Splices +{ + using tuple = std::tuple<>; +}; + //! implementation details for template meta programming namespace Detail { @@ -145,7 +132,97 @@ struct GetDefined> typename GetNextTypeTag, void>::type>; }; -//! helper struct to extract get the Property specilization given a TypeTag, asserts that the property is defined + +//! check if a splice S is defined +template +constexpr auto isDefinedSplice(int) +-> decltype(std::integral_constant>::value>{}) +{ return {}; } + +//! fall back if a splice is defined +template +constexpr std::true_type isDefinedSplice(...) { return {}; } + +template +struct GetSplicesTypeTags; + +template +struct GetNextSplicesTypeTag; + +template +struct GetNextSplicesTypeTag, std::enable_if_t(int{}), void>> +{ using tuple = typename GetSplicesTypeTags::tuple; }; + +template +struct GetNextSplicesTypeTag, std::enable_if_t(int{}), void>> +{ using tuple = std::tuple<>; }; + +template +struct GetNextSplicesTypeTag, std::enable_if_t(int{}), void>> +{ using tuple = typename GetSplicesTypeTags>>::tuple; }; + +template +struct GetNextSplicesTypeTag, std::enable_if_t(int{}), void>> +{ using tuple = typename GetSplicesTypeTags>::tuple; }; + +template +struct GetSplicesTypeTags> +{ + using LastSplices = Splices; + using nexttuple = typename GetNextSplicesTypeTag, void>::tuple; + // originally intended +// using tuple = std::conditional_t(int{}), +// typename ConCatTuples::tuple, +// nexttuple>; + using tuple = std::conditional_t(int{}), + typename LastSplices::tuple, + typename GetNextSplicesTypeTag, void>::tuple>; +}; + +template +struct GetSplicesTypeTags> +{ + using FirstSplices = Splices; + using nexttuple = typename GetNextSplicesTypeTag, void>::tuple; + // originally intended +// using tuple = std::conditional_t(int{}), +// typename ConCatTuples::tuple, +// nexttuple>; + using tuple = std::conditional_t(int{}), + typename FirstSplices::tuple, + typename GetNextSplicesTypeTag, void>::tuple>; +}; + +} // end namespace Detail + +template +struct SpatialDiscretizationSplice { using type = UndefinedProperty; }; + +namespace TTag { +struct MyTTag {}; +struct MySDTTag {}; +} + +template +struct SpatialDiscretizationSplice +{ using type = TTag::MySDTTag; }; + +template +struct VtkOutputFormat { using type = UndefinedProperty; }; + +template +struct VtkOutputFormat +{ static constexpr auto value = 2; }; + +namespace TTag { +struct FvBaseDiscretization; +struct VcfvDiscretization; +struct MultiPhaseBaseModel; +} + +namespace Detail { + + //! helper struct to extract get the Property specilization given a TypeTag, asserts that the property is defined template class Property> struct GetPropImpl { @@ -157,14 +234,19 @@ struct GetPropImpl using testtype2 = std::conditional_t(int{}), QType, UndefinedProperty>; static_assert(!std::is_same::value, "VtkOutputFormat is undefined in MySDTTag!"); -// using testtype = typename Detail::GetDefined -// >::type; + using RType = Properties::VtkOutputFormat; + using testtype3 = std::conditional_t(int{}), RType, UndefinedProperty>; + static_assert(!std::is_same::value, "VtkOutputFormat is undefined in FvBaseDiscretization!"); + // works: +// using type = typename Detail::GetDefined +// >::type; + using tuple = typename GetSplicesTypeTags>::tuple; using type = typename Detail::GetDefined + typename ConCatTuples, tuple>::type >::type; static_assert(!std::is_same::value, "Property is undefined!"); }; diff --git a/opm/models/utils/propertysystemmacros.hh b/opm/models/utils/propertysystemmacros.hh index 8eb628a16..f18e18285 100644 --- a/opm/models/utils/propertysystemmacros.hh +++ b/opm/models/utils/propertysystemmacros.hh @@ -345,12 +345,6 @@ struct GetTypeTagInheritance> typedef typename RevertedTupleOuter::template RevertedTupleInner::type type; }; -template -struct Splices -{ - using tuple = std::tuple<>; -}; - #define SET_SPLICES(TypeTagName, ...) \ template \ struct Splices \