-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathtype_traits.h
More file actions
1610 lines (1333 loc) · 65.3 KB
/
type_traits.h
File metadata and controls
1610 lines (1333 loc) · 65.3 KB
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is a part of TiledArray.
* Copyright (C) 2013 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/>.
*
*/
#ifndef TILEDARRAY_TYPE_TRAITS_H__INCLUDED
#define TILEDARRAY_TYPE_TRAITS_H__INCLUDED
/*
* N.B. this must be pure c++, usable without any context other than
* the current compiler + library + C++ standard.
* DO NOT include non-standard headers here!
*/
#include <cassert>
#include <complex>
#include <functional>
#include <iterator>
#include <utility>
#if __cplusplus <= 201703L
#include <boost/tuple/tuple.hpp>
#endif
//////////////////////////////////////////////////////////////////////////////////////////////
// implement C++17's type traits features if using CUDA with older C++ compiler
#if __cplusplus <= 201402L
// GNU stdlibc++ provides void_t if -gnu++11 or -gnu++14 are given
#if __GNUC__ && defined(__GLIBCXX__) && !__STRICT_ANSI__ && \
__cplusplus >= 201103L
#define HAVE_VOID_T
#endif
#ifndef HAVE_VOID_T // implement void_t if needed
namespace std {
template <typename... Ts>
struct make_void {
using type = void;
};
template <typename... Ts>
using void_t = typename make_void<Ts...>::type;
} // namespace std
#endif
namespace std {
template <class T>
inline constexpr bool is_integral_v = is_integral<T>::value;
}
#endif // C++14 only
//////////////////////////////////////////////////////////////////////////////////////////////
// forward declarations
namespace madness {
template <typename T>
class Future;
} // namespace madness
namespace TiledArray {
struct Range1;
template <typename>
class Tile;
class DensePolicy;
struct ZeroTensor;
template <typename, typename>
class DistArray;
namespace detail {
template <typename, typename>
class LazyArrayTile;
} // namespace detail
} // namespace TiledArray
//////////////////////////////////////////////////////////////////////////////////////////////
// see https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Member_Detector
/// this generates struct \c has_member_##Type<T> whose
/// public constexpr member variable \c value is true if \c T::Member is a
/// member variable or function.
#define GENERATE_HAS_MEMBER(Member) \
template <typename T, typename Enabler = void> \
class __has_member_##Member : public std::false_type {}; \
template <typename T> \
class __has_member_##Member< \
T, typename std::enable_if<std::is_class<T>::value || \
std::is_union<T>::value>::type> { \
using Yes = char[2]; \
using No = char[1]; \
\
struct Fallback { \
int Member; \
}; \
struct Derived : T, Fallback {}; \
\
template <class U> \
static No &test(decltype(U::Member) *); \
template <typename U> \
static Yes &test(U *); \
\
public: \
static constexpr bool value = \
sizeof(test<Derived>(nullptr)) == sizeof(Yes); \
}; \
\
template <class T> \
struct has_member_##Member \
: public std::integral_constant<bool, __has_member_##Member<T>::value> { \
};
/// this generates struct \c has_member_type_##Type<T> whose
/// public constexpr member variable \c value is true if \c T::Member is a
/// valid type.
#define GENERATE_HAS_MEMBER_TYPE(Type) \
template <typename T, typename Enabler = void> \
class __has_member_type_##Type : public std::false_type {}; \
template <typename T> \
class __has_member_type_##Type< \
T, typename std::enable_if<std::is_class<T>::value || \
std::is_union<T>::value>::type> { \
using Yes = char[2]; \
using No = char[1]; \
\
struct Fallback { \
struct Type {}; \
}; \
struct Derived : T, Fallback {}; \
\
template <class U> \
static No &test(typename U::Type *); \
template <typename U> \
static Yes &test(U *); \
\
public: \
static constexpr bool value = \
sizeof(test<Derived>(nullptr)) == sizeof(Yes); \
}; \
\
template <class T> \
struct has_member_type_##Type \
: public std::integral_constant<bool, \
__has_member_type_##Type<T>::value> {}; \
\
template <class T> \
constexpr const bool has_member_type_##Type##_v = \
has_member_type_##Type<T>::value;
/// this generates struct \c has_member_function_Member<T,R,Args...> whose
/// public constexpr member variable \c value is true if \c T::Member is a
/// member function that takes \c Args and returns \c R .
/// \note if T is a const type, only const member functions will be
/// detected, hence
/// \c has_member_function_Member_anyreturn<const T,R,Args...>::value &&
/// \c !has_member_function_Member_anyreturn<T,R,Args...>::value
/// evaluates to true if there is only a const T::Member
#define GENERATE_HAS_MEMBER_FUNCTION(Member) \
template <typename T, typename Result, typename... Args> \
class __has_member_function_##Member { \
using Yes = char; \
using No = int; \
template <typename U, Result (U::*)(Args...)> \
struct Check; \
template <typename U, Result (U::*)(Args...) const> \
struct CheckConst; \
template <typename U> \
static Yes test_const(CheckConst<U, &U::Member> *); \
template <typename U> \
static No test_const(...); \
template <typename U> \
static Yes test_nonconst(Check<U, &U::Member> *); \
template <typename U> \
static No test_nonconst(...); \
\
public: \
static constexpr const bool value = \
sizeof(test_const<T>(0)) == sizeof(Yes) || \
(!std::is_const<T>::value ? sizeof(test_nonconst<T>(0)) == sizeof(Yes) \
: false); \
}; \
template <class T, typename Result, typename... Args> \
struct has_member_function_##Member \
: public std::integral_constant< \
bool, __has_member_function_##Member<T, Result, Args...>::value> { \
}; \
\
template <class T, typename Result, typename... Args> \
constexpr const bool has_member_function_##Member##_v = \
has_member_function_##Member<T, Result, Args...>::value;
/// this generates struct \c has_member_function_Member_anyreturn<T,Args...>
/// whose public constexpr member variable \c value is true if \c T::Member
/// is a member function that takes \c Args and returns any type.
/// \note if T is a const type, only const member functions will be
/// detected, hence
/// \c has_member_function_Member_anyreturn<const T,Args...>::value &&
/// \c !has_member_function_Member_anyreturn<T,Args...>::value
/// evaluates to true if there is only a const T::Member
#define GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(Member) \
template <typename T, typename... Args> \
class __has_member_function_##Member##_anyreturn { \
using Yes = char; \
using No = int; \
template <typename U, typename... Args_> \
static auto func(void *) \
-> decltype(std::add_pointer_t<decltype(std::declval<U>().Member( \
std::declval<Args_>()...))>{}, \
Yes{}); \
template <typename U, typename... Args_> \
static No func(...); \
\
public: \
static constexpr const bool value = \
sizeof(func<T, Args...>(0)) == sizeof(Yes); \
}; \
template <class T, typename... Args> \
struct has_member_function_##Member##_anyreturn \
: public std::integral_constant< \
bool, \
__has_member_function_##Member##_anyreturn<T, Args...>::value> {}; \
\
template <class T, typename... Args> \
constexpr const bool has_member_function_##Member##_anyreturn_v = \
has_member_function_##Member##_anyreturn<T, Args...>::value;
/// this generates struct \c is_free_function_Function_anyreturn<Args...> whose
/// public constexpr member variable \c value is true if \c Function is a
/// free function that takes \c Args and returns any value.
/// \note to ensure that \c Function can be looked up if
/// it can't be found via ADL, it may be necessary
/// to add \c "using namespace::Function" BEFORE using this macro.
#define GENERATE_IS_FREE_FUNCTION_ANYRETURN(Function) \
template <typename... Args> \
class __is_free_function_##Function##_anyreturn { \
using Yes = char; \
using No = int; \
template <typename... Args_> \
static auto func(void *) \
-> decltype(std::add_pointer_t< \
decltype(Function(std::declval<Args_>()...))>{}, \
Yes{}); \
template <typename...> \
static No func(...); \
\
public: \
static constexpr const bool value = \
sizeof(func<Args...>(0)) == sizeof(Yes); \
}; \
template <typename... Args> \
struct is_free_function_##Function##_anyreturn \
: public std::integral_constant< \
bool, __is_free_function_##Function##_anyreturn<Args...>::value> { \
}; \
\
template <typename... Args> \
constexpr const bool is_free_function_##Function##_anyreturn_v = \
is_free_function_##Function##_anyreturn<Args...>::value;
/// this generates struct \c is_free_function_std_Function_anyreturn<Args...>
/// whose public constexpr member variable \c value is true if \c
/// ::std::Function is a free function that takes \c Args and returns any value.
#define GENERATE_IS_FREE_FUNCTION_STD_ANYRETURN(Function) \
template <typename... Args> \
class __is_free_function_std_##Function##_anyreturn { \
using Yes = char; \
using No = int; \
template <typename... Args_> \
static auto func(void *) \
-> decltype(std::add_pointer_t<decltype(::std::Function( \
std::declval<Args_>()...))>{}, \
Yes{}); \
template <typename...> \
static No func(...); \
\
public: \
static constexpr const bool value = \
sizeof(func<Args...>(0)) == sizeof(Yes); \
}; \
template <typename... Args> \
struct is_free_function_std_##Function##_anyreturn \
: public std::integral_constant< \
bool, \
__is_free_function_std_##Function##_anyreturn<Args...>::value> {}; \
\
template <typename... Args> \
constexpr const bool is_free_function_std_##Function##_anyreturn_v = \
is_free_function_std_##Function##_anyreturn<Args...>::value;
namespace TiledArray {
namespace detail {
/////////////////////////////
// standard container traits (incomplete)
GENERATE_HAS_MEMBER_TYPE(value_type)
GENERATE_HAS_MEMBER_TYPE(allocator_type)
GENERATE_HAS_MEMBER_TYPE(size_type)
GENERATE_HAS_MEMBER_TYPE(difference_type)
GENERATE_HAS_MEMBER_TYPE(reference)
GENERATE_HAS_MEMBER_TYPE(const_reference)
GENERATE_HAS_MEMBER_TYPE(pointer)
GENERATE_HAS_MEMBER_TYPE(const_pointer)
GENERATE_HAS_MEMBER_TYPE(iterator)
GENERATE_HAS_MEMBER_TYPE(const_iterator)
GENERATE_HAS_MEMBER_TYPE(reverse_iterator)
GENERATE_HAS_MEMBER_TYPE(const_reverse_iterator)
GENERATE_HAS_MEMBER_TYPE(key_type)
GENERATE_HAS_MEMBER_TYPE(mapped_type)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(size)
GENERATE_HAS_MEMBER_FUNCTION(size)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(data)
GENERATE_HAS_MEMBER_FUNCTION(data)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(empty)
GENERATE_HAS_MEMBER_FUNCTION(empty)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(clear)
GENERATE_HAS_MEMBER_FUNCTION(clear)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(resize)
// Tensor-only
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(total_size)
GENERATE_HAS_MEMBER_FUNCTION(total_size)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(nbatch)
GENERATE_HAS_MEMBER_FUNCTION(nbatch)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(begin)
GENERATE_HAS_MEMBER_FUNCTION(begin)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(end)
GENERATE_HAS_MEMBER_FUNCTION(end)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(cbegin)
GENERATE_HAS_MEMBER_FUNCTION(cbegin)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(cend)
GENERATE_HAS_MEMBER_FUNCTION(cend)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(rbegin)
GENERATE_HAS_MEMBER_FUNCTION(rbegin)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(rend)
GENERATE_HAS_MEMBER_FUNCTION(rend)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(crbegin)
GENERATE_HAS_MEMBER_FUNCTION(crbegin)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(crend)
GENERATE_HAS_MEMBER_FUNCTION(crend)
/////////////////////////////
// standard iterator traits
// GENERATE_HAS_MEMBER_TYPE(value_type)
// GENERATE_HAS_MEMBER_TYPE(difference_type)
// GENERATE_HAS_MEMBER_TYPE(reference)
// GENERATE_HAS_MEMBER_TYPE(pointer)
GENERATE_HAS_MEMBER_TYPE(iterator_category)
// these are useful to detect presence of overloads
GENERATE_IS_FREE_FUNCTION_ANYRETURN(size)
GENERATE_IS_FREE_FUNCTION_ANYRETURN(data)
GENERATE_IS_FREE_FUNCTION_ANYRETURN(empty)
//////// Tile concept checks
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(permute)
GENERATE_HAS_MEMBER_FUNCTION(permute)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(add)
GENERATE_HAS_MEMBER_FUNCTION(add)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(add_to)
GENERATE_HAS_MEMBER_FUNCTION(add_to)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(subt)
GENERATE_HAS_MEMBER_FUNCTION(subt)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(subt_to)
GENERATE_HAS_MEMBER_FUNCTION(subt_to)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(mult)
GENERATE_HAS_MEMBER_FUNCTION(mult)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(mult_to)
GENERATE_HAS_MEMBER_FUNCTION(mult_to)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(scale)
GENERATE_HAS_MEMBER_FUNCTION(scale)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(scale_to)
GENERATE_HAS_MEMBER_FUNCTION(scale_to)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(neg)
GENERATE_HAS_MEMBER_FUNCTION(neg)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(neg_to)
GENERATE_HAS_MEMBER_FUNCTION(neg_to)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(conj)
GENERATE_HAS_MEMBER_FUNCTION(conj)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(conj_to)
GENERATE_HAS_MEMBER_FUNCTION(conj_to)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(shift)
GENERATE_HAS_MEMBER_FUNCTION(shift)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(shift_to)
GENERATE_HAS_MEMBER_FUNCTION(shift_to)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(unary)
GENERATE_HAS_MEMBER_FUNCTION(unary)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(inplace_unary)
GENERATE_HAS_MEMBER_FUNCTION(inplace_unary)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(binary)
GENERATE_HAS_MEMBER_FUNCTION(binary)
GENERATE_HAS_MEMBER_FUNCTION_ANYRETURN(inplace_binary)
GENERATE_HAS_MEMBER_FUNCTION(inplace_binary)
GENERATE_IS_FREE_FUNCTION_ANYRETURN(permute)
} // namespace detail
} // namespace TiledArray
namespace TiledArray {
namespace detail {
/// @brief helper to implement other metafunctions
/// @c is_type<T>::value is true if @c T is a valid type
/// @tparam T a type
template <typename T>
struct is_type : public std::true_type {};
/// @tparam T a type
/// @c is_type_v<T> is an alias for @c is_type<T>::value
template <typename T>
constexpr const bool is_type_v = is_type<T>::value;
/// @brief helper to implement other metafunctions
/// @c is_complete_type<T>::value is true if @c T is a complete type
/// @tparam T a type
/// @note see
/// https://stackoverflow.com/questions/1625105/how-to-write-is-complete-template
template <typename T, typename = void>
struct is_complete_type : std::false_type {};
template <>
struct is_complete_type<void> : std::false_type {};
template <typename T>
struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {};
/// @tparam T a type
/// @c is_complete_type_v<T> is an alias for @c is_complete_type<T>::value
template <typename T>
constexpr const bool is_complete_type_v = is_complete_type<T>::value;
} // namespace detail
} // namespace TiledArray
namespace TiledArray {
/**
* \addtogroup TileInterface
* @{
*/
template <typename>
struct eval_trait;
namespace detail {
GENERATE_HAS_MEMBER_TYPE(eval_type)
/// evaluates to true if \c From has an (explicit or implicit) conversion
/// function that produces \c To from \c From , i.e. there exists \c
/// From::operator \c To() \note I do not yet know how to distinguish explicit
/// from implicit operators; some observable behavior does depend on this (e.g.
/// given an explicit converting ctor A::A(C) and an B::operator C(), explicit
/// conversion of B into A will be possible if B::operator C is implicit.
#if !defined(__INTEL_COMPILER_BUILD_DATE)
template <typename From, typename To, typename Enabler = void>
struct has_conversion_operator : std::false_type {};
template <typename From, typename To>
struct has_conversion_operator<
From, To,
typename std::enable_if<
is_type<decltype(std::declval<From>().operator To())>::value>::type>
: std::true_type {};
template <typename From, typename To>
struct has_conversion_operator<
From, To,
typename std::enable_if<
is_type<decltype(std::declval<From>().operator To &())>::value>::type>
: std::true_type {};
#else
template <typename From, typename To>
struct has_conversion_operator {
/*
* see
* https://stackoverflow.com/questions/87372/check-if-a-class-has-a-member-function-of-a-given-signature#answer-10707822
* this works for icc and all other compilers tested:
* <iframe width="800px" height="200px"
* src="https://godbolt.org/e?readOnly=true&hideEditorToolbars=true#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAM1QDsCBlZAQwBtMQBGAFlICsQAJlKtmtUMgCkggELSZpAM6Z2yAnjqVMtdAGFUrAK4BbWl1Lb0AGTy1MAORMAjTMRDc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icC6IoAZ/QhD1Mac01p%2BKznclWQVMM3BFLIELAC6MsyN4QFwIQRMIxhCTH0K89gydUGxurZKmQoyIWTIIswLAbgoxTKEIIOZ3BuDDHRJ4dYHhlnrEEFs5ZwgGkDEOWmjFZyLlXJuW2h5MBECg3mNuAgHzgKPG%2BXW8wBJy1uGEHyxgLA8XCuZEibwPL9lNKOemxpIwN60JHpmsM2bc1/MmIW4tra7mTOmcOuZgh1jcC2WGGdyz0SCAQ7wOdC7jmdMaSu65tyJnJoGCMxdJzl1rpA10ORmhuBAA"></iframe>
*/
/* operator has correct sig */
template <typename A>
static std::true_type test(To (A::*)() const) {
return std::true_type();
}
/* operator exists */
template <typename A>
static decltype(test(&A::operator To)) test(decltype(&A::operator To),
void *) {
/* Operator exists. What about sig? */
typedef decltype(test(&A::operator To)) return_type;
return return_type();
}
/* operator does not exist */
template <typename A>
static std::false_type test(...) {
return std::false_type();
}
/* This will be either `std::true_type` or `std::false_type` */
typedef decltype(test<From>(0, 0)) type;
static const bool value = type::value; /* Which is it? */
};
#endif
/// \c has_conversion_operator_v<From, To> is an alias for \c
/// has_conversion_operator<From, To>::value
template <class From, class To>
constexpr const bool has_conversion_operator_v =
has_conversion_operator<From, To>::value;
/// evaluates to true if can construct \c To from \c From , i.e. if there is
/// a converting constructor \c To::To(From) or if \c From has an implicit
/// or explicit conversion function to \c To, i.e. \c operator \c To()
template <class From, class To>
struct is_explicitly_convertible : public std::is_constructible<To, From> {};
/// \c is_explicitly_convertible_v<From, To> is an alias for \c
/// is_explicitly_convertible<From, To>::value
template <class From, class To>
constexpr const bool is_explicitly_convertible_v =
is_explicitly_convertible<From, To>::value;
/// evaluates to true if can implicitly convert \c To from \c From , i.e.
/// if \c From has an implicit
/// conversion function to \c To, i.e. \c operator \c To()
/// \note this is just an alias to std::is_convertible
template <class From, class To>
struct is_implicitly_convertible : public std::is_convertible<From, To> {};
/// \c is_implicitly_convertible_v<From, To> is an alias for \c
/// is_implicitly_convertible<From, To>::value
template <class From, class To>
constexpr const bool is_implicitly_convertible_v =
is_implicitly_convertible<From, To>::value;
/// evaluates to true if can convert \c To from \c From , either explicitly
/// or implicitly
/// \note contrast to std::is_convertible which checks for implicit conversion
/// only
template <class From, class To>
struct is_convertible
: public std::integral_constant<
bool, is_implicitly_convertible<From, To>::value ||
is_explicitly_convertible<From, To>::value> {};
/// \c is_convertible_v<From, To> is an alias for \c is_convertible<From,
/// To>::value
template <class From, class To>
constexpr const bool is_convertible_v = is_convertible<From, To>::value;
template <typename T, typename Enabler = void>
struct eval_trait_base {
typedef T type;
static constexpr bool is_consumable = false;
static constexpr bool nonblocking = false;
}; // struct eval_trait
template <typename T>
struct eval_trait_base<
T,
typename std::enable_if<
has_member_type_eval_type<T>::value &&
(detail::is_explicitly_convertible<T, typename T::eval_type>::value ||
detail::is_explicitly_convertible<
T, madness::Future<typename T::eval_type>>::value ||
detail::is_implicitly_convertible<T, typename T::eval_type>::value ||
detail::is_implicitly_convertible<
T, madness::Future<typename T::eval_type>>::value)>::type> {
typedef typename T::eval_type type;
static constexpr bool is_consumable = false;
static constexpr bool nonblocking =
detail::is_explicitly_convertible<
T, madness::Future<typename T::eval_type>>::value ||
detail::is_implicitly_convertible<
T, madness::Future<typename T::eval_type>>::value;
}; // struct eval_trait
} // namespace detail
/// Determine the object type used in the evaluation of tensor expressions
/// This trait class allows user to specify the object type used in an
/// expression by providing a (partial) template specialization of this class
/// for a user defined tile types. The default implementation uses
/// `T::eval_type` the evaluation type, if no specialization has been
/// provided. If no specialization is provided and the tile does not define
/// an `eval_type`, the tile is not treated as a lazy tile. This class also
/// provides the `is_consumable` flag that indicates if the evaluated tile
/// object is consumable.
/// \tparam T The lazy tile type
template <typename T>
struct eval_trait : public TiledArray::detail::eval_trait_base<T> {};
/// Detect lazy evaluation tiles
/// \c is_lazy_tile evaluates to \c std::true_type when T is a tile that
/// uses the lazy evaluation mechanism (i.e. when <tt>T != T::eval_type</tt>),
/// otherwise it evaluates to \c std::false_type .
/// \tparam T The tile type to test
template <typename T>
struct is_lazy_tile
: public std::integral_constant<
bool, !std::is_same<T, typename eval_trait<T>::type>::value> {};
template <typename Tile, typename Policy>
struct is_lazy_tile<DistArray<Tile, Policy>> : public std::false_type {};
/// \c is_lazy_tile_v<T> is an alias for \c is_lazy_tile<T>::value
template <typename T>
constexpr const bool is_lazy_tile_v = is_lazy_tile<T>::value;
/// Consumable tile type trait
/// This trait is used to determine if a tile type is consumable in tensor
/// arithmetic operations. That is, temporary tiles may appear on the left-
/// hand side of add-to (+=), subtract-to (-=), and multiply-to (*=)
/// operations. By default, all tile types are assumed to be
/// consumable except lazy tiles. Users should provide a (partial)
/// specialization of this `struct` to disable consumable tile operations.
/// \tparam T The tile type
template <typename T>
struct is_consumable_tile
: public std::integral_constant<bool, !is_lazy_tile<T>::value> {};
template <>
struct is_consumable_tile<ZeroTensor> : public std::false_type {};
/// \c is_consumable_tile_v<T> is an alias for \c is_consumable_tile<T>::value
template <typename T>
constexpr const bool is_consumable_tile_v = is_consumable_tile<T>::value;
/** @}*/
namespace detail {
template <typename T>
struct is_complex : public std::false_type {};
template <typename T>
struct is_complex<std::complex<T>> : public std::true_type {};
/// \c is_complex_v<T> is an alias for \c is_complex<T>::value
template <typename T>
constexpr const bool is_complex_v = is_complex<T>::value;
template <typename T, typename Enabler = void>
struct complex_t_impl;
template <typename T>
struct complex_t_impl<std::complex<T>> {
using type = std::complex<T>;
};
template <typename T>
struct complex_t_impl<T, std::enable_if_t<std::is_floating_point_v<T>>> {
using type = std::complex<T>;
};
/// evaluates to std::complex<T> if T is real, else T
/// @note specialize complex_t_impl<T> to customize the behavior for type T
template <typename T>
using complex_t = typename complex_t_impl<T>::type;
template <typename T, typename Enabler = void>
struct real_t_impl;
template <typename T>
struct real_t_impl<std::complex<T>> {
using type = T;
};
template <typename T>
struct real_t_impl<T, std::enable_if_t<std::is_floating_point_v<T>>> {
using type = T;
};
/// evaluates to U if T is std::complex<U>, or if T is real then evaluates to T
/// @note specialize real_t_impl<T> to customize the behavior for type T
template <typename T>
using real_t = typename real_t_impl<T>::type;
template <typename T>
struct is_numeric : public std::is_arithmetic<T> {};
template <typename T>
struct is_numeric<std::complex<T>> : public is_numeric<T> {};
template <>
struct is_numeric<bool> : public std::false_type {};
/// \c is_numeric_v<T> is an alias for \c is_numeric<T>::value
template <typename T>
constexpr const bool is_numeric_v = is_numeric<T>::value;
/// SFINAE type for enabling code when \c T is a numeric type
template <typename T, typename U = void>
using enable_if_numeric_t = std::enable_if_t<is_numeric_v<T>, U>;
template <typename T>
struct is_scalar : public is_numeric<T> {};
template <typename T>
struct is_scalar<std::complex<T>> : public std::false_type {};
/// \c is_scalar_v<T> is an alias for \c is_scalar_v<T>
template <typename T>
constexpr const bool is_scalar_v = is_scalar<T>::value;
template <typename T>
struct is_blas_numeric : public std::false_type {};
template <>
struct is_blas_numeric<float> : public std::true_type {};
template <>
struct is_blas_numeric<double> : public std::true_type {};
template <>
struct is_blas_numeric<std::complex<float>> : public std::true_type {};
template <>
struct is_blas_numeric<std::complex<double>> : public std::true_type {};
/// \c is_blas_numeric_v<T> is an alias for \c is_blas_numeric<T>::value
template <typename T>
constexpr const bool is_blas_numeric_v = is_blas_numeric<T>::value;
/// Detect tiles used by \c ArrayEvalImpl
/// \c is_array_tile evaluates to \c std::true_type when \c T is a \c
/// LazyArrayTile<U> , i.e. when it is a lazy tile wrapper used by e.g. \c
/// ArrayEvalImpl . otherwise it evaluates to \c std::false_type . Note that \c
/// is_array_tile<T> implies \c is_lazy_tile<T> , but \c is_lazy_tile<T> does
/// not imply \c is_array_tile<T> .
// \tparam T The tile type to test
template <typename T>
struct is_array_tile : public std::false_type {};
template <typename T, typename Op>
struct is_array_tile<TiledArray::detail::LazyArrayTile<T, Op>>
: public std::true_type {}; // struct is_array_tile
/// \c is_array_tile_v<T> is an alias for \c is_array_tile<T>::value
template <typename T>
constexpr const bool is_array_tile_v = is_array_tile<T>::value;
/// Detect a lazy evaluation tile that are not a \c LazyArrayTile
/// \c is_non_array_lazy_tile evaluates to \c std::true_type when T is a
/// tile that uses the lazy evaluation mechanism (i.e. when
/// <tt>T != T::eval_type</tt>), and not a \c LazyArrayTile , otherwise it
/// evaluates to \c std::false_type .
/// \tparam T The tile type to test
template <typename T>
struct is_non_array_lazy_tile
: public std::integral_constant<bool, is_lazy_tile<T>::value &&
(!is_array_tile<T>::value)> {
}; // struct is_non_array_lazy_tile
/// \c is_non_array_lazy_tile_v<T> is an alias for \c
/// is_non_array_lazy_tile<T>::value
template <typename T>
constexpr const bool is_non_array_lazy_tile_v =
is_non_array_lazy_tile<T>::value;
/// Type trait for extracting the numeric type of tensors and arrays.
/// \tparam T The type to extract a numeric type from
/// \tparam Enabler Type used to selectively implement partial specializations
/// -# if T is numeric, numeric_type<T>::type evaluates to T
/// -# if T is not numeric and T::value_type is a valid type, will evaluate to
/// numeric_type<T::value_type>::type,
/// and so on recursively
/// -# otherwise it's undefined
template <typename T, typename Enabler = void>
struct numeric_type;
template <typename T>
struct numeric_type<T, typename std::enable_if<is_numeric_v<T>>::type> {
typedef T type;
};
template <typename T>
struct numeric_type<
T, typename std::enable_if<has_member_type_value_type<T>::value &&
(!is_lazy_tile<T>::value) &&
(!is_numeric_v<T>)>::type>
: public numeric_type<typename T::value_type> {};
template <typename T>
struct numeric_type<T, typename std::enable_if<is_lazy_tile<T>::value &&
!is_numeric_v<T>>::type>
: public numeric_type<typename eval_trait<T>::type> {};
/// \c numeric_t<T> is an alias for \c numeric_type<T>::type
template <typename T>
using numeric_t = typename TiledArray::detail::numeric_type<T>::type;
/// Type trait for extracting the scalar type of tensors and arrays.
/// \tparam T The type to extract a numeric type from
/// \tparam Enabler Type used to selectively implement partial
/// specializations
/// -# if T is a scalar type, i.e. \c is_scalar_v<T> is true (e.g. \c
/// int or \c float), \c scalar_type<T>::type evaluates to \c T
/// -# if T is std::complex<U>, scalar_type<T>::type evaluates to U
/// -# if T is not a scalar or complex type, will evaluate to \c
/// scalar_type<numeric_type<T>::type>::type, and so on recursively
/// -# otherwise it's undefined
template <typename T, typename Enabler = void>
struct scalar_type;
template <typename T>
struct scalar_type<T, typename std::enable_if<is_scalar_v<T>>::type> {
typedef T type;
};
template <typename T>
struct scalar_type<std::complex<T>, void> : public scalar_type<T> {};
template <typename T>
struct scalar_type<T, typename std::enable_if<!is_numeric_v<T>>::type>
: public scalar_type<typename numeric_type<T>::type> {};
/// \c scalar_t<T> is an alias for \c scalar_type<T>::type
template <typename T>
using scalar_t = typename TiledArray::detail::scalar_type<T>::type;
/// is true type if `T::rebind_t<Element>` is defined
template <typename T, typename Element, typename = void>
struct has_rebind : std::false_type {};
template <typename T, typename Element>
struct has_rebind<T, Element,
std::void_t<typename T::template rebind_t<Element>>>
: std::true_type {};
/// alias to has_rebind<T, Element>::value
template <typename T, typename Element>
inline constexpr bool has_rebind_v = has_rebind<T, Element>::value;
/// is true type if `T::rebind_numeric_t<Numeric>` is defined
template <typename T, typename Numeric, typename = void>
struct has_rebind_numeric : std::false_type {};
template <typename T, typename Numeric>
struct has_rebind_numeric<
T, Numeric, std::void_t<typename T::template rebind_numeric_t<Numeric>>>
: std::true_type {};
/// alias to has_rebind_numeric<T, Element>::value
template <typename T, typename Element>
inline constexpr bool has_rebind_numeric_v =
has_rebind_numeric<T, Element>::value;
template <typename T>
struct is_strictly_ordered_helper {
using Yes = char;
using No = int;
template <typename U>
static auto test(void *)
-> decltype(std::add_pointer_t<decltype(std::declval<U>() <
std::declval<U>())>{},
Yes{});
template <typename...>
static No test(...);
public:
static constexpr const bool value = sizeof(test<T>(0)) == sizeof(Yes);
};
///////// is_less_than_comparable /////////
template <typename T, typename = std::void_t<>>
struct is_less_than_comparable : public std::false_type {};
template <typename T>
struct is_less_than_comparable<T,
std::void_t<decltype(std::declval<const T &>() <
std::declval<const T &>())>>
: public std::true_type {};
template <typename T>
static constexpr bool is_less_than_comparable_v =
is_less_than_comparable<T>::value;
///////// are_less_than_comparable /////////
template <typename T, typename U, typename = std::void_t<>>
struct are_less_than_comparable : public std::false_type {};
template <typename T, typename U>
struct are_less_than_comparable<
T, U,
std::void_t<decltype(std::declval<const T &>() <
std::declval<const U &>())>> : public std::true_type {
};
template <typename T, typename U>
static constexpr bool are_less_than_comparable_v =
are_less_than_comparable<T, U>::value;
///////// is_less_than_or_equal_comparable /////////
template <typename T, typename = std::void_t<>>
struct is_less_than_or_equal_comparable : public std::false_type {};
template <typename T>
struct is_less_than_or_equal_comparable<
T, std::void_t<decltype(std::declval<const T &>() <=
std::declval<const T &>())>>
: public std::true_type {};
template <typename T>
static constexpr bool is_less_than_or_equal_comparable_v =
is_less_than_or_equal_comparable<T>::value;
///////// are_less_than_comparable /////////
template <typename T, typename U, typename = std::void_t<>>
struct are_less_than_or_equal_comparable : public std::false_type {};
template <typename T, typename U>
struct are_less_than_or_equal_comparable<
T, U,
std::void_t<decltype(std::declval<const T &>() <=
std::declval<const U &>())>> : public std::true_type {
};
template <typename T, typename U>
static constexpr bool are_less_than_or_equal_comparable_v =
are_less_than_or_equal_comparable<T, U>::value;
///////// is_greater_than_comparable /////////
template <typename T, typename = std::void_t<>>
struct is_greater_than_comparable : public std::false_type {};
template <typename T>
struct is_greater_than_comparable<
T, std::void_t<decltype(std::declval<const T &>() >
std::declval<const T &>())>>
: public std::true_type {};
template <typename T>
static constexpr bool is_greater_than_comparable_v =
is_greater_than_comparable<T>::value;
///////// are_greater_than_comparable /////////
template <typename T, typename U, typename = std::void_t<>>
struct are_greater_than_comparable : public std::false_type {};
template <typename T, typename U>
struct are_greater_than_comparable<
T, U,
std::void_t<decltype(std::declval<const T &>() >
std::declval<const U &>())>> : public std::true_type {
};
template <typename T, typename U>
static constexpr bool are_greater_than_comparable_v =
are_greater_than_comparable<T, U>::value;
///////// is_greater_than_or_equal_comparable /////////
template <typename T, typename = std::void_t<>>
struct is_greater_than_or_equal_comparable : public std::false_type {};
template <typename T>
struct is_greater_than_or_equal_comparable<
T, std::void_t<decltype(std::declval<const T &>() >=
std::declval<const T &>())>>
: public std::true_type {};
template <typename T>
static constexpr bool is_greater_than_or_equal_comparable_v =
is_greater_than_or_equal_comparable<T>::value;
///////// are_greater_than_comparable /////////
template <typename T, typename U, typename = std::void_t<>>