| 1 |
// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
// vi: set et ts=8 sw=2 sts=2: |
| 3 |
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root |
| 4 |
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later |
| 5 |
|
| 6 |
#include <config.h> |
| 7 |
|
| 8 |
#include <cstdlib> |
| 9 |
#include <utility> |
| 10 |
#include <type_traits> |
| 11 |
#include <tuple> |
| 12 |
|
| 13 |
#include <dune/common/indices.hh> |
| 14 |
#include <dune/common/hybridmultiindex.hh> |
| 15 |
#include <dune/common/typetree/childaccess.hh> |
| 16 |
#include <dune/common/typetree/test/testtypetreeutilities.hh> |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
// Bring concepts into scope |
| 22 |
using namespace Dune::Indices; |
| 23 |
|
| 24 |
template<class Tree, class Child, std::size_t... i> |
| 25 |
void checkChild() { |
| 26 |
|
| 27 |
auto tree = Tree{}; |
| 28 |
using TreePath = Dune::HybridMultiIndex<Dune::index_constant<i>...>; |
| 29 |
auto treePath = TreePath{}; |
| 30 |
|
| 31 |
using ChildByIndices = Dune::TypeTree::Child<Tree, i...>; |
| 32 |
static_assert(std::is_same_v<Child, ChildByIndices>); |
| 33 |
|
| 34 |
using ChildByTreePath = Dune::TypeTree::ChildForTreePath<Tree, TreePath>; |
| 35 |
static_assert(std::is_same_v<Child, ChildByTreePath>); |
| 36 |
|
| 37 |
const auto& childByIndices = Dune::TypeTree::child(tree, Dune::index_constant<i>{}...); |
| 38 |
static_assert(std::is_same_v<Child, std::decay_t<decltype(childByIndices)>>); |
| 39 |
|
| 40 |
const auto& childByTreePath = Dune::TypeTree::child(tree, treePath); |
| 41 |
static_assert(std::is_same_v<Child, std::decay_t<decltype(childByTreePath)>>); |
| 42 |
} |
| 43 |
|
| 44 |
template<class Tree, class... Child> |
| 45 |
void checkChildren() { |
| 46 |
using DeducedChildren = Dune::TypeTree::Impl::Children<Tree>; |
| 47 |
if constexpr (sizeof...(Child)>0) |
| 48 |
static_assert(std::is_same_v<DeducedChildren, std::tuple<Child...>>); |
| 49 |
else |
| 50 |
static_assert(std::is_same_v<DeducedChildren, void>); |
| 51 |
} |
| 52 |
|
| 53 |
int main() { |
| 54 |
|
| 55 |
// Use tags to generate different type nodes |
| 56 |
using TagA = Dune::index_constant<23>; |
| 57 |
using TagB = Dune::index_constant<42>; |
| 58 |
using TagC = Dune::index_constant<237>; |
| 59 |
using TagD = Dune::index_constant<47>; |
| 60 |
|
| 61 |
using Tree = NonUniformInner<TagA, |
| 62 |
UniformStaticInner<TagB, |
| 63 |
Leaf<TagA> |
| 64 |
, 3>, |
| 65 |
Leaf<TagB>, |
| 66 |
NonUniformInner<TagC, |
| 67 |
Leaf<TagC>, |
| 68 |
Leaf<TagD> |
| 69 |
> |
| 70 |
>; |
| 71 |
|
| 72 |
checkChild<Tree, |
| 73 |
Tree |
| 74 |
>(); |
| 75 |
|
| 76 |
checkChildren<Tree, |
| 77 |
UniformStaticInner<TagB, |
| 78 |
Leaf<TagA> |
| 79 |
, 3>, |
| 80 |
Leaf<TagB>, |
| 81 |
NonUniformInner<TagC, |
| 82 |
Leaf<TagC>, |
| 83 |
Leaf<TagD> |
| 84 |
> |
| 85 |
>(); |
| 86 |
|
| 87 |
checkChild<Tree, |
| 88 |
UniformStaticInner<TagB, |
| 89 |
Leaf<TagA> |
| 90 |
, 3> |
| 91 |
, 0>(); |
| 92 |
|
| 93 |
checkChildren<Dune::TypeTree::Child<Tree, 0>>(); |
| 94 |
|
| 95 |
checkChild<Tree, |
| 96 |
Leaf<TagA> |
| 97 |
, 0, 0>(); |
| 98 |
|
| 99 |
checkChildren<Dune::TypeTree::Child<Tree, 0, 0>>(); |
| 100 |
|
| 101 |
checkChild<Tree, |
| 102 |
Leaf<TagB> |
| 103 |
, 1>(); |
| 104 |
|
| 105 |
checkChildren<Dune::TypeTree::Child<Tree, 1>>(); |
| 106 |
|
| 107 |
checkChild<Tree, |
| 108 |
NonUniformInner<TagC, |
| 109 |
Leaf<TagC>, |
| 110 |
Leaf<TagD> |
| 111 |
> |
| 112 |
, 2>(); |
| 113 |
|
| 114 |
checkChildren<Dune::TypeTree::Child<Tree, 2>, |
| 115 |
Leaf<TagC>, |
| 116 |
Leaf<TagD> |
| 117 |
>(); |
| 118 |
|
| 119 |
checkChild<Tree, |
| 120 |
Leaf<TagC> |
| 121 |
, 2, 0>(); |
| 122 |
|
| 123 |
checkChildren<Dune::TypeTree::Child<Tree, 2, 0>>(); |
| 124 |
|
| 125 |
checkChild<Tree, |
| 126 |
Leaf<TagD> |
| 127 |
, 2, 1>(); |
| 128 |
|
| 129 |
checkChildren<Dune::TypeTree::Child<Tree, 2, 1>>(); |
| 130 |
|
| 131 |
return EXIT_SUCCESS; |
| 132 |
} |