-
Notifications
You must be signed in to change notification settings - Fork 320
/
Copy pathbdlb_nullablevalue.t.cpp
7831 lines (6381 loc) · 281 KB
/
bdlb_nullablevalue.t.cpp
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
// bdlb_nullablevalue.t.cpp -*-C++-*-
// ----------------------------------------------------------------------------
// NOTICE
//
// This component is not up to date with current BDE coding standards, and
// should not be used as an example for new development.
// ----------------------------------------------------------------------------
#include <bdlb_nullablevalue.h>
#include <bslalg_constructorproxy.h>
#include <bslh_hash.h>
#include <bslim_testutil.h>
#include <bslma_default.h>
#include <bslma_defaultallocatorguard.h>
#include <bslma_destructorguard.h>
#include <bslma_testallocator.h>
#include <bslma_testallocatormonitor.h>
#include <bslma_usesbslmaallocator.h>
#include <bslmf_assert.h>
#include <bsls_asserttest.h>
#include <bsls_objectbuffer.h>
#include <bsls_platform.h>
#include <bsls_types.h>
#include <bsltf_templatetestfacility.h>
#include <bsltf_testvaluesarray.h>
#include <bslx_testinstream.h>
#include <bslx_testoutstream.h>
#include <bsl_cstdlib.h> // 'atoi'
#include <bsl_exception.h>
#include <bsl_iostream.h>
#include <bsl_sstream.h>
#include <bsl_string.h>
#include <bsl_typeinfo.h>
#include <bsl_vector.h>
using namespace BloombergLP;
using namespace bsl;
namespace std
{
/* template <typename _Alloc>
struct uses_allocator<bsl::string, _Alloc> : true_type {};
template <typename TYPE, typename _Alloc>
struct uses_allocator<bslalg::ConstructorProxy<bdlb::NullableValue<TYPE>>, _Alloc> : true_type {};
template <typename _Alloc>
struct uses_allocator<bsltf::AllocTestType, _Alloc> : true_type {};
template <typename _Alloc>
struct uses_allocator<bsltf::MovableAllocTestType, _Alloc> : true_type {};
template <typename _Alloc>
struct uses_allocator<bsltf::MoveOnlyAllocTestType, _Alloc> : true_type {};
template <typename _Alloc>
struct uses_allocator<bsltf::AllocBitwiseMoveableTestType, _Alloc> : true_type {};
*/}
// ============================================================================
// TEST PLAN
// ----------------------------------------------------------------------------
// Overview
// --------
// This component implements a wrapper for a value-semantic type, and itself
// exhibits value-semantic properties.
//
// Global Concerns:
// o No memory is allocated from the global-allocator.
// ----------------------------------------------------------------------------
// TYPEDEFS
// [ 3] typedef TYPE ValueType;
//
// CREATORS
// [ 3] NullableValue();
// [ 3] NullableValue(bslma::Allocator *basicAllocator);
// [ 6] NullableValue(const NullableValue& original);
// [ 6] NullableValue(const NullableValue& original, *ba);
// [21] NullableValue(NullableValue&& original);
// [21] NullableValue(NullableValue&& original, *ba);
// [ 9] NullableValue(const TYPE& value);
// [ 9] NullableValue(const TYPE& value, *ba);
// [23] NullableValue(TYPE&& value);
// [23] NullableValue(TYPE&& value, *ba);
// [11] NullableValue(const OTHER_TYPE& value);
// [11] NullableValue(const OTHER_TYPE& value, *ba);
// [11] NullableValue(const NullableValue<OTHER_TYPE>&o);
// [11] NullableValue(const NullableValue<OTHER_TYPE>&o, *ba);
// [ 3] ~NullableValue();
//
// MANIPULATORS
// [ 7] NullableValue& operator=(const NullableValue& rhs);
// [22] NullableValue& operator=(NullableValue&& rhs);
// [12] NullableValue& operator=(const NullableValue<OTHER_TYPE>& rhs);
// [10] NullableValue& operator=(const TYPE& rhs);
// [24] NullableValue& operator=(TYPE&& rhs);
// [12] NullableValue& operator=(const OTHER_TYPE& rhs);
// [13] void swap(NullableValue<TYPE>& other);
// [ 3] TYPE& makeValue(const TYPE& value);
// [12] TYPE& makeValue(const OTHER_TYPE& value);
// [10] TYPE& makeValue();
// [19] TYPE& makeValueInplace(ARGS&&... args);
// [ 8] STREAM& bdexStreamIn(STREAM& stream, int version);
// [10] void reset();
// [10] TYPE& value();
// [14] TYPE valueOr(const TYPE& value) const;
// [15] const TYPE *valueOr(const TYPE *value) const;
// [26] const TYPE *addressOr(const TYPE *address) const;
// [16] const TYPE *valueOrNull() const;
//
// ACCESSORS
// [ 8] STREAM& bdexStreamOut(STREAM& stream, int version) const;
// [ 3] bool isNull() const;
// [ 8] int maxSupportedBdexVersion(int) const;
// [ 4] ostream& print(ostream& s, int l=0, int spl=4) const;
// [ 3] const TYPE& value() const;
//
// FREE OPERATORS
// [ 5] bool operator==(const NullableValue<LHS_TYPE>&, <RHS_TYPE>&);
// [ 5] bool operator==(const NullableValue<TYPE>&, const TYPE&);
// [ 5] bool operator==(const TYPE&, const NullableValue<TYPE>&);
// [ 5] bool operator!=(const NullableValue<LHS_TYPE>&, <RHS_TYPE>&);
// [ 5] bool operator!=(const NullableValue<TYPE>&, const TYPE&);
// [ 5] bool operator!=(const TYPE&, const NullableValue<TYPE>&);
// [ 5] bool operator< (const NullableValue<LHS_TYPE>&, <RHS_TYPE>&);
// [ 5] bool operator< (const NullableValue<TYPE>&, const TYPE&);
// [ 5] bool operator< (const TYPE&, const NullableValue<TYPE>&);
// [ 5] bool operator<=(const NullableValue<LHS_TYPE>&, <RHS_TYPE>&);
// [ 5] bool operator<=(const NullableValue<TYPE>&, const TYPE&);
// [ 5] bool operator<=(const TYPE&, const NullableValue<TYPE>&);
// [ 5] bool operator> (const NullableValue<LHS_TYPE>&, <RHS_TYPE>&);
// [ 5] bool operator> (const NullableValue<TYPE>&, const TYPE&);
// [ 5] bool operator> (const TYPE&, const NullableValue<TYPE>&);
// [ 5] bool operator>=(const NullableValue<LHS_TYPE>&, <RHS_TYPE>&);
// [ 5] bool operator>=(const NullableValue<TYPE>&, const TYPE&);
// [ 5] bool operator>=(const TYPE&, const NullableValue<TYPE>&);
// [17] bool operator==(const NullableValue<TYPE>&, const TYPE&);
// [17] bool operator==(const TYPE&, const NullableValue<TYPE>&);
// [17] bool operator!=(const NullableValue<TYPE>&, const TYPE&);
// [17] bool operator!=(const TYPE&, const NullableValue<TYPE>&);
// [ 4] ostream& operator<<(ostream&, const NullableValue<TYPE>&);
// [20] void hashAppend(HASHALG& hashAlg, NullableValue<TYPE>& input);
// ----------------------------------------------------------------------------
// [ 1] BREATHING TEST 1: Using 'bsl::string'
// [ 2] BREATHING TEST 2: Using 'int'
// [27] USAGE EXAMPLE
// [25] Concern: Types that are not copy-assignable can be used.
// ----------------------------------------------------------------------------
// ============================================================================
// STANDARD BDE ASSERT TEST FUNCTION
// ----------------------------------------------------------------------------
namespace {
int testStatus = 0;
void aSsErT(bool condition, const char *message, int line)
{
if (condition) {
cout << "Error " __FILE__ "(" << line << "): " << message
<< " (failed)" << endl;
if (0 <= testStatus && testStatus <= 100) {
++testStatus;
}
}
}
} // close unnamed namespace
// ============================================================================
// STANDARD BDE TEST DRIVER MACRO ABBREVIATIONS
// ----------------------------------------------------------------------------
#define ASSERT BSLIM_TESTUTIL_ASSERT
#define ASSERTV BSLIM_TESTUTIL_ASSERTV
#define LOOP_ASSERT BSLIM_TESTUTIL_LOOP_ASSERT
#define LOOP0_ASSERT BSLIM_TESTUTIL_LOOP0_ASSERT
#define LOOP1_ASSERT BSLIM_TESTUTIL_LOOP1_ASSERT
#define LOOP2_ASSERT BSLIM_TESTUTIL_LOOP2_ASSERT
#define LOOP3_ASSERT BSLIM_TESTUTIL_LOOP3_ASSERT
#define LOOP4_ASSERT BSLIM_TESTUTIL_LOOP4_ASSERT
#define LOOP5_ASSERT BSLIM_TESTUTIL_LOOP5_ASSERT
#define LOOP6_ASSERT BSLIM_TESTUTIL_LOOP6_ASSERT
#define Q BSLIM_TESTUTIL_Q // Quote identifier literally.
#define P BSLIM_TESTUTIL_P // Print identifier and value.
#define P_ BSLIM_TESTUTIL_P_ // P(X) without '\n'.
#define T_ BSLIM_TESTUTIL_T_ // Print a tab (w/o newline).
#define L_ BSLIM_TESTUTIL_L_ // current Line number
// ============================================================================
// NEGATIVE-TEST MACRO ABBREVIATIONS
// ----------------------------------------------------------------------------
#define ASSERT_SAFE_PASS(EXPR) BSLS_ASSERTTEST_ASSERT_SAFE_PASS(EXPR)
#define ASSERT_SAFE_FAIL(EXPR) BSLS_ASSERTTEST_ASSERT_SAFE_FAIL(EXPR)
#define ASSERT_PASS(EXPR) BSLS_ASSERTTEST_ASSERT_PASS(EXPR)
#define ASSERT_FAIL(EXPR) BSLS_ASSERTTEST_ASSERT_FAIL(EXPR)
#define ASSERT_OPT_PASS(EXPR) BSLS_ASSERTTEST_ASSERT_OPT_PASS(EXPR)
#define ASSERT_OPT_FAIL(EXPR) BSLS_ASSERTTEST_ASSERT_OPT_FAIL(EXPR)
#define ASSERT_SAFE_PASS_RAW(EXPR) BSLS_ASSERTTEST_ASSERT_SAFE_PASS_RAW(EXPR)
#define ASSERT_SAFE_FAIL_RAW(EXPR) BSLS_ASSERTTEST_ASSERT_SAFE_FAIL_RAW(EXPR)
#define ASSERT_PASS_RAW(EXPR) BSLS_ASSERTTEST_ASSERT_PASS_RAW(EXPR)
#define ASSERT_FAIL_RAW(EXPR) BSLS_ASSERTTEST_ASSERT_FAIL_RAW(EXPR)
#define ASSERT_OPT_PASS_RAW(EXPR) BSLS_ASSERTTEST_ASSERT_OPT_PASS_RAW(EXPR)
#define ASSERT_OPT_FAIL_RAW(EXPR) BSLS_ASSERTTEST_ASSERT_OPT_FAIL_RAW(EXPR)
//=============================================================================
// COMPONENT-SPECIFIC MACROS FOR TESTING
//-----------------------------------------------------------------------------
#if defined(BSLS_PLATFORM_CMP_IBM) || defined(BSLS_PLATFORM_CMP_SUN)
# define BDLB_FUNCTION_DOES_NOT_DECAY_TO_POINTER_TO_FUNCTION 1
#endif
// ============================================================================
// GLOBAL TEST VALUES
// ----------------------------------------------------------------------------
static bool verbose;
static bool veryVerbose;
static bool veryVeryVerbose;
static bool veryVeryVeryVerbose;
const int MAX_NUM_PARAMS = 5; // max in simulation of variadic templates
// Define 'bsl::string' value long enough to ensure dynamic memory allocation.
#ifdef BSLS_PLATFORM_CPU_32_BIT
#define SUFFICIENTLY_LONG_STRING "123456789012345678901234567890123"
#else // 64_BIT
#define SUFFICIENTLY_LONG_STRING "12345678901234567890123456789012" \
"123456789012345678901234567890123"
#endif
BSLMF_ASSERT(sizeof SUFFICIENTLY_LONG_STRING > sizeof(bsl::string));
// NOTE: A bug in the IBM xlC compiler (Version: 12.01.0000.0012) was worked
// around with the following otherwise unnecessary overload added to the
// interface:
//..
// TYPE& makeValue(const TYPE& value);
//..
// However, it was decided that we would not change the interface to cater to
// xlC and had the client modify their code instead.
//
// The obscure test case (distilled from DRQS 98587609) that demonstrates the
// issue could not be replicated in the test driver because it apparently
// requires two translation units ('paramutil.cpp' and 'client.cpp' below):
//..
// // paramutil.h
// namespace ParamUtil {
// extern const char L_SOME_STRING[];
// }
//
// // paramutil.cpp
// #include <paramutil.h>
// namespace ParamUtil {
// const char L_SOME_STRING[] = "L_SOME_STRING";
// }
//
// // client.cpp
// #include <paramutil.h>
// ...
// bdlb::NullableValue<bsl::string> mX;
// mX.makeValue(ParamUtil::L_SOME_STRING);
// ...
//..
//=============================================================================
// GLOBAL HELPER FUNCTIONS FOR TESTING
//-----------------------------------------------------------------------------
template <class LHS_TYPE, class RHS_TYPE>
void testRelationalOperations(int i,
int j,
const LHS_TYPE& lhs,
const RHS_TYPE& rhs)
// Test all the relational operations for the specified 'lhs' and 'rhs'.
// The relation between 'lhs' and 'rhs' is expected to be exactly the same
// as between the specified 'i' and 'j'.
{
const bool isSame = (i == j);
const bool isILess = (i < j);
const bool isJLess = (j < i);
ASSERTV(lhs, rhs, isSame == (lhs == rhs));
ASSERTV(lhs, rhs, !isSame == (lhs != rhs));
ASSERTV(lhs, rhs, isILess == (lhs < rhs));
ASSERTV(lhs, rhs, !isILess == (lhs >= rhs));
ASSERTV(lhs, rhs, !isJLess == (lhs <= rhs));
ASSERTV(lhs, rhs, isJLess == (lhs > rhs));
}
// ============================================================================
// GLOBAL HELPER CLASSES FOR TESTING
// ----------------------------------------------------------------------------
// =============
// class TmvipSa
// =============
template <class TYPE>
class TmvipSa {
// Test Make Value In Place Sans (without) Allocator
// CLASS DATA
static int s_ctorCalled;
static int s_dtorCount;
// DATA
TYPE d_a1;
TYPE d_a2;
TYPE d_a3;
TYPE d_a4;
TYPE d_a5;
public:
// CLASS METHODS
static void resetCtorCalled();
// Set a negative value to the static value that is returned by the
// 'ctorCalled' class method. Note that a negative values corresponds
// to none of the constructors of this class.
static void resetDtorCount();
// Set to 0 the static value that is incremented when an object of this
// class is destroyed.
static int ctorCalled();
// Return the value set by by the most recent of the following actions:
//: o The negative value set by a call to 'resetCtorCalled' class
//: method.
//: o The number of arguments in the most recently called of the
//: overloaded value constructors of this class.
static int dtorCount();
// Return the number of objects of this class destroyed since the most
// recent call to the 'resetDtorCount' class method.
// CREATORS
TmvipSa();
explicit TmvipSa(const TYPE& a1);
TmvipSa(const TYPE& a1,
const TYPE& a2);
TmvipSa(const TYPE& a1,
const TYPE& a2,
const TYPE& a3);
TmvipSa(const TYPE& a1,
const TYPE& a2,
const TYPE& a3,
const TYPE& a4);
TmvipSa(const TYPE& a1,
const TYPE& a2,
const TYPE& a3,
const TYPE& a4,
const TYPE& a5);
// Create a test object having the default value (i.e., 'TYPE()') for
// attributes 1 to N, where N is the maximum number of parameters we
// are supporting in our simulation of C++11 variadic templates.
// Optionally specify values for attributes 1, 1 and 2, 1 to 3, ..., or
// 1 to N. Set the value returned by the 'ctorCalled' class method to
// the number of parameters in the overload called.
TmvipSa(const TmvipSa& original);
// Create an object having the same attribute values as the specified
// 'original'.
~TmvipSa();
// Destroy this object and increment the value reported by the
// 'dtorCount()' class method.
// ACCESSORS
const TYPE& a1() const;
const TYPE& a2() const;
const TYPE& a3() const;
const TYPE& a4() const;
const TYPE& a5() const;
// Return a reference providing non-modifiable access to the 'aN'
// attribute of this object, where N is the maximum number of
// parameters we are supporting in our simulation of C++11 variadic
// templates.
};
// -------------
// class TmvipSa
// -------------
// CLASS DATA
template <class TYPE>
int TmvipSa<TYPE>::s_ctorCalled = -1;
template <class TYPE>
int TmvipSa<TYPE>::s_dtorCount = 0;
// CLASS METHODS
template <class TYPE>
void TmvipSa<TYPE>::resetCtorCalled()
{
s_ctorCalled = -1;
}
template <class TYPE>
void TmvipSa<TYPE>::resetDtorCount()
{
s_dtorCount = 0;
}
template <class TYPE>
int TmvipSa<TYPE>::ctorCalled()
{
return s_ctorCalled;
}
template <class TYPE>
int TmvipSa<TYPE>::dtorCount()
{
return s_dtorCount;
}
// CREATORS
template <class TYPE>
TmvipSa<TYPE>::TmvipSa()
: d_a1()
, d_a2()
, d_a3()
, d_a4()
, d_a5()
{
s_ctorCalled = 0;
}
template <class TYPE>
TmvipSa<TYPE>::TmvipSa(const TYPE& a1)
: d_a1(a1)
, d_a2()
, d_a3()
, d_a4()
, d_a5()
{
s_ctorCalled = 1;
}
template <class TYPE>
TmvipSa<TYPE>::TmvipSa(const TYPE& a1,
const TYPE& a2)
: d_a1(a1)
, d_a2(a2)
, d_a3()
, d_a4()
, d_a5()
{
s_ctorCalled = 2;
}
template <class TYPE>
TmvipSa<TYPE>::TmvipSa(const TYPE& a1,
const TYPE& a2,
const TYPE& a3)
: d_a1(a1)
, d_a2(a2)
, d_a3(a3)
, d_a4()
, d_a5()
{
s_ctorCalled = 3;
}
template <class TYPE>
TmvipSa<TYPE>::TmvipSa(const TYPE& a1,
const TYPE& a2,
const TYPE& a3,
const TYPE& a4)
: d_a1(a1)
, d_a2(a2)
, d_a3(a3)
, d_a4(a4)
, d_a5()
{
s_ctorCalled = 4;
}
template <class TYPE>
TmvipSa<TYPE>::TmvipSa(const TYPE& a1,
const TYPE& a2,
const TYPE& a3,
const TYPE& a4,
const TYPE& a5)
: d_a1(a1)
, d_a2(a2)
, d_a3(a3)
, d_a4(a4)
, d_a5(a5)
{
s_ctorCalled = 5;
}
template <class TYPE>
TmvipSa<TYPE>::TmvipSa(const TmvipSa& original)
: d_a1(original.d_a1)
, d_a2(original.d_a2)
, d_a3(original.d_a3)
, d_a4(original.d_a4)
, d_a5(original.d_a5)
{
}
template <class TYPE>
TmvipSa<TYPE>::~TmvipSa()
{
++s_dtorCount;
}
// ACCESSORS
template <class TYPE>
const TYPE& TmvipSa<TYPE>::a1() const
{
return d_a1;
}
template <class TYPE>
const TYPE& TmvipSa<TYPE>::a2() const
{
return d_a2;
}
template <class TYPE>
const TYPE& TmvipSa<TYPE>::a3() const
{
return d_a3;
}
template <class TYPE>
const TYPE& TmvipSa<TYPE>::a4() const
{
return d_a4;
}
template <class TYPE>
const TYPE& TmvipSa<TYPE>::a5() const
{
return d_a5;
}
// =============
// class TmvipAa
// =============
template <class TYPE>
class TmvipAa {
// Test Make Value In Place Avec (with) Allocator
// CLASS DATA
static int s_ctorCalled;
static int s_dtorCount;
// DATA
TYPE d_a1;
TYPE d_a2;
TYPE d_a3;
TYPE d_a4;
TYPE d_a5;
TYPE *d_data_p; // owned
bslma::Allocator *d_allocator_p; // held
// PRIVATE MANIPULATORS
void destroyData() const;
public:
// TRAITS
BSLMF_NESTED_TRAIT_DECLARATION(TmvipAa,
bslma::UsesBslmaAllocator);
// CLASS METHODS
static void resetCtorCalled();
// Set a negative value to the static value that is returned by the
// 'ctorCalled' class method. Note that a negative value corresponds
// to none of the constructors of this class.
static void resetDtorCount();
// Set to 0 the static value that is incremented when an object of this
// class is destroyed.
static int ctorCalled();
// Return the value set by by the most recent of the following actions:
//: o The negative value set by a call to 'resetCtorCalled' class
//: method.
//: o The number of arguments in the most recently called of the
//: overloaded value constructors of this class.
static int dtorCount();
// Return the number of objects of this class destroyed since the most
// recent call to the 'resetDtorCount' class method.
// CREATORS
explicit TmvipAa(bslma::Allocator *basicAllocator = 0);
explicit TmvipAa(const TYPE& a1,
bslma::Allocator *basicAllocator = 0);
TmvipAa(const TYPE& a1,
const TYPE& a2,
bslma::Allocator *basicAllocator = 0);
TmvipAa(const TYPE& a1,
const TYPE& a2,
const TYPE& a3,
bslma::Allocator *basicAllocator = 0);
TmvipAa(const TYPE& a1,
const TYPE& a2,
const TYPE& a3,
const TYPE& a4,
bslma::Allocator *basicAllocator = 0);
TmvipAa(const TYPE& a1,
const TYPE& a2,
const TYPE& a3,
const TYPE& a4,
const TYPE& a5,
bslma::Allocator *basicAllocator = 0);
// Create a test object having the default value (i.e., 'TYPE()') for
// attributes 1 to N, where N is the maximum number of parameters we
// are supporting in our simulation of C++11 variadic templates.
// Optionally specify values for attributes 1, 1 and 2, 1 to 3, ..., or
// 1 to N. Optionally specify a 'basicAllocator' used to supply
// memory. If 'basicAllocator' is 0, the currently installed default
// allocator is used. Set the value returned by the 'ctorCalled' class
// method to the number of parameters -- not counting the optional
// allocator argument -- in the overload called. Use 'basicAllocator'
// to allocate a single 'TYPE()' object so the behavior of
// 'bdlb::NullableValue' after an exception can be checked for each
// constructor (including the default constructor). The allocated
// object is destroyed by '~TmvipAa()'.
TmvipAa(const TmvipAa& original, bslma::Allocator *basicAllocator = 0);
// Create an object having the same attribute values as the specified
// 'original'. Optionally specify a 'basicAllocator' used to supply
// memory. If 'bbasicAllocator' is 0, the currently installed default
// allocator is used.
~TmvipAa();
// Destroy this object and increment the value reported by the
// 'dtorCount' class method and the value reported by the
// 'TmvipSA::dtorCount' class method (in the base class).
// ACCESSORS
const TYPE& a1() const;
const TYPE& a2() const;
const TYPE& a3() const;
const TYPE& a4() const;
const TYPE& a5() const;
// Return a reference providing non-modifiable access to the 'aN'
// attribute of this object, where N is the maximum number of
// parameters we are supporting in our simulation of C++11 variadic
// templates.
// Aspect
bslma::Allocator *allocator() const;
// Return the address of the allocator specified on construction.
};
// -------------
// class TmvipAa
// -------------
// CLASS DATA
template <class TYPE>
int TmvipAa<TYPE>::s_ctorCalled = -3;
template <class TYPE>
int TmvipAa<TYPE>::s_dtorCount = 0;
// CLASS METHODS
template <class TYPE>
void TmvipAa<TYPE>::resetCtorCalled()
{
s_ctorCalled = -3;
}
template <class TYPE>
void TmvipAa<TYPE>::resetDtorCount()
{
s_dtorCount = 0;
}
template <class TYPE>
int TmvipAa<TYPE>::ctorCalled()
{
return s_ctorCalled;
}
template <class TYPE>
int TmvipAa<TYPE>::dtorCount()
{
return s_dtorCount;
}
// PRIVATE MANIPULATORS
template <class TYPE>
void TmvipAa<TYPE>::destroyData() const
{
d_allocator_p->deleteObject(d_data_p);
}
// CREATORS
template <class TYPE>
TmvipAa<TYPE>::TmvipAa(bslma::Allocator *basicAllocator)
: d_a1(basicAllocator)
, d_a2(basicAllocator)
, d_a3(basicAllocator)
, d_a4(basicAllocator)
, d_a5(basicAllocator)
, d_allocator_p(bslma::Default::allocator(basicAllocator))
{
d_data_p = new (*d_allocator_p) TYPE(d_allocator_p);
s_ctorCalled = 0;
}
template <class TYPE>
TmvipAa<TYPE>::TmvipAa(const TYPE& a1,
bslma::Allocator *basicAllocator)
: d_a1(a1, basicAllocator)
, d_a2(basicAllocator)
, d_a3(basicAllocator)
, d_a4(basicAllocator)
, d_a5(basicAllocator)
, d_allocator_p(bslma::Default::allocator(basicAllocator))
{
d_data_p = new (*d_allocator_p) TYPE(d_allocator_p);
s_ctorCalled = 1;
}
template <class TYPE>
TmvipAa<TYPE>::TmvipAa(const TYPE& a1,
const TYPE& a2,
bslma::Allocator *basicAllocator)
: d_a1(a1, basicAllocator)
, d_a2(a2, basicAllocator)
, d_a3(basicAllocator)
, d_a4(basicAllocator)
, d_a5(basicAllocator)
, d_allocator_p(bslma::Default::allocator(basicAllocator))
{
d_data_p = new (*d_allocator_p) TYPE(d_allocator_p);
s_ctorCalled = 2;
}
template <class TYPE>
TmvipAa<TYPE>::TmvipAa(const TYPE& a1,
const TYPE& a2,
const TYPE& a3,
bslma::Allocator *basicAllocator)
: d_a1(a1, basicAllocator)
, d_a2(a2, basicAllocator)
, d_a3(a3, basicAllocator)
, d_a4(basicAllocator)
, d_a5(basicAllocator)
, d_allocator_p(bslma::Default::allocator(basicAllocator))
{
d_data_p = new (*d_allocator_p) TYPE(d_allocator_p);
s_ctorCalled = 3;
}
template <class TYPE>
TmvipAa<TYPE>::TmvipAa(const TYPE& a1,
const TYPE& a2,
const TYPE& a3,
const TYPE& a4,
bslma::Allocator *basicAllocator)
: d_a1(a1, basicAllocator)
, d_a2(a2, basicAllocator)
, d_a3(a3, basicAllocator)
, d_a4(a4, basicAllocator)
, d_a5(basicAllocator)
, d_allocator_p(bslma::Default::allocator(basicAllocator))
{
d_data_p = new (*d_allocator_p) TYPE(d_allocator_p);
s_ctorCalled = 4;
}
template <class TYPE>
TmvipAa<TYPE>::TmvipAa(const TYPE& a1,
const TYPE& a2,
const TYPE& a3,
const TYPE& a4,
const TYPE& a5,
bslma::Allocator *basicAllocator)
: d_a1(a1, basicAllocator)
, d_a2(a2, basicAllocator)
, d_a3(a3, basicAllocator)
, d_a4(a4, basicAllocator)
, d_a5(a5, basicAllocator)
, d_allocator_p(bslma::Default::allocator(basicAllocator))
{
d_data_p = new (*d_allocator_p) TYPE(d_allocator_p);
s_ctorCalled = 5;
}
template <class TYPE>
TmvipAa<TYPE>::TmvipAa(const TmvipAa& original,
bslma::Allocator *basicAllocator)
: d_a1(original.d_a1, basicAllocator)
, d_a2(original.d_a2, basicAllocator)
, d_a3(original.d_a3, basicAllocator)
, d_a4(original.d_a3, basicAllocator)
, d_a5(original.d_a3, basicAllocator)
, d_allocator_p(bslma::Default::allocator(basicAllocator))
{
d_data_p = new (*d_allocator_p) TYPE(d_allocator_p);
}
template <class TYPE>
TmvipAa<TYPE>::~TmvipAa()
{
destroyData();
++s_dtorCount;
}
// ACCESSORS
template <class TYPE>
const TYPE& TmvipAa<TYPE>::a1() const
{
return d_a1;
}
template <class TYPE>
const TYPE& TmvipAa<TYPE>::a2() const
{
return d_a2;
}
template <class TYPE>
const TYPE& TmvipAa<TYPE>::a3() const
{
return d_a3;
}
template <class TYPE>
const TYPE& TmvipAa<TYPE>::a4() const
{
return d_a4;
}
template <class TYPE>
const TYPE& TmvipAa<TYPE>::a5() const
{
return d_a5;
}
template <class TYPE>
bslma::Allocator *TmvipAa<TYPE>::allocator() const
{
return d_allocator_p;
}
#ifdef BDE_BUILD_TARGET_EXC
// ==============================
// class TmvipSa_WithThrowingCtor
// ==============================
template <class TYPE>
class TmvipSa_WithThrowingCtor {
// Test Make Value In Place Sans (without) Allocator with Throwing Ctor
// CLASS DATA
static int s_ctorCalled;
static int s_dtorCount;
// DATA
TYPE d_a1;
TYPE d_a2;
TYPE d_a3;
TYPE d_a4;
TYPE d_a5;
public:
// CLASS METHODS
static void resetCtorCalled();
// Set a negative value to the static value that is returned by the
// 'ctorCalled' class method. Note that a negative values corresponds
// to none of the constructors of this class.
static void resetDtorCount();
// Set to 0 the static value that is incremented when an object of this
// class is destroyed.
static int ctorCalled();
// Return the value set by by the most recent of the following actions:
//: o The negative value set by a call to 'resetCtorCalled' class
//: method.
//: o The number of arguments in the most recently called of the
//: overloaded value constructors of this class.
static int dtorCount();
// Return the value the number of objects of this class destroyed since
// the most recent call to the 'resetDtorCount' class method.
// CREATORS
TmvipSa_WithThrowingCtor();
explicit TmvipSa_WithThrowingCtor(const TYPE& a1);
TmvipSa_WithThrowingCtor(const TYPE& a1,
const TYPE& a2);
TmvipSa_WithThrowingCtor(const TYPE& a1,
const TYPE& a2,
const TYPE& a3);
TmvipSa_WithThrowingCtor(const TYPE& a1,
const TYPE& a2,
const TYPE& a3,
const TYPE& a4);
TmvipSa_WithThrowingCtor(const TYPE& a1,
const TYPE& a2,
const TYPE& a3,
const TYPE& a4,
const TYPE& a5);
// Create a test object having the default value (i.e., 'TYPE()') for
// attributes 1 to N, where N is the maximum number of parameters we
// are supporting in our simulation of C++11 variadic templates.
// Optionally specify values for attributes 1, 1 and 2, 1 to 3, ..., or
// 1 to N. Set the value returned by the 'ctorCalled' class method to
// the number of parameters in the overload called *and* throw
// 'bsl::exception'.
TmvipSa_WithThrowingCtor(const TYPE& a1,
const TYPE& a2,
const TYPE& a3,
const TYPE& a4,
const TYPE& a5,
const TYPE& a6);
// Create a test object having the default value (i.e., 'TYPE()') for
// attributes 1 to N, where N is the maximum number of parameters we
// are supporting in our simulation of C++11 variadic templates.
// Optionally specify values for attributes 1, 1 and 2, 1 to 3, ..., or
// 1 to N. The value of parameter N+1 is ignored. Set the value
// returned by the 'ctorCalled' class method to the number of
// parameters in the overload called. Note that this constructor does
// *not* thrown any exception.
TmvipSa_WithThrowingCtor(const TmvipSa_WithThrowingCtor& original);
// Create an object having the same attribute values as the specified
// 'original'.
~TmvipSa_WithThrowingCtor();
// Destroy this object and increment the value reported by the
// 'dtorCount()' class method.
// ACCESSORS
const TYPE& a1() const;
const TYPE& a2() const;
const TYPE& a3() const;
const TYPE& a4() const;
const TYPE& a5() const;
// Return a reference providing non-modifiable access to the 'aN'
// attribute of this object, where N is the maximum number of
// parameters we are supporting in our simulation of C++11 variadic
// templates.
};
// ------------------------------
// class TmvipSa_WithThrowingCtor
// ------------------------------
// CLASS DATA
template <class TYPE>
int TmvipSa_WithThrowingCtor<TYPE>::s_ctorCalled = -2;
template <class TYPE>
int TmvipSa_WithThrowingCtor<TYPE>::s_dtorCount = 0;
// CLASS METHODS
template <class TYPE>
void TmvipSa_WithThrowingCtor<TYPE>::resetCtorCalled()
{
s_ctorCalled = -1;
}
template <class TYPE>
void TmvipSa_WithThrowingCtor<TYPE>::resetDtorCount()
{
s_dtorCount = 0;
}
template <class TYPE>
int TmvipSa_WithThrowingCtor<TYPE>::ctorCalled()
{
return s_ctorCalled;
}
template <class TYPE>
int TmvipSa_WithThrowingCtor<TYPE>::dtorCount()
{
return s_dtorCount;
}
// CREATORS
template <class TYPE>
TmvipSa_WithThrowingCtor<TYPE>::TmvipSa_WithThrowingCtor()
: d_a1()