[dune-functions] [Dune-functions-commit] [Commit] dune-functions - 3979792: Add helper to directly access the type of nested children
Steffen Müthing
steffen.muething at iwr.uni-heidelberg.de
Thu Sep 10 14:56:58 CEST 2015
Hi,
> Am 10.09.2015 um 00:01 schrieb Carsten Gräser <graeser at mi.fu-Berlin.de>:
>
> Am 09.09.2015 um 23:32 schrieb Christian Engwer:
>> shouldn't parts of these changes go to typetree?
> Yes, of course. This is true for most stuff in this header, but:
>
> a) I'm not sure, if I have write access.
> b) I'd like to discuss this with Steffen before.
sorry for replying a little late…
> c) I can imagine that typetree already contains such functionality
> and I just don't know where to find and how to use it.
>
There is already something like ChildType in typetree, but its interface is a little less pretty. I finished
implementing the nice child(node,_1,3,_4,…) syntax yesterday (adding the SFINAE safeguards tripled
the size of the implementation), and that turns ChildType into a simple template alias to a decltype. I’ll
put that into typetree and push it as soon as I’ve written the documentation.
I had to discover that while I implemented a hybrid TreePath, it was never used and thus kind of ugly.
I’ll clean that up and put it into the implementation of dune-functions.
@Carsten: My implementation is basically built around a std::tuple as well, I just don’t use std::integral_constant
directly, but an inherited type fixed_index. Those types are also used for the fixed indices in the child method
(_1,_2), and when overloading those things, it’s just clearer to write fixed_index<i> instead of integral_constant<std::size_t,i>.
The Path itself also inherits from std::tuple, again mostly because it is clearer for anyone who has to read the code.
There is also a function in TypeTree that takes a TreePath and gets the corresponding child (but I’ll make that
forward to the new child method…).
Steffen
> The latter also applies to the hybrid index stuff. In fact
> treepath.hh looks really scary to me. So I quickly stopped
> trying to understand it and cooked up the std::tuple solution.
> For me this seems to do all that's needed in a very simple
> and intuitive way, but -> b).
>
> Best,
> Carsten
>
>
>>
>> Christian
>>
>> On Wed, Sep 09, 2015 at 11:28:30PM +0200, Carsten Gräser wrote:
>>> New commit, appeared at Wed Sep 9 23:28:30 2015 +0200
>>> as part of the following ref changes:
>>>
>>> branch refs/heads/master updated from 3c6f97c -> 4d7b5b3
>>>
>>> Browsable version: http://cgit.dune-project.org/repositories/dune-functions/commit/?id=3979792d3142a7e4301cf4a8a870efaad82d3972
>>>
>>> ======================================================================
>>>
>>> commit 3979792d3142a7e4301cf4a8a870efaad82d3972
>>> Author: Carsten Gräser <graeser at mi.fu-berlin.de>
>>> Date: Wed Sep 9 23:24:05 2015 +0200
>>>
>>> Add helper to directly access the type of nested children
>>>
>>> To get the type of the child with relative tree path (3,7,1)
>>> you can now use ChildType<Node, 3, 7, 1>
>>>
>>> dune/functions/functionspacebases/tupletreepath.hh | 25 ++++++++++++++++++++++
>>> 1 file changed, 25 insertions(+)
>>>
>>>
>>>
>>> diff --git a/dune/functions/functionspacebases/tupletreepath.hh b/dune/functions/functionspacebases/tupletreepath.hh
>>> index e4f6bc8..7504caf 100644
>>> --- a/dune/functions/functionspacebases/tupletreepath.hh
>>> +++ b/dune/functions/functionspacebases/tupletreepath.hh
>>> @@ -196,6 +196,31 @@ auto getChild(Tree&& tree, const std::tuple<I...>& tp)
>>>
>>>
>>>
>>> +namespace Imp {
>>> +
>>> +template<class Node, int... Path>
>>> +struct ChildTypeHelper{};
>>> +
>>> +template<class Node, int FirstChild, int... Path>
>>> +struct ChildTypeHelper<Node, FirstChild, Path...>
>>> +{
>>> + using Type = typename ChildTypeHelper<typename Node::template Child<FirstChild>::Type, Path...>::Type;
>>> +};
>>> +
>>> +template<class Node>
>>> +struct ChildTypeHelper<Node>
>>> +{
>>> + using Type = Node;
>>> +};
>>> +
>>> +
>>> +}
>>> +
>>> +// Simplify access to type of child
>>> +template<class Node, int... Path>
>>> +using ChildType = typename Imp::ChildTypeHelper<Node, Path...>::Type;
>>> +
>>> +
>>> } // namespace Functions
>>> } // namespace Dune
>
> _______________________________________________
> dune-functions mailing list
> dune-functions at dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune-functions
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 455 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <https://lists.dune-project.org/pipermail/dune-functions/attachments/20150910/de50e694/attachment.sig>
More information about the dune-functions
mailing list