1 // PR gcov-profile/88045
2 // { dg-options "-fprofile-arcs -ftest-coverage -std=c++11" }
3 // { dg-do run { target native } }
4 /* { dg-skip-if "requires hosted libstdc++ for vector" { ! hostedlib } } */
11 size_t size() const { return n; };
13 explicit Foo(size_t a_n) : n{a_n} {};
16 template<template<typename...> class C, typename Head, typename... Tail>
17 struct make_with_tail {
18 using type = C<Tail...>;
21 template<template<typename...> class C, typename T, typename Head, typename... Tail>
22 struct make_with_tail_1 {
23 using type = C<T, Tail...>;
26 template<typename Head, typename... Tail>
30 template<typename... Ts>
32 using root_type = typename head<Ts...>::type;
33 using branch_type = typename make_with_tail<Tree, Ts...>::type;
34 Tree(root_type a_root, std::vector<branch_type> a_branches) :
35 root{std::move(a_root)},
36 branches{std::move(a_branches)}
40 explicit Tree(root_type a_root) : root{std::move(a_root)}, branches{root.size()}
45 std::vector<branch_type> branches;
52 template<typename... Axes>
53 size_t size(const Tree<Axes...>& tree)
55 return std::accumulate(
56 tree.branches.begin(),
59 [](const size_t& count, const typename make_with_tail<Tree, Axes...>::type& branch) {
60 return count + size(branch);
65 inline size_t size(const Tree<>& /* empty tree */)
70 int main(int argc, char *argv[])
72 size(Tree<Foo, Foo, Foo>{Foo{4}, {Tree<Foo, Foo>{Foo{2}, {Tree<Foo>{Foo{205}},
73 Tree<Foo>{Foo{261}}}},
74 Tree<Foo, Foo>{Foo{4}, {Tree<Foo>{Foo{875}},
77 Tree<Foo>{Foo{302}}}},
78 Tree<Foo, Foo>{Foo{6}, {Tree<Foo>{Foo{111}},
83 Tree<Foo>{Foo{735}}}},
84 Tree<Foo, Foo>{Foo{3}, {Tree<Foo>{Foo{791}},
86 Tree<Foo>{Foo{841}}}}}});
91 // { dg-final { run-gcov pr88045.C } }