Commit 69efea94 authored by Simon Praetorius's avatar Simon Praetorius

removed free function childStorage() and type aliases ChildStorage and...

removed free function childStorage() and type aliases ChildStorage and ConstChildStorage from node implementations
parent 9c273f9c
Pipeline #26136 passed with stage
in 2 minutes and 51 seconds
......@@ -31,25 +31,12 @@ namespace Dune {
// end of the recursion, there are no child indices, so just return the node itself
// ********************************************************************************
struct IsPointerLike {
template <class Node>
auto require(const Node& node) -> decltype(*node);
};
template<typename Node>
auto child(Node&& node) -> decltype(std::forward<Node>(node))
{
return std::forward<Node>(node);
}
// for now, this wants the passed-in object to be pointer-like. I don't know how clever
// that is in the long run, though.
template<typename Node, typename std::enable_if_t<Dune::models<IsPointerLike,Node>(),int> = 0>
auto childStorage(Node&& node)
{
return std::forward<Node>(node);
}
// ********************************************************************************
// next index is a compile-time constant
// ********************************************************************************
......@@ -74,15 +61,6 @@ namespace Dune {
return child(std::forward<Node>(node).template child<i>(),j...);
}
template<typename Node, std::size_t i, typename... J,
typename std::enable_if<
Dune::models<HasTemplateChildMethod, decltype(*std::declval<std::decay_t<Node>>())>() &&
(i < StaticDegree<decltype(*std::declval<Node>())>::value), int>::type = 0>
decltype(auto) childStorage(Node&& node, index_constant<i>, J... j)
{
return childStorage(std::forward<Node>(node)->template childStorage<i>(),j...);
}
// This overload is only present to give useful compiler
// error messages via static_assert in case the other overloads
// fail.
......@@ -119,34 +97,12 @@ namespace Dune {
return child(std::forward<Node>(node).child(i),j...);
}
template<typename Node, typename... J>
decltype(auto)
childStorage(
Node&& node,
std::enable_if_t<
std::is_convertible<
NodeTag<decltype(*std::declval<Node>())>,
PowerNodeTag
>{},
std::size_t> i,
J... j
)
{
return childStorage(std::forward<Node>(node)->childStorage(i),j...);
}
template<typename Node, typename... Indices, std::size_t... i>
decltype(auto) child(Node&& node, HybridTreePath<Indices...> tp, std::index_sequence<i...>)
{
return child(std::forward<Node>(node),treePathEntry<i>(tp)...);
}
template<typename Node, typename... Indices, std::size_t... i>
decltype(auto) childStorage(Node&& node, HybridTreePath<Indices...> tp, std::index_sequence<i...>)
{
return childStorage(std::forward<Node>(node),treePathEntry<i>(tp)...);
}
} // namespace imp
#endif // DOXYGEN
......@@ -184,17 +140,6 @@ namespace Dune {
return impl::child(std::forward<Node>(node),indices...);
}
template<typename Node, typename... Indices>
#ifdef DOXYGEN
ImplementationDefined childStorage(Node&& node, Indices... indices)
#else
auto childStorage(Node&& node, Indices... indices)
#endif
{
//static_assert(sizeof...(Indices) > 0, "childStorage() cannot be called with an empty list of child indices");
return impl::childStorage(&node,indices...);
}
//! Extracts the child of a node given by a static TreePath object.
/**
* Use this function to extract a (possibly indirect) child of a TypeTree node.
......@@ -224,17 +169,6 @@ namespace Dune {
return child(std::forward<Node>(node),index_constant<Indices>{}...);
}
template<typename Node, std::size_t... Indices>
#ifdef DOXYGEN
ImplementationDefined childStorage(Node&& node, TreePath<Indices...> treePath)
#else
auto childStorage(Node&& node, TreePath<Indices...>)
#endif
{
static_assert(sizeof...(Indices) > 0, "childStorage() cannot be called with an empty TreePath");
return impl::childStorage(&node,index_constant<Indices>{}...);
}
//! Extracts the child of a node given by a HybridTreePath object.
/**
* Use this function to extract a (possibly indirect) child of a TypeTree node.
......@@ -269,17 +203,6 @@ namespace Dune {
return impl::child(std::forward<Node>(node),tp,std::index_sequence_for<Indices...>{});
}
template<typename Node, typename... Indices>
#ifdef DOXYGEN
ImplementationDefined child(Node&& node, HybridTreePath<Indices...> treePath)
#else
auto childStorage(Node&& node, HybridTreePath<Indices...> tp)
#endif
{
static_assert(sizeof...(Indices) > 0, "childStorage() cannot be called with an empty TreePath");
return impl::childStorage(&node,tp,std::index_sequence_for<Indices...>{});
}
#ifndef DOXYGEN
......
......@@ -63,12 +63,6 @@ namespace Dune {
//! The type of the child.
typedef typename std::tuple_element<k,ChildTypes>::type type;
//! The storage type of the child.
typedef typename std::tuple_element<k,NodeStorage>::type Storage;
//! The const storage type of the child.
typedef std::shared_ptr<const typename std::tuple_element<k,ChildTypes>::type> ConstStorage;
};
//! @name Child Access
......@@ -79,7 +73,7 @@ namespace Dune {
* \returns a reference to the i-th child.
*/
template<std::size_t k>
typename Child<k>::Type& child(index_constant<k> = {})
auto& child (index_constant<k> = {})
{
return *std::get<k>(_children);
}
......@@ -89,7 +83,7 @@ namespace Dune {
* \returns a const reference to the i-th child.
*/
template<std::size_t k>
const typename Child<k>::Type& child(index_constant<k> = {}) const
const auto& child (index_constant<k> = {}) const
{
return *std::get<k>(_children);
}
......@@ -99,7 +93,7 @@ namespace Dune {
* \returns a copy of the object storing the i-th child.
*/
template<std::size_t k>
typename Child<k>::Storage childStorage(index_constant<k> = {})
auto childStorage (index_constant<k> = {})
{
return std::get<k>(_children);
}
......@@ -112,33 +106,33 @@ namespace Dune {
* \returns a copy of the object storing the i-th child.
*/
template<std::size_t k>
typename Child<k>::ConstStorage childStorage(index_constant<k> = {}) const
auto childStorage (index_constant<k> = {}) const
{
return std::get<k>(_children);
}
//! Sets the i-th child to the passed-in value.
template<std::size_t k>
void setChild(typename Child<k>::Type& child, index_constant<k> = {})
void setChild (typename Child<k>::Type& child, index_constant<k> = {})
{
std::get<k>(_children) = stackobject_to_shared_ptr(child);
}
//! Store the passed value in k-th child.
template<std::size_t k>
void setChild(typename Child<k>::Type&& child, index_constant<k> = {})
void setChild (typename Child<k>::Type&& child, index_constant<k> = {})
{
std::get<k>(_children) = convert_arg(std::move(child));
}
//! Sets the storage of the i-th child to the passed-in value.
template<std::size_t k>
void setChild(typename Child<k>::Storage child, index_constant<k> = {})
void setChild (std::shared_ptr<typename Child<k>::Type> child, index_constant<k> = {})
{
std::get<k>(_children) = child;
std::get<k>(_children) = std::move(child);
}
const NodeStorage& nodeStorage() const
const NodeStorage& nodeStorage () const
{
return _children;
}
......@@ -176,7 +170,7 @@ namespace Dune {
#else
template<typename I0, typename... I,
std::enable_if_t<(sizeof...(I) > 0) || IsTreePath<I0>::value, int > = 0>
decltype(auto) child(I0 i0, I... i)
decltype(auto) child (I0 i0, I... i)
#endif
{
static_assert(sizeof...(I) > 0 || impl::_non_empty_tree_path(I0{}),
......@@ -196,7 +190,7 @@ namespace Dune {
#else
template<typename I0, typename... I,
std::enable_if_t<(sizeof...(I) > 0) || IsTreePath<I0>::value, int > = 0>
decltype(auto) child(I0 i0, I... i) const
decltype(auto) child (I0 i0, I... i) const
#endif
{
static_assert(sizeof...(I) > 0 || impl::_non_empty_tree_path(I0{}),
......@@ -225,17 +219,17 @@ namespace Dune {
//! Initialize all children with the passed-in objects.
template<typename... Args, typename = typename std::enable_if<(sizeof...(Args) == CHILDREN)>::type>
CompositeNode(Args&&... args)
CompositeNode (Args&&... args)
: _children(convert_arg(std::forward<Args>(args))...)
{}
//! Initialize the CompositeNode with copies of the passed in Storage objects.
CompositeNode(std::shared_ptr<Children>... children)
: _children(children...)
CompositeNode (std::shared_ptr<Children>... children)
: _children(std::move(children)...)
{}
//! Initialize the CompositeNode with a copy of the passed-in storage type.
CompositeNode(const NodeStorage& children)
CompositeNode (const NodeStorage& children)
: _children(children)
{}
......
......@@ -115,7 +115,7 @@ namespace Dune {
//! The number of children.
static const std::size_t CHILDREN = filter_result::size;
static constexpr std::size_t degree()
static constexpr std::size_t degree ()
{
return filter_result::size;
}
......@@ -137,12 +137,6 @@ namespace Dune {
//! The type of the child.
typedef typename OriginalChild::type type;
//! The storage type of the child.
typedef typename OriginalChild::Storage Storage;
//! The const storage type of the child.
typedef typename OriginalChild::ConstStorage ConstStorage;
};
//! @name Child Access
......@@ -152,9 +146,9 @@ namespace Dune {
/**
* \returns a reference to the i-th child.
*/
template<std::size_t k>
typename std::enable_if<lazy_enable<k>::value,typename Child<k>::Type&>::type
child(Dune::index_constant<k> = {})
template<std::size_t k,
typename std::enable_if<lazy_enable<k>::value, int>::type = 0>
auto& child (Dune::index_constant<k> = {})
{
return _node->template child<Child<k>::mapped_index>();
}
......@@ -164,7 +158,7 @@ namespace Dune {
* \returns a const reference to the i-th child.
*/
template<std::size_t k>
const typename Child<k>::Type& child(Dune::index_constant<k> = {}) const
const auto& child (Dune::index_constant<k> = {}) const
{
return _node->template child<Child<k>::mapped_index>();
}
......@@ -173,9 +167,9 @@ namespace Dune {
/**
* \returns a copy of the object storing the i-th child.
*/
template<std::size_t k>
typename std::enable_if<lazy_enable<k>::value,typename Child<k>::Storage>::type
childStorage()
template<std::size_t k,
typename std::enable_if<lazy_enable<k>::value, int>::type = 0>
auto childStorage (Dune::index_constant<k> = {})
{
return _node->template childStorage<Child<k>::mapped_index>();
}
......@@ -188,23 +182,16 @@ namespace Dune {
* \returns a copy of the object storing the i-th child.
*/
template<std::size_t k>
typename Child<k>::ConstStorage childStorage() const
auto childStorage (Dune::index_constant<k> = {}) const
{
return _node->template childStorage<Child<k>::mapped_index>();
}
//! Sets the i-th child to the passed-in value.
template<std::size_t k>
void setChild(typename Child<k>::type& child, typename std::enable_if<lazy_enable<k>::value,void*>::type = 0)
{
_node->template childStorage<Child<k>::mapped_index>() = stackobject_to_shared_ptr(child);
}
//! Sets the storage of the i-th child to the passed-in value.
template<std::size_t k>
void setChild(typename Child<k>::storage_type child, typename std::enable_if<lazy_enable<k>::value,void*>::type = 0)
template<std::size_t k, class ChildType>
void setChild (ChildType&& child, typename std::enable_if<lazy_enable<k>::value,void*>::type = 0)
{
_node->template childStorage<Child<k>::mapped_index>() = child;
_node->template setChild<Child<k>::mapped_index>(std::forward<ChildType>(child));
}
//! @}
......@@ -220,7 +207,7 @@ namespace Dune {
*/
template<bool enabled = !nodeIsConst>
typename std::enable_if<enabled,Node&>::type
unfiltered()
unfiltered ()
{
return *_node;
}
......@@ -229,7 +216,7 @@ namespace Dune {
/**
* \returns A const reference to the original, unfiltered node.
*/
const Node& unfiltered() const
const Node& unfiltered () const
{
return *_node;
}
......@@ -240,7 +227,7 @@ namespace Dune {
*/
template<bool enabled = !nodeIsConst>
typename std::enable_if<enabled,std::shared_ptr<Node> >::type
unfilteredStorage()
unfilteredStorage ()
{
return _node;
}
......@@ -249,7 +236,7 @@ namespace Dune {
/**
* \returns A shared_ptr to the original, unfiltered node.
*/
std::shared_ptr<const Node> unfilteredStorage() const
std::shared_ptr<const Node> unfilteredStorage () const
{
return _node;
}
......@@ -262,12 +249,12 @@ namespace Dune {
//! @{
//! Initialize the CompositeNode with copies of the passed in Storage objects.
FilteredCompositeNode(std::shared_ptr<Node> node)
: _node(node)
FilteredCompositeNode (std::shared_ptr<Node> node)
: _node(std::move(node))
{}
//! Initialize the CompositeNode with a copy of the passed-in storage type.
FilteredCompositeNode(Node& node)
FilteredCompositeNode (Node& node)
: _node(stackobject_to_shared_ptr(node))
{}
......
......@@ -46,7 +46,7 @@ namespace Dune {
{
typedef std::tuple<typename Node::template Child<FilterEntries::original_index>...> Children;
typedef std::tuple<typename Node::template Child<FilterEntries::original_index>::Type...> ChildTypes;
typedef std::tuple<typename Node::template Child<FilterEntries::original_index>::Storage...> NodeStorage;
typedef std::tuple<std::shared_ptr<typename Node::template Child<FilterEntries::original_index>::Type>...> NodeStorage;
};
};
......
......@@ -63,7 +63,7 @@ namespace Dune {
//! The number of children.
static const std::size_t CHILDREN = k;
static constexpr std::size_t degree()
static constexpr std::size_t degree ()
{
return k;
}
......@@ -74,14 +74,8 @@ namespace Dune {
//! The type of each child.
typedef T ChildType;
//! The storage type of each child.
typedef std::shared_ptr<T> ChildStorageType;
//! The const version of the storage type of each child.
typedef std::shared_ptr<const T> ChildConstStorageType;
//! The type used for storing the children.
typedef std::array<ChildStorageType,k> NodeStorage;
typedef std::array<std::shared_ptr<T>,k> NodeStorage;
//! Access to the type and storage type of the i-th child.
......@@ -96,12 +90,6 @@ namespace Dune {
//! The type of the child.
typedef T type;
//! The storage type of the child.
typedef ChildStorageType Storage;
//! The const storage type of the child.
typedef ChildConstStorageType ConstStorage;
};
//! @name Child Access (templated methods)
......@@ -134,7 +122,7 @@ namespace Dune {
* \returns a copy of the object storing the i-th child.
*/
template<std::size_t i>
ChildStorageType childStorage(index_constant<i> = {})
auto childStorage (index_constant<i> = {})
{
static_assert((i < CHILDREN), "child index out of range");
return _children[i];
......@@ -148,7 +136,7 @@ namespace Dune {
* \returns a copy of the object storing the i-th child.
*/
template<std::size_t i>
ChildConstStorageType childStorage(index_constant<i> = {}) const
auto childStorage (index_constant<i> = {}) const
{
static_assert((i < CHILDREN), "child index out of range");
return _children[i];
......@@ -164,7 +152,7 @@ namespace Dune {
//! Store the passed value in i-th child.
template<std::size_t i>
void setChild(T&& t, index_constant<i> = {})
void setChild (T&& t, index_constant<i> = {})
{
static_assert((i < CHILDREN), "child index out of range");
_children[i] = convert_arg(std::move(t));
......@@ -172,10 +160,10 @@ namespace Dune {
//! Sets the stored value representing the i-th child to the passed-in value.
template<std::size_t i>
void setChild (ChildStorageType st, index_constant<i> = {})
void setChild (std::shared_ptr<T> st, index_constant<i> = {})
{
static_assert((i < CHILDREN), "child index out of range");
_children[i] = st;
_children[i] = std::move(st);
}
//! @}
......@@ -208,7 +196,7 @@ namespace Dune {
/**
* \returns a copy of the object storing the i-th child.
*/
ChildStorageType childStorage(std::size_t i)
auto childStorage (std::size_t i)
{
assert(i < CHILDREN && "child index out of range");
return _children[i];
......@@ -221,10 +209,10 @@ namespace Dune {
* become const.
* \returns a copy of the object storing the i-th child.
*/
ChildConstStorageType childStorage (std::size_t i) const
auto childStorage (std::size_t i) const
{
assert(i < CHILDREN && "child index out of range");
return (_children[i]);
return _children[i];
}
//! Sets the i-th child to the passed-in value.
......@@ -235,20 +223,20 @@ namespace Dune {
}
//! Store the passed value in i-th child.
void setChild(std::size_t i, T&& t)
void setChild (std::size_t i, T&& t)
{
assert(i < CHILDREN && "child index out of range");
_children[i] = convert_arg(std::move(t));
}
//! Sets the stored value representing the i-th child to the passed-in value.
void setChild (std::size_t i, ChildStorageType st)
void setChild (std::size_t i, std::shared_ptr<T> st)
{
assert(i < CHILDREN && "child index out of range");
_children[i] = st;
_children[i] = std::move(st);
}
const NodeStorage& nodeStorage() const
const NodeStorage& nodeStorage () const
{
return _children;
}
......@@ -286,7 +274,7 @@ namespace Dune {
#else
template<typename I0, typename... I,
std::enable_if_t<(sizeof...(I) > 0) || IsTreePath<I0>::value, int > = 0>
decltype(auto) child(I0 i0, I... i)
decltype(auto) child (I0 i0, I... i)
#endif
{
static_assert(sizeof...(I) > 0 || impl::_non_empty_tree_path(I0{}),
......@@ -306,7 +294,7 @@ namespace Dune {
#else
template<typename I0, typename... I,
std::enable_if_t<(sizeof...(I) > 0) || IsTreePath<I0>::value, int > = 0>
decltype(auto) child(I0 i0, I... i) const
decltype(auto) child (I0 i0, I... i) const
#endif
{
static_assert(sizeof...(I) > 0 || impl::_non_empty_tree_path(I0{}),
......@@ -335,7 +323,7 @@ namespace Dune {
{}
//! Initialize the PowerNode with a copy of the passed-in storage type.
explicit PowerNode(const NodeStorage& children)
explicit PowerNode (const NodeStorage& children)
: _children(children)
{}
......
......@@ -63,9 +63,9 @@ namespace Dune {
/**
* \returns a reference to the i-th child.
*/
template<std::size_t k>
typename std::enable_if<lazy_enabled<k>::value,typename Child<k>::Type&>::type
child(Dune::index_constant<k> = {})
template<std::size_t k,
typename std::enable_if<lazy_enabled<k>::value, int>::type = 0>
auto& child(Dune::index_constant<k> = {})
{
return node().proxiedNode().template child<k>();
}
......@@ -75,7 +75,7 @@ namespace Dune {
* \returns a const reference to the i-th child.
*/
template<std::size_t k>
const typename Child<k>::Type& child(Dune::index_constant<k> = {}) const
const auto& child (Dune::index_constant<k> = {}) const
{
return node().proxiedNode().template child<k>();
}
......@@ -84,9 +84,9 @@ namespace Dune {
/**
* \returns a copy of the object storing the i-th child.
*/
template<std::size_t k>
typename std::enable_if<lazy_enabled<k>::value,typename Child<k>::Storage>::type
childStorage()
template<std::size_t k,
typename std::enable_if<lazy_enabled<k>::value, int>::type = 0>
auto childStorage (Dune::index_constant<k> = {})
{
return node().proxiedNode().template childStorage<k>();
}
......@@ -99,23 +99,16 @@ namespace Dune {
* \returns a copy of the object storing the i-th child.
*/
template<std::size_t k>
typename Child<k>::ConstStorage childStorage() const
auto childStorage (Dune::index_constant<k> = {}) const
{
return node().proxiedNode().template childStorage<k>();
}
//! Sets the i-th child to the passed-in value.
template<std::size_t k>
void setChild(typename Child<k>::type& child, typename std::enable_if<lazy_enabled<k>::value,void*>::type = 0)
{
node().proxiedNode().template childStorage<k>() = stackobject_to_shared_ptr(child);
}
//! Sets the storage of the i-th child to the passed-in value.
template<std::size_t k>
void setChild(typename Child<k>::storage_type child, typename std::enable_if<lazy_enabled<k>::value,void*>::type = 0)
template<std::size_t k, class ProxyChild>
void setChild (ProxyChild&& child, typename std::enable_if<lazy_enabled<k>::value,void*>::type = 0)
{
node().proxiedNode().template childStorage<k>() = child;
node().proxiedNode().template setChild<k>(std::forward<ProxyChild>(child));
}
const typename ProxiedNode::NodeStorage& nodeStorage() const
......@@ -161,9 +154,9 @@ namespace Dune {
/**
* \returns a reference to the i-th child.
*/
template<bool enabled = !proxiedNodeIsConst>
typename std::enable_if<enabled,typename ProxiedNode::ChildType&>::type
child (std::size_t i)
template<bool enabled = !proxiedNodeIsConst,