Repository navigation
Expand file tree
/
Copy pathfixed_array.hpp
More file actions
2472 lines (2086 loc) · 102 KB
/
Copy pathfixed_array.hpp
File metadata and controls
2472 lines (2086 loc) · 102 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
/* /////////////////////////////////////////////////////////////////////////
* File: stlsoft/containers/fixed_array.hpp
*
* Purpose: Contains the fixed_array_1d, fixed_array_2d, fixed_array_3d,
* fixed_array_4d template classes.
*
* Created: 4th August 1998
* Updated: 20th March 2025
*
* Thanks: Neal Becker for suggesting the uninitialised mode, requesting
* the function call operator, and for requesting the
* with-allocator constructor overloads.
*
* Thorsten Ottosen for suggesting swap() and mutating data(), and
* for providing suggested implementations.
*
* Home: http://stlsoft.org/
*
* Copyright (c) 2019-2025, Matthew Wilson and Synesis Information Systems
* Copyright (c) 1998-2019, Matthew Wilson and Synesis Software
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name(s) of Matthew Wilson and Synesis Information Systems
* nor the names of any contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ////////////////////////////////////////////////////////////////////// */
/** \file stlsoft/containers/fixed_array.hpp
*
* \brief [C++] Definition of the stlsoft::fixed_array_1d,
* stlsoft::fixed_array_2d, stlsoft::fixed_array_3d, and
* stlsoft::fixed_array_4d multidimensional array class templates
* (\ref group__library__Container "Container" Library).
*/
#ifndef STLSOFT_INCL_STLSOFT_CONTAINERS_HPP_FIXED_ARRAY
#define STLSOFT_INCL_STLSOFT_CONTAINERS_HPP_FIXED_ARRAY
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define STLSOFT_VER_STLSOFT_CONTAINERS_HPP_FIXED_ARRAY_MAJOR 4
# define STLSOFT_VER_STLSOFT_CONTAINERS_HPP_FIXED_ARRAY_MINOR 9
# define STLSOFT_VER_STLSOFT_CONTAINERS_HPP_FIXED_ARRAY_REVISION 14
# define STLSOFT_VER_STLSOFT_CONTAINERS_HPP_FIXED_ARRAY_EDIT 210
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* /////////////////////////////////////////////////////////////////////////
* includes
*/
#ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
# include <stlsoft/stlsoft.h>
#endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
#ifdef STLSOFT_TRACE_INCLUDE
# pragma message(__FILE__)
#endif /* STLSOFT_TRACE_INCLUDE */
#if defined(STLSOFT_COMPILER_IS_MSVC) && \
_MSC_VER < 1200
# error stlsoft/containers/fixed_array.hpp is not compatible with Visual C++ 5.0 or earlier
#endif /* compiler */
#ifndef STLSOFT_INCL_STLSOFT_MEMORY_UTIL_HPP_ALLOCATOR_SELECTOR
# include <stlsoft/memory/util/allocator_selector.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_MEMORY_UTIL_HPP_ALLOCATOR_SELECTOR */
#ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER
# include <stlsoft/util/std/iterator_helper.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER */
#ifndef STLSOFT_INCL_STLSOFT_CONTAINERS_UTIL_HPP_ARRAY_POLICIES
# include <stlsoft/containers/util/array_policies.hpp> // for stlsoft::do_construction()
#endif /* !STLSOFT_INCL_STLSOFT_CONTAINERS_UTIL_HPP_ARRAY_POLICIES */
#ifndef STLSOFT_INCL_STLSOFT_META_HPP_CAPABILITIES
# include <stlsoft/meta/capabilities.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_META_HPP_CAPABILITIES */
#ifndef STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS
# include <stlsoft/collections/util/collections.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS */
#ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_STD_SWAP
# include <stlsoft/util/std_swap.hpp>
#endif /* !STLSOFT_INCL_STLSOFT_UTIL_HPP_STD_SWAP */
#if defined(STLSOFT_COMPILER_IS_MSVC) && \
defined(STLSOFT_CF_STD_LIBRARY_IS_STLPORT)
# ifndef STLSOFT_INCL_STRING
# define STLSOFT_INCL_STRING
# include <string> // for std::string - sigh!
# endif /* !STLSOFT_INCL_STRING */
#endif /* compiler */
#ifndef STLSOFT_INCL_STDEXCEPT
# define STLSOFT_INCL_STDEXCEPT
# include <stdexcept> // for std::out_of_range
#endif /* !STLSOFT_INCL_STDEXCEPT */
/* /////////////////////////////////////////////////////////////////////////
* namespace
*/
#ifndef STLSOFT_NO_NAMESPACE
namespace stlsoft
{
#endif /* STLSOFT_NO_NAMESPACE */
/* /////////////////////////////////////////////////////////////////////////
* forward declarations
*/
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
template< ss_typename_param_k T
, ss_typename_param_k A
, ss_typename_param_k P
, ss_bool_t R
>
class fixed_array_1d;
template< ss_typename_param_k T
, ss_typename_param_k A
, ss_typename_param_k P
, ss_bool_t R
>
class fixed_array_2d;
template< ss_typename_param_k T
, ss_typename_param_k A
, ss_typename_param_k P
, ss_bool_t R
>
class fixed_array_3d;
template< ss_typename_param_k T
, ss_typename_param_k A
, ss_typename_param_k P
, ss_bool_t R
>
class fixed_array_4d;
template< ss_typename_param_k T
, ss_typename_param_k A
, ss_typename_param_k P
, ss_bool_t R
>
class fixed_array_5d;
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* /////////////////////////////////////////////////////////////////////////
* classes
*/
/** 1 dimensional fixed array
*
* \ingroup group__library__Container
*
* \param T The value type
* \param A The allocator type
* \param P The construction policy type
*/
template< ss_typename_param_k T
#ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
, ss_typename_param_k A = ss_typename_type_def_k allocator_selector<T>::allocator_type
, ss_typename_param_k P = do_construction<T>
, ss_bool_t R = true
#else /* ? STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
, ss_typename_param_k A
, ss_typename_param_k P
, ss_typename_param_k R
#endif /* STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
>
// class fixed_array_1d
class fixed_array_1d
: protected A
, public stl_collection_tag
{
public:
typedef fixed_array_1d<T, A, P, R> class_type;
typedef T dimension_element_type;
typedef /* const */ dimension_element_type const_dimension_element_type;
typedef A allocator_type;
typedef T value_type;
typedef value_type& reference;
typedef value_type const& const_reference;
typedef value_type* pointer;
typedef value_type const* const_pointer;
typedef ss_size_t size_type;
typedef ss_size_t index_type;
typedef ss_ptrdiff_t difference_type;
typedef ss_bool_t bool_type;
typedef
#if !defined(STLSOFT_COMPILER_IS_BORLAND)
ss_typename_type_k
#endif /* compiler */
pointer_iterator < value_type
, pointer
, reference
>::type iterator;
typedef
#if !defined(STLSOFT_COMPILER_IS_BORLAND)
ss_typename_type_k
#endif /* compiler */
pointer_iterator < value_type const
, const_pointer
, const_reference
>::type const_iterator;
#if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
typedef reverse_iterator_base < iterator
, value_type
, reference
, pointer
, difference_type
> reverse_iterator;
typedef const_reverse_iterator_base < const_iterator
, value_type const
, const_reference
, const_pointer
, difference_type
> const_reverse_iterator;
#endif /* STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT */
// Construction
private:
fixed_array_1d(T *data, index_type d0);
public:
ss_explicit_k fixed_array_1d(index_type d0);
fixed_array_1d(index_type d0, allocator_type const& ator);
fixed_array_1d(index_type d0, value_type const& t);
fixed_array_1d(index_type d0, value_type const& t, allocator_type const& ator);
fixed_array_1d(class_type const& rhs);
~fixed_array_1d() STLSOFT_NOEXCEPT;
private:
void operator =(class_type const&) STLSOFT_COPY_ASSIGNMENT_PROSCRIBED;
public:
allocator_type get_allocator() const;
void swap(class_type& rhs) STLSOFT_NOEXCEPT;
// Access
public:
reference at(index_type i0);
const_reference at(index_type i0) const;
reference at_unchecked(index_type i0);
const_reference at_unchecked(index_type i0) const;
#ifndef STLSOFT_FIXED_ARRAY_NO_FUNCTION_OP
reference operator ()(index_type i0);
const_reference operator ()(index_type i0) const;
#endif /* !STLSOFT_FIXED_ARRAY_NO_FUNCTION_OP */
reference operator [](index_type i0);
const_reference operator [](index_type i0) const;
/// Providing the evil operator, in order to support &ar[0]
// pointer operator &();
/// Providing the evil operator, in order to support &ar[0]
// const_pointer operator &() const;
reference front();
reference back();
const_reference front() const;
const_reference back() const;
// State
public:
index_type dimension0() const;
index_type size() const;
bool_type empty() const;
static size_type max_size();
// Iteration
public:
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
#if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
reverse_iterator rbegin();
reverse_iterator rend();
const_reverse_iterator rbegin() const;
const_reverse_iterator rend() const;
#endif /* STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT */
// Access
public:
pointer data();
const_pointer data() const;
// Implementation
private:
pointer allocate_(size_type n);
void deallocate_(pointer p, size_type n);
pointer data_();
index_type calc_index_(index_type i0) const;
void range_check_(index_type i0) const stlsoft_throw_1(STLSOFT_NS_QUAL_STD(out_of_range) );
allocator_type& get_allocator_();
// Members
private:
T* m_data;
index_type m_d0;
friend class fixed_array_2d<T, A, P, true>;
friend class fixed_array_2d<T, A, P, false>;
};
/** 2 dimensional fixed array
*
* \ingroup group__library__Container
*
* \param T The value type
* \param A The allocator type
* \param P The construction policy type
*/
template< ss_typename_param_k T
#ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
, ss_typename_param_k A = ss_typename_type_def_k allocator_selector<T>::allocator_type
, ss_typename_param_k P = do_construction<T>
, ss_bool_t R = true
#else /* ? STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
, ss_typename_param_k A
, ss_typename_param_k P
, ss_bool_t R
#endif /* STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
>
// class fixed_array_2d
class fixed_array_2d
: protected A
, public stl_collection_tag
{
public:
typedef fixed_array_2d<T, A, P, R> class_type;
typedef fixed_array_1d<T, A, P, false> dimension_element_type;
typedef /* const */ dimension_element_type const_dimension_element_type;
typedef A allocator_type;
typedef T value_type;
typedef value_type& reference;
typedef value_type const& const_reference;
typedef value_type* pointer;
typedef value_type const* const_pointer;
typedef ss_size_t size_type;
typedef ss_size_t index_type;
typedef ss_ptrdiff_t difference_type;
typedef ss_bool_t bool_type;
typedef
#if !defined(STLSOFT_COMPILER_IS_BORLAND)
ss_typename_type_k
#endif /* compiler */
pointer_iterator < value_type
, pointer
, reference
>::type iterator;
typedef
#if !defined(STLSOFT_COMPILER_IS_BORLAND)
ss_typename_type_k
#endif /* compiler */
pointer_iterator < value_type const
, const_pointer
, const_reference
>::type const_iterator;
#if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
typedef reverse_iterator_base < iterator
, value_type
, reference
, pointer
, difference_type
> reverse_iterator;
typedef const_reverse_iterator_base < const_iterator
, value_type const
, const_reference
, const_pointer
, difference_type
> const_reverse_iterator;
#endif /* STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT */
// Construction
private:
fixed_array_2d(T *data, index_type d0, index_type d1);
public:
fixed_array_2d(index_type d0, index_type d1);
fixed_array_2d(index_type d0, index_type d1, allocator_type const& ator);
fixed_array_2d(index_type d0, index_type d1, value_type const& t);
fixed_array_2d(index_type d0, index_type d1, value_type const& t, allocator_type const& ator);
fixed_array_2d(class_type const& rhs);
~fixed_array_2d() STLSOFT_NOEXCEPT;
private:
void operator =(class_type const&) STLSOFT_COPY_ASSIGNMENT_PROSCRIBED;
public:
allocator_type get_allocator() const;
void swap(class_type& rhs) STLSOFT_NOEXCEPT;
// Access
public:
reference at(index_type i0, index_type i1);
const_reference at(index_type i0, index_type i1) const;
reference at_unchecked(index_type i0, index_type i1);
const_reference at_unchecked(index_type i0, index_type i1) const;
#ifndef STLSOFT_FIXED_ARRAY_NO_FUNCTION_OP
reference operator ()(index_type i0, index_type i1);
const_reference operator ()(index_type i0, index_type i1) const;
#endif /* !STLSOFT_FIXED_ARRAY_NO_FUNCTION_OP */
dimension_element_type at(index_type i0);
const_dimension_element_type at(index_type i0) const;
dimension_element_type at_unchecked(index_type i0);
const_dimension_element_type at_unchecked(index_type i0) const;
dimension_element_type operator [](index_type i0);
const_dimension_element_type operator [](index_type i0) const;
/// A reference to the first element in the array
reference front();
reference back();
const_reference front() const;
const_reference back() const;
// State
public:
index_type dimension0() const;
index_type dimension1() const;
index_type size() const;
bool_type empty() const;
static size_type max_size();
// Iteration
public:
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
#if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
reverse_iterator rbegin();
reverse_iterator rend();
const_reverse_iterator rbegin() const;
const_reverse_iterator rend() const;
#endif /* STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT */
// Access
public:
pointer data();
const_pointer data() const;
// Implementation
private:
pointer allocate_(size_type n);
void deallocate_(pointer p, size_type n);
pointer data_();
index_type calc_index_(index_type i0, index_type i1) const;
void range_check_(index_type i0, index_type i1) const stlsoft_throw_1(STLSOFT_NS_QUAL_STD(out_of_range) );
void range_check_(index_type i0) const stlsoft_throw_1(STLSOFT_NS_QUAL_STD(out_of_range) );
allocator_type& get_allocator_();
// Members
private:
T* m_data;
index_type m_d0;
index_type m_d1;
size_type m_size;
friend class fixed_array_3d<T, A, P, true>;
friend class fixed_array_3d<T, A, P, false>;
};
/** 3 dimensional fixed array
*
* \ingroup group__library__Container
*
* \param T The value type
* \param A The allocator type
* \param P The construction policy type
*/
template< ss_typename_param_k T
#ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
, ss_typename_param_k A = ss_typename_type_def_k allocator_selector<T>::allocator_type
, ss_typename_param_k P = do_construction<T>
, ss_bool_t R = true
#else /* ? STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
, ss_typename_param_k A
, ss_typename_param_k P
, ss_bool_t R
#endif /* STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
>
// class fixed_array_3d
class fixed_array_3d
: protected A
, public stl_collection_tag
{
public:
typedef fixed_array_3d<T, A, P, R> class_type;
typedef fixed_array_2d<T, A, P, false> dimension_element_type;
typedef /* const */ dimension_element_type const_dimension_element_type;
typedef A allocator_type;
typedef T value_type;
typedef value_type& reference;
typedef value_type const& const_reference;
typedef value_type* pointer;
typedef value_type const* const_pointer;
typedef ss_size_t size_type;
typedef ss_size_t index_type;
typedef ss_ptrdiff_t difference_type;
typedef ss_bool_t bool_type;
typedef
#if !defined(STLSOFT_COMPILER_IS_BORLAND)
ss_typename_type_k
#endif /* compiler */
pointer_iterator < value_type
, pointer
, reference
>::type iterator;
typedef
#if !defined(STLSOFT_COMPILER_IS_BORLAND)
ss_typename_type_k
#endif /* compiler */
pointer_iterator < value_type const
, const_pointer
, const_reference
>::type const_iterator;
#if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
typedef reverse_iterator_base < iterator
, value_type
, reference
, pointer
, difference_type
> reverse_iterator;
typedef const_reverse_iterator_base < const_iterator
, value_type const
, const_reference
, const_pointer
, difference_type
> const_reverse_iterator;
#endif /* STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT */
// Construction
private:
fixed_array_3d(pointer data, index_type d0, index_type d1, index_type d2);
public:
fixed_array_3d(index_type d0, index_type d1, index_type d2);
fixed_array_3d(index_type d0, index_type d1, index_type d2, allocator_type const& ator);
fixed_array_3d(index_type d0, index_type d1, index_type d2, value_type const& t);
fixed_array_3d(index_type d0, index_type d1, index_type d2, value_type const& t, allocator_type const& ator);
fixed_array_3d(class_type const& rhs);
~fixed_array_3d() STLSOFT_NOEXCEPT;
private:
void operator =(class_type const&) STLSOFT_COPY_ASSIGNMENT_PROSCRIBED;
public:
allocator_type get_allocator() const;
void swap(class_type& rhs) STLSOFT_NOEXCEPT;
// Access
public:
reference at(index_type i0, index_type i1, index_type i2);
const_reference at(index_type i0, index_type i1, index_type i3) const;
reference at_unchecked(index_type i0, index_type i1, index_type i2);
const_reference at_unchecked(index_type i0, index_type i1, index_type i2) const;
#ifndef STLSOFT_FIXED_ARRAY_NO_FUNCTION_OP
reference operator ()(index_type i0, index_type i1, index_type i2);
const_reference operator ()(index_type i0, index_type i1, index_type i2) const;
#endif /* !STLSOFT_FIXED_ARRAY_NO_FUNCTION_OP */
dimension_element_type at(index_type i0);
const_dimension_element_type at(index_type i0) const;
dimension_element_type at_unchecked(index_type i0);
const_dimension_element_type at_unchecked(index_type i0) const;
dimension_element_type operator [](index_type i0);
const_dimension_element_type operator [](index_type i0) const;
reference front();
reference back();
const_reference front() const;
const_reference back() const;
// State
public:
index_type dimension0() const;
index_type dimension1() const;
index_type dimension2() const;
index_type size() const;
bool_type empty() const;
static size_type max_size();
// Iteration
public:
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
#if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
reverse_iterator rbegin();
reverse_iterator rend();
const_reverse_iterator rbegin() const;
const_reverse_iterator rend() const;
#endif /* STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT */
// Access
public:
pointer data();
const_pointer data() const;
// Implementation
private:
pointer allocate_(size_type n);
void deallocate_(pointer p, size_type n);
pointer data_();
index_type calc_index_(index_type i0, index_type i1, index_type i2) const;
void range_check_(index_type i0, index_type i1, index_type i2) const stlsoft_throw_1(STLSOFT_NS_QUAL_STD(out_of_range) );
void range_check_(index_type i0) const stlsoft_throw_1(STLSOFT_NS_QUAL_STD(out_of_range) );
allocator_type& get_allocator_();
// Members
private:
T* m_data;
index_type m_d0;
index_type m_d1;
index_type m_d2;
friend class fixed_array_4d<T, A, P, true>;
friend class fixed_array_4d<T, A, P, false>;
};
/** 4 dimensional fixed array
*
* \ingroup group__library__Container
*
* \param T The value type
* \param A The allocator type
* \param P The construction policy type
*/
template< ss_typename_param_k T
#ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
, ss_typename_param_k A = ss_typename_type_def_k allocator_selector<T>::allocator_type
, ss_typename_param_k P = do_construction<T>
, ss_bool_t R = true
#else /* ? STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
, ss_typename_param_k A
, ss_typename_param_k P
, ss_bool_t R
#endif /* STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
>
// class fixed_array_4d
class fixed_array_4d
: protected A
, public stl_collection_tag
{
public:
typedef fixed_array_4d<T, A, P, R> class_type;
typedef fixed_array_3d<T, A, P, false> dimension_element_type;
typedef /* const */ dimension_element_type const_dimension_element_type;
typedef A allocator_type;
typedef T value_type;
typedef value_type& reference;
typedef value_type const& const_reference;
typedef value_type* pointer;
typedef value_type const* const_pointer;
typedef ss_size_t size_type;
typedef ss_size_t index_type;
typedef ss_ptrdiff_t difference_type;
typedef ss_bool_t bool_type;
typedef
#if !defined(STLSOFT_COMPILER_IS_BORLAND)
ss_typename_type_k
#endif /* compiler */
pointer_iterator < value_type
, pointer
, reference
>::type iterator;
typedef
#if !defined(STLSOFT_COMPILER_IS_BORLAND)
ss_typename_type_k
#endif /* compiler */
pointer_iterator < value_type const
, const_pointer
, const_reference
>::type const_iterator;
#if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
typedef reverse_iterator_base < iterator
, value_type
, reference
, pointer
, difference_type
> reverse_iterator;
typedef const_reverse_iterator_base < const_iterator
, value_type const
, const_reference
, const_pointer
, difference_type
> const_reverse_iterator;
#endif /* STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT */
// Construction
private:
fixed_array_4d(T *data, index_type d0, index_type d1, index_type d2, index_type d3);
public:
fixed_array_4d(index_type d0, index_type d1, index_type d2, index_type d3);
fixed_array_4d(index_type d0, index_type d1, index_type d2, index_type d3, allocator_type const& ator);
fixed_array_4d(index_type d0, index_type d1, index_type d2, index_type d3, value_type const& t);
fixed_array_4d(index_type d0, index_type d1, index_type d2, index_type d3, value_type const& t, allocator_type const& ator);
fixed_array_4d(class_type const& rhs);
~fixed_array_4d() STLSOFT_NOEXCEPT;
private:
void operator =(class_type const&) STLSOFT_COPY_ASSIGNMENT_PROSCRIBED;
public:
allocator_type get_allocator() const;
void swap(class_type& rhs) STLSOFT_NOEXCEPT;
// Access
public:
reference at(index_type i0, index_type i1, index_type i2, index_type i3);
const_reference at(index_type i0, index_type i1, index_type i2, index_type i3) const;
reference at_unchecked(index_type i0, index_type i1, index_type i2, index_type i3);
const_reference at_unchecked(index_type i0, index_type i1, index_type i2, index_type i3) const;
#ifndef STLSOFT_FIXED_ARRAY_NO_FUNCTION_OP
reference operator ()(index_type i0, index_type i1, index_type i2, index_type i3);
const_reference operator ()(index_type i0, index_type i1, index_type i2, index_type i3) const;
#endif /* !STLSOFT_FIXED_ARRAY_NO_FUNCTION_OP */
dimension_element_type at(index_type i0);
const_dimension_element_type at(index_type i0) const;
dimension_element_type at_unchecked(index_type i0);
const_dimension_element_type at_unchecked(index_type i0) const;
dimension_element_type operator [](index_type i0);
const_dimension_element_type operator [](index_type i0) const;
reference front();
reference back();
const_reference front() const;
const_reference back() const;
// State
public:
index_type dimension0() const;
index_type dimension1() const;
index_type dimension2() const;
index_type dimension3() const;
index_type size() const;
bool_type empty() const;
static size_type max_size();
// Iteration
public:
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
#if defined(STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT)
reverse_iterator rbegin();
reverse_iterator rend();
const_reverse_iterator rbegin() const;
const_reverse_iterator rend() const;
#endif /* STLSOFT_LF_BIDIRECTIONAL_ITERATOR_SUPPORT */
// Access
public:
pointer data();
const_pointer data() const;
// Implementation
private:
pointer allocate_(size_type n);
void deallocate_(pointer p, size_type n);
pointer data_();
index_type calc_index_(index_type i0, index_type i1, index_type i2, index_type i3) const;
void range_check_(index_type i0, index_type i1, index_type i2, index_type i3) const stlsoft_throw_1(STLSOFT_NS_QUAL_STD(out_of_range) );
void range_check_(index_type i0) const stlsoft_throw_1(STLSOFT_NS_QUAL_STD(out_of_range) );
allocator_type& get_allocator_();
// Members
private:
T* m_data;
index_type m_d0;
index_type m_d1;
index_type m_d2;
index_type m_d3;
friend class fixed_array_5d<T, A, P, true>;
friend class fixed_array_5d<T, A, P, false>;
};
/* /////////////////////////////////////////////////////////////////////////
* implementation
*/
#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
// fixed_array_1d
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline ss_typename_type_ret_k fixed_array_1d<T, A, P, R>::pointer fixed_array_1d<T, A, P, R>::allocate_(ss_typename_type_k fixed_array_1d<T, A, P, R>::size_type n)
{
allocator_type& ator = *this;
#ifdef STLSOFT_LF_ALLOCATOR_ALLOCATE_HAS_HINT
return ator.allocate(n, NULL);
#else /* ? STLSOFT_LF_ALLOCATOR_ALLOCATE_HAS_HINT */
return ator.allocate(n);
#endif /* STLSOFT_LF_ALLOCATOR_ALLOCATE_HAS_HINT */
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline void fixed_array_1d<T, A, P, R>::deallocate_(ss_typename_type_k fixed_array_1d<T, A, P, R>::pointer p, ss_typename_type_k fixed_array_1d<T, A, P, R>::size_type n)
{
allocator_type& ator = *this;
ator.deallocate(p, n);
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline ss_typename_type_ret_k fixed_array_1d<T, A, P, R>::pointer fixed_array_1d<T, A, P, R>::data_()
{
return m_data;
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline ss_typename_type_ret_k fixed_array_1d<T, A, P, R>::index_type fixed_array_1d<T, A, P, R>::calc_index_(ss_typename_type_k fixed_array_1d<T, A, P, R>::index_type i0) const
{
return i0;
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline void fixed_array_1d<T, A, P, R>::range_check_(ss_typename_type_k fixed_array_1d<T, A, P, R>::index_type i0) const stlsoft_throw_1(STLSOFT_NS_QUAL_STD(out_of_range) )
{
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
if (!(i0 < m_d0))
{
STLSOFT_THROW_X(STLSOFT_NS_QUAL_STD(out_of_range)("fixed array index out of range"));
}
#else
STLSOFT_MESSAGE_ASSERT("fixed array index out of range", i0 < m_d0);
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline ss_typename_type_k fixed_array_1d<T, A, P, R>::allocator_type& fixed_array_1d<T, A, P, R>::get_allocator_()
{
return *this;
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline fixed_array_1d<T, A, P, R>::fixed_array_1d(T* src, ss_typename_type_k fixed_array_1d<T, A, P, R>::index_type d0)
: m_data(src)
, m_d0(d0)
{
STLSOFT_STATIC_ASSERT(!R);
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline fixed_array_1d<T, A, P, R>::fixed_array_1d(ss_typename_type_k fixed_array_1d<T, A, P, R>::index_type d0)
: m_data(allocate_(d0))
, m_d0(d0)
{
STLSOFT_STATIC_ASSERT(R);
array_range_initialiser<T, A, P>::construct(*this, data_(), size());
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline fixed_array_1d<T, A, P, R>::fixed_array_1d(ss_typename_type_k fixed_array_1d<T, A, P, R>::index_type d0, ss_typename_type_k fixed_array_1d<T, A, P, R>::allocator_type const& ator)
: allocator_type(ator)
, m_data(allocate_(d0))
, m_d0(d0)
{
STLSOFT_STATIC_ASSERT(R);
array_range_initialiser<T, A, P>::construct(*this, data_(), size());
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline fixed_array_1d<T, A, P, R>::fixed_array_1d(ss_typename_type_k fixed_array_1d<T, A, P, R>::index_type d0, value_type const& t)
: m_data(allocate_(d0))
, m_d0(d0)
{
STLSOFT_STATIC_ASSERT(R);
array_range_initialiser<T, A, P>::construct(*this, data_(), size(), t);
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline fixed_array_1d<T, A, P, R>::fixed_array_1d(ss_typename_type_k fixed_array_1d<T, A, P, R>::index_type d0, value_type const& t, ss_typename_type_k fixed_array_1d<T, A, P, R>::allocator_type const& ator)
: allocator_type(ator)
, m_data(allocate_(d0))
, m_d0(d0)
{
STLSOFT_STATIC_ASSERT(R);
array_range_initialiser<T, A, P>::construct(*this, data_(), size(), t);
}
#ifdef STLSOFT_MULTIDIM_ARRAY_FEATURE_REQUIRES_COPY_CTOR_WITH_RVO
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline fixed_array_1d<T, A, P, R>::fixed_array_1d(fixed_array_1d<T, A, P, R> const& rhs)
: m_data(R ? allocate_(rhs.dimension0()) : rhs.m_data)
, m_d0(rhs.dimension0())
{
if (R)
{
array_range_initialiser<T, A, P>::copy_construct(*this, data_(), rhs.data(), size());
}
}
#else /* ? STLSOFT_MULTIDIM_ARRAY_FEATURE_REQUIRES_COPY_CTOR_WITH_RVO */
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline fixed_array_1d<T, A, P, R>::fixed_array_1d(fixed_array_1d<T, A, P, R> const& rhs)
: m_data(allocate_(rhs.dimension0()))
, m_d0(rhs.dimension0())
{
STLSOFT_STATIC_ASSERT(R);
array_range_initialiser<T, A, P>::copy_construct(*this, data_(), rhs.data(), size());
}
#endif /* STLSOFT_MULTIDIM_ARRAY_FEATURE_REQUIRES_COPY_CTOR_WITH_RVO */
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline fixed_array_1d<T, A, P, R>::~fixed_array_1d() STLSOFT_NOEXCEPT
{
if (R)
{
array_range_initialiser<T, A, P>::destroy(*this, data_(), size());
deallocate_(m_data, size());
}
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline ss_typename_type_k fixed_array_1d<T, A, P, R>::allocator_type fixed_array_1d<T, A, P, R>::get_allocator() const
{
return *this;
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline void fixed_array_1d<T, A, P, R>::swap(ss_typename_type_k fixed_array_1d<T, A, P, R>::class_type& rhs) STLSOFT_NOEXCEPT
{
// We don't need to do any construct and swap here, because all the
// variables that are being swapped are simple types (integers and
// pointers).
std_swap(get_allocator_(), rhs.get_allocator_());
std_swap(m_data, rhs.m_data);
std_swap(m_d0, rhs.m_d0);
}
template <ss_typename_param_k T, ss_typename_param_k A, ss_typename_param_k P, ss_bool_t R>
inline ss_typename_type_ret_k fixed_array_1d<T, A, P, R>::reference fixed_array_1d<T, A, P, R>::at(ss_typename_type_k fixed_array_1d<T, A, P, R>::index_type i0)
{
range_check_(i0);
return m_data[i0];
}