• The caller must ensure that the destination range is big enough or that insert iterators are used. • See Section 9.4.2, page 454, for the implementation of the copy() algorithm. • Since C++11, if the source elements are no longer used, you should prefer move() over copy() and move_backward() over and copy_backward() (see Section 11.6.2, page 561). • Before C++11, no copy_if() and copy_n() algorithms were provided. To copy only those elements meeting a certain criterion, you had to use remove_copy_if() (see Section 11.7.1, page 577) with a negated predicate. • Use reverse_copy() to reverse the order of the elements during the copy (see Section 11.8.1, page 583). Note that reverse_copy() may be slightly more efficient than using copy() with reverse iterators. • To assign all elements of a container, use the assignment operator if the containers have the same type (see Section 8.4, page 406) or the assign() member function if the containers have different types (see Section 8.4, page 407). • To remove elementswhile they are being copied, use remove_copy() and remove_copy_if() (see Section 11.7.1, page 577). • To modify elements while they are being copied, use transform() (see Section 11.6.3, page 563) or replace_copy() (see Section 11.6.6, page 573). • Use partition_copy() (see Section 11.8.6, page 594) to copy elements into two destination ranges: one fulfilling and one not fulfilling a predicate. • Complexity: linear (numElems assignments). The following example shows some simple calls of copy() (see Section 11.6.2, page 562, for a corresponding version using move() when possible):
•โทรต้องให้แน่ใจว่าช่วงปลายทางมีขนาดใหญ่พอหรือว่าใส่ iterators ถูกนำมาใช้ •ดูมาตรา 9.4.2, หน้า 454, สำหรับการดำเนินงานของการคัดลอก () ขั้นตอนวิธีการ •ตั้งแต่ C + +11 ถ้าองค์ประกอบของแหล่งที่มาจะไม่ใช้คุณควรต้องการย้าย () ผ่านการคัดลอก () และ move_backward () กว่าและ copy_backward () (ดูมาตรา 11.6.2, หน้า 561) •ก่อน C + +11 ไม่มี copy_if () และ copy_n () ขั้นตอนวิธีการได้ให้ เพื่อคัดลอกองค์ประกอบเหล่านั้นเท่านั้นการประชุมเกณฑ์บางอย่างคุณต้องใช้ remove_copy_if () (ดูมาตรา 11.7.1, หน้า 577) ที่มีการกล่าวเมื่อตะกี้ •ใช้ reverse_copy () เพื่อกลับคำสั่งขององค์ประกอบระหว่างการคัดลอก (ดูมาตรา 11.8.1, หน้า 583) หมายเหตุ reverse_copy ที่ () อาจจะเล็กน้อยมีประสิทธิภาพมากขึ้นกว่าการใช้สำเนา () ที่มี iterators กลับ •การกำหนดองค์ประกอบทั้งหมดของภาชนะที่ใช้ประกอบการมอบหมายถ้าภาชนะบรรจุที่มีชนิดเดียวกัน (ดูมาตรา 8.4, หน้า 406) หรือกำหนด () ฟังก์ชันสมาชิกถ้าภาชนะบรรจุที่มีชนิดที่แตกต่างกัน (ดูมาตรา 8.4, หน้า 407) •ในการลบ elementswhile พวกเขาจะถูกคัดลอกใช้ remove_copy () และ remove_copy_if () (ดูมาตรา 11.7.1, หน้า 577) •การปรับเปลี่ยนองค์ประกอบในขณะที่พวกเขาจะถูกคัดลอกใช้แปลง () (ดูมาตรา 11.6.3, หน้า 563) หรือ replace_copy () (ดูมาตรา 11.6.6, หน้า 573) •ใช้ partition_copy () (ดูมาตรา 11.8.6, หน้า 594) เพื่อคัดลอกองค์ประกอบเป็นสองหัวข้อช่วงหนึ่งการตอบสนองและเป็นหนึ่งในไม่ปฏิบัติตามคำกริยา •ซับซ้อน: เชิงเส้น (ที่ได้รับมอบหมาย numElems) ตัวอย่างต่อไปนี้แสดงให้เห็นว่าบางสายที่ง่ายของการคัดลอก () (ดูมาตรา 11.6.2, หน้า 562 สำหรับรุ่นที่ตรงกันโดยใช้ย้าย () เมื่อเป็นไปได้):
การแปล กรุณารอสักครู่..
