File Coverage

/usr/local/lib/perl5/site_perl/5.26.1/XS/libboost/mini.x/i/boost/container/detail/copy_move_algo.hpp
Criterion Covered Total %
statement 0 6 0.0
branch 0 4 0.0
condition n/a
subroutine n/a
pod n/a
total 0 10 0.0


line stmt bran cond sub pod time code
1             //////////////////////////////////////////////////////////////////////////////
2             //
3             // (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost
4             // Software License, Version 1.0. (See accompanying file
5             // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6             //
7             // See http://www.boost.org/libs/container for documentation.
8             //
9             //////////////////////////////////////////////////////////////////////////////
10             #ifndef BOOST_CONTAINER_DETAIL_COPY_MOVE_ALGO_HPP
11             #define BOOST_CONTAINER_DETAIL_COPY_MOVE_ALGO_HPP
12              
13             #ifndef BOOST_CONFIG_HPP
14             # include
15             #endif
16              
17             #if defined(BOOST_HAS_PRAGMA_ONCE)
18             # pragma once
19             #endif
20              
21             // container
22             #include
23             // container/detail
24             #include
25             #include
26             #include
27             #include
28             #include
29              
30             // move
31             #include
32             #include
33             #include
34             // other
35             #include
36             // std
37             #include //for memmove/memcpy
38              
39             #if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
40             #pragma GCC diagnostic push
41             //pair memcpy optimizations rightfully detected by GCC
42             # if defined(BOOST_GCC) && (BOOST_GCC >= 80000)
43             # pragma GCC diagnostic ignored "-Wclass-memaccess"
44             # endif
45             //GCC 8 seems a bit confused about array access error with static_vector
46             //when out of bound exceptions are being thrown.
47             # if defined(BOOST_GCC) && (BOOST_GCC >= 80000) && (BOOST_GCC < 80200)
48             # pragma GCC diagnostic ignored "-Wstringop-overflow"
49             # endif
50             # pragma GCC diagnostic ignored "-Warray-bounds"
51             #endif
52              
53             namespace boost {
54             namespace container {
55             namespace dtl {
56              
57             template
58             struct are_elements_contiguous
59             {
60             static const bool value = false;
61             };
62              
63             /////////////////////////
64             // raw pointers
65             /////////////////////////
66              
67             template
68             struct are_elements_contiguous
69             {
70             static const bool value = true;
71             };
72              
73             /////////////////////////
74             // move iterators
75             /////////////////////////
76              
77             template
78             struct are_elements_contiguous< ::boost::move_iterator >
79             : are_elements_contiguous
80             {};
81              
82             } //namespace dtl {
83              
84             /////////////////////////
85             // predeclarations
86             /////////////////////////
87              
88             template
89             class vec_iterator;
90              
91             } //namespace container {
92              
93             namespace interprocess {
94              
95             template
96             class offset_ptr;
97              
98             } //namespace interprocess {
99              
100             namespace container {
101              
102             namespace dtl {
103              
104             /////////////////////////
105             //vector_[const_]iterator
106             /////////////////////////
107              
108             template
109             struct are_elements_contiguous >
110             {
111             static const bool value = true;
112             };
113              
114             /////////////////////////
115             // offset_ptr
116             /////////////////////////
117              
118             template
119             struct are_elements_contiguous< ::boost::interprocess::offset_ptr >
120             {
121             static const bool value = true;
122             };
123              
124             template
125             struct are_contiguous_and_same
126             : boost::move_detail::and_
127             < are_elements_contiguous
128             , are_elements_contiguous
129             , is_same< typename remove_const< typename ::boost::container::iterator_traits::value_type >::type
130             , typename ::boost::container::iterator_traits::value_type
131             >
132             >
133             {};
134              
135             template
136             struct is_memtransfer_copy_assignable
137             : boost::move_detail::and_
138             < are_contiguous_and_same
139             , dtl::is_trivially_copy_assignable< typename ::boost::container::iterator_traits::value_type >
140             >
141             {};
142              
143             template
144             struct is_memtransfer_copy_constructible
145             : boost::move_detail::and_
146             < are_contiguous_and_same
147             , dtl::is_trivially_copy_constructible< typename ::boost::container::iterator_traits::value_type >
148             >
149             {};
150              
151             template
152             struct enable_if_memtransfer_copy_constructible
153             : enable_if, R>
154             {};
155              
156             template
157             struct disable_if_memtransfer_copy_constructible
158             : disable_if, R>
159             {};
160              
161             template
162             struct enable_if_memtransfer_copy_assignable
163             : enable_if, R>
164             {};
165              
166             template
167             struct disable_if_memtransfer_copy_assignable
168             : disable_if, R>
169             {};
170              
171             template
172            
173             typename F> // F models ForwardIterator
174             inline F memmove(I f, I l, F r) BOOST_NOEXCEPT_OR_NOTHROW
175             {
176             typedef typename boost::container::iterator_traits::value_type value_type;
177             value_type *const dest_raw = boost::movelib::iterator_to_raw_pointer(r);
178             const value_type *const beg_raw = boost::movelib::iterator_to_raw_pointer(f);
179             const value_type *const end_raw = boost::movelib::iterator_to_raw_pointer(l);
180             if(BOOST_LIKELY(beg_raw != end_raw)){
181             BOOST_ASSERT(beg_raw != 0);
182             const typename boost::container::iterator_traits::difference_type n = end_raw - beg_raw;
183             std::memmove(dest_raw, beg_raw, sizeof(value_type)*n);
184             boost::container::iterator_advance(r, n);
185             }
186             return r;
187             }
188              
189             template
190            
191             typename U, // U models unsigned integral constant
192             typename F> // F models ForwardIterator
193             F memmove_n(I f, U n, F r) BOOST_NOEXCEPT_OR_NOTHROW
194             {
195             typedef typename boost::container::iterator_traits::value_type value_type;
196             if(BOOST_LIKELY(n)){
197             std::memmove(boost::movelib::iterator_to_raw_pointer(r), boost::movelib::iterator_to_raw_pointer(f), sizeof(value_type)*n);
198             boost::container::iterator_advance(r, n);
199             }
200              
201             return r;
202             }
203              
204             template
205            
206             typename U, // U models unsigned integral constant
207             typename F> // F models ForwardIterator
208             I memmove_n_source(I f, U n, F r) BOOST_NOEXCEPT_OR_NOTHROW
209             {
210             if(BOOST_LIKELY(n)){
211             typedef typename boost::container::iterator_traits::value_type value_type;
212             std::memmove(boost::movelib::iterator_to_raw_pointer(r), boost::movelib::iterator_to_raw_pointer(f), sizeof(value_type)*n);
213             boost::container::iterator_advance(f, n);
214             }
215             return f;
216             }
217              
218             template
219            
220             typename U, // U models unsigned integral constant
221             typename F> // F models ForwardIterator
222             I memmove_n_source_dest(I f, U n, F &r) BOOST_NOEXCEPT_OR_NOTHROW
223             {
224             typedef typename boost::container::iterator_traits::value_type value_type;
225             if(BOOST_LIKELY(n)){
226             std::memmove(boost::movelib::iterator_to_raw_pointer(r), boost::movelib::iterator_to_raw_pointer(f), sizeof(value_type)*n);
227             boost::container::iterator_advance(f, n);
228             boost::container::iterator_advance(r, n);
229             }
230             return f;
231             }
232              
233             template
234             struct is_memzero_initializable
235             {
236             typedef typename ::boost::container::iterator_traits::value_type value_type;
237             static const bool value = are_elements_contiguous::value &&
238             ( dtl::is_integral::value || dtl::is_enum::value
239             #if defined(BOOST_CONTAINER_MEMZEROED_POINTER_IS_NULL)
240             || dtl::is_pointer::value
241             #endif
242             #if defined(BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_ZERO)
243             || dtl::is_floating_point::value
244             #endif
245             #if defined(BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_ZERO) && defined(BOOST_CONTAINER_MEMZEROED_POINTER_IS_NULL)
246             || dtl::is_pod::value
247             #endif
248             );
249             };
250              
251             template
252             struct enable_if_memzero_initializable
253             : enable_if_c::value, R>
254             {};
255              
256             template
257             struct disable_if_memzero_initializable
258             : enable_if_c::value, R>
259             {};
260              
261             template
262             struct enable_if_trivially_destructible
263             : enable_if_c < dtl::is_trivially_destructible
264             ::value_type>::value
265             , R>
266             {};
267              
268             template
269             struct disable_if_trivially_destructible
270             : enable_if_c
271             ::value_type>::value
272             , R>
273             {};
274              
275             } //namespace dtl {
276              
277             //////////////////////////////////////////////////////////////////////////////
278             //
279             // uninitialized_move_alloc
280             //
281             //////////////////////////////////////////////////////////////////////////////
282              
283              
284             //! Effects:
285             //! \code
286             //! for (; f != l; ++r, ++f)
287             //! allocator_traits::construct(a, &*r, boost::move(*f));
288             //! \endcode
289             //!
290             //! Returns: r
291             template
292            
293             typename I, // I models InputIterator
294             typename F> // F models ForwardIterator
295             inline typename dtl::disable_if_memtransfer_copy_constructible::type
296             uninitialized_move_alloc(Allocator &a, I f, I l, F r)
297             {
298             F back = r;
299             BOOST_TRY{
300             while (f != l) {
301             allocator_traits::construct(a, boost::movelib::iterator_to_raw_pointer(r), boost::move(*f));
302             ++f; ++r;
303             }
304             }
305             BOOST_CATCH(...){
306             for (; back != r; ++back){
307             allocator_traits::destroy(a, boost::movelib::iterator_to_raw_pointer(back));
308             }
309             BOOST_RETHROW;
310             }
311             BOOST_CATCH_END
312             return r;
313             }
314              
315             template
316            
317             typename I, // I models InputIterator
318             typename F> // F models ForwardIterator
319             inline typename dtl::enable_if_memtransfer_copy_constructible::type
320             uninitialized_move_alloc(Allocator &, I f, I l, F r) BOOST_NOEXCEPT_OR_NOTHROW
321             { return dtl::memmove(f, l, r); }
322              
323             //////////////////////////////////////////////////////////////////////////////
324             //
325             // uninitialized_move_alloc_n
326             //
327             //////////////////////////////////////////////////////////////////////////////
328              
329             //! Effects:
330             //! \code
331             //! for (; n--; ++r, ++f)
332             //! allocator_traits::construct(a, &*r, boost::move(*f));
333             //! \endcode
334             //!
335             //! Returns: r
336             template
337            
338             typename I, // I models InputIterator
339             typename F> // F models ForwardIterator
340             inline typename dtl::disable_if_memtransfer_copy_constructible::type
341             uninitialized_move_alloc_n(Allocator &a, I f, typename boost::container::allocator_traits::size_type n, F r)
342             {
343             F back = r;
344             BOOST_TRY{
345             while (n--) {
346             allocator_traits::construct(a, boost::movelib::iterator_to_raw_pointer(r), boost::move(*f));
347             ++f; ++r;
348             }
349             }
350             BOOST_CATCH(...){
351             for (; back != r; ++back){
352             allocator_traits::destroy(a, boost::movelib::iterator_to_raw_pointer(back));
353             }
354             BOOST_RETHROW;
355             }
356             BOOST_CATCH_END
357             return r;
358             }
359              
360             template
361            
362             typename I, // I models InputIterator
363             typename F> // F models ForwardIterator
364             inline typename dtl::enable_if_memtransfer_copy_constructible::type
365             uninitialized_move_alloc_n(Allocator &, I f, typename boost::container::allocator_traits::size_type n, F r) BOOST_NOEXCEPT_OR_NOTHROW
366             { return dtl::memmove_n(f, n, r); }
367              
368             //////////////////////////////////////////////////////////////////////////////
369             //
370             // uninitialized_move_alloc_n_source
371             //
372             //////////////////////////////////////////////////////////////////////////////
373              
374             //! Effects:
375             //! \code
376             //! for (; n--; ++r, ++f)
377             //! allocator_traits::construct(a, &*r, boost::move(*f));
378             //! \endcode
379             //!
380             //! Returns: f (after incremented)
381             template
382            
383             typename I, // I models InputIterator
384             typename F> // F models ForwardIterator
385             inline typename dtl::disable_if_memtransfer_copy_constructible::type
386             uninitialized_move_alloc_n_source(Allocator &a, I f, typename boost::container::allocator_traits::size_type n, F r)
387             {
388             F back = r;
389             BOOST_TRY{
390             while (n--) {
391             allocator_traits::construct(a, boost::movelib::iterator_to_raw_pointer(r), boost::move(*f));
392             ++f; ++r;
393             }
394             }
395             BOOST_CATCH(...){
396             for (; back != r; ++back){
397             allocator_traits::destroy(a, boost::movelib::iterator_to_raw_pointer(back));
398             }
399             BOOST_RETHROW;
400             }
401             BOOST_CATCH_END
402             return f;
403             }
404              
405             template
406            
407             typename I, // I models InputIterator
408             typename F> // F models ForwardIterator
409             inline typename dtl::enable_if_memtransfer_copy_constructible::type
410             uninitialized_move_alloc_n_source(Allocator &, I f, typename boost::container::allocator_traits::size_type n, F r) BOOST_NOEXCEPT_OR_NOTHROW
411             { return dtl::memmove_n_source(f, n, r); }
412              
413             //////////////////////////////////////////////////////////////////////////////
414             //
415             // uninitialized_copy_alloc
416             //
417             //////////////////////////////////////////////////////////////////////////////
418              
419             //! Effects:
420             //! \code
421             //! for (; f != l; ++r, ++f)
422             //! allocator_traits::construct(a, &*r, *f);
423             //! \endcode
424             //!
425             //! Returns: r
426             template
427            
428             typename I, // I models InputIterator
429             typename F> // F models ForwardIterator
430             inline typename dtl::disable_if_memtransfer_copy_constructible::type
431             uninitialized_copy_alloc(Allocator &a, I f, I l, F r)
432             {
433             F back = r;
434             BOOST_TRY{
435             while (f != l) {
436             allocator_traits::construct(a, boost::movelib::iterator_to_raw_pointer(r), *f);
437             ++f; ++r;
438             }
439             }
440             BOOST_CATCH(...){
441             for (; back != r; ++back){
442             allocator_traits::destroy(a, boost::movelib::iterator_to_raw_pointer(back));
443             }
444             BOOST_RETHROW;
445             }
446             BOOST_CATCH_END
447             return r;
448             }
449              
450             template
451            
452             typename I, // I models InputIterator
453             typename F> // F models ForwardIterator
454             inline typename dtl::enable_if_memtransfer_copy_constructible::type
455             uninitialized_copy_alloc(Allocator &, I f, I l, F r) BOOST_NOEXCEPT_OR_NOTHROW
456             { return dtl::memmove(f, l, r); }
457              
458             //////////////////////////////////////////////////////////////////////////////
459             //
460             // uninitialized_copy_alloc_n
461             //
462             //////////////////////////////////////////////////////////////////////////////
463              
464             //! Effects:
465             //! \code
466             //! for (; n--; ++r, ++f)
467             //! allocator_traits::construct(a, &*r, *f);
468             //! \endcode
469             //!
470             //! Returns: r
471             template
472            
473             typename I, // I models InputIterator
474             typename F> // F models ForwardIterator
475             inline typename dtl::disable_if_memtransfer_copy_constructible::type
476             uninitialized_copy_alloc_n(Allocator &a, I f, typename boost::container::allocator_traits::size_type n, F r)
477             {
478             F back = r;
479             BOOST_TRY{
480             while (n--) {
481             allocator_traits::construct(a, boost::movelib::iterator_to_raw_pointer(r), *f);
482             ++f; ++r;
483             }
484             }
485             BOOST_CATCH(...){
486             for (; back != r; ++back){
487             allocator_traits::destroy(a, boost::movelib::iterator_to_raw_pointer(back));
488             }
489             BOOST_RETHROW;
490             }
491             BOOST_CATCH_END
492             return r;
493             }
494              
495             template
496            
497             typename I, // I models InputIterator
498             typename F> // F models ForwardIterator
499             inline typename dtl::enable_if_memtransfer_copy_constructible::type
500             uninitialized_copy_alloc_n(Allocator &, I f, typename boost::container::allocator_traits::size_type n, F r) BOOST_NOEXCEPT_OR_NOTHROW
501             { return dtl::memmove_n(f, n, r); }
502              
503             //////////////////////////////////////////////////////////////////////////////
504             //
505             // uninitialized_copy_alloc_n_source
506             //
507             //////////////////////////////////////////////////////////////////////////////
508              
509             //! Effects:
510             //! \code
511             //! for (; n--; ++r, ++f)
512             //! allocator_traits::construct(a, &*r, *f);
513             //! \endcode
514             //!
515             //! Returns: f (after incremented)
516             template
517            
518             typename I, // I models InputIterator
519             typename F> // F models ForwardIterator
520             inline typename dtl::disable_if_memtransfer_copy_constructible::type
521             uninitialized_copy_alloc_n_source(Allocator &a, I f, typename boost::container::allocator_traits::size_type n, F r)
522             {
523             F back = r;
524             BOOST_TRY{
525             while (n--) {
526             boost::container::construct_in_place(a, boost::movelib::iterator_to_raw_pointer(r), f);
527             ++f; ++r;
528             }
529             }
530             BOOST_CATCH(...){
531             for (; back != r; ++back){
532             allocator_traits::destroy(a, boost::movelib::iterator_to_raw_pointer(back));
533             }
534             BOOST_RETHROW;
535             }
536             BOOST_CATCH_END
537             return f;
538             }
539              
540             template
541            
542             typename I, // I models InputIterator
543             typename F> // F models ForwardIterator
544             inline typename dtl::enable_if_memtransfer_copy_constructible::type
545             uninitialized_copy_alloc_n_source(Allocator &, I f, typename boost::container::allocator_traits::size_type n, F r) BOOST_NOEXCEPT_OR_NOTHROW
546             { return dtl::memmove_n_source(f, n, r); }
547              
548             //////////////////////////////////////////////////////////////////////////////
549             //
550             // uninitialized_value_init_alloc_n
551             //
552             //////////////////////////////////////////////////////////////////////////////
553              
554             //! Effects:
555             //! \code
556             //! for (; n--; ++r, ++f)
557             //! allocator_traits::construct(a, &*r);
558             //! \endcode
559             //!
560             //! Returns: r
561             template
562            
563             typename F> // F models ForwardIterator
564             inline typename dtl::disable_if_memzero_initializable::type
565             uninitialized_value_init_alloc_n(Allocator &a, typename boost::container::allocator_traits::size_type n, F r)
566             {
567             F back = r;
568             BOOST_TRY{
569             while (n--) {
570             allocator_traits::construct(a, boost::movelib::iterator_to_raw_pointer(r));
571             ++r;
572             }
573             }
574             BOOST_CATCH(...){
575             for (; back != r; ++back){
576             allocator_traits::destroy(a, boost::movelib::iterator_to_raw_pointer(back));
577             }
578             BOOST_RETHROW;
579             }
580             BOOST_CATCH_END
581             return r;
582             }
583              
584             template
585            
586             typename F> // F models ForwardIterator
587             inline typename dtl::enable_if_memzero_initializable::type
588             uninitialized_value_init_alloc_n(Allocator &, typename boost::container::allocator_traits::size_type n, F r)
589             {
590             typedef typename boost::container::iterator_traits::value_type value_type;
591             std::memset((void*)boost::movelib::iterator_to_raw_pointer(r), 0, sizeof(value_type)*n);
592             boost::container::iterator_advance(r, n);
593             return r;
594             }
595              
596             //////////////////////////////////////////////////////////////////////////////
597             //
598             // uninitialized_default_init_alloc_n
599             //
600             //////////////////////////////////////////////////////////////////////////////
601              
602             //! Effects:
603             //! \code
604             //! for (; n--; ++r, ++f)
605             //! allocator_traits::construct(a, &*r);
606             //! \endcode
607             //!
608             //! Returns: r
609             template
610            
611             typename F> // F models ForwardIterator
612             inline F uninitialized_default_init_alloc_n(Allocator &a, typename boost::container::allocator_traits::size_type n, F r)
613             {
614             F back = r;
615             BOOST_TRY{
616             while (n--) {
617             allocator_traits::construct(a, boost::movelib::iterator_to_raw_pointer(r), default_init);
618             ++r;
619             }
620             }
621             BOOST_CATCH(...){
622             for (; back != r; ++back){
623             allocator_traits::destroy(a, boost::movelib::iterator_to_raw_pointer(back));
624             }
625             BOOST_RETHROW;
626             }
627             BOOST_CATCH_END
628             return r;
629             }
630              
631             //////////////////////////////////////////////////////////////////////////////
632             //
633             // uninitialized_fill_alloc
634             //
635             //////////////////////////////////////////////////////////////////////////////
636              
637             //! Effects:
638             //! \code
639             //! for (; f != l; ++r, ++f)
640             //! allocator_traits::construct(a, &*r, *f);
641             //! \endcode
642             //!
643             //! Returns: r
644             template
645            
646             typename F, // F models ForwardIterator
647             typename T>
648             inline void uninitialized_fill_alloc(Allocator &a, F f, F l, const T &t)
649             {
650             F back = f;
651             BOOST_TRY{
652             while (f != l) {
653             allocator_traits::construct(a, boost::movelib::iterator_to_raw_pointer(f), t);
654             ++f;
655             }
656             }
657             BOOST_CATCH(...){
658             for (; back != l; ++back){
659             allocator_traits::destroy(a, boost::movelib::iterator_to_raw_pointer(back));
660             }
661             BOOST_RETHROW;
662             }
663             BOOST_CATCH_END
664             }
665              
666              
667             //////////////////////////////////////////////////////////////////////////////
668             //
669             // uninitialized_fill_alloc_n
670             //
671             //////////////////////////////////////////////////////////////////////////////
672              
673             //! Effects:
674             //! \code
675             //! for (; n--; ++r, ++f)
676             //! allocator_traits::construct(a, &*r, v);
677             //! \endcode
678             //!
679             //! Returns: r
680             template
681            
682             typename T,
683             typename F> // F models ForwardIterator
684             inline F uninitialized_fill_alloc_n(Allocator &a, const T &v, typename boost::container::allocator_traits::size_type n, F r)
685             {
686             F back = r;
687             BOOST_TRY{
688             while (n--) {
689             allocator_traits::construct(a, boost::movelib::iterator_to_raw_pointer(r), v);
690             ++r;
691             }
692             }
693             BOOST_CATCH(...){
694             for (; back != r; ++back){
695             allocator_traits::destroy(a, boost::movelib::iterator_to_raw_pointer(back));
696             }
697             BOOST_RETHROW;
698             }
699             BOOST_CATCH_END
700             return r;
701             }
702              
703             //////////////////////////////////////////////////////////////////////////////
704             //
705             // copy
706             //
707             //////////////////////////////////////////////////////////////////////////////
708              
709             template
710            
711             typename F> // F models ForwardIterator
712             inline typename dtl::disable_if_memtransfer_copy_assignable::type
713             copy(I f, I l, F r)
714             {
715             while (f != l) {
716             *r = *f;
717             ++f; ++r;
718             }
719             return r;
720             }
721              
722             template
723            
724             typename F> // F models ForwardIterator
725             inline typename dtl::enable_if_memtransfer_copy_assignable::type
726             copy(I f, I l, F r) BOOST_NOEXCEPT_OR_NOTHROW
727             { return dtl::memmove(f, l, r); }
728              
729             //////////////////////////////////////////////////////////////////////////////
730             //
731             // copy_n
732             //
733             //////////////////////////////////////////////////////////////////////////////
734              
735             template
736            
737             typename U, // U models unsigned integral constant
738             typename F> // F models ForwardIterator
739             inline typename dtl::disable_if_memtransfer_copy_assignable::type
740             copy_n(I f, U n, F r)
741             {
742             while (n) {
743             --n;
744             *r = *f;
745             ++f; ++r;
746             }
747             return r;
748             }
749              
750             template
751            
752             typename U, // U models unsigned integral constant
753             typename F> // F models ForwardIterator
754             inline typename dtl::enable_if_memtransfer_copy_assignable::type
755             copy_n(I f, U n, F r) BOOST_NOEXCEPT_OR_NOTHROW
756             { return dtl::memmove_n(f, n, r); }
757              
758             //////////////////////////////////////////////////////////////////////////////
759             //
760             // copy_n_source
761             //
762             //////////////////////////////////////////////////////////////////////////////
763              
764             template
765            
766             typename U, // U models unsigned integral constant
767             typename F> // F models ForwardIterator
768             inline typename dtl::disable_if_memtransfer_copy_assignable::type
769             copy_n_source(I f, U n, F r)
770             {
771             while (n--) {
772             boost::container::assign_in_place(r, f);
773             ++f; ++r;
774             }
775             return f;
776             }
777              
778             template
779            
780             typename U, // U models unsigned integral constant
781             typename F> // F models ForwardIterator
782             inline typename dtl::enable_if_memtransfer_copy_assignable::type
783             copy_n_source(I f, U n, F r) BOOST_NOEXCEPT_OR_NOTHROW
784             { return dtl::memmove_n_source(f, n, r); }
785              
786             //////////////////////////////////////////////////////////////////////////////
787             //
788             // copy_n_source_dest
789             //
790             //////////////////////////////////////////////////////////////////////////////
791              
792             template
793            
794             typename U, // U models unsigned integral constant
795             typename F> // F models ForwardIterator
796             inline typename dtl::disable_if_memtransfer_copy_assignable::type
797             copy_n_source_dest(I f, U n, F &r)
798             {
799             while (n--) {
800             *r = *f;
801             ++f; ++r;
802             }
803             return f;
804             }
805              
806             template
807            
808             typename U, // U models unsigned integral constant
809             typename F> // F models ForwardIterator
810             inline typename dtl::enable_if_memtransfer_copy_assignable::type
811             copy_n_source_dest(I f, U n, F &r) BOOST_NOEXCEPT_OR_NOTHROW
812             { return dtl::memmove_n_source_dest(f, n, r); }
813              
814             //////////////////////////////////////////////////////////////////////////////
815             //
816             // move
817             //
818             //////////////////////////////////////////////////////////////////////////////
819              
820             template
821            
822             typename F> // F models ForwardIterator
823             inline typename dtl::disable_if_memtransfer_copy_assignable::type
824             move(I f, I l, F r)
825             {
826             while (f != l) {
827             *r = ::boost::move(*f);
828             ++f; ++r;
829             }
830             return r;
831             }
832              
833             template
834            
835             typename F> // F models ForwardIterator
836             inline typename dtl::enable_if_memtransfer_copy_assignable::type
837             move(I f, I l, F r) BOOST_NOEXCEPT_OR_NOTHROW
838             { return dtl::memmove(f, l, r); }
839              
840             //////////////////////////////////////////////////////////////////////////////
841             //
842             // move_n
843             //
844             //////////////////////////////////////////////////////////////////////////////
845              
846             template
847            
848             typename U, // U models unsigned integral constant
849             typename F> // F models ForwardIterator
850             inline typename dtl::disable_if_memtransfer_copy_assignable::type
851             move_n(I f, U n, F r)
852             {
853             while (n--) {
854             *r = ::boost::move(*f);
855             ++f; ++r;
856             }
857             return r;
858             }
859              
860             template
861            
862             typename U, // U models unsigned integral constant
863             typename F> // F models ForwardIterator
864             inline typename dtl::enable_if_memtransfer_copy_assignable::type
865             move_n(I f, U n, F r) BOOST_NOEXCEPT_OR_NOTHROW
866             { return dtl::memmove_n(f, n, r); }
867              
868              
869             //////////////////////////////////////////////////////////////////////////////
870             //
871             // move_backward
872             //
873             //////////////////////////////////////////////////////////////////////////////
874              
875             template
876            
877             typename F> // F models ForwardIterator
878             inline typename dtl::disable_if_memtransfer_copy_assignable::type
879             move_backward(I f, I l, F r)
880             {
881             while (f != l) {
882             --l; --r;
883             *r = ::boost::move(*l);
884             }
885             return r;
886             }
887              
888             template
889            
890             typename F> // F models ForwardIterator
891             inline typename dtl::enable_if_memtransfer_copy_assignable::type
892             move_backward(I f, I l, F r) BOOST_NOEXCEPT_OR_NOTHROW
893             {
894             typedef typename boost::container::iterator_traits::value_type value_type;
895             const typename boost::container::iterator_traits::difference_type n = boost::container::iterator_distance(f, l);
896             r -= n;
897             std::memmove((boost::movelib::iterator_to_raw_pointer)(r), (boost::movelib::iterator_to_raw_pointer)(f), sizeof(value_type)*n);
898             return r;
899             }
900              
901             //////////////////////////////////////////////////////////////////////////////
902             //
903             // move_n_source_dest
904             //
905             //////////////////////////////////////////////////////////////////////////////
906              
907             template
908            
909             ,typename U // U models unsigned integral constant
910             ,typename F> // F models ForwardIterator
911             inline typename dtl::disable_if_memtransfer_copy_assignable::type
912             move_n_source_dest(I f, U n, F &r)
913             {
914             while (n--) {
915             *r = ::boost::move(*f);
916             ++f; ++r;
917             }
918             return f;
919             }
920              
921             template
922            
923             ,typename U // U models unsigned integral constant
924             ,typename F> // F models ForwardIterator
925             inline typename dtl::enable_if_memtransfer_copy_assignable::type
926             move_n_source_dest(I f, U n, F &r) BOOST_NOEXCEPT_OR_NOTHROW
927             { return dtl::memmove_n_source_dest(f, n, r); }
928              
929             //////////////////////////////////////////////////////////////////////////////
930             //
931             // move_n_source
932             //
933             //////////////////////////////////////////////////////////////////////////////
934              
935             template
936            
937             ,typename U // U models unsigned integral constant
938             ,typename F> // F models ForwardIterator
939             inline typename dtl::disable_if_memtransfer_copy_assignable::type
940             move_n_source(I f, U n, F r)
941             {
942             while (n--) {
943             *r = ::boost::move(*f);
944             ++f; ++r;
945             }
946             return f;
947             }
948              
949             template
950            
951             ,typename U // U models unsigned integral constant
952             ,typename F> // F models ForwardIterator
953             inline typename dtl::enable_if_memtransfer_copy_assignable::type
954             move_n_source(I f, U n, F r) BOOST_NOEXCEPT_OR_NOTHROW
955             { return dtl::memmove_n_source(f, n, r); }
956              
957             //////////////////////////////////////////////////////////////////////////////
958             //
959             // destroy_alloc_n
960             //
961             //////////////////////////////////////////////////////////////////////////////
962              
963             template
964            
965             ,typename I // I models InputIterator
966             ,typename U> // U models unsigned integral constant
967             inline typename dtl::disable_if_trivially_destructible::type
968 0           destroy_alloc_n(Allocator &a, I f, U n)
969             {
970 0 0         while(n){
    0          
971 0           --n;
972 0           allocator_traits::destroy(a, boost::movelib::iterator_to_raw_pointer(f));
973 0           ++f;
974             }
975 0           }
976              
977             template
978            
979             ,typename I // I models InputIterator
980             ,typename U> // U models unsigned integral constant
981             inline typename dtl::enable_if_trivially_destructible::type
982             destroy_alloc_n(Allocator &, I, U)
983             {}
984              
985             //////////////////////////////////////////////////////////////////////////////
986             //
987             // deep_swap_alloc_n
988             //
989             //////////////////////////////////////////////////////////////////////////////
990              
991             template
992            
993             ,typename Allocator
994             ,typename F // F models ForwardIterator
995             ,typename G // G models ForwardIterator
996             >
997             inline typename dtl::disable_if_memtransfer_copy_assignable::type
998             deep_swap_alloc_n( Allocator &a, F short_range_f, typename allocator_traits::size_type n_i
999             , G large_range_f, typename allocator_traits::size_type n_j)
1000             {
1001             typename allocator_traits::size_type n = 0;
1002             for (; n != n_i ; ++short_range_f, ++large_range_f, ++n){
1003             boost::adl_move_swap(*short_range_f, *large_range_f);
1004             }
1005             boost::container::uninitialized_move_alloc_n(a, large_range_f, n_j - n_i, short_range_f); // may throw
1006             boost::container::destroy_alloc_n(a, large_range_f, n_j - n_i);
1007             }
1008              
1009             static const std::size_t DeepSwapAllocNMaxStorage = std::size_t(1) << std::size_t(11); //2K bytes
1010              
1011             template
1012            
1013             ,typename Allocator
1014             ,typename F // F models ForwardIterator
1015             ,typename G // G models ForwardIterator
1016             >
1017             inline typename dtl::enable_if_c
1018             < dtl::is_memtransfer_copy_assignable::value && (MaxTmpBytes <= DeepSwapAllocNMaxStorage) && false
1019             , void>::type
1020             deep_swap_alloc_n( Allocator &a, F short_range_f, typename allocator_traits::size_type n_i
1021             , G large_range_f, typename allocator_traits::size_type n_j)
1022             {
1023             typedef typename allocator_traits::value_type value_type;
1024             typedef typename dtl::aligned_storage
1025             ::value>::type storage_type;
1026             storage_type storage;
1027              
1028             const std::size_t n_i_bytes = sizeof(value_type)*n_i;
1029             void *const large_ptr = static_cast(boost::movelib::iterator_to_raw_pointer(large_range_f));
1030             void *const short_ptr = static_cast(boost::movelib::iterator_to_raw_pointer(short_range_f));
1031             void *const stora_ptr = static_cast(boost::movelib::iterator_to_raw_pointer(storage.data));
1032             std::memcpy(stora_ptr, large_ptr, n_i_bytes);
1033             std::memcpy(large_ptr, short_ptr, n_i_bytes);
1034             std::memcpy(short_ptr, stora_ptr, n_i_bytes);
1035             boost::container::iterator_advance(large_range_f, n_i);
1036             boost::container::iterator_advance(short_range_f, n_i);
1037             boost::container::uninitialized_move_alloc_n(a, large_range_f, n_j - n_i, short_range_f); // may throw
1038             boost::container::destroy_alloc_n(a, large_range_f, n_j - n_i);
1039             }
1040              
1041             template
1042            
1043             ,typename Allocator
1044             ,typename F // F models ForwardIterator
1045             ,typename G // G models ForwardIterator
1046             >
1047             inline typename dtl::enable_if_c
1048             < dtl::is_memtransfer_copy_assignable::value && true//(MaxTmpBytes > DeepSwapAllocNMaxStorage)
1049             , void>::type
1050             deep_swap_alloc_n( Allocator &a, F short_range_f, typename allocator_traits::size_type n_i
1051             , G large_range_f, typename allocator_traits::size_type n_j)
1052             {
1053             typedef typename allocator_traits::value_type value_type;
1054             typedef typename dtl::aligned_storage
1055             ::value>::type storage_type;
1056             storage_type storage;
1057             const std::size_t sizeof_storage = sizeof(storage);
1058              
1059             std::size_t n_i_bytes = sizeof(value_type)*n_i;
1060             char *large_ptr = static_cast(static_cast(boost::movelib::iterator_to_raw_pointer(large_range_f)));
1061             char *short_ptr = static_cast(static_cast(boost::movelib::iterator_to_raw_pointer(short_range_f)));
1062             char *stora_ptr = static_cast(static_cast(storage.data));
1063              
1064             std::size_t szt_times = n_i_bytes/sizeof_storage;
1065             const std::size_t szt_rem = n_i_bytes%sizeof_storage;
1066              
1067             //Loop unrolling using Duff's device, as it seems it helps on some architectures
1068             const std::size_t Unroll = 4;
1069             std::size_t n = (szt_times + (Unroll-1))/Unroll;
1070             const std::size_t branch_number = (!szt_times)*Unroll + (szt_times % Unroll);
1071             switch(branch_number){
1072             case 4:
1073             break;
1074             case 0: do{
1075             std::memcpy(stora_ptr, large_ptr, sizeof_storage);
1076             std::memcpy(large_ptr, short_ptr, sizeof_storage);
1077             std::memcpy(short_ptr, stora_ptr, sizeof_storage);
1078             large_ptr += sizeof_storage;
1079             short_ptr += sizeof_storage;
1080             BOOST_FALLTHROUGH;
1081             case 3:
1082             std::memcpy(stora_ptr, large_ptr, sizeof_storage);
1083             std::memcpy(large_ptr, short_ptr, sizeof_storage);
1084             std::memcpy(short_ptr, stora_ptr, sizeof_storage);
1085             large_ptr += sizeof_storage;
1086             short_ptr += sizeof_storage;
1087             BOOST_FALLTHROUGH;
1088             case 2:
1089             std::memcpy(stora_ptr, large_ptr, sizeof_storage);
1090             std::memcpy(large_ptr, short_ptr, sizeof_storage);
1091             std::memcpy(short_ptr, stora_ptr, sizeof_storage);
1092             large_ptr += sizeof_storage;
1093             short_ptr += sizeof_storage;
1094             BOOST_FALLTHROUGH;
1095             case 1:
1096             std::memcpy(stora_ptr, large_ptr, sizeof_storage);
1097             std::memcpy(large_ptr, short_ptr, sizeof_storage);
1098             std::memcpy(short_ptr, stora_ptr, sizeof_storage);
1099             large_ptr += sizeof_storage;
1100             short_ptr += sizeof_storage;
1101             } while(--n);
1102             }
1103             std::memcpy(stora_ptr, large_ptr, szt_rem);
1104             std::memcpy(large_ptr, short_ptr, szt_rem);
1105             std::memcpy(short_ptr, stora_ptr, szt_rem);
1106             boost::container::iterator_advance(large_range_f, n_i);
1107             boost::container::iterator_advance(short_range_f, n_i);
1108             boost::container::uninitialized_move_alloc_n(a, large_range_f, n_j - n_i, short_range_f); // may throw
1109             boost::container::destroy_alloc_n(a, large_range_f, n_j - n_i);
1110             }
1111              
1112              
1113             //////////////////////////////////////////////////////////////////////////////
1114             //
1115             // copy_assign_range_alloc_n
1116             //
1117             //////////////////////////////////////////////////////////////////////////////
1118              
1119             template
1120            
1121             ,typename I // F models InputIterator
1122             ,typename O // G models OutputIterator
1123             >
1124             void copy_assign_range_alloc_n( Allocator &a, I inp_start, typename allocator_traits::size_type n_i
1125             , O out_start, typename allocator_traits::size_type n_o )
1126             {
1127             if (n_o < n_i){
1128             inp_start = boost::container::copy_n_source_dest(inp_start, n_o, out_start); // may throw
1129             boost::container::uninitialized_copy_alloc_n(a, inp_start, n_i - n_o, out_start);// may throw
1130             }
1131             else{
1132             out_start = boost::container::copy_n(inp_start, n_i, out_start); // may throw
1133             boost::container::destroy_alloc_n(a, out_start, n_o - n_i);
1134             }
1135             }
1136              
1137             //////////////////////////////////////////////////////////////////////////////
1138             //
1139             // move_assign_range_alloc_n
1140             //
1141             //////////////////////////////////////////////////////////////////////////////
1142              
1143             template
1144            
1145             ,typename I // F models InputIterator
1146             ,typename O // G models OutputIterator
1147             >
1148             void move_assign_range_alloc_n( Allocator &a, I inp_start, typename allocator_traits::size_type n_i
1149             , O out_start, typename allocator_traits::size_type n_o )
1150             {
1151             if (n_o < n_i){
1152             inp_start = boost::container::move_n_source_dest(inp_start, n_o, out_start); // may throw
1153             boost::container::uninitialized_move_alloc_n(a, inp_start, n_i - n_o, out_start); // may throw
1154             }
1155             else{
1156             out_start = boost::container::move_n(inp_start, n_i, out_start); // may throw
1157             boost::container::destroy_alloc_n(a, out_start, n_o - n_i);
1158             }
1159             }
1160              
1161             } //namespace container {
1162             } //namespace boost {
1163              
1164             //#pragma GCC diagnostic ignored "-Wclass-memaccess"
1165             #if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
1166             #pragma GCC diagnostic pop
1167             #endif
1168              
1169             #endif //#ifndef BOOST_CONTAINER_DETAIL_COPY_MOVE_ALGO_HPP