File: type_traits.cpp

package info (click to toggle)
tiledarray 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 9,568 kB
  • sloc: cpp: 53,449; javascript: 1,599; sh: 393; ansic: 226; python: 223; xml: 195; makefile: 36
file content (277 lines) | stat: -rw-r--r-- 10,871 bytes parent folder | download
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*
 *  This file is a part of TiledArray.
 *  Copyright (C) 2017  Virginia Tech
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  Eduard Valeyev
 *  Department of Chemistry, Virginia Tech
 *
 *  type_traits.cpp
 *  Apr 7, 2017
 *
 */

#include "unit_test_config.h"

#include <algorithm>
#include <unordered_map>
#include <vector>

#include "TiledArray/dist_eval/array_eval.h"
#include "TiledArray/tensor.h"
#include "TiledArray/tile_op/noop.h"
#include "TiledArray/type_traits.h"

struct TypeTraitsFixture {
  TypeTraitsFixture() {}

  ~TypeTraitsFixture() {}

};  // TypeTraitsFixture

BOOST_FIXTURE_TEST_SUITE(type_traits_suite, TypeTraitsFixture)

BOOST_AUTO_TEST_CASE(sanity) {
  constexpr bool double_has_value_type =
      TiledArray::detail::has_member_type_value_type<double>::value;
  BOOST_CHECK(!double_has_value_type);
}

BOOST_AUTO_TEST_CASE(vector) {
  using container = std::vector<int>;

  constexpr bool has_value_type =
      TiledArray::detail::has_member_type_value_type<container>::value;
  BOOST_CHECK(has_value_type);
  constexpr bool has_allocator_type =
      TiledArray::detail::has_member_type_allocator_type<container>::value;
  BOOST_CHECK(has_allocator_type);
  constexpr bool has_size_type =
      TiledArray::detail::has_member_type_size_type<container>::value;
  BOOST_CHECK(has_size_type);
  constexpr bool has_difference_type =
      TiledArray::detail::has_member_type_difference_type<container>::value;
  BOOST_CHECK(has_difference_type);
  constexpr bool has_reference =
      TiledArray::detail::has_member_type_reference<container>::value;
  BOOST_CHECK(has_reference);
  constexpr bool has_const_reference =
      TiledArray::detail::has_member_type_const_reference<container>::value;
  BOOST_CHECK(has_const_reference);
  constexpr bool has_pointer =
      TiledArray::detail::has_member_type_pointer<container>::value;
  BOOST_CHECK(has_pointer);
  constexpr bool has_const_pointer =
      TiledArray::detail::has_member_type_const_pointer<container>::value;
  BOOST_CHECK(has_const_pointer);
  constexpr bool has_iterator =
      TiledArray::detail::has_member_type_iterator<container>::value;
  BOOST_CHECK(has_iterator);
  constexpr bool has_const_iterator =
      TiledArray::detail::has_member_type_const_iterator<container>::value;
  BOOST_CHECK(has_const_iterator);
  constexpr bool has_reverse_iterator =
      TiledArray::detail::has_member_type_reverse_iterator<container>::value;
  BOOST_CHECK(has_reverse_iterator);
  constexpr bool has_const_reverse_iterator =
      TiledArray::detail::has_member_type_const_reverse_iterator<
          container>::value;
  BOOST_CHECK(has_const_reverse_iterator);

  constexpr bool has_size =
      TiledArray::detail::has_member_function_size_anyreturn<container>::value;
  constexpr bool has_size_const =
      TiledArray::detail::has_member_function_size_anyreturn<
          const container>::value;
  constexpr bool has_size_size_type =
      TiledArray::detail::has_member_function_size<container,
                                                   container::size_type>::value;
  constexpr bool has_size_size_type_const =
      TiledArray::detail::has_member_function_size<const container,
                                                   container::size_type>::value;
  constexpr bool has_size_bool =
      TiledArray::detail::has_member_function_size<const container,
                                                   bool>::value;
  BOOST_CHECK(has_size && has_size_const);
  BOOST_CHECK(has_size_size_type);
  BOOST_CHECK(has_size_size_type_const);
  BOOST_CHECK(!has_size_bool);

  constexpr bool has_empty =
      TiledArray::detail::has_member_function_empty_anyreturn<container>::value;
  constexpr bool has_empty_bool =
      TiledArray::detail::has_member_function_empty<container, bool>::value;
  BOOST_CHECK(has_empty);
  BOOST_CHECK(has_empty_bool);

  constexpr bool has_clear =
      TiledArray::detail::has_member_function_clear_anyreturn<container>::value;
  constexpr bool has_clear_const =
      TiledArray::detail::has_member_function_clear_anyreturn<
          const container>::value;
  constexpr bool has_clear_void =
      TiledArray::detail::has_member_function_clear<container, void>::value;
  constexpr bool has_clear_void_const =
      TiledArray::detail::has_member_function_clear<const container,
                                                    void>::value;
  constexpr bool has_clear_bool =
      TiledArray::detail::has_member_function_clear<container, bool>::value;
  constexpr bool has_clear_bool_const =
      TiledArray::detail::has_member_function_clear<const container,
                                                    bool>::value;
  BOOST_CHECK(has_clear);
  BOOST_CHECK(!has_clear_const);
  BOOST_CHECK(has_clear_void);
  BOOST_CHECK(!has_clear_void_const);
  BOOST_CHECK(!has_clear_bool);
  BOOST_CHECK(!has_clear_bool_const);

  constexpr bool has_begin =
      TiledArray::detail::has_member_function_begin_anyreturn<container>::value;
  constexpr bool has_cbegin =
      TiledArray::detail::has_member_function_cbegin_anyreturn<
          container>::value;
  constexpr bool has_rbegin =
      TiledArray::detail::has_member_function_rbegin_anyreturn<
          container>::value;
  constexpr bool has_crbegin =
      TiledArray::detail::has_member_function_crbegin_anyreturn<
          container>::value;
  constexpr bool has_end =
      TiledArray::detail::has_member_function_end_anyreturn<container>::value;
  constexpr bool has_cend =
      TiledArray::detail::has_member_function_cend_anyreturn<container>::value;
  constexpr bool has_rend =
      TiledArray::detail::has_member_function_rend_anyreturn<container>::value;
  constexpr bool has_crend =
      TiledArray::detail::has_member_function_crend_anyreturn<container>::value;
  BOOST_CHECK(has_begin);
  BOOST_CHECK(has_cbegin);
  BOOST_CHECK(has_rbegin);
  BOOST_CHECK(has_crbegin);
  BOOST_CHECK(has_end);
  BOOST_CHECK(has_cend);
  BOOST_CHECK(has_rend);
  BOOST_CHECK(has_crend);
}

BOOST_AUTO_TEST_CASE(unordered_map) {
  using container = std::unordered_map<int, int>;
  constexpr bool has_begin =
      TiledArray::detail::has_member_function_begin_anyreturn<container>::value;
  constexpr bool has_cbegin =
      TiledArray::detail::has_member_function_cbegin_anyreturn<
          container>::value;
  constexpr bool has_rbegin =
      TiledArray::detail::has_member_function_rbegin_anyreturn<
          container>::value;
  constexpr bool has_crbegin =
      TiledArray::detail::has_member_function_crbegin_anyreturn<
          container>::value;
  constexpr bool has_end =
      TiledArray::detail::has_member_function_end_anyreturn<container>::value;
  constexpr bool has_cend =
      TiledArray::detail::has_member_function_cend_anyreturn<container>::value;
  constexpr bool has_rend =
      TiledArray::detail::has_member_function_rend_anyreturn<container>::value;
  constexpr bool has_crend =
      TiledArray::detail::has_member_function_crend_anyreturn<container>::value;
  BOOST_CHECK(has_begin);
  BOOST_CHECK(has_cbegin);
  BOOST_CHECK(!has_rbegin);
  BOOST_CHECK(!has_crbegin);
  BOOST_CHECK(has_end);
  BOOST_CHECK(has_cend);
  BOOST_CHECK(!has_rend);
  BOOST_CHECK(!has_crend);
}

using std::max;
GENERATE_IS_FREE_FUNCTION_ANYRETURN(max)

BOOST_AUTO_TEST_CASE(_max_) {
  constexpr bool there_is_max_int_int =
      is_free_function_max_anyreturn_v<int, int>;
  constexpr bool there_is_max_int_double =
      is_free_function_max_anyreturn_v<int, double>;
  BOOST_CHECK(there_is_max_int_int);
  BOOST_CHECK(!there_is_max_int_double);
}

using std::min;
GENERATE_IS_FREE_FUNCTION_ANYRETURN(min)

BOOST_AUTO_TEST_CASE(_min_) {
  constexpr bool there_is_min_int_int =
      is_free_function_min_anyreturn_v<int, int>;
  constexpr bool there_is_min_int_double =
      is_free_function_min_anyreturn_v<int, double>;
  BOOST_CHECK(there_is_min_int_int);
  BOOST_CHECK(!there_is_min_int_double);
}

struct IncompleteType;
struct CompleteType {};

BOOST_AUTO_TEST_CASE(is_complete_type) {
  constexpr bool void_is_complete_type =
      TiledArray::detail::is_complete_type_v<void>;
  BOOST_CHECK(!void_is_complete_type);
  constexpr bool IncompleteType_is_complete_type =
      TiledArray::detail::is_complete_type_v<IncompleteType>;
  BOOST_CHECK(!IncompleteType_is_complete_type);
  constexpr bool CompleteType_is_complete_type =
      TiledArray::detail::is_complete_type_v<CompleteType>;
  BOOST_CHECK(CompleteType_is_complete_type);
}

BOOST_AUTO_TEST_CASE(convertibility) {
  using TileD = TiledArray::Tensor<double>;
  using LazyTileD = TiledArray::detail::LazyArrayTile<
      TileD, TiledArray::detail::Noop<TileD, TileD, true>>;
  {
    using T = LazyTileD;
    constexpr bool lazy_tile_is_explconv_to_tile =
        TiledArray::detail::is_explicitly_convertible<
            T, typename T::eval_type>::value;
    constexpr bool lazy_tile_is_implconv_to_tile =
        TiledArray::detail::is_implicitly_convertible<
            T, typename T::eval_type>::value;
    BOOST_CHECK(lazy_tile_is_explconv_to_tile);
    BOOST_CHECK(!lazy_tile_is_implconv_to_tile);
    constexpr bool lazy_tile_is_explconv_to_tilefut =
        TiledArray::detail::is_explicitly_convertible<
            T, madness::Future<typename T::eval_type>>::value;
    constexpr bool lazy_tile_is_implconv_to_tilefut =
        TiledArray::detail::is_implicitly_convertible<
            T, madness::Future<typename T::eval_type>>::value;
    constexpr bool lazy_tile_has_explconv_to_tilefut =
        TiledArray::detail::has_conversion_operator_v<
            T, madness::Future<typename T::eval_type>>;
    BOOST_CHECK(!lazy_tile_is_explconv_to_tilefut);
    BOOST_CHECK(!lazy_tile_is_implconv_to_tilefut);
    BOOST_CHECK(!lazy_tile_has_explconv_to_tilefut);

    constexpr bool lazy_tile_has_conversion_operator_to_tile =
        TiledArray::detail::has_conversion_operator_v<T, TileD>;
    constexpr bool lazy_tile_has_conversion_operator_to_tilefut =
        TiledArray::detail::has_conversion_operator_v<T,
                                                      madness::Future<TileD>>;
    BOOST_CHECK(lazy_tile_has_conversion_operator_to_tile);
    BOOST_CHECK(!lazy_tile_has_conversion_operator_to_tilefut);
  }
}

BOOST_AUTO_TEST_SUITE_END()