Daily bump.
[gcc.git] / gcc / testsuite / g++.dg / gcov / pr88045.C
blob329c74fb93dbbc888ea6e626f98b851e3b60d9b1
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 } } */
6 #include <numeric>
7 #include <vector>
8 #include <stdlib.h>
10 struct Foo {
11     size_t size() const { return n; };
12     const size_t 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>
27 struct head {
28     using type = Head;
30 template<typename... Ts>
31 struct Tree {
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)}
37     {
38     }
40     explicit Tree(root_type a_root) : root{std::move(a_root)}, branches{root.size()}
41     {
42     }
44     root_type                root;
45     std::vector<branch_type> branches;
48 template<>
49 struct Tree<> {
52 template<typename... Axes>
53 size_t size(const Tree<Axes...>& tree)
55     return std::accumulate(
56         tree.branches.begin(),
57         tree.branches.end(),
58         0,
59         [](const size_t& count, const typename make_with_tail<Tree, Axes...>::type& branch) {
60             return count + size(branch);
61         });
64 template<>
65 inline size_t size(const Tree<>& /* empty tree */)
67     return 1;
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}},
75                                                               Tree<Foo>{Foo{492}},
76                                                               Tree<Foo>{Foo{398}},
77                                                               Tree<Foo>{Foo{302}}}},
78                                       Tree<Foo, Foo>{Foo{6}, {Tree<Foo>{Foo{111}},
79                                                               Tree<Foo>{Foo{436}},
80                                                               Tree<Foo>{Foo{388}},
81                                                               Tree<Foo>{Foo{879}},
82                                                               Tree<Foo>{Foo{783}},
83                                                               Tree<Foo>{Foo{735}}}},
84                                       Tree<Foo, Foo>{Foo{3}, {Tree<Foo>{Foo{791}},
85                                                               Tree<Foo>{Foo{  5}},
86                                                               Tree<Foo>{Foo{841}}}}}});
88     return 0;
91 // { dg-final { run-gcov pr88045.C } }