Embedded Template Library  1.0
memory.h
Go to the documentation of this file.
1 
3 /******************************************************************************
4 The MIT License(MIT)
5 
6 Embedded Template Library.
7 https://github.com/ETLCPP/etl
8 https://www.etlcpp.com
9 
10 Copyright(c) 2017 jwellbelove
11 
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files(the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions :
18 
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21 
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29 ******************************************************************************/
30 
31 #ifndef ETL_MEMORY_INCLUDED
32 #define ETL_MEMORY_INCLUDED
33 
34 #include "platform.h"
35 #include "algorithm.h"
36 #include "type_traits.h"
37 #include "iterator.h"
38 #include "utility.h"
39 #include "nullptr.h"
40 #include "alignment.h"
41 #include "placement_new.h"
42 
43 #include <assert.h>
44 #include <string.h>
45 
46 #if ETL_USING_STL
47  #include <memory>
48 #endif
49 
52 
53 namespace etl
54 {
55  //*****************************************************************************
59  //*****************************************************************************
60  template <typename T>
61  T* addressof(T& t)
62  {
63 #if ETL_CPP11_SUPPORTED && ETL_USING_STL
64  return std::addressof(t);
65 #else
66  return reinterpret_cast<T*>(&const_cast<char&>(reinterpret_cast<const volatile char&>(t)));
67 #endif
68  }
69 
70 #if ETL_NOT_USING_STL
71  //*****************************************************************************
75  //*****************************************************************************
76  template <typename TOutputIterator, typename T>
78  uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T& value)
79  {
80  etl::fill(o_begin, o_end, value);
81 
82  return o_end;
83  }
84 
85  //*****************************************************************************
89  //*****************************************************************************
90  template <typename TOutputIterator, typename T>
92  uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T& value)
93  {
94  typedef typename etl::iterator_traits<TOutputIterator>::value_type value_type;
95 
96  while (o_begin != o_end)
97  {
98  ::new (static_cast<void*>(etl::addressof(*o_begin))) value_type(value);
99  ++o_begin;
100  }
101 
102  return o_end;
103  }
104 
105  //*****************************************************************************
110  //*****************************************************************************
111  template <typename TOutputIterator, typename T, typename TCounter>
113  uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T& value, TCounter& count)
114  {
115  count += int32_t(etl::distance(o_begin, o_end));
116 
117  etl::fill(o_begin, o_end, value);
118 
119  return o_end;
120  }
121 
122  //*****************************************************************************
127  //*****************************************************************************
128  template <typename TOutputIterator, typename T, typename TCounter>
130  uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T& value, TCounter& count)
131  {
132  count += int32_t(etl::distance(o_begin, o_end));
133 
134  etl::uninitialized_fill(o_begin, o_end, value);
135 
136  return o_end;
137  }
138 #else
139  //*****************************************************************************
144  //*****************************************************************************
145  template <typename TOutputIterator, typename T>
146  TOutputIterator uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T& value)
147  {
148  std::uninitialized_fill(o_begin, o_end, value);
149 
150  return o_end;
151  }
152 
153  //*****************************************************************************
158  //*****************************************************************************
159  template <typename TOutputIterator, typename T, typename TCounter>
160  TOutputIterator uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T& value, TCounter& count)
161  {
162  count += int32_t(etl::distance(o_begin, o_end));
163 
164  std::uninitialized_fill(o_begin, o_end, value);
165 
166  return o_end;
167  }
168 #endif
169 
170 #if ETL_NOT_USING_STL || ETL_CPP11_NOT_SUPPORTED
171  //*****************************************************************************
175  //*****************************************************************************
176  template <typename TOutputIterator, typename TSize, typename T>
177  TOutputIterator uninitialized_fill_n(TOutputIterator o_begin, TSize n, const T& value)
178  {
179  return etl::uninitialized_fill(o_begin, o_begin + n, value);
180  }
181 
182  //*****************************************************************************
187  //*****************************************************************************
188  template <typename TOutputIterator, typename TSize, typename T, typename TCounter>
189  TOutputIterator uninitialized_fill_n(TOutputIterator o_begin, TSize n, const T& value, TCounter& count)
190  {
191  count += n;
192 
193  return etl::uninitialized_fill(o_begin, o_begin + n, value);
194  }
195 #else
196  //*****************************************************************************
200  //*****************************************************************************
201  template <typename TOutputIterator, typename TSize, typename T>
202  TOutputIterator uninitialized_fill_n(TOutputIterator o_begin, TSize n, const T& value)
203  {
204  return std::uninitialized_fill_n(o_begin, n, value);
205  }
206 
207  //*****************************************************************************
212  //*****************************************************************************
213  template <typename TOutputIterator, typename TSize, typename T, typename TCounter>
214  TOutputIterator uninitialized_fill_n(TOutputIterator o_begin, TSize n, const T& value, TCounter& count)
215  {
216  count += n;
217 
218  return std::uninitialized_fill_n(o_begin, n, value);
219  }
220 #endif
221 
222 #if ETL_NOT_USING_STL
223  //*****************************************************************************
227  //*****************************************************************************
228  template <typename TInputIterator, typename TOutputIterator>
230  uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin)
231  {
232  return etl::copy(i_begin, i_end, o_begin);
233  }
234 
235  //*****************************************************************************
239  //*****************************************************************************
240  template <typename TInputIterator, typename TOutputIterator>
242  uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin)
243  {
244  typedef typename etl::iterator_traits<TOutputIterator>::value_type value_type;
245 
246  TOutputIterator o_end = o_begin;
247 
248  while (i_begin != i_end)
249  {
250  ::new (static_cast<void*>(etl::addressof(*o_end))) value_type(*i_begin);
251  ++i_begin;
252  ++o_end;
253  }
254 
255  return o_end;
256  }
257 
258  //*****************************************************************************
263  //*****************************************************************************
264  template <typename TInputIterator, typename TOutputIterator, typename TCounter>
266  uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter& count)
267  {
268  TOutputIterator o_end = etl::copy(i_begin, i_end, o_begin);
269  count += int32_t(etl::distance(i_begin, i_end));
270 
271  return o_end;
272  }
273 
274  //*****************************************************************************
279  //*****************************************************************************
280  template <typename TInputIterator, typename TOutputIterator, typename TCounter>
282  uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter& count)
283  {
284  TOutputIterator o_end = etl::uninitialized_copy(i_begin, i_end, o_begin);
285 
286  count += int32_t(etl::distance(i_begin, i_end));
287 
288  return o_end;
289  }
290 #else
291  //*****************************************************************************
295  //*****************************************************************************
296  template <typename TInputIterator, typename TOutputIterator>
297  TOutputIterator uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin)
298  {
299  return std::uninitialized_copy(i_begin, i_end, o_begin);
300  }
301 
302  //*****************************************************************************
307  //*****************************************************************************
308  template <typename TInputIterator, typename TOutputIterator, typename TCounter>
309  TOutputIterator uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter& count)
310  {
311  count += int32_t(etl::distance(i_begin, i_end));
312 
313  return std::uninitialized_copy(i_begin, i_end, o_begin);
314  }
315 #endif
316 
317 #if ETL_NOT_USING_STL || ETL_CPP11_NOT_SUPPORTED
318  //*****************************************************************************
322  //*****************************************************************************
323  template <typename TInputIterator, typename TSize, typename TOutputIterator>
324  TOutputIterator uninitialized_copy_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin)
325  {
326  return etl::uninitialized_copy(i_begin, i_begin + n, o_begin);
327  }
328 
329  //*****************************************************************************
334  //*****************************************************************************
335  template <typename TInputIterator, typename TSize, typename TOutputIterator, typename TCounter>
336  TOutputIterator uninitialized_copy_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TCounter& count)
337  {
338  count += n;
339 
340  return etl::uninitialized_copy(i_begin, i_begin + n, o_begin);
341  }
342 #else
343  //*****************************************************************************
347  //*****************************************************************************
348  template <typename TInputIterator, typename TSize, typename TOutputIterator>
349  TOutputIterator uninitialized_copy_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin)
350  {
351  return std::uninitialized_copy_n(i_begin, n, o_begin);
352  }
353 
354  //*****************************************************************************
359  //*****************************************************************************
360  template <typename TInputIterator, typename TSize, typename TOutputIterator, typename TCounter>
361  TOutputIterator uninitialized_copy_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TCounter& count)
362  {
363  count += n;
364 
365  return std::uninitialized_copy_n(i_begin, n, o_begin);
366 }
367 #endif
368 
369 #if ETL_CPP11_SUPPORTED
370 #if ETL_NOT_USING_STL || ETL_CPP17_NOT_SUPPORTED
371  //*****************************************************************************
375  //*****************************************************************************
376  template <typename TInputIterator, typename TOutputIterator>
378  uninitialized_move(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin)
379  {
380  return etl::move(i_begin, i_end, o_begin);
381  }
382 
383  //*****************************************************************************
387  //*****************************************************************************
388  template <typename TInputIterator, typename TOutputIterator>
390  uninitialized_move(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin)
391  {
392  typedef typename etl::iterator_traits<TOutputIterator>::value_type value_type;
393 
394  TOutputIterator o_end = o_begin;
395 
396  while (i_begin != i_end)
397  {
398  ::new (static_cast<void*>(etl::addressof(*o_end))) value_type(etl::move(*i_begin));
399  ++i_begin;
400  ++o_end;
401  }
402 
403  return o_end;
404  }
405 
406  //*****************************************************************************
411  //*****************************************************************************
412  template <typename TInputIterator, typename TOutputIterator, typename TCounter>
414  uninitialized_move(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter& count)
415  {
416  TOutputIterator o_end = etl::move(i_begin, i_end, o_begin);
417  count += int32_t(etl::distance(i_begin, i_end));
418 
419  return o_end;
420  }
421 
422  //*****************************************************************************
427  //*****************************************************************************
428  template <typename TInputIterator, typename TOutputIterator, typename TCounter>
430  uninitialized_move(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter& count)
431  {
432  TOutputIterator o_end = etl::uninitialized_move(i_begin, i_end, o_begin);
433 
434  count += int32_t(etl::distance(i_begin, i_end));
435 
436  return o_end;
437  }
438 #else
439  //*****************************************************************************
443  //*****************************************************************************
444  template <typename TInputIterator, typename TOutputIterator>
445  TOutputIterator uninitialized_move(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin)
446  {
447  return std::uninitialized_move(i_begin, i_end, o_begin);
448  }
449 
450  //*****************************************************************************
455  //*****************************************************************************
456  template <typename TInputIterator, typename TOutputIterator, typename TCounter>
457  TOutputIterator uninitialized_move(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter& count)
458  {
459  count += int32_t(etl::distance(i_begin, i_end));
460 
461  return std::uninitialized_move(i_begin, i_end, o_begin);
462  }
463 #endif
464 #else
465  // C++03
466  //*****************************************************************************
470  //*****************************************************************************
471  template <typename TInputIterator, typename TOutputIterator>
472  TOutputIterator uninitialized_move(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin)
473  {
474  // Move not supported. Defer to copy.
475  return ETL_OR_STD::uninitialized_copy(i_begin, i_end, o_begin);
476  }
477 
478  //*****************************************************************************
483  //*****************************************************************************
484  template <typename TInputIterator, typename TOutputIterator, typename TCounter>
485  TOutputIterator uninitialized_move(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter& count)
486  {
487  count += int32_t(etl::distance(i_begin, i_end));
488 
489  // Move not supported. Defer to copy.
490  return ETL_OR_STD::uninitialized_copy(i_begin, i_end, o_begin);
491  }
492 #endif
493 
494 #if ETL_CPP11_SUPPORTED
495 #if ETL_NOT_USING_STL || ETL_CPP17_NOT_SUPPORTED
496  //*****************************************************************************
500  //*****************************************************************************
501  template <typename TInputIterator, typename TSize, typename TOutputIterator>
503  uninitialized_move_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin)
504  {
505  return etl::move(i_begin, i_begin + n, o_begin);
506  }
507 
508  //*****************************************************************************
512  //*****************************************************************************
513  template <typename TInputIterator, typename TSize, typename TOutputIterator>
515  uninitialized_move_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin)
516  {
517  typedef typename etl::iterator_traits<TOutputIterator>::value_type value_type;
518 
519  TOutputIterator o_end = o_begin;
520 
521  while (n-- != 0)
522  {
523  ::new (static_cast<void*>(etl::addressof(*o_end))) value_type(etl::move(*i_begin));
524  ++i_begin;
525  ++o_end;
526  }
527 
528  return o_end;
529  }
530 
531  //*****************************************************************************
536  //*****************************************************************************
537  template <typename TInputIterator, typename TSize, typename TOutputIterator, typename TCounter>
539  uninitialized_move_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TCounter& count)
540  {
541  TOutputIterator o_end = etl::move(i_begin, i_begin + n, o_begin);
542  count += TCounter(n);
543 
544  return o_end;
545  }
546 
547  //*****************************************************************************
552  //*****************************************************************************
553  template <typename TInputIterator, typename TSize, typename TOutputIterator, typename TCounter>
555  uninitialized_move_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TCounter& count)
556  {
557  TOutputIterator o_end = etl::uninitialized_move(i_begin, i_begin + n, o_begin);
558 
559  count += TCounter(n);
560 
561  return o_end;
562  }
563 #else
564  //*****************************************************************************
568  //*****************************************************************************
569  template <typename TInputIterator, typename TSize, typename TOutputIterator>
570  TOutputIterator uninitialized_move_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin)
571  {
572  return std::uninitialized_move(i_begin, i_begin + n, o_begin);
573  }
574 
575  //*****************************************************************************
580  //*****************************************************************************
581  template <typename TInputIterator, typename TSize, typename TOutputIterator, typename TCounter>
582  TOutputIterator uninitialized_move_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TCounter& count)
583  {
584  count += TCounter(n);
585 
586  return std::uninitialized_move(i_begin, i_begin + n, o_begin);
587  }
588 #endif
589 #else
590  // C++03
591  //*****************************************************************************
595  //*****************************************************************************
596  template <typename TInputIterator, typename TSize, typename TOutputIterator>
597  TOutputIterator uninitialized_move_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin)
598  {
599  // Move not supported. Defer to copy.
600 #if ETL_CPP11_SUPPORTED
601  return std::uninitialized_copy_n(i_begin, n, o_begin);
602 #else
603  return etl::uninitialized_copy_n(i_begin, n, o_begin);
604 #endif
605  }
606 
607  //*****************************************************************************
612  //*****************************************************************************
613  template <typename TInputIterator, typename TSize, typename TOutputIterator, typename TCounter>
614  TOutputIterator uninitialized_move_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TCounter& count)
615  {
616  count += TCounter(n);
617 
618  // Move not supported. Defer to copy.
619 #if ETL_CPP11_SUPPORTED
620  return std::uninitialized_copy_n(i_begin, n, o_begin);
621 #else
622  return etl::uninitialized_copy_n(i_begin, n, o_begin);
623 #endif
624  }
625 #endif
626 
627 #if ETL_NOT_USING_STL || ETL_CPP17_NOT_SUPPORTED
628  //*****************************************************************************
632  //*****************************************************************************
633  template <typename TOutputIterator>
635  uninitialized_default_construct(TOutputIterator /*o_begin*/, TOutputIterator /*o_end*/)
636  {
637  // Do nothing
638  }
639 
640  //*****************************************************************************
644  //*****************************************************************************
645  template <typename TOutputIterator>
647  uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end)
648  {
649 
650  typedef typename etl::iterator_traits<TOutputIterator>::value_type value_type;
651 
652  while (o_begin != o_end)
653  {
654  ::new (static_cast<void*>(etl::addressof(*o_begin))) value_type;
655  ++o_begin;
656  }
657  }
658 
659  //*****************************************************************************
664  //*****************************************************************************
665  template <typename TOutputIterator, typename TCounter>
667  uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end, TCounter& count)
668  {
669  count = int32_t(etl::distance(o_begin, o_end));
670  }
671 
672  //*****************************************************************************
677  //*****************************************************************************
678  template <typename TOutputIterator, typename TCounter>
680  uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end, TCounter& count)
681  {
682  count += int32_t(etl::distance(o_begin, o_end));
683 
684  etl::uninitialized_default_construct(o_begin, o_end);
685  }
686 #else
687  //*****************************************************************************
691  //*****************************************************************************
692  template <typename TOutputIterator>
694  uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end)
695  {
696  std::uninitialized_default_construct(o_begin, o_end);
697  }
698 
699  //*****************************************************************************
704  //*****************************************************************************
705  template <typename TOutputIterator, typename TCounter>
707  uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end, TCounter& count)
708  {
709  count = int32_t(etl::distance(o_begin, o_end));
710 
711  std::uninitialized_default_construct(o_begin, o_end);
712  }
713 #endif
714 
715 #if ETL_NOT_USING_STL || ETL_CPP17_NOT_SUPPORTED
716  //*****************************************************************************
720  //*****************************************************************************
721  template <typename TOutputIterator, typename TSize>
723  uninitialized_default_construct_n(TOutputIterator o_begin, TSize n)
724  {
725  TOutputIterator o_end = o_begin + n;
726  return o_end;
727  }
728 
729  //*****************************************************************************
733  //*****************************************************************************
734  template <typename TOutputIterator, typename TSize>
736  uninitialized_default_construct_n(TOutputIterator o_begin, TSize n)
737  {
738  TOutputIterator o_end = o_begin + n;
739 
740  etl::uninitialized_default_construct(o_begin, o_end);
741 
742  return o_end;
743  }
744 
745  //*****************************************************************************
750  //*****************************************************************************
751  template <typename TOutputIterator, typename TSize, typename TCounter>
753  uninitialized_default_construct_n(TOutputIterator o_begin, TSize n, TCounter& count)
754  {
755  TOutputIterator o_end = o_begin + n;
756 
757  count += n;
758 
759  return o_end;
760  }
761 
762  //*****************************************************************************
767  //*****************************************************************************
768  template <typename TOutputIterator, typename TSize, typename TCounter>
770  uninitialized_default_construct_n(TOutputIterator o_begin, TSize n, TCounter& count)
771  {
772  TOutputIterator o_end = o_begin + n;
773 
774  etl::uninitialized_default_construct(o_begin, o_end);
775 
776  count += n;
777 
778  return o_end;
779  }
780 #else
781  //*****************************************************************************
785  //*****************************************************************************
786  template <typename TOutputIterator, typename TSize>
787  TOutputIterator uninitialized_default_construct_n(TOutputIterator o_begin, TSize n)
788  {
789  return std::uninitialized_default_construct_n(o_begin, n);
790  }
791 
792  //*****************************************************************************
797  //*****************************************************************************
798  template <typename TOutputIterator, typename TSize, typename TCounter>
799  TOutputIterator uninitialized_default_construct_n(TOutputIterator o_begin, TSize n, TCounter& count)
800  {
801  count += n;
802 
803  return std::uninitialized_default_construct_n(o_begin, n);
804  }
805 #endif
806 
807 #if ETL_NOT_USING_STL || ETL_CPP17_NOT_SUPPORTED
808  //*****************************************************************************
812  //*****************************************************************************
813  template <typename TOutputIterator>
815  uninitialized_value_construct(TOutputIterator o_begin, TOutputIterator o_end)
816  {
817  typedef typename etl::iterator_traits<TOutputIterator>::value_type value_type;
818 
819  etl::fill(o_begin, o_end, value_type());
820  }
821 
822  //*****************************************************************************
826  //*****************************************************************************
827  template <typename TOutputIterator>
829  uninitialized_value_construct(TOutputIterator o_begin, TOutputIterator o_end)
830  {
831  typedef typename etl::iterator_traits<TOutputIterator>::value_type value_type;
832 
833  while (o_begin != o_end)
834  {
835  ::new (static_cast<void*>(etl::addressof(*o_begin))) value_type();
836  ++o_begin;
837  }
838  }
839 
840  //*****************************************************************************
845  //*****************************************************************************
846  template <typename TOutputIterator, typename TCounter>
847  void uninitialized_value_construct(TOutputIterator o_begin, TOutputIterator o_end, TCounter& count)
848  {
849  count += int32_t(etl::distance(o_begin, o_end));
850 
851  etl::uninitialized_value_construct(o_begin, o_end);
852  }
853 #else
854  //*****************************************************************************
858  //*****************************************************************************
859  template <typename TOutputIterator>
860  void uninitialized_value_construct(TOutputIterator o_begin, TOutputIterator o_end)
861  {
862  std::uninitialized_value_construct(o_begin, o_end);
863  }
864 
865  //*****************************************************************************
870  //*****************************************************************************
871  template <typename TOutputIterator, typename TCounter>
872  void uninitialized_value_construct(TOutputIterator o_begin, TOutputIterator o_end, TCounter& count)
873  {
874  count += int32_t(etl::distance(o_begin, o_end));
875 
876  std::uninitialized_value_construct(o_begin, o_end);
877  }
878 
879 #endif
880 
881 #if ETL_NOT_USING_STL || ETL_CPP17_NOT_SUPPORTED
882  //*****************************************************************************
886  //*****************************************************************************
887  template <typename TOutputIterator, typename TSize>
888  TOutputIterator uninitialized_value_construct_n(TOutputIterator o_begin, TSize n)
889  {
890  TOutputIterator o_end = o_begin + n;
891 
892  etl::uninitialized_value_construct(o_begin, o_end);
893 
894  return o_end;
895  }
896 
897  //*****************************************************************************
902  //*****************************************************************************
903  template <typename TOutputIterator, typename TSize, typename TCounter>
904  TOutputIterator uninitialized_value_construct_n(TOutputIterator o_begin, TSize n, TCounter& count)
905  {
906  TOutputIterator o_end = o_begin + n;
907 
908  etl::uninitialized_value_construct(o_begin, o_end);
909 
910  count += n;
911 
912  return o_end;
913  }
914 #else
915  //*****************************************************************************
919  //*****************************************************************************
920  template <typename TOutputIterator, typename TSize>
921  TOutputIterator uninitialized_value_construct_n(TOutputIterator o_begin, TSize n)
922  {
923  return std::uninitialized_value_construct_n(o_begin, n);
924  }
925 
926  //*****************************************************************************
931  //*****************************************************************************
932  template <typename TOutputIterator, typename TSize, typename TCounter>
933  TOutputIterator uninitialized_value_construct_n(TOutputIterator o_begin, TSize n, TCounter& count)
934  {
935  count += n;
936 
937  return std::uninitialized_value_construct_n(o_begin, n);
938  }
939 #endif
940 
941 #if ETL_NOT_USING_STL || ETL_CPP17_NOT_SUPPORTED
942  //*****************************************************************************
946  //*****************************************************************************
947  template <typename T>
949  destroy_at(T* /*p*/)
950  {
951  }
952 
953  //*****************************************************************************
957  //*****************************************************************************
958  template <typename T>
961  {
962  p->~T();
963  }
964 
965  //*****************************************************************************
970  //*****************************************************************************
971  template <typename T, typename TCounter>
973  destroy_at(T* /*p*/, TCounter& count)
974  {
975  --count;
976  }
977 
978  //*****************************************************************************
983  //*****************************************************************************
984  template <typename T, typename TCounter>
986  destroy_at(T* p, TCounter& count)
987  {
988  p->~T();
989  --count;
990  }
991 #else
992  //*****************************************************************************
996  //*****************************************************************************
997  template <typename T>
998  void destroy_at(T* p)
999  {
1000  std::destroy_at(p);
1001  }
1002 
1003  //*****************************************************************************
1008  //*****************************************************************************
1009  template <typename T, typename TCounter>
1010  void destroy_at(T* p, TCounter& count)
1011  {
1012  --count;
1013  std::destroy_at(p);
1014  }
1015 #endif
1016 
1017 #if ETL_NOT_USING_STL || ETL_CPP17_NOT_SUPPORTED
1018  //*****************************************************************************
1022  //*****************************************************************************
1023  template <typename TIterator>
1025  destroy(TIterator /*i_begin*/, TIterator /*i_end*/)
1026  {
1027  }
1028 
1029  //*****************************************************************************
1033  //*****************************************************************************
1034  template <typename TIterator>
1036  destroy(TIterator i_begin, TIterator i_end)
1037  {
1038  while (i_begin != i_end)
1039  {
1040  etl::destroy_at(etl::addressof(*i_begin));
1041  ++i_begin;
1042  }
1043  }
1044 
1045  //*****************************************************************************
1050  //*****************************************************************************
1051  template <typename TIterator, typename TCounter>
1053  destroy(TIterator i_begin, TIterator i_end, TCounter& count)
1054  {
1055  count -= int32_t(etl::distance(i_begin, i_end));
1056  }
1057 
1058  //*****************************************************************************
1063  //*****************************************************************************
1064  template <typename TIterator, typename TCounter>
1066  destroy(TIterator i_begin, TIterator i_end, TCounter& count)
1067  {
1068  count -= int32_t(etl::distance(i_begin, i_end));
1069 
1070  while (i_begin != i_end)
1071  {
1072  etl::destroy_at(etl::addressof(*i_begin));
1073  ++i_begin;
1074  }
1075  }
1076 #else
1077  //*****************************************************************************
1081  //*****************************************************************************
1082  template <typename TIterator>
1083  void destroy(TIterator i_begin, TIterator i_end)
1084  {
1085  std::destroy(i_begin, i_end);
1086  }
1087 
1088  //*****************************************************************************
1093  //*****************************************************************************
1094  template <typename TIterator, typename TCounter>
1095  void destroy(TIterator i_begin, TIterator i_end, TCounter& count)
1096  {
1097  count -= int32_t(etl::distance(i_begin, i_end));
1098 
1099  std::destroy(i_begin, i_end);
1100  }
1101 #endif
1102 
1103 #if ETL_NOT_USING_STL || ETL_CPP17_NOT_SUPPORTED
1104  //*****************************************************************************
1108  //*****************************************************************************
1109  template <typename TIterator, typename TSize>
1111  destroy_n(TIterator i_begin, TSize n)
1112  {
1113  return i_begin + n;
1114  }
1115 
1116  //*****************************************************************************
1120  //*****************************************************************************
1121  template <typename TIterator, typename TSize>
1123  destroy_n(TIterator i_begin, TSize n)
1124  {
1125  while (n > 0)
1126  {
1127  etl::destroy_at(etl::addressof(*i_begin));
1128  ++i_begin;
1129  --n;
1130  }
1131 
1132  return i_begin;
1133  }
1134 
1135  //*****************************************************************************
1140  //*****************************************************************************
1141  template <typename TIterator, typename TSize, typename TCounter>
1143  destroy_n(TIterator i_begin, TSize n, TCounter& count)
1144  {
1145  count -= n;
1146  return i_begin + n;
1147  }
1148 
1149  //*****************************************************************************
1154  //*****************************************************************************
1155  template <typename TIterator, typename TSize, typename TCounter>
1157  destroy_n(TIterator i_begin, TSize n, TCounter& count)
1158  {
1159  count -= n;
1160 
1161  while (n > 0)
1162  {
1163  etl::destroy_at(etl::addressof(*i_begin));
1164  ++i_begin;
1165  --n;
1166  }
1167 
1168  return i_begin;
1169  }
1170 #else
1171  //*****************************************************************************
1175  //*****************************************************************************
1176  template <typename TIterator, typename TSize>
1177  TIterator destroy_n(TIterator i_begin, TSize n)
1178  {
1179  return std::destroy_n(i_begin, n);
1180  }
1181 
1182  //*****************************************************************************
1187  //*****************************************************************************
1188  template <typename TIterator, typename TSize, typename TCounter>
1189  TIterator destroy_n(TIterator i_begin, TSize n, TCounter& count)
1190  {
1191  count -= n;
1192 
1193  return std::destroy_n(i_begin, n);
1194  }
1195 #endif
1196 
1197  //*****************************************************************************
1202  //*****************************************************************************
1203  template <typename T>
1205  {
1206  void operator()(T* p) const
1207  {
1208  delete p;
1209  }
1210  };
1211 
1212  //*****************************************************************************
1217  //*****************************************************************************
1218  template <typename T>
1219  struct default_delete<T[]>
1220  {
1221  template <class U>
1222  void operator()(U* p) const
1223  {
1224  delete[] p;
1225  }
1226  };
1227 
1228  //*****************************************************************************
1233  //*****************************************************************************
1234  template <typename T, typename TDeleter = etl::default_delete<T> >
1236  {
1237  public:
1238 
1239  typedef T element_type;
1240  typedef T* pointer;
1241  typedef T& reference;
1242 
1243  //*********************************
1244  ETL_CONSTEXPR unique_ptr() ETL_NOEXCEPT
1245  : p(ETL_NULLPTR)
1246  {
1247  }
1248 
1249  //*********************************
1250  ETL_CONSTEXPR explicit unique_ptr(pointer p_) ETL_NOEXCEPT
1251  : p(p_)
1252  {
1253  }
1254 
1255 #if ETL_CPP11_SUPPORTED
1256  //*********************************
1257  unique_ptr(unique_ptr&& p_) ETL_NOEXCEPT
1258  : p(p_.release())
1259  {
1260  }
1261 #endif
1262 
1263  //*********************************
1265  TDeleter,
1266  typename etl::add_lvalue_reference<const TDeleter>::type>::type deleter_) ETL_NOEXCEPT
1267  : p(p_)
1268  , deleter(deleter_)
1269  {
1270  }
1271 
1272 #if ETL_CPP11_SUPPORTED
1273  //*********************************
1274  unique_ptr(pointer p_, typename etl::remove_reference<TDeleter>::type&& deleter_) ETL_NOEXCEPT
1275  : p(p_)
1276  , deleter(etl::move(deleter_))
1277  {
1278  }
1279 #endif
1280 
1281  //*********************************
1282  ~unique_ptr()
1283  {
1284  deleter(p);
1285  }
1286 
1287  //*********************************
1288  ETL_CONSTEXPR pointer get() const ETL_NOEXCEPT
1289  {
1290  return p;
1291  }
1292 
1293  //*********************************
1294  TDeleter& get_deleter() ETL_NOEXCEPT
1295  {
1296  return deleter;
1297  }
1298 
1299  //*********************************
1300  const TDeleter& get_deleter() const ETL_NOEXCEPT
1301  {
1302  return deleter;
1303  }
1304 
1305  //*********************************
1306  pointer release() ETL_NOEXCEPT
1307  {
1308  pointer value = p;
1309  p = ETL_NULLPTR;
1310 
1311  return value;
1312  }
1313 
1314  //*********************************
1315  void reset(pointer p_ = pointer()) ETL_NOEXCEPT
1316  {
1317  assert(p_ != p);
1318 
1319  pointer value = p;
1320  p = p_;
1321  deleter(value);
1322  }
1323 
1324  //*********************************
1325  void swap(unique_ptr& value) ETL_NOEXCEPT
1326  {
1327  using ETL_OR_STD::swap;
1328 
1329  swap(p, value.p);
1330  }
1331 
1332  //*********************************
1333  ETL_CONSTEXPR operator bool() const ETL_NOEXCEPT
1334  {
1335  return (p != ETL_NULLPTR);
1336  }
1337 
1338 #if ETL_CPP11_SUPPORTED && ETL_USING_STL
1339  //*********************************
1340  unique_ptr& operator =(std::nullptr_t) ETL_NOEXCEPT
1341  {
1342  reset(nullptr);
1343 
1344  return *this;
1345  }
1346 #else
1347  //*********************************
1348  unique_ptr& operator =(void*) ETL_NOEXCEPT
1349  {
1350  reset(NULL);
1351 
1352  return *this;
1353  }
1354 #endif
1355 
1356 #if ETL_CPP11_SUPPORTED
1357  //*********************************
1358  unique_ptr& operator =(unique_ptr&& p_) ETL_NOEXCEPT
1359  {
1360  reset(p_.release());
1361 
1362  return *this;
1363  }
1364 #endif
1365 
1366  //*********************************
1367  ETL_CONSTEXPR reference operator *() const
1368  {
1369  return *get();
1370  }
1371 
1372  //*********************************
1373  ETL_CONSTEXPR pointer operator ->() const ETL_NOEXCEPT
1374  {
1375  return get();
1376  }
1377 
1378  //*********************************
1379  ETL_CONSTEXPR reference operator [](size_t i) const
1380  {
1381  return p[i];
1382  }
1383 
1384  private:
1385 
1386  // Deleted.
1387  unique_ptr(const unique_ptr&) ETL_DELETE;
1388  unique_ptr& operator =(const unique_ptr&) ETL_DELETE;
1389 
1390  TDeleter deleter;
1391 
1392  pointer p;
1393  };
1394 
1395  //*****************************************************************************
1400  //*****************************************************************************
1401  template<typename T, typename TDeleter>
1402  class unique_ptr<T[], TDeleter>
1403  {
1404  public:
1405 
1406  typedef T element_type;
1407  typedef T* pointer;
1408  typedef T& reference;
1409 
1410  //*********************************
1411  ETL_CONSTEXPR unique_ptr() ETL_NOEXCEPT
1412  : p(ETL_NULLPTR)
1413  {
1414  }
1415 
1416  //*********************************
1417  ETL_CONSTEXPR explicit unique_ptr(pointer p_) ETL_NOEXCEPT
1418  : p(p_)
1419  {
1420  }
1421 
1422 #if ETL_CPP11_SUPPORTED
1423  //*********************************
1424  unique_ptr(unique_ptr&& p_) ETL_NOEXCEPT
1425  : p(p_.release())
1426  {
1427  }
1428 #endif
1429 
1430  //*********************************
1431  ~unique_ptr()
1432  {
1433  deleter(p);
1434  }
1435 
1436  //*********************************
1437  ETL_CONSTEXPR pointer get() const ETL_NOEXCEPT
1438  {
1439  return p;
1440  }
1441 
1442  //*********************************
1443  TDeleter& get_deleter() ETL_NOEXCEPT
1444  {
1445  return deleter;
1446  }
1447 
1448  //*********************************
1449  const TDeleter& get_deleter() const ETL_NOEXCEPT
1450  {
1451  return deleter;
1452  }
1453 
1454  //*********************************
1455  pointer release() ETL_NOEXCEPT
1456  {
1457  pointer value = p;
1458  p = ETL_NULLPTR;
1459  return value;
1460  }
1461 
1462  //*********************************
1463  void reset(pointer p_) ETL_NOEXCEPT
1464  {
1465  assert(p_ != p);
1466 
1467  pointer value = p;
1468  p = p_;
1469  delete[] value;
1470  }
1471 
1472  //*********************************
1473  void swap(unique_ptr& v) ETL_NOEXCEPT
1474  {
1475  using ETL_OR_STD::swap;
1476 
1477  swap(p, v.p);
1478  }
1479 
1480  //*********************************
1481  ETL_CONSTEXPR operator bool() const ETL_NOEXCEPT
1482  {
1483  return (p != ETL_NULLPTR);
1484  }
1485 
1486 #if ETL_CPP11_SUPPORTED
1487  //*********************************
1488  unique_ptr& operator =(unique_ptr&& p_) ETL_NOEXCEPT
1489  {
1490  reset(p_.release());
1491 
1492  return *this;
1493  }
1494 #endif
1495 
1496  //*********************************
1497  ETL_CONSTEXPR reference operator *() const
1498  {
1499  return *p;
1500  }
1501 
1502  //*********************************
1503  ETL_CONSTEXPR pointer operator ->() const ETL_NOEXCEPT
1504  {
1505  return p;
1506  }
1507 
1508  //*********************************
1509  ETL_CONSTEXPR reference operator [](size_t i) const
1510  {
1511  return p[i];
1512  }
1513 
1514  private:
1515 
1516  // Deleted.
1517  unique_ptr(const unique_ptr&) ETL_DELETE;
1518  unique_ptr& operator =(const unique_ptr&) ETL_DELETE;
1519 
1520  TDeleter deleter;
1521 
1522  pointer p;
1523  };
1524 }
1525 
1526 //*****************************************************************************
1527 // Global functions for unique_ptr
1528 //*****************************************************************************
1529 template<typename T1, typename D1, typename T2, typename D2>
1530 bool operator ==(const etl::unique_ptr<T1, D1>&lhs, const etl::unique_ptr<T2, D2>& rhs)
1531 {
1532  return lhs.get() == rhs.get();
1533 }
1534 
1535 //*********************************
1536 template<typename T1, typename D1, typename T2, typename D2>
1537 bool operator <(const etl::unique_ptr<T1, D1>&lhs, const etl::unique_ptr<T2, D2>& rhs)
1538 {
1539  return reinterpret_cast<char*>(lhs.get()) < reinterpret_cast<char*>(rhs.get());
1540 }
1541 
1542 //*********************************
1543 template<typename T1, typename D1, typename T2, typename D2>
1544 bool operator <=(const etl::unique_ptr<T1, D1>&lhs, const etl::unique_ptr<T2, D2>& rhs)
1545 {
1546  return !(rhs < lhs);
1547 }
1548 
1549 //*********************************
1550 template<typename T1, typename D1, typename T2, typename D2>
1551 bool operator >(const etl::unique_ptr<T1, D1>&lhs, const etl::unique_ptr<T2, D2>& rhs)
1552 {
1553  return (rhs < lhs);
1554 }
1555 
1556 //*********************************
1557 template<typename T1, typename D1, typename T2, typename D2>
1558 bool operator >=(const etl::unique_ptr<T1, D1>&lhs, const etl::unique_ptr<T2, D2>& rhs)
1559 {
1560  return !(lhs < rhs);
1561 }
1562 
1563 namespace etl
1564 {
1565  //*****************************************************************************
1568  //*****************************************************************************
1569  template <typename T>
1572  {
1573  }
1574 
1575  //*****************************************************************************
1578  //*****************************************************************************
1579  template <typename T, typename TCounter>
1581  create_default_at(T* /*p*/, TCounter& count)
1582  {
1583  ++count;
1584  }
1585 
1586  //*****************************************************************************
1589  //*****************************************************************************
1590  template <typename T>
1593  {
1594  ::new (p) T;
1595  }
1596 
1597  //*****************************************************************************
1600  //*****************************************************************************
1601  template <typename T, typename TCounter>
1603  create_default_at(T* p, TCounter& count)
1604  {
1605  ::new (p) T;
1606  ++count;
1607  }
1608 
1609  //*****************************************************************************
1612  //*****************************************************************************
1613  template <typename T>
1614  void create_value_at(T* p)
1615  {
1616  ::new (p) T();
1617  }
1618 
1619  //*****************************************************************************
1622  //*****************************************************************************
1623  template <typename T, typename TCounter>
1624  void create_value_at(T* p, TCounter& count)
1625  {
1626  ::new (p) T();
1627  ++count;
1628  }
1629 
1630  //*****************************************************************************
1633  //*****************************************************************************
1634  template <typename T>
1635  void create_copy_at(T* p, const T& value)
1636  {
1637  ::new (p) T(value);
1638  }
1639 
1640 #if ETL_CPP11_SUPPORTED
1641  //*****************************************************************************
1644  //*****************************************************************************
1645  template <typename T>
1646  void create_copy_at(T* p, T&& value)
1647  {
1648  ::new (p) T(etl::move(value));
1649  }
1650 #endif
1651 
1652  //*****************************************************************************
1655  //*****************************************************************************
1656  template <typename T, typename TCounter>
1657  void create_copy_at(T* p, const T& value, TCounter& count)
1658  {
1659  ::new (p) T(value);
1660  ++count;
1661  }
1662 
1663  //*****************************************************************************
1666  //*****************************************************************************
1667  template <typename T>
1669  {
1670  ::new (p) T();
1671  return *reinterpret_cast<T*>(p);
1672  }
1673 
1674  //*****************************************************************************
1677  //*****************************************************************************
1678  template <typename T, typename TCounter>
1679  T& make_default_at(T* p, TCounter& count)
1680  {
1681  ::new (p) T();
1682  ++count;
1683  return *reinterpret_cast<T*>(p);
1684  }
1685 
1686  //*****************************************************************************
1689  //*****************************************************************************
1690  template <typename T>
1691  T& make_copy_at(T* p, const T& other)
1692  {
1693  ::new (p) T(other);
1694  return *reinterpret_cast<T*>(p);
1695  }
1696 
1697 #if ETL_CPP11_SUPPORTED
1698  //*****************************************************************************
1701  //*****************************************************************************
1702  template <typename T>
1703  T& make_copy_at(T* p, T&& other)
1704  {
1705  ::new (p) T(etl::move(other));
1706  return *reinterpret_cast<T*>(p);
1707  }
1708 #endif
1709 
1710  //*****************************************************************************
1713  //*****************************************************************************
1714  template <typename T, typename TCounter>
1715  T& make_copy_at(T* p, const T& other, TCounter& count)
1716  {
1717  ::new (p) T(other);
1718  ++count;
1719  return *reinterpret_cast<T*>(p);
1720  }
1721 
1722  //*****************************************************************************
1725  //*****************************************************************************
1726  template <typename T, typename TParameter>
1727  T& make_value_at(T* p, const TParameter& value)
1728  {
1729  ::new (p) T(value);
1730  return *reinterpret_cast<T*>(p);
1731  }
1732 
1733 #if ETL_CPP11_SUPPORTED
1734  //*****************************************************************************
1737  //*****************************************************************************
1738  template <typename T, typename TParameter>
1739  T& make_value_at(T* p, TParameter&& value)
1740  {
1741  ::new (p) T(etl::move(value));
1742  return *reinterpret_cast<T*>(p);
1743  }
1744 #endif
1745 
1746  //*****************************************************************************
1749  //*****************************************************************************
1750  template <typename T, typename TParameter, typename TCounter>
1751  T& make_value_at(T* p, const TParameter& value, TCounter& count)
1752  {
1753  ::new (p) T(value);
1754  ++count;
1755  return *reinterpret_cast<T*>(p);
1756  }
1757 
1758  //*****************************************************************************
1762  //*****************************************************************************
1763  template <typename T>
1765  {
1766  void create_copy_at(void* p)
1767  {
1768  new (p) T(static_cast<const T&>(*this));
1769  }
1770 
1771  template <typename TCounter>
1772  void create_copy_at(void* p, TCounter& count)
1773  {
1774  new (p) T(static_cast<const T&>(*this));
1775  ++count;
1776  }
1777 
1778  T& make_copy_at(void* p)
1779  {
1780  new (p) T(static_cast<const T&>(*this));
1781  return *reinterpret_cast<T*>(p);
1782  }
1783 
1784  template <typename TCounter>
1785  T& make_copy_at(void* p, TCounter& count)
1786  {
1787  new (p) T(static_cast<const T&>(*this));
1788  ++count;
1789  return *reinterpret_cast<T*>(p);
1790  }
1791  };
1792 
1793  //*****************************************************************************
1798  //*****************************************************************************
1799  inline void memory_clear(volatile char* p, size_t n)
1800  {
1801  while (n--)
1802  {
1803  *p++ = 0;
1804  }
1805  }
1806 
1807  //*****************************************************************************
1812  //*****************************************************************************
1813  template <typename T>
1814  void memory_clear(volatile T &object)
1815  {
1816  memory_clear(reinterpret_cast<volatile char*>(&object), sizeof(T));
1817  }
1818 
1819  //*****************************************************************************
1825  //*****************************************************************************
1826  template <typename T>
1827  void memory_clear_range(volatile T* begin, size_t n)
1828  {
1829  memory_clear(reinterpret_cast<volatile char*>(begin), n * sizeof(T));
1830  }
1831 
1832  //*****************************************************************************
1838  //*****************************************************************************
1839  template <typename T>
1840  void memory_clear_range(volatile T* begin, volatile T* end)
1841  {
1842  const size_t n = static_cast<size_t>(etl::distance(begin, end));
1843 
1845  }
1846 
1847  //*****************************************************************************
1853  //*****************************************************************************
1854  inline void memory_set(volatile char* p, size_t n, char value)
1855  {
1856  while (n--)
1857  {
1858  *p++ = value;
1859  }
1860  }
1861 
1862  //*****************************************************************************
1868  //*****************************************************************************
1869  template <typename T>
1870  void memory_set(volatile T &object, const char value)
1871  {
1872  memory_set(reinterpret_cast<volatile char*>(&object), sizeof(T), value);
1873  }
1874 
1875  //*****************************************************************************
1882  //*****************************************************************************
1883  template <typename T>
1884  void memory_set_range(volatile T* begin, size_t n, const char value)
1885  {
1886  memory_set(reinterpret_cast<volatile char*>(begin), n * sizeof(T), value);
1887  }
1888 
1889  //*****************************************************************************
1896  //*****************************************************************************
1897  template <typename T>
1898  void memory_set_range(volatile T* begin, volatile T* end, const char value)
1899  {
1900  const size_t n = static_cast<size_t>(etl::distance(begin, end));
1901 
1902  memory_set_range(begin, n, value);
1903  }
1904 
1905  //*****************************************************************************
1911  //*****************************************************************************
1912  template <typename T>
1914  {
1915  ~wipe_on_destruct()
1916  {
1917  memory_clear(static_cast<volatile T&>(*this));
1918  }
1919  };
1920 
1921  //***************************************************************************
1924  //***************************************************************************
1925  template <size_t OBJECT_SIZE_, size_t N_OBJECTS_, size_t ALIGNMENT_>
1927  {
1928  public:
1929 
1930  static ETL_CONSTANT size_t OBJECT_SIZE = OBJECT_SIZE_;
1931  static ETL_CONSTANT size_t N_OBJECTS = N_OBJECTS_;
1932  static ETL_CONSTANT size_t ALIGNMENT = ALIGNMENT_;
1933 
1935  template <typename T>
1936  operator T& ()
1937  {
1938  ETL_STATIC_ASSERT((etl::is_same<T*, void*>::value || ((ALIGNMENT % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
1939  return *reinterpret_cast<T*>(raw);
1940  }
1941 
1943  template <typename T>
1944  operator const T& () const
1945  {
1946  ETL_STATIC_ASSERT((etl::is_same<T*, void*>::value || ((ALIGNMENT % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
1947  return *reinterpret_cast<const T*>(raw);
1948  }
1949 
1951  template <typename T>
1952  operator T* ()
1953  {
1954  ETL_STATIC_ASSERT((etl::is_same<T*, void*>::value || ((ALIGNMENT % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
1955  return reinterpret_cast<T*>(raw);
1956  }
1957 
1959  template <typename T>
1960  operator const T* () const
1961  {
1962  ETL_STATIC_ASSERT((etl::is_same<T*, void*>::value || ((ALIGNMENT % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
1963  return reinterpret_cast<const T*>(raw);
1964  }
1965 
1966 #if ETL_CPP11_SUPPORTED && !defined(ETL_COMPILER_ARM5) && !defined(ETL_UNINITIALIZED_BUFFER_FORCE_CPP03)
1967  alignas(ALIGNMENT) char raw[OBJECT_SIZE * N_OBJECTS];
1968 #else
1969  union
1970  {
1971  char raw[OBJECT_SIZE * N_OBJECTS];
1972  typename etl::type_with_alignment<ALIGNMENT>::type etl_alignment_type; // A POD type that has the same alignment as ALIGNMENT.
1973  };
1974 #endif
1975  };
1976 
1977  //***************************************************************************
1980  //***************************************************************************
1981  template <typename T, size_t N_OBJECTS_>
1983  {
1984  public:
1985 
1986  typedef T value_type;
1987  typedef T& reference;
1988  typedef const T& const_reference;
1989  typedef T* pointer;
1990  typedef const T* const_pointer;
1991  typedef T* iterator;
1992  typedef const T* const_iterator;
1993 
1994  static ETL_CONSTANT size_t OBJECT_SIZE = sizeof(T);
1995  static ETL_CONSTANT size_t N_OBJECTS = N_OBJECTS_;
1996  static ETL_CONSTANT size_t ALIGNMENT = etl::alignment_of<T>::value;
1997 
1999  T& operator [](int i)
2000  {
2001  return ((T*)this->raw)[i];
2002  }
2003 
2005  const T& operator [](int i) const
2006  {
2007  return ((T*)this->raw)[i];
2008  }
2009 
2011  operator T& ()
2012  {
2013  return *reinterpret_cast<T*>(raw);
2014  }
2015 
2017  operator const T& () const
2018  {
2019  return *reinterpret_cast<const T*>(raw);
2020  }
2021 
2023  operator T* ()
2024 
2025  {
2026  return reinterpret_cast<T*>(raw);
2027  }
2028 
2030  operator const T* () const
2031  {
2032  return reinterpret_cast<const T*>(raw);
2033  }
2034 
2035  T* begin()
2036  {
2037  return reinterpret_cast<const T*>(raw);
2038  }
2039 
2040  const T* begin() const
2041  {
2042  return reinterpret_cast<const T*>(raw);
2043  }
2044 
2045  T* end()
2046  {
2047  return reinterpret_cast<const T*>(raw + (sizeof(T) * N_OBJECTS));
2048  }
2049 
2050  const T* end() const
2051  {
2052  return reinterpret_cast<const T*>(raw + (sizeof(T) * N_OBJECTS));
2053  }
2054 
2055 #if ETL_CPP11_SUPPORTED && !defined(ETL_COMPILER_ARM5) && !defined(ETL_UNINITIALIZED_BUFFER_FORCE_CPP03)
2056  alignas(ALIGNMENT) char raw[sizeof(T) * N_OBJECTS];
2057 #else
2058  union
2059  {
2060  char raw[sizeof(T) * N_OBJECTS];
2061  typename etl::type_with_alignment<ALIGNMENT>::type etl_alignment_type; // A POD type that has the same alignment as ALIGNMENT.
2062  };
2063 #endif
2064  };
2065 
2066 #if ETL_CPP14_SUPPORTED
2067  template <typename T, size_t N_OBJECTS>
2068  using uninitialized_buffer_of_v = typename uninitialized_buffer_of<T, N_OBJECTS>::buffer;
2069 #endif
2070 }
2071 
2072 #endif
T & operator[](int i)
Index operator.
Definition: memory.h:1999
Definition: memory.h:1927
Definition: memory.h:1983
ETL_CONSTEXPR TContainer::iterator begin(TContainer &container)
Definition: container.h:49
ETL_CONSTEXPR TContainer::iterator end(TContainer &container)
Definition: container.h:99
Definition: memory.h:1236
TOutputIterator uninitialized_value_construct_n(TOutputIterator o_begin, TSize n, TCounter &count)
Definition: memory.h:904
TOutputIterator uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T &value)
Definition: memory.h:146
TOutputIterator uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T &value, TCounter &count)
Definition: memory.h:160
etl::enable_if< etl::is_trivially_constructible< typename etl::iterator_traits< TOutputIterator >::value_type >::value, void >::type uninitialized_value_construct(TOutputIterator o_begin, TOutputIterator o_end)
Definition: memory.h:815
TOutputIterator uninitialized_fill_n(TOutputIterator o_begin, TSize n, const T &value, TCounter &count)
Definition: memory.h:189
void memory_set_range(volatile T *begin, size_t n, const char value)
Definition: memory.h:1884
TOutputIterator uninitialized_value_construct_n(TOutputIterator o_begin, TSize n)
Definition: memory.h:888
void create_copy_at(T *p, const T &value)
Definition: memory.h:1635
etl::enable_if< etl::is_trivially_destructible< T >::value, void >::type destroy_at(T *)
Definition: memory.h:949
etl::enable_if< etl::is_trivially_constructible< typename etl::iterator_traits< TOutputIterator >::value_type >::value, TOutputIterator >::type uninitialized_default_construct_n(TOutputIterator o_begin, TSize n)
Definition: memory.h:723
TOutputIterator uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter &count)
Definition: memory.h:309
etl::enable_if< etl::is_trivially_destructible< typename etl::iterator_traits< TIterator >::value_type >::value, TIterator >::type destroy_n(TIterator i_begin, TSize n)
Definition: memory.h:1111
void create_value_at(T *p)
Definition: memory.h:1614
T & make_default_at(T *p)
Definition: memory.h:1668
void memory_clear_range(volatile T *begin, size_t n)
Definition: memory.h:1827
void memory_set(volatile char *p, size_t n, char value)
Definition: memory.h:1854
TOutputIterator uninitialized_move_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin)
Definition: memory.h:597
TOutputIterator uninitialized_copy_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin)
Definition: memory.h:324
etl::enable_if< etl::is_trivially_destructible< typename etl::iterator_traits< TIterator >::value_type >::value, void >::type destroy(TIterator, TIterator)
Definition: memory.h:1025
etl::enable_if< etl::is_trivially_constructible< T >::value, void >::type create_default_at(T *)
Definition: memory.h:1571
TOutputIterator uninitialized_move(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin)
Definition: memory.h:472
TOutputIterator uninitialized_move(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter &count)
Definition: memory.h:485
etl::enable_if< etl::is_trivially_constructible< typename etl::iterator_traits< TOutputIterator >::value_type >::value, void >::type uninitialized_default_construct(TOutputIterator, TOutputIterator)
Definition: memory.h:635
T & make_value_at(T *p, const TParameter &value)
Definition: memory.h:1727
void memory_clear(volatile char *p, size_t n)
Definition: memory.h:1799
TOutputIterator uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin)
Definition: memory.h:297
T & make_copy_at(T *p, const T &other)
Definition: memory.h:1691
TOutputIterator uninitialized_fill_n(TOutputIterator o_begin, TSize n, const T &value)
Definition: memory.h:177
void uninitialized_value_construct(TOutputIterator o_begin, TOutputIterator o_end, TCounter &count)
Definition: memory.h:847
T * addressof(T &t)
Definition: memory.h:61
TOutputIterator uninitialized_copy_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TCounter &count)
Definition: memory.h:336
Definition: memory.h:1765
Definition: memory.h:1205
Definition: memory.h:1914
add_rvalue_reference
Definition: type_traits_generator.h:1348
conditional
Definition: type_traits_generator.h:1202
enable_if
Definition: type_traits_generator.h:1228
is_reference
Definition: type_traits_generator.h:1051
is_same
Definition: type_traits_generator.h:981
Definition: absolute.h:37
void swap(etl::array< T, SIZE > &lhs, etl::array< T, SIZE > &rhs)
Template deduction guides.
Definition: array.h:570
etl::enable_if<!etl::is_trivially_constructible< typename etl::iterator_traits< TOutputIterator >::value_type >::value, TOutputIterator >::type uninitialized_default_construct_n(TOutputIterator o_begin, TSize n, TCounter &count)
Definition: memory.h:770
etl::enable_if<!etl::is_trivially_constructible< typename etl::iterator_traits< TOutputIterator >::value_type >::value, void >::type uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end, TCounter &count)
Definition: memory.h:680
etl::enable_if<!etl::is_trivially_destructible< typename etl::iterator_traits< TIterator >::value_type >::value, void >::type destroy(TIterator i_begin, TIterator i_end, TCounter &count)
Definition: memory.h:1066
etl::enable_if<!etl::is_trivially_destructible< typename etl::iterator_traits< TIterator >::value_type >::value, TIterator >::type destroy_n(TIterator i_begin, TSize n, TCounter &count)
Definition: memory.h:1157
etl::enable_if<!etl::is_trivially_destructible< T >::value, void >::type destroy_at(T *p, TCounter &count)
Definition: memory.h:986