File: deduction_guides_test.cpp

package info (click to toggle)
boost1.74 1.74.0%2Bds1-21
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 463,588 kB
  • sloc: cpp: 3,338,117; xml: 131,293; python: 33,088; ansic: 14,292; asm: 4,038; sh: 3,353; makefile: 1,193; perl: 1,036; yacc: 478; php: 212; ruby: 102; lisp: 24; sql: 13; csh: 6
file content (151 lines) | stat: -rw-r--r-- 6,062 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright 2018 Hans Dembinski
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <boost/histogram/accumulators/weighted_sum.hpp>
#include <boost/histogram/axis.hpp>
#include <boost/histogram/axis/ostream.hpp>
#include <boost/histogram/histogram.hpp>
#include <boost/histogram/ostream.hpp>
#include <boost/histogram/storage_adaptor.hpp>
#include <boost/histogram/unlimited_storage.hpp>
#include <tuple>
#include <type_traits>
#include <vector>
#include "std_ostream.hpp"
#include "throw_exception.hpp"

using namespace boost::histogram;
namespace tr = axis::transform;

// tests requires a C++17 compatible compiler

#define TEST BOOST_TEST_TRAIT_SAME

int main() {
  using axis::null_type;

  {
    using axis::regular;
    BOOST_TEST_TRAIT_SAME(decltype(regular(1, 0.0, 1.0)),
                          regular<double, tr::id, null_type>);
    BOOST_TEST_TRAIT_SAME(decltype(regular(1, 0, 1)), regular<double, tr::id, null_type>);
    BOOST_TEST_TRAIT_SAME(decltype(regular(1, 0.0f, 1.0f)),
                          regular<float, tr::id, null_type>);
    BOOST_TEST_TRAIT_SAME(decltype(regular(1, 0, 1, 0)), regular<double, tr::id, int>);
    BOOST_TEST_TRAIT_SAME(decltype(regular(1, 0.0f, 1.0f, "x")),
                          regular<float, tr::id, std::string>);
    BOOST_TEST_TRAIT_SAME(decltype(regular(tr::sqrt(), 1, 0, 1)),
                          regular<double, tr::sqrt, null_type>);
    BOOST_TEST_TRAIT_SAME(decltype(regular(tr::sqrt(), 1, 0.0f, 1.0f, "x")),
                          regular<float, tr::sqrt, std::string>);
    BOOST_TEST_TRAIT_SAME(decltype(regular(tr::sqrt(), 1, 0, 1, 0)),
                          regular<double, tr::sqrt, int>);
  }

  {
    using axis::integer;
    BOOST_TEST_TRAIT_SAME(decltype(integer(1, 2)), integer<int, null_type>);
    BOOST_TEST_TRAIT_SAME(decltype(integer(1l, 2l)), integer<int, null_type>);
    BOOST_TEST_TRAIT_SAME(decltype(integer(1.0, 2.0)), integer<double, null_type>);
    BOOST_TEST_TRAIT_SAME(decltype(integer(1.0f, 2.0f)), integer<float, null_type>);
    BOOST_TEST_TRAIT_SAME(decltype(integer(1, 2, "foo")), integer<int, std::string>);
    BOOST_TEST_TRAIT_SAME(decltype(integer(1, 2, 0)), integer<int, int>);
  }

  {
    using axis::variable;
    BOOST_TEST_TRAIT_SAME(decltype(variable{-1.0f, 1.0f}), variable<float, null_type>);
    BOOST_TEST_TRAIT_SAME(decltype(variable{-1, 0, 1, 2}), variable<double, null_type>);
    BOOST_TEST_TRAIT_SAME(decltype(variable{-1.0, 1.0}), variable<double, null_type>);
    BOOST_TEST_TRAIT_SAME(decltype(variable({-1, 0, 1}, "foo")),
                          variable<double, std::string>);
    BOOST_TEST_TRAIT_SAME(decltype(variable({-1, 1}, 0)), variable<double, int>);

    BOOST_TEST_TRAIT_SAME(decltype(variable(std::vector<int>{{-1, 1}})),
                          variable<double, null_type>);
    BOOST_TEST_TRAIT_SAME(decltype(variable(std::vector<float>{{-1.0f, 1.0f}})),
                          variable<float, null_type>);
    BOOST_TEST_TRAIT_SAME(decltype(variable(std::vector<int>{{-1, 1}}, "foo")),
                          variable<double, std::string>);
    BOOST_TEST_TRAIT_SAME(decltype(variable(std::vector<int>{{-1, 1}}, 0)),
                          variable<double, int>);
  }

  {
    using axis::category;
    BOOST_TEST_TRAIT_SAME(decltype(category{1, 2}), category<int, null_type>);
    BOOST_TEST_TRAIT_SAME(decltype(category{"x", "y"}), category<std::string, null_type>);
    BOOST_TEST_TRAIT_SAME(decltype(category({1, 2}, "foo")), category<int, std::string>);
    BOOST_TEST_TRAIT_SAME(decltype(category({1, 2}, 0)), category<int, int>);
  }

  {
    using axis::boolean;
    BOOST_TEST_TRAIT_SAME(decltype(boolean{}), boolean<null_type>);
    BOOST_TEST_TRAIT_SAME(decltype(boolean{"foo"}), boolean<std::string>);
  }

  {
    auto h = histogram(axis::regular(3, -1, 1), axis::integer(0, 4));
    BOOST_TEST_TRAIT_SAME(decltype(h),
                          histogram<std::tuple<axis::regular<double, tr::id, null_type>,
                                               axis::integer<int, null_type>>>);
    BOOST_TEST_EQ(h.axis(0), axis::regular(3, -1, 1));
    BOOST_TEST_EQ(h.axis(1), axis::integer(0, 4));
  }

  {
    auto h = histogram(std::tuple(axis::regular(3, -1, 1), axis::integer(0, 4)),
                       weight_storage());
    BOOST_TEST_TRAIT_SAME(decltype(h),
                          histogram<std::tuple<axis::regular<double, tr::id, null_type>,
                                               axis::integer<int, null_type>>,
                                    weight_storage>);
    BOOST_TEST_EQ(h.axis(0), axis::regular(3, -1, 1));
    BOOST_TEST_EQ(h.axis(1), axis::integer(0, 4));
  }

  {
    auto a0 = axis::regular(5, 0, 5);
    auto a1 = axis::regular(3, -1, 1);
    auto axes = {a0, a1};
    auto h = histogram(axes);
    BOOST_TEST_TRAIT_SAME(
        decltype(h), histogram<std::vector<axis::regular<double, tr::id, null_type>>>);
    BOOST_TEST_EQ(h.rank(), 2);
    BOOST_TEST_EQ(h.axis(0), a0);
    BOOST_TEST_EQ(h.axis(1), a1);
  }

  {
    auto a0 = axis::regular(5, 0, 5);
    auto a1 = axis::regular(3, -1, 1);
    auto axes = {a0, a1};
    auto h = histogram(axes, weight_storage());
    BOOST_TEST_TRAIT_SAME(
        decltype(h),
        histogram<std::vector<axis::regular<double, tr::id, null_type>>, weight_storage>);
    BOOST_TEST_EQ(h.rank(), 2);
    BOOST_TEST_EQ(h.axis(0), a0);
    BOOST_TEST_EQ(h.axis(1), a1);
  }

  {
    auto a0 = axis::regular(5, 0, 5);
    auto a1 = axis::regular(3, -1, 1);
    auto axes = std::vector<decltype(a0)>{{a0, a1}};
    auto h = histogram(axes);
    BOOST_TEST_TRAIT_SAME(
        decltype(h), histogram<std::vector<axis::regular<double, tr::id, null_type>>>);
    BOOST_TEST_EQ(h.rank(), 2);
    BOOST_TEST_EQ(h.axis(0), a0);
    BOOST_TEST_EQ(h.axis(1), a1);
  }

  return boost::report_errors();
}