forked from duneroadrunner/SaferCPlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsescope.h
2069 lines (1783 loc) · 99.8 KB
/
msescope.h
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
// Copyright (c) 2015 Noah Lopez
// Use, modification, and distribution is subject to 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)
#pragma once
#ifndef MSESCOPE_H_
#define MSESCOPE_H_
//include "mseprimitives.h"
#include "msepointerbasics.h"
#include <utility>
#include <unordered_set>
#include <functional>
#include <cassert>
#ifdef _MSC_VER
#pragma warning( push )
#pragma warning( disable : 4100 4456 4189 )
#endif /*_MSC_VER*/
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
#pragma clang diagnostic ignored "-Wunused-function"
#pragma clang diagnostic ignored "-Wunused-value"
#else /*__clang__*/
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#pragma GCC diagnostic ignored "-Wunused-value"
#endif /*__GNUC__*/
#endif /*__clang__*/
/* Defining MSE_SCOPEPOINTER_USE_RELAXED_REGISTERED will cause relaxed registered pointers to be used to help catch
misuse of scope pointers in debug mode. Additionally defining MSE_SCOPEPOINTER_RUNTIME_CHECKS_ENABLED will cause
mse::TRelaxedRegisteredObj to be used in non-debug modes as well. */
#ifdef MSE_SCOPEPOINTER_USE_RELAXED_REGISTERED
#include "mserelaxedregistered.h"
#endif // MSE_SCOPEPOINTER_USE_RELAXED_REGISTERED
#if defined(MSE_SAFER_SUBSTITUTES_DISABLED) || defined(MSE_SAFERPTR_DISABLED)
#define MSE_SCOPEPOINTER_DISABLED
#endif /*defined(MSE_SAFER_SUBSTITUTES_DISABLED) || defined(MSE_SAFERPTR_DISABLED)*/
/* Note that by default, MSE_SCOPEPOINTER_DISABLED is defined in non-debug builds. This is enacted in "msepointerbasics.h". */
#ifndef _NOEXCEPT
#define _NOEXCEPT
#endif /*_NOEXCEPT*/
namespace mse {
/* This macro roughly simulates constructor inheritance. */
#define MSE_SCOPE_USING(Derived, Base) MSE_USING(Derived, Base)
template<typename _Ty> class TScopeID {};
/* moved to msepointerbasics.h */
//class XScopeTagBase { public: void xscope_tag() const {} };
/* Note that objects not derived from ReferenceableByScopePointerTagBase might still be targeted by a scope pointer via
make_pointer_to_member(). */
class ReferenceableByScopePointerTagBase {};
class ContainsNonOwningScopeReferenceTagBase {};
class XScopeContainsNonOwningScopeReferenceTagBase : public ContainsNonOwningScopeReferenceTagBase, public XScopeTagBase {};
template<typename _Ty>
class TPlaceHolder_msescope {};
template<typename _Ty>
class TPlaceHolder2_msescope {};
template<typename T>
struct HasXScopeReturnableTagMethod
{
template<typename U, void(U::*)() const> struct SFINAE {};
template<typename U> static char Test(SFINAE<U, &U::xscope_returnable_tag>*);
template<typename U> static int Test(...);
static const bool Has = (sizeof(Test<T>(0)) == sizeof(char));
};
/*
template<typename T>
struct HasXScopeNotReturnableTagMethod
{
template<typename U, void(U::*)() const> struct SFINAE {};
template<typename U> static char Test(SFINAE<U, &U::xscope_not_returnable_tag>*);
template<typename U> static int Test(...);
static const bool Has = (sizeof(Test<T>(0)) == sizeof(char));
};
*/
/* determines if a given type is an instantiation of a given template */
template<typename T, template<typename> class TT>
struct is_instantiation_of_msescope : std::false_type { };
template<typename T, template<typename> class TT>
struct is_instantiation_of_msescope<TT<T>, TT> : std::true_type { };
#ifdef MSE_SCOPEPOINTER_DISABLED
//TScopeID
template<typename _Ty> using TXScopePointer = _Ty*;
template<typename _Ty> using TXScopeConstPointer = const _Ty*;
template<typename _Ty> using TXScopeNotNullPointer = _Ty*;
template<typename _Ty> using TXScopeNotNullConstPointer = const _Ty*;
template<typename _Ty> using TXScopeFixedPointer = _Ty*;
template<typename _Ty> using TXScopeFixedConstPointer = const _Ty*;
template<typename _TROy> using TXScopeObjBase = _TROy;
template<typename _TROy> using TXScopeObj = _TROy;
template<typename _Ty> using TXScopeItemFixedPointer = _Ty*;
template<typename _Ty> using TXScopeItemFixedConstPointer = const _Ty*;
template<typename _Ty> using TXScopeCagedItemFixedPointerToRValue = _Ty*;
template<typename _Ty> using TXScopeCagedItemFixedConstPointerToRValue = const _Ty*;
//template<typename _TROy> using TXScopeReturnValue = _TROy;
template<typename _TROy> class TXScopeOwnerPointer;
template<typename _Ty> auto xscope_ifptr_to(_Ty&& _X) { return std::addressof(_X); }
template<typename _Ty> auto xscope_ifptr_to(const _Ty& _X) { return std::addressof(_X); }
//template<typename _Ty> const _Ty& return_value(const _Ty& _X) { return _X; }
//template<typename _Ty> _Ty&& return_value(_Ty&& _X) { return std::forward<decltype(_X)>(_X); }
template<typename _TROy> using TNonXScopeObj = _TROy;
#else /*MSE_SCOPEPOINTER_DISABLED*/
#ifdef MSE_SCOPEPOINTER_USE_RELAXED_REGISTERED
template<typename _Ty> using TXScopePointerBase = mse::TRelaxedRegisteredPointer<_Ty>;
template<typename _Ty> using TXScopeConstPointerBase = mse::TRelaxedRegisteredConstPointer<_Ty>;
template<typename _TROz> using TXScopeObjBase = mse::TRelaxedRegisteredObj<_TROz>;
#else // MSE_SCOPEPOINTER_USE_RELAXED_REGISTERED
template<typename _Ty> using TXScopePointerBase = TPointerForLegacy<_Ty, TScopeID<const _Ty>>;
template<typename _Ty> using TXScopeConstPointerBase = TPointerForLegacy<const _Ty, TScopeID<const _Ty>>;
template<typename _TROz>
class TXScopeObjBase : public _TROz {
public:
MSE_SCOPE_USING(TXScopeObjBase, _TROz);
TXScopeObjBase(const TXScopeObjBase& _X) : _TROz(_X) {}
TXScopeObjBase(TXScopeObjBase&& _X) : _TROz(std::forward<decltype(_X)>(_X)) {}
TXScopeObjBase& operator=(TXScopeObjBase&& _X) { _TROz::operator=(std::forward<decltype(_X)>(_X)); return (*this); }
TXScopeObjBase& operator=(const TXScopeObjBase& _X) { _TROz::operator=(_X); return (*this); }
template<class _Ty2>
TXScopeObjBase& operator=(_Ty2&& _X) { _TROz::operator=(std::forward<decltype(_X)>(_X)); return (*this); }
template<class _Ty2>
TXScopeObjBase& operator=(const _Ty2& _X) { _TROz::operator=(_X); return (*this); }
};
#endif // MSE_SCOPEPOINTER_USE_RELAXED_REGISTERED
template <class _Ty, class _Ty2, class = typename std::enable_if<
(!std::is_same<_Ty&&, _Ty2>::value) || (!std::is_rvalue_reference<_Ty2>::value)
, void>::type>
static void valid_if_not_rvalue_reference_of_given_type(_Ty2 src) {}
template<typename _Ty> class TXScopeObj;
template<typename _Ty> class TXScopeNotNullPointer;
template<typename _Ty> class TXScopeNotNullConstPointer;
template<typename _Ty> class TXScopeFixedPointer;
template<typename _Ty> class TXScopeFixedConstPointer;
template<typename _Ty> class TXScopeOwnerPointer;
template<typename _Ty> class TXScopeItemFixedPointer;
template<typename _Ty> class TXScopeItemFixedConstPointer;
template<typename _Ty> class TXScopeCagedItemFixedPointerToRValue;
template<typename _Ty> class TXScopeCagedItemFixedConstPointerToRValue;
namespace rsv {
template<typename _Ty> class TXScopeItemFixedPointerFParam;
template<typename _Ty> class TXScopeItemFixedConstPointerFParam;
}
/* Use TXScopeFixedPointer instead. */
template<typename _Ty>
class TXScopePointer : public TXScopePointerBase<_Ty>, public XScopeContainsNonOwningScopeReferenceTagBase, public StrongPointerNotAsyncShareableTagBase {
public:
private:
TXScopePointer() : TXScopePointerBase<_Ty>() {}
TXScopePointer(TXScopeObj<_Ty>* ptr) : TXScopePointerBase<_Ty>(ptr) {}
TXScopePointer(const TXScopePointer& src_cref) : TXScopePointerBase<_Ty>(src_cref) {}
template<class _Ty2, class = typename std::enable_if<std::is_convertible<_Ty2 *, _Ty *>::value, void>::type>
TXScopePointer(const TXScopePointer<_Ty2>& src_cref) : TXScopePointerBase<_Ty>(TXScopePointerBase<_Ty2>(src_cref)) {}
virtual ~TXScopePointer() {}
TXScopePointer<_Ty>& operator=(TXScopeObj<_Ty>* ptr) {
return TXScopePointerBase<_Ty>::operator=(ptr);
}
TXScopePointer<_Ty>& operator=(const TXScopePointer<_Ty>& _Right_cref) {
return TXScopePointerBase<_Ty>::operator=(_Right_cref);
}
operator bool() const {
bool retval = ((*static_cast<const TXScopePointerBase<_Ty>*>(this)) != nullptr);
return retval;
}
/* This native pointer cast operator is just for compatibility with existing/legacy code and ideally should never be used. */
explicit operator _Ty*() const {
_Ty* retval = (*static_cast<const TXScopePointerBase<_Ty>*>(this));
return retval;
}
explicit operator TXScopeObj<_Ty>*() const {
TXScopeObj<_Ty>* retval = (*static_cast<const TXScopePointerBase<_Ty>*>(this));
return retval;
}
TXScopePointer<_Ty>* operator&() { return this; }
const TXScopePointer<_Ty>* operator&() const { return this; }
friend class TXScopeNotNullPointer<_Ty>;
};
/* Use TXScopeFixedConstPointer instead. */
template<typename _Ty>
class TXScopeConstPointer : public TXScopeConstPointerBase<const _Ty>, public XScopeContainsNonOwningScopeReferenceTagBase, public StrongPointerNotAsyncShareableTagBase {
public:
private:
TXScopeConstPointer() : TXScopeConstPointerBase<const _Ty>() {}
TXScopeConstPointer(const TXScopeObj<_Ty>* ptr) : TXScopeConstPointerBase<const _Ty>(ptr) {}
TXScopeConstPointer(const TXScopeConstPointer& src_cref) : TXScopeConstPointerBase<const _Ty>(src_cref) {}
template<class _Ty2, class = typename std::enable_if<std::is_convertible<_Ty2 *, _Ty *>::value, void>::type>
TXScopeConstPointer(const TXScopeConstPointer<_Ty2>& src_cref) : TXScopeConstPointerBase<const _Ty>(src_cref) {}
TXScopeConstPointer(const TXScopePointer<_Ty>& src_cref) : TXScopeConstPointerBase<const _Ty>(src_cref) {}
template<class _Ty2, class = typename std::enable_if<std::is_convertible<_Ty2 *, _Ty *>::value, void>::type>
TXScopeConstPointer(const TXScopePointer<_Ty2>& src_cref) : TXScopeConstPointerBase<const _Ty>(TXScopeConstPointerBase<_Ty2>(src_cref)) {}
virtual ~TXScopeConstPointer() {}
TXScopeConstPointer<_Ty>& operator=(const TXScopeObj<_Ty>* ptr) {
return TXScopeConstPointerBase<_Ty>::operator=(ptr);
}
TXScopeConstPointer<_Ty>& operator=(const TXScopeConstPointer<_Ty>& _Right_cref) {
return TXScopeConstPointerBase<_Ty>::operator=(_Right_cref);
}
TXScopeConstPointer<_Ty>& operator=(const TXScopePointer<_Ty>& _Right_cref) { return (*this).operator=(TXScopeConstPointer(_Right_cref)); }
operator bool() const {
bool retval = (*static_cast<const TXScopeConstPointerBase<_Ty>*>(this));
return retval;
}
/* This native pointer cast operator is just for compatibility with existing/legacy code and ideally should never be used. */
explicit operator const _Ty*() const {
const _Ty* retval = (*static_cast<const TXScopeConstPointerBase<const _Ty>*>(this));
return retval;
}
explicit operator const TXScopeObj<_Ty>*() const {
const TXScopeObj<_Ty>* retval = (*static_cast<const TXScopeConstPointerBase<const _Ty>*>(this));
return retval;
}
TXScopeConstPointer<_Ty>* operator&() { return this; }
const TXScopeConstPointer<_Ty>* operator&() const { return this; }
friend class TXScopeNotNullConstPointer<_Ty>;
};
/* Use TXScopeFixedPointer instead. */
template<typename _Ty>
class TXScopeNotNullPointer : public TXScopePointer<_Ty> {
public:
private:
TXScopeNotNullPointer(TXScopeObj<_Ty>* ptr) : TXScopePointer<_Ty>(ptr) {}
TXScopeNotNullPointer(const TXScopeNotNullPointer& src_cref) : TXScopePointer<_Ty>(src_cref) {}
template<class _Ty2, class = typename std::enable_if<std::is_convertible<_Ty2 *, _Ty *>::value, void>::type>
TXScopeNotNullPointer(const TXScopeNotNullPointer<_Ty2>& src_cref) : TXScopePointer<_Ty>(src_cref) {}
virtual ~TXScopeNotNullPointer() {}
TXScopeNotNullPointer<_Ty>& operator=(const TXScopePointer<_Ty>& _Right_cref) {
TXScopePointer<_Ty>::operator=(_Right_cref);
return (*this);
}
operator bool() const { return (*static_cast<const TXScopePointer<_Ty>*>(this)); }
/* This native pointer cast operator is just for compatibility with existing/legacy code and ideally should never be used. */
explicit operator _Ty*() const { return TXScopePointer<_Ty>::operator _Ty*(); }
explicit operator TXScopeObj<_Ty>*() const { return TXScopePointer<_Ty>::operator TXScopeObj<_Ty>*(); }
TXScopeNotNullPointer<_Ty>* operator&() { return this; }
const TXScopeNotNullPointer<_Ty>* operator&() const { return this; }
friend class TXScopeFixedPointer<_Ty>;
};
/* Use TXScopeFixedConstPointer instead. */
template<typename _Ty>
class TXScopeNotNullConstPointer : public TXScopeConstPointer<_Ty> {
public:
private:
TXScopeNotNullConstPointer(const TXScopeNotNullConstPointer<_Ty>& src_cref) : TXScopeConstPointer<_Ty>(src_cref) {}
template<class _Ty2, class = typename std::enable_if<std::is_convertible<_Ty2 *, _Ty *>::value, void>::type>
TXScopeNotNullConstPointer(const TXScopeNotNullConstPointer<_Ty2>& src_cref) : TXScopeConstPointer<_Ty>(src_cref) {}
TXScopeNotNullConstPointer(const TXScopeNotNullPointer<_Ty>& src_cref) : TXScopeConstPointer<_Ty>(src_cref) {}
template<class _Ty2, class = typename std::enable_if<std::is_convertible<_Ty2 *, _Ty *>::value, void>::type>
TXScopeNotNullConstPointer(const TXScopeNotNullPointer<_Ty2>& src_cref) : TXScopeConstPointer<_Ty>(src_cref) {}
virtual ~TXScopeNotNullConstPointer() {}
operator bool() const { return (*static_cast<const TXScopeConstPointer<_Ty>*>(this)); }
/* This native pointer cast operator is just for compatibility with existing/legacy code and ideally should never be used. */
explicit operator const _Ty*() const { return TXScopeConstPointer<_Ty>::operator const _Ty*(); }
explicit operator const TXScopeObj<_Ty>*() const { return TXScopeConstPointer<_Ty>::operator const TXScopeObj<_Ty>*(); }
TXScopeNotNullConstPointer(const TXScopeObj<_Ty>* ptr) : TXScopeConstPointer<_Ty>(ptr) {}
TXScopeNotNullConstPointer<_Ty>* operator&() { return this; }
const TXScopeNotNullConstPointer<_Ty>* operator&() const { return this; }
friend class TXScopeFixedConstPointer<_Ty>;
};
/* A TXScopeFixedPointer points to a TXScopeObj. Its intended for very limited use. Basically just to pass a TXScopeObj
by reference as a function parameter. TXScopeFixedPointers can be obtained from TXScopeObj's "&" (address of) operator. */
template<typename _Ty>
class TXScopeFixedPointer : public TXScopeNotNullPointer<_Ty> {
public:
TXScopeFixedPointer(const TXScopeFixedPointer& src_cref) : TXScopeNotNullPointer<_Ty>(src_cref) {}
template<class _Ty2, class = typename std::enable_if<std::is_convertible<_Ty2 *, _Ty *>::value, void>::type>
TXScopeFixedPointer(const TXScopeFixedPointer<_Ty2>& src_cref) : TXScopeNotNullPointer<_Ty>(src_cref) {}
virtual ~TXScopeFixedPointer() {}
operator bool() const { return (*static_cast<const TXScopeNotNullPointer<_Ty>*>(this)); }
/* This native pointer cast operator is just for compatibility with existing/legacy code and ideally should never be used. */
explicit operator _Ty*() const { return TXScopeNotNullPointer<_Ty>::operator _Ty*(); }
explicit operator TXScopeObj<_Ty>*() const { return TXScopeNotNullPointer<_Ty>::operator TXScopeObj<_Ty>*(); }
void xscope_tag() const {}
private:
TXScopeFixedPointer(TXScopeObj<_Ty>* ptr) : TXScopeNotNullPointer<_Ty>(ptr) {}
#ifdef MSE_SCOPE_DISABLE_MOVE_RESTRICTIONS
/* Disabling public move construction prevents some unsafe operations, like some, but not all,
attempts to use a TXScopeFixedPointer<> as a return value. But it also prevents some safe
operations too, like initialization via '=' (assignment operator). And the set of prevented
operations might not be consistent across compilers. We're deciding here that the minor safety
benefits outweigh the minor inconveniences. Note that we can't disable public move construction
in the other scope pointers as it would interfere with implicit conversions. */
TXScopeFixedPointer(TXScopeFixedPointer&& src_ref) : TXScopeNotNullPointer<_Ty>(src_ref) {
int q = 5;
}
#endif // !MSE_SCOPE_DISABLE_MOVE_RESTRICTIONS
TXScopeFixedPointer<_Ty>& operator=(const TXScopeFixedPointer<_Ty>& _Right_cref) = delete;
void* operator new(size_t size) { return ::operator new(size); }
TXScopeFixedPointer<_Ty>* operator&() { return this; }
const TXScopeFixedPointer<_Ty>* operator&() const { return this; }
friend class TXScopeObj<_Ty>;
};
template<typename _Ty>
class TXScopeFixedConstPointer : public TXScopeNotNullConstPointer<_Ty> {
public:
TXScopeFixedConstPointer(const TXScopeFixedConstPointer<_Ty>& src_cref) : TXScopeNotNullConstPointer<_Ty>(src_cref) {}
template<class _Ty2, class = typename std::enable_if<std::is_convertible<_Ty2 *, _Ty *>::value, void>::type>
TXScopeFixedConstPointer(const TXScopeFixedConstPointer<_Ty2>& src_cref) : TXScopeNotNullConstPointer<_Ty>(src_cref) {}
TXScopeFixedConstPointer(const TXScopeFixedPointer<_Ty>& src_cref) : TXScopeNotNullConstPointer<_Ty>(src_cref) {}
template<class _Ty2, class = typename std::enable_if<std::is_convertible<_Ty2 *, _Ty *>::value, void>::type>
TXScopeFixedConstPointer(const TXScopeFixedPointer<_Ty2>& src_cref) : TXScopeNotNullConstPointer<_Ty>(src_cref) {}
virtual ~TXScopeFixedConstPointer() {}
operator bool() const { return (*static_cast<const TXScopeNotNullConstPointer<_Ty>*>(this)); }
/* This native pointer cast operator is just for compatibility with existing/legacy code and ideally should never be used. */
explicit operator const _Ty*() const { return TXScopeNotNullConstPointer<_Ty>::operator const _Ty*(); }
explicit operator const TXScopeObj<_Ty>*() const { return TXScopeNotNullConstPointer<_Ty>::operator const TXScopeObj<_Ty>*(); }
void xscope_tag() const {}
private:
TXScopeFixedConstPointer(const TXScopeObj<_Ty>* ptr) : TXScopeNotNullConstPointer<_Ty>(ptr) {}
TXScopeFixedConstPointer<_Ty>& operator=(const TXScopeFixedConstPointer<_Ty>& _Right_cref) = delete;
void* operator new(size_t size) { return ::operator new(size); }
TXScopeFixedConstPointer<_Ty>* operator&() { return this; }
const TXScopeFixedConstPointer<_Ty>* operator&() const { return this; }
friend class TXScopeObj<_Ty>;
};
/* TXScopeObj is intended as a transparent wrapper for other classes/objects with "scope lifespans". That is, objects
that are either allocated on the stack, or whose "owning" pointer is allocated on the stack. Unfortunately it's not
really possible to completely prevent misuse. For example, std::list<TXScopeObj<mse::CInt>> is an improper, and
dangerous, use of TXScopeObj<>. So we provide the option of using an mse::TRelaxedRegisteredObj as TXScopeObj's base
class to enforce safety and to help catch misuse. Defining MSE_SCOPEPOINTER_USE_RELAXED_REGISTERED will cause
mse::TRelaxedRegisteredObj to be used in non-debug modes as well. */
template<typename _TROy>
class TXScopeObj : public TXScopeObjBase<_TROy>
, public std::conditional<std::is_base_of<XScopeTagBase, _TROy>::value, TPlaceHolder_msescope<TXScopeObj<_TROy> >, XScopeTagBase>::type
, public std::conditional<std::is_base_of<ReferenceableByScopePointerTagBase, _TROy>::value, TPlaceHolder2_msescope<TXScopeObj<_TROy> >, ReferenceableByScopePointerTagBase>::type
{
public:
TXScopeObj(const TXScopeObj& _X) : TXScopeObjBase<_TROy>(_X) {}
#ifdef MSE_SCOPE_DISABLE_MOVE_RESTRICTIONS
explicit TXScopeObj(TXScopeObj&& _X) : TXScopeObjBase<_TROy>(std::forward<decltype(_X)>(_X)) {}
#endif // !MSE_SCOPE_DISABLE_MOVE_RESTRICTIONS
MSE_SCOPE_USING(TXScopeObj, TXScopeObjBase<_TROy>);
virtual ~TXScopeObj() {}
TXScopeObj& operator=(TXScopeObj&& _X) {
valid_if_not_rvalue_reference_of_given_type<TXScopeObj, decltype(_X)>(_X);
TXScopeObjBase<_TROy>::operator=(std::forward<decltype(_X)>(_X));
return (*this);
}
TXScopeObj& operator=(const TXScopeObj& _X) { TXScopeObjBase<_TROy>::operator=(_X); return (*this); }
template<class _Ty2>
TXScopeObj& operator=(_Ty2&& _X) {
TXScopeObjBase<_TROy>::operator=(std::forward<decltype(_X)>(_X));
return (*this);
}
template<class _Ty2>
TXScopeObj& operator=(const _Ty2& _X) { TXScopeObjBase<_TROy>::operator=(_X); return (*this); }
const TXScopeFixedPointer<_TROy> operator&() & {
return this;
}
const TXScopeFixedConstPointer<_TROy> operator&() const & {
return this;
}
const TXScopeItemFixedPointer<_TROy> mse_xscope_ifptr() & { return &(*this); }
const TXScopeItemFixedConstPointer<_TROy> mse_xscope_ifptr() const & { return &(*this); }
TXScopeCagedItemFixedConstPointerToRValue<_TROy> operator&() && {
return TXScopeItemFixedConstPointer<_TROy>(TXScopeFixedPointer<_TROy>(this));
}
TXScopeCagedItemFixedConstPointerToRValue<_TROy> operator&() const && {
return TXScopeFixedConstPointer<_TROy>(TXScopeConstPointer<_TROy>(this));
}
const TXScopeCagedItemFixedConstPointerToRValue<_TROy> mse_xscope_ifptr() && { return &(*this); }
const TXScopeCagedItemFixedConstPointerToRValue<_TROy> mse_xscope_ifptr() const && { return &(*this); }
void xscope_tag() const {}
//void xscope_contains_accessible_scope_address_of_operator_tag() const {}
/* This type can be safely used as a function return value if _Ty is also safely returnable. */
template<class _Ty2 = _TROy, class = typename std::enable_if<(std::is_same<_Ty2, _TROy>::value) && (
(std::integral_constant<bool, HasXScopeReturnableTagMethod<_Ty2>::Has>()) || (!std::is_base_of<XScopeTagBase, _Ty2>::value)
), void>::type>
void xscope_returnable_tag() const {} /* Indication that this type is can be used as a function return value. */
private:
void* operator new(size_t size) { return ::operator new(size); }
friend class TXScopeOwnerPointer<_TROy>;
};
template<typename _Ty>
auto xscope_ifptr_to(_Ty&& _X) {
return _X.mse_xscope_ifptr();
}
template<typename _Ty>
auto xscope_ifptr_to(const _Ty& _X) {
return _X.mse_xscope_ifptr();
}
namespace us {
/* A couple of unsafe functions for internal use. */
template<typename _Ty>
TXScopeItemFixedPointer<_Ty> unsafe_make_xscope_pointer_to(_Ty& ref);
template<typename _Ty>
TXScopeItemFixedConstPointer<_Ty> unsafe_make_xscope_const_pointer_to(const _Ty& cref);
}
/* While TXScopeFixedPointer<> points to a TXScopeObj<>, TXScopeItemFixedPointer<> is intended to be able to point to a
TXScopeObj<>, any member of a TXScopeObj<>, or various other items with scope lifetime that, for various reasons, aren't
declared as TXScopeObj<>. */
template<typename _Ty>
class TXScopeItemFixedPointer : public TXScopePointerBase<_Ty>, public XScopeContainsNonOwningScopeReferenceTagBase, public StrongPointerNotAsyncShareableTagBase {
public:
TXScopeItemFixedPointer(const TXScopeItemFixedPointer& src_cref) = default;
template<class _Ty2, class = typename std::enable_if<std::is_convertible<_Ty2 *, _Ty *>::value, void>::type>
TXScopeItemFixedPointer(const TXScopeItemFixedPointer<_Ty2>& src_cref) : TXScopePointerBase<_Ty>(static_cast<const TXScopePointerBase<_Ty2>&>(src_cref)) {}
TXScopeItemFixedPointer(const TXScopeFixedPointer<_Ty>& src_cref) : TXScopeItemFixedPointer(std::addressof(*src_cref)) {}
template<class _Ty2, class = typename std::enable_if<std::is_convertible<_Ty2 *, _Ty *>::value, void>::type>
TXScopeItemFixedPointer(const TXScopeFixedPointer<_Ty2>& src_cref) : TXScopeItemFixedPointer(static_cast<const TXScopeFixedPointer<_Ty>&>(src_cref)) {}
//TXScopeItemFixedPointer(const TXScopeOwnerPointer<_Ty>& src_cref) : TXScopeItemFixedPointer(&(*src_cref)) {}
template<class _Ty2, class = typename std::enable_if<std::is_convertible<_Ty2 *, _Ty *>::value, void>::type>
TXScopeItemFixedPointer(const TXScopeOwnerPointer<_Ty2>& src_cref) : TXScopeItemFixedPointer(&(*src_cref)) {}
//template<class _Ty2, class = typename std::enable_if<std::is_convertible<_Ty2 *, _Ty *>::value, void>::type>
//TXScopeItemFixedPointer(const TXScopeWeakFixedPointer<_Ty, _Ty2>& src_cref) : TXScopeItemFixedPointer(std::addressof(*src_cref)) {}
virtual ~TXScopeItemFixedPointer() {}
//operator bool() const { return (*static_cast<const TXScopePointerBase<_Ty>*>(this)); }
/* This native pointer cast operator is just for compatibility with existing/legacy code and ideally should never be used. */
explicit operator _Ty*() const { return TXScopePointerBase<_Ty>::operator _Ty*(); }
void xscope_tag() const {}
private:
TXScopeItemFixedPointer(_Ty* ptr) : TXScopePointerBase<_Ty>(ptr) {}
TXScopeItemFixedPointer<_Ty>& operator=(const TXScopeItemFixedPointer<_Ty>& _Right_cref) = delete;
void* operator new(size_t size) { return ::operator new(size); }
TXScopeItemFixedPointer<_Ty>* operator&() { return this; }
const TXScopeItemFixedPointer<_Ty>* operator&() const { return this; }
/* These versions of make_xscope_pointer_to_member() are actually now deprecated. */
template<class _TTargetType, class _Ty2>
friend TXScopeItemFixedPointer<_TTargetType> make_xscope_pointer_to_member(_TTargetType& target, const TXScopeFixedPointer<_Ty2> &lease_pointer);
template<class _TTargetType, class _Ty2>
friend TXScopeItemFixedPointer<_TTargetType> make_xscope_pointer_to_member(_TTargetType& target, const TXScopeItemFixedPointer<_Ty2> &lease_pointer);
template<class _Ty2> friend TXScopeItemFixedPointer<_Ty2> us::unsafe_make_xscope_pointer_to(_Ty2& ref);
};
template<typename _Ty>
class TXScopeItemFixedConstPointer : public TXScopeConstPointerBase<_Ty>, public XScopeContainsNonOwningScopeReferenceTagBase, public StrongPointerNotAsyncShareableTagBase {
public:
TXScopeItemFixedConstPointer(const TXScopeItemFixedConstPointer<_Ty>& src_cref) = default;
template<class _Ty2, class = typename std::enable_if<std::is_convertible<_Ty2 *, _Ty *>::value, void>::type>
TXScopeItemFixedConstPointer(const TXScopeItemFixedConstPointer<_Ty2>& src_cref) : TXScopeConstPointerBase<_Ty>(static_cast<const TXScopeConstPointerBase<_Ty2>&>(src_cref)) {}
TXScopeItemFixedConstPointer(const TXScopeItemFixedPointer<_Ty>& src_cref) : TXScopeConstPointerBase<_Ty>(src_cref) {}
template<class _Ty2, class = typename std::enable_if<std::is_convertible<_Ty2 *, _Ty *>::value, void>::type>
TXScopeItemFixedConstPointer(const TXScopeItemFixedPointer<_Ty2>& src_cref) : TXScopeConstPointerBase<_Ty>(TXScopeConstPointerBase<_Ty2>(src_cref)) {}
TXScopeItemFixedConstPointer(const TXScopeFixedConstPointer<_Ty>& src_cref) : TXScopeItemFixedConstPointer(std::addressof(*src_cref)) {}
template<class _Ty2, class = typename std::enable_if<std::is_convertible<_Ty2 *, _Ty *>::value, void>::type>
TXScopeItemFixedConstPointer(const TXScopeFixedConstPointer<_Ty2>& src_cref) : TXScopeItemFixedConstPointer(static_cast<const TXScopeFixedConstPointer<_Ty>&>(src_cref)) {}
TXScopeItemFixedConstPointer(const TXScopeFixedPointer<_Ty>& src_cref) : TXScopeItemFixedConstPointer(std::addressof(*src_cref)) {}
template<class _Ty2, class = typename std::enable_if<std::is_convertible<_Ty2 *, _Ty *>::value, void>::type>
TXScopeItemFixedConstPointer(const TXScopeFixedPointer<_Ty2>& src_cref) : TXScopeItemFixedConstPointer(static_cast<const TXScopeFixedPointer<_Ty>&>(src_cref)) {}
//TXScopeItemFixedConstPointer(const TXScopeOwnerPointer<_Ty>& src_cref) : TXScopeItemFixedConstPointer(&(*src_cref)) {}
template<class _Ty2, class = typename std::enable_if<std::is_convertible<_Ty2 *, _Ty *>::value, void>::type>
TXScopeItemFixedConstPointer(const TXScopeOwnerPointer<_Ty2>& src_cref) : TXScopeItemFixedConstPointer(&(*src_cref)) {}
virtual ~TXScopeItemFixedConstPointer() {}
//operator bool() const { return (*static_cast<const TXScopeConstPointerBase<_Ty>*>(this)); }
/* This native pointer cast operator is just for compatibility with existing/legacy code and ideally should never be used. */
explicit operator const _Ty*() const { return TXScopeConstPointerBase<_Ty>::operator const _Ty*(); }
void xscope_tag() const {}
private:
TXScopeItemFixedConstPointer(const _Ty* ptr) : TXScopeConstPointerBase<_Ty>(ptr) {}
TXScopeItemFixedConstPointer<_Ty>& operator=(const TXScopeItemFixedConstPointer<_Ty>& _Right_cref) = delete;
void* operator new(size_t size) { return ::operator new(size); }
TXScopeItemFixedConstPointer<_Ty>* operator&() { return this; }
const TXScopeItemFixedConstPointer<_Ty>* operator&() const { return this; }
/* These versions of make_xscope_pointer_to_member() are actually now deprecated. */
template<class _TTargetType, class _Ty2>
friend TXScopeItemFixedConstPointer<_TTargetType> make_xscope_pointer_to_member(const _TTargetType& target, const TXScopeFixedConstPointer<_Ty2> &lease_pointer);
template<class _TTargetType, class _Ty2>
friend TXScopeItemFixedConstPointer<_TTargetType> make_xscope_const_pointer_to_member(const _TTargetType& target, const TXScopeFixedPointer<_Ty2> &lease_pointer);
template<class _TTargetType, class _Ty2>
friend TXScopeItemFixedConstPointer<_TTargetType> make_xscope_const_pointer_to_member(const _TTargetType& target, const TXScopeFixedConstPointer<_Ty2> &lease_pointer);
template<class _TTargetType, class _Ty2>
friend TXScopeItemFixedConstPointer<_TTargetType> make_xscope_pointer_to_member(const _TTargetType& target, const TXScopeItemFixedConstPointer<_Ty2> &lease_pointer);
template<class _TTargetType, class _Ty2>
friend TXScopeItemFixedConstPointer<_TTargetType> make_xscope_const_pointer_to_member(const _TTargetType& target, const TXScopeItemFixedPointer<_Ty2> &lease_pointer);
template<class _TTargetType, class _Ty2>
friend TXScopeItemFixedConstPointer<_TTargetType> make_xscope_const_pointer_to_member(const _TTargetType& target, const TXScopeItemFixedConstPointer<_Ty2> &lease_pointer);
template<class _Ty2> friend TXScopeItemFixedConstPointer<_Ty2> us::unsafe_make_xscope_const_pointer_to(const _Ty2& cref);
};
/* TXScopeCagedItemFixedPointerToRValue<> holds a TXScopeItemFixedPointer<> that points to an r-value which can only be
accessed when converted to a rsv::TXScopeItemFixedPointerFParam<>. */
template<typename _Ty>
class TXScopeCagedItemFixedPointerToRValue : public XScopeContainsNonOwningScopeReferenceTagBase, public StrongPointerNotAsyncShareableTagBase {
public:
void xscope_tag() const {}
private:
TXScopeCagedItemFixedPointerToRValue(const TXScopeCagedItemFixedPointerToRValue&) = delete;
TXScopeCagedItemFixedPointerToRValue(TXScopeCagedItemFixedPointerToRValue&&) = default;
TXScopeCagedItemFixedPointerToRValue(const TXScopeItemFixedPointer<_Ty>& ptr) : m_xscope_ptr(ptr) {}
#ifdef MSE_SCOPE_DISABLE_MOVE_RESTRICTIONS
TXScopeCagedItemFixedPointerToRValue(TXScopeCagedItemFixedPointerToRValue&& src_ref) : m_xscope_ptr(src_ref) {}
#endif // !MSE_SCOPE_DISABLE_MOVE_RESTRICTIONS
auto uncaged_pointer() const {
return m_xscope_ptr;
}
TXScopeCagedItemFixedPointerToRValue<_Ty>& operator=(const TXScopeCagedItemFixedPointerToRValue<_Ty>& _Right_cref) = delete;
MSE_DEFAULT_OPERATOR_NEW_AND_AMPERSAND_DECLARATION;
TXScopeItemFixedPointer<_Ty> m_xscope_ptr;
friend class TXScopeObj<_Ty>;
template<class _Ty2> friend class rsv::TXScopeItemFixedPointerFParam;
template<class _Ty2> friend class rsv::TXScopeItemFixedConstPointerFParam;
};
template<typename _Ty>
class TXScopeCagedItemFixedConstPointerToRValue : public XScopeContainsNonOwningScopeReferenceTagBase, public StrongPointerNotAsyncShareableTagBase {
public:
void xscope_tag() const {}
private:
TXScopeCagedItemFixedConstPointerToRValue(const TXScopeCagedItemFixedConstPointerToRValue& src_cref) = delete;
TXScopeCagedItemFixedConstPointerToRValue(TXScopeCagedItemFixedConstPointerToRValue&& src_cref) = default;
TXScopeCagedItemFixedConstPointerToRValue(const TXScopeItemFixedConstPointer<_Ty>& ptr) : m_xscope_ptr(ptr) {}
#ifdef MSE_SCOPE_DISABLE_MOVE_RESTRICTIONS
TXScopeCagedItemFixedConstPointerToRValue(TXScopeCagedItemFixedConstPointerToRValue&& src_ref) : m_xscope_ptr(src_ref) {}
#endif // !MSE_SCOPE_DISABLE_MOVE_RESTRICTIONS
auto uncaged_pointer() const { return m_xscope_ptr; }
TXScopeCagedItemFixedConstPointerToRValue<_Ty>& operator=(const TXScopeCagedItemFixedConstPointerToRValue<_Ty>& _Right_cref) = delete;
MSE_DEFAULT_OPERATOR_NEW_AND_AMPERSAND_DECLARATION;
TXScopeItemFixedConstPointer<_Ty> m_xscope_ptr;
friend class TXScopeObj<_Ty>;
template<class _Ty2> friend class rsv::TXScopeItemFixedConstPointerFParam;
template<typename _Ty2> friend auto pointer_to(_Ty2&& _X) -> decltype(&std::forward<_Ty2>(_X));
};
}
namespace std {
template<class _Ty>
struct hash<mse::TXScopeItemFixedPointer<_Ty> > { // hash functor
typedef mse::TXScopeItemFixedPointer<_Ty> argument_type;
typedef size_t result_type;
size_t operator()(const mse::TXScopeItemFixedPointer<_Ty>& _Keyval) const _NOEXCEPT {
const _Ty* ptr1 = nullptr;
if (_Keyval) {
ptr1 = std::addressof(*_Keyval);
}
return (hash<const _Ty *>()(ptr1));
}
};
template<class _Ty>
struct hash<mse::TXScopeFixedPointer<_Ty> > { // hash functor
typedef mse::TXScopeFixedPointer<_Ty> argument_type;
typedef size_t result_type;
size_t operator()(const mse::TXScopeFixedPointer<_Ty>& _Keyval) const _NOEXCEPT {
const _Ty* ptr1 = nullptr;
if (_Keyval) {
ptr1 = std::addressof(*_Keyval);
}
return (hash<const _Ty *>()(ptr1));
}
};
template<class _Ty>
struct hash<mse::TXScopeItemFixedConstPointer<_Ty> > { // hash functor
typedef mse::TXScopeItemFixedConstPointer<_Ty> argument_type;
typedef size_t result_type;
size_t operator()(const mse::TXScopeItemFixedConstPointer<_Ty>& _Keyval) const _NOEXCEPT {
const _Ty* ptr1 = nullptr;
if (_Keyval) {
ptr1 = std::addressof(*_Keyval);
}
return (hash<const _Ty *>()(ptr1));
}
};
template<class _Ty>
struct hash<mse::TXScopeFixedConstPointer<_Ty> > { // hash functor
typedef mse::TXScopeFixedConstPointer<_Ty> argument_type;
typedef size_t result_type;
size_t operator()(const mse::TXScopeFixedConstPointer<_Ty>& _Keyval) const _NOEXCEPT {
const _Ty* ptr1 = nullptr;
if (_Keyval) {
ptr1 = std::addressof(*_Keyval);
}
return (hash<const _Ty *>()(ptr1));
}
};
}
namespace mse {
template<typename _TROy>
class TNonXScopeObj : public _TROy {
public:
MSE_USING(TNonXScopeObj, _TROy);
TNonXScopeObj(const TNonXScopeObj& _X) : _TROy(_X) {}
TNonXScopeObj(TNonXScopeObj&& _X) : _TROy(std::forward<decltype(_X)>(_X)) {}
virtual ~TNonXScopeObj() {
mse::T_valid_if_not_an_xscope_type<_TROy>();
}
TNonXScopeObj& operator=(TNonXScopeObj&& _X) { _TROy::operator=(std::forward<decltype(_X)>(_X)); return (*this); }
TNonXScopeObj& operator=(const TNonXScopeObj& _X) { _TROy::operator=(_X); return (*this); }
template<class _Ty2>
TNonXScopeObj& operator=(_Ty2&& _X) { _TROy::operator=(std::forward<decltype(_X)>(_X)); return (*this); }
//TNonXScopeObj& operator=(_Ty2&& _X) { static_cast<_TROy&>(*this) = (std::forward<decltype(_X)>(_X)); return (*this); }
template<class _Ty2>
TNonXScopeObj& operator=(const _Ty2& _X) { _TROy::operator=(_X); return (*this); }
auto operator&() {
return &(static_cast<_TROy&>(*this));
}
auto operator&() const {
return &(static_cast<const _TROy&>(*this));
}
};
#endif /*MSE_SCOPEPOINTER_DISABLED*/
namespace rsv {
/* TXScopeItemFixedPointerFParam<> is just a version of TXScopeItemFixedPointer<> which may only be used for
function parameter declations. It has the extra ability to accept (caged) scope pointers to r-value scope objects
(i.e. supports temporaries by scope reference). */
#ifdef MSE_SCOPEPOINTER_DISABLED
template<typename _Ty> using TXScopeItemFixedPointerFParamBase = TPointer<_Ty>;
template<typename _Ty> using TXScopeItemFixedConstPointerFParamBase = TPointer<const _Ty>;
#else /*MSE_SCOPEPOINTER_DISABLED*/
template<typename _Ty> using TXScopeItemFixedPointerFParamBase = TXScopeItemFixedPointer<_Ty>;
template<typename _Ty> using TXScopeItemFixedConstPointerFParamBase = TXScopeItemFixedConstPointer<_Ty>;
#endif /*MSE_SCOPEPOINTER_DISABLED*/
template<typename _Ty>
class TXScopeItemFixedPointerFParam : public TXScopeItemFixedPointerFParamBase<_Ty> {
public:
typedef TXScopeItemFixedPointerFParamBase<_Ty> base_class;
MSE_SCOPE_USING(TXScopeItemFixedPointerFParam, base_class);
TXScopeItemFixedPointerFParam(const TXScopeItemFixedPointerFParam& src_cref) = default;
#ifndef MSE_SCOPEPOINTER_DISABLED
template<class _Ty2, class = typename std::enable_if<std::is_convertible<_Ty2 *, _Ty *>::value, void>::type>
TXScopeItemFixedPointerFParam(const TXScopeCagedItemFixedPointerToRValue<_Ty2>& src_cref) : base_class(src_cref.uncaged_pointer()) {}
#endif //!MSE_SCOPEPOINTER_DISABLED
virtual ~TXScopeItemFixedPointerFParam() {}
void xscope_not_returnable_tag() const {}
void xscope_tag() const {}
private:
TXScopeItemFixedPointerFParam<_Ty>& operator=(const TXScopeItemFixedPointerFParam<_Ty>& _Right_cref) = delete;
MSE_DEFAULT_OPERATOR_NEW_AND_AMPERSAND_DECLARATION;
};
template<typename _Ty>
class TXScopeItemFixedConstPointerFParam : public TXScopeItemFixedConstPointerFParamBase<_Ty> {
public:
typedef TXScopeItemFixedConstPointerFParamBase<_Ty> base_class;
MSE_SCOPE_USING(TXScopeItemFixedConstPointerFParam, base_class);
TXScopeItemFixedConstPointerFParam(const TXScopeItemFixedConstPointerFParam<_Ty>& src_cref) = default;
TXScopeItemFixedConstPointerFParam(const TXScopeItemFixedPointerFParam<_Ty>& src_cref) : base_class(src_cref) {}
#ifndef MSE_SCOPEPOINTER_DISABLED
template<class _Ty2, class = typename std::enable_if<std::is_convertible<_Ty2 *, _Ty *>::value, void>::type>
TXScopeItemFixedConstPointerFParam(const TXScopeCagedItemFixedConstPointerToRValue<_Ty2>& src_cref) : base_class(src_cref.uncaged_pointer()) {}
template<class _Ty2, class = typename std::enable_if<std::is_convertible<_Ty2 *, _Ty *>::value, void>::type>
TXScopeItemFixedConstPointerFParam(const TXScopeCagedItemFixedPointerToRValue<_Ty2>& src_cref) : base_class(src_cref.uncaged_pointer()) {}
#endif //!MSE_SCOPEPOINTER_DISABLED
virtual ~TXScopeItemFixedConstPointerFParam() {}
void xscope_not_returnable_tag() const {}
void xscope_tag() const {}
private:
TXScopeItemFixedConstPointerFParam<_Ty>& operator=(const TXScopeItemFixedConstPointerFParam<_Ty>& _Right_cref) = delete;
MSE_DEFAULT_OPERATOR_NEW_AND_AMPERSAND_DECLARATION;
};
}
namespace rsv {
/* rsv::TFParam<> is just a transparent template wrapper for function parameter declarations. In most cases
use of this wrapper is not necessary, but in some cases it enables functionality only available to variables
that are function parameters. Specifically, it allows functions to support scope pointer/references to
temporary objects. For safety reasons, by default, scope pointer/references to temporaries are actually
"functionally disabled" types distinct from regular scope pointer/reference types. Because it's safe to do so
in the case of function parameters, the rsv::TFParam<> wrapper enables certain scope pointer/reference types
(like TXScopeItemFixedPointer<>, and "random access section" types) to be constructed from their
"functionally disabled" counterparts.
*/
template<typename _Ty>
class TFParam : public _Ty {
public:
typedef _Ty base_class;
MSE_USING_AND_DEFAULT_COPY_AND_MOVE_CONSTRUCTOR_DECLARATIONS(TFParam, base_class);
private:
MSE_USING_ASSIGNMENT_OPERATOR_AND_DEFAULT_OPERATOR_NEW_AND_AMPERSAND_DECLARATION(base_class);
};
template<typename _Ty> using TXScopeFParam = TFParam<_Ty>;
namespace impl {
namespace fparam {
template<typename _Ty>
const auto& as_an_fparam_helper1(std::false_type, const _Ty& param) {
return param;
}
template<typename _Ty>
auto as_an_fparam_helper1(std::true_type, const _Ty& param) -> typename TFParam<typename std::remove_reference<_Ty>::type>::base_class {
return TFParam<typename std::remove_reference<_Ty>::type>(param);
}
template<typename _Ty>
auto as_an_fparam_helper1(std::false_type, _Ty&& param) {
return std::forward<_Ty>(param);
}
template<typename _Ty>
auto as_an_fparam_helper1(std::true_type, _Ty&& param) -> typename TFParam<typename std::remove_reference<_Ty>::type>::base_class {
return TFParam<typename std::remove_reference<_Ty>::type>(std::forward<_Ty>(param));
}
}
}
template<typename _Ty>
auto as_an_fparam(const _Ty& param) -> decltype(impl::fparam::as_an_fparam_helper1(typename std::is_base_of<XScopeTagBase, _Ty>::type(), param)) {
return impl::fparam::as_an_fparam_helper1(typename std::is_base_of<XScopeTagBase, _Ty>::type(), param);
}
template<typename _Ty>
auto as_an_fparam(_Ty&& param) {
return impl::fparam::as_an_fparam_helper1(typename std::is_base_of<XScopeTagBase, _Ty>::type(), std::forward<_Ty>(param));
}
template<typename _Ty>
auto xscope_as_an_fparam(const _Ty& param) -> decltype(as_an_fparam(param)) {
return as_an_fparam(param);
}
template<typename _Ty>
auto xscope_as_an_fparam(_Ty&& param) {
return as_an_fparam(std::forward<_Ty>(param));
}
/* Template specializations of TFParam<>. There are a number of them. */
#ifndef MSE_SCOPEPOINTER_DISABLED
template<typename _Ty>
class TFParam<mse::TXScopeItemFixedConstPointer<_Ty> > : public TXScopeItemFixedConstPointerFParam<_Ty> {
public:
typedef TXScopeItemFixedConstPointerFParam<_Ty> base_class;
MSE_USING_AND_DEFAULT_COPY_AND_MOVE_CONSTRUCTOR_DECLARATIONS(TFParam, base_class);
void xscope_not_returnable_tag() const {}
void xscope_tag() const {}
private:
MSE_USING_ASSIGNMENT_OPERATOR_AND_DEFAULT_OPERATOR_NEW_AND_AMPERSAND_DECLARATION(base_class);
};
template<typename _Ty>
class TFParam<const mse::TXScopeItemFixedConstPointer<_Ty> > : public TXScopeItemFixedConstPointerFParam<_Ty> {
public:
typedef TXScopeItemFixedConstPointerFParam<_Ty> base_class;
MSE_USING_AND_DEFAULT_COPY_AND_MOVE_CONSTRUCTOR_DECLARATIONS(TFParam, base_class);
void xscope_not_returnable_tag() const {}
void xscope_tag() const {}
private:
MSE_USING_ASSIGNMENT_OPERATOR_AND_DEFAULT_OPERATOR_NEW_AND_AMPERSAND_DECLARATION(base_class);
};
template<typename _Ty>
class TFParam<mse::TXScopeCagedItemFixedConstPointerToRValue<_Ty> > : public TXScopeItemFixedConstPointerFParam<_Ty> {
public:
typedef TXScopeItemFixedConstPointerFParam<_Ty> base_class;
MSE_USING_AND_DEFAULT_COPY_AND_MOVE_CONSTRUCTOR_DECLARATIONS(TFParam, base_class);
void xscope_not_returnable_tag() const {}
void xscope_tag() const {}
private:
MSE_USING_ASSIGNMENT_OPERATOR_AND_DEFAULT_OPERATOR_NEW_AND_AMPERSAND_DECLARATION(base_class);
};
#endif //!MSE_SCOPEPOINTER_DISABLED
template<typename _Ty>
class TFParam<_Ty*> : public TPointer<_Ty> {
public:
typedef TPointer<_Ty> base_class;
MSE_USING_AND_DEFAULT_COPY_AND_MOVE_CONSTRUCTOR_DECLARATIONS(TFParam, base_class);
private:
MSE_USING_ASSIGNMENT_OPERATOR_AND_DEFAULT_OPERATOR_NEW_AND_AMPERSAND_DECLARATION(base_class);
};
template<typename _Ty>
class TFParam<_Ty* const> : public TPointer<_Ty> {
public:
typedef TPointer<_Ty> base_class;
MSE_USING_AND_DEFAULT_COPY_AND_MOVE_CONSTRUCTOR_DECLARATIONS(TFParam, base_class);
private:
MSE_USING_ASSIGNMENT_OPERATOR_AND_DEFAULT_OPERATOR_NEW_AND_AMPERSAND_DECLARATION(base_class);
};
/* These specializations for native arrays aren't actually meant to be used. They're just needed because when you call
as_an_fparam() on a native array, msvc2017 will try to instantiate a TFParam<> with the native array even though it is
determined at compile that it will never be used. clang6, for example, doesn't have the same issue. */
template<typename _Ty, size_t _Size>
class TFParam<const _Ty[_Size]> : public TPointer<const _Ty> {
public:
typedef TPointer<const _Ty> base_class;
MSE_DEFAULT_COPY_AND_MOVE_CONSTRUCTOR_DECLARATIONS(TFParam);
TFParam(const _Ty(¶m)[_Size]) : base_class(param) {}
private:
MSE_DEFAULT_OPERATOR_NEW_AND_AMPERSAND_DECLARATION;
};
template<typename _Ty, size_t _Size>
class TFParam<_Ty[_Size]> : public TPointer<_Ty> {
public:
typedef TPointer<_Ty> base_class;
MSE_DEFAULT_COPY_AND_MOVE_CONSTRUCTOR_DECLARATIONS(TFParam);
TFParam(_Ty(¶m)[_Size]) : base_class(param) {}
private:
MSE_DEFAULT_OPERATOR_NEW_AND_AMPERSAND_DECLARATION;
};
/* rsv::TReturnableFParam<> is just a transparent template wrapper for function parameter declarations. Like
us::FParam<>, in most cases use of this wrapper is not necessary, but in some cases it enables functionality
only available to variables that are function parameters. Specifically, rsv::TReturnableFParam<> "marks"
scope pointer/reference parameters as safe to use as the return value of the function, whereas by default,
scope pointer/references are not considered safe to use as a return value. Note that unlike us::FParam<>,
rsv::TReturnableFParam<> does not enable the function to accept scope pointer/reference temporaries.
*/
template<typename _Ty>
class TReturnableFParam : public _Ty {
public:
typedef _Ty base_class;
typedef _Ty returnable_fparam_contained_type;
MSE_USING_AND_DEFAULT_COPY_AND_MOVE_CONSTRUCTOR_DECLARATIONS(TReturnableFParam, base_class);
void returnable_once_tag() const {}
void xscope_returnable_tag() const {}
private:
MSE_USING_ASSIGNMENT_OPERATOR_AND_DEFAULT_OPERATOR_NEW_AND_AMPERSAND_DECLARATION(base_class);
};
template<typename _Ty> using TXScopeReturnableFParam = TReturnableFParam<_Ty>;
template<typename _Ty>
auto returnable_fparam_as_base_type(TReturnableFParam<_Ty>&& _X) {
return std::forward<_Ty>(_X);
}
template<typename _Ty>
auto returnable_fparam_as_base_type(const TReturnableFParam<_Ty>& _X) -> const typename TReturnableFParam<_Ty>::base_class& {
return _X;
}
namespace impl {
namespace returnable_fparam {
template<typename _Ty>
const auto& as_a_returnable_fparam_helper1(std::false_type, const _Ty& param) {
return param;
}
template<typename _Ty>
auto as_a_returnable_fparam_helper1(std::true_type, const _Ty& param) -> TReturnableFParam<typename std::remove_reference<_Ty>::type> {
return TReturnableFParam<typename std::remove_reference<_Ty>::type>(param);
}
template<typename _Ty>
auto as_a_returnable_fparam_helper1(std::false_type, _Ty&& param) {
return std::forward<_Ty>(param);
}
template<typename _Ty>
auto as_a_returnable_fparam_helper1(std::true_type, _Ty&& param) -> TReturnableFParam<typename std::remove_reference<_Ty>::type> {
return TReturnableFParam<typename std::remove_reference<_Ty>::type>(std::forward<_Ty>(param));
}
}
}
template<typename _Ty>
auto as_a_returnable_fparam(const _Ty& param) -> decltype(impl::returnable_fparam::as_a_returnable_fparam_helper1(typename std::is_base_of<XScopeTagBase, _Ty>::type(), param)) {
return impl::returnable_fparam::as_a_returnable_fparam_helper1(typename std::is_base_of<XScopeTagBase, _Ty>::type(), param);
}
template<typename _Ty>
auto as_a_returnable_fparam(_Ty&& param) {
return impl::returnable_fparam::as_a_returnable_fparam_helper1(typename std::is_base_of<XScopeTagBase, _Ty>::type(), std::forward<_Ty>(param));
}
template<typename _Ty>
auto xscope_as_a_returnable_fparam(const _Ty& param) -> decltype(as_a_returnable_fparam(param)) {
return as_a_returnable_fparam(param);
}
template<typename _Ty>
auto xscope_as_a_returnable_fparam(_Ty&& param) {
return as_a_returnable_fparam(std::forward<_Ty>(param));
}
/* Template specializations of TReturnableFParam<>. */
template<typename _Ty>
class TReturnableFParam<_Ty*> : public TPointer<_Ty> {
public:
typedef TPointer<_Ty> base_class;
MSE_USING_AND_DEFAULT_COPY_AND_MOVE_CONSTRUCTOR_DECLARATIONS(TReturnableFParam, base_class);
#if defined(MSE_REGISTEREDPOINTER_DISABLED) || defined(MSE_SCOPEPOINTER_DISABLED) || defined(MSE_SAFER_SUBSTITUTES_DISABLED) || defined(MSE_SAFERPTR_DISABLED)
void xscope_returnable_tag() const {} /* Indication that this type is eligible to be used as a function return value. */
#endif /*defined(MSE_REGISTEREDPOINTER_DISABLED) || defined(MSE_SCOPEPOINTER_DISABLED) || defined(MSE_SAFER_SUBSTITUTES_DISABLED) || defined(MSE_SAFERPTR_DISABLED)*/
private:
MSE_USING_ASSIGNMENT_OPERATOR_AND_DEFAULT_OPERATOR_NEW_AND_AMPERSAND_DECLARATION(base_class);
};
template<typename _Ty>
class TReturnableFParam<_Ty* const> : public TPointer<_Ty> {
public:
typedef TPointer<_Ty> base_class;
MSE_USING_AND_DEFAULT_COPY_AND_MOVE_CONSTRUCTOR_DECLARATIONS(TReturnableFParam, base_class);
#if defined(MSE_REGISTEREDPOINTER_DISABLED) || defined(MSE_SCOPEPOINTER_DISABLED) || defined(MSE_SAFER_SUBSTITUTES_DISABLED) || defined(MSE_SAFERPTR_DISABLED)
void xscope_returnable_tag() const {} /* Indication that this type is eligible to be used as a function return value. */
#endif /*defined(MSE_REGISTEREDPOINTER_DISABLED) || defined(MSE_SCOPEPOINTER_DISABLED) || defined(MSE_SAFER_SUBSTITUTES_DISABLED) || defined(MSE_SAFERPTR_DISABLED)*/
private:
MSE_USING_ASSIGNMENT_OPERATOR_AND_DEFAULT_OPERATOR_NEW_AND_AMPERSAND_DECLARATION(base_class);
};
}
/* If a rsv::TReturnableFParam<> wrapped reference is used to make a pointer to a member of its target object, then the