• The first form returns the position of the first element in the range [beg,end) that has a value
equal to value.
• The second form returns the position of the first element in the range [beg,end) for which the
unary predicate
op(elem)
yields true.
• The third form (available since C++11) returns the position of the first element in the range
[beg,end) for which the unary predicate
op(elem)
yields false.
• All algorithms return end if no matching elements are found.
• Note that op should not change its state during a function call. See Section 10.1.4, page 483, for
details.
• op should not modify the passed arguments.
• If the range is sorted, you should use the lower_bound(), upper_bound(), equal_range(),
or binary_search() algorithms (see Section 11.10, page 608).
• Associative and unordered containers provide an equivalent member function, find() (see Section
8.3.3, page 405), which has a better complexity (logarithmic for associative and even constant
for unordered containers).
• Complexity: linear (at most, numElems comparisons or calls of op(), respectively).
The following example demonstrates how to use find() to find a subrange starting with the first
element with value 4 and ending after the second 4, if any
•แบบฟอร์มแรกส่งกลับค่าตำแหน่งขององค์ประกอบแรกในช่วง [beg,end) ที่มีค่า
เท่ากับค่า
•แบบสองส่งกลับค่าตำแหน่งขององค์ประกอบแรกในช่วง [beg,end) ที่
เพรดิเคตเดี่ยว
op (elem)
ทำให้เป็นจริง
•ที่สามแบบฟอร์ม (ใช้ได้ตั้งแต่ C 11) ส่งกลับค่าตำแหน่งขององค์ประกอบแรกในช่วง
[วอนจบ) ที่ predicate
op(elem) เดี่ยว
ทำให้เป็นเท็จ
•อัลกอริทึมทั้งหมดกลับสิ้นสุดไม่มีองค์ประกอบที่ตรงกันอยู่
•หมายเหตุ op ที่ควรเปลี่ยนสถานะในระหว่างการเรียกฟังก์ชัน ดูส่วน 10.1.4 หน้า 483
รายละเอียด
• op ควรปรับเปลี่ยนการส่งผ่านอาร์กิวเมนต์ด้วย
•ถ้าช่วงมีการเรียงลำดับ คุณควรใช้ lower_bound(), upper_bound(), equal_range (),
หรืออัลกอริทึม binary_search() (ดูส่วน 11.10 หน้า 608) .
•เกี่ยวข้อง และนำภาชนะบรรจุให้มีฟังก์ชันเทียบเท่าสมาชิก find() (ดูส่วน
8.3.3 หน้า 405), ซึ่งมีความซับซ้อนที่ดีขึ้น (ลอการิทึมสำหรับค่าคงที่เกี่ยวข้อง และแม้
สำหรับบรรจุภัณฑ์นำ) .
•ความซับซ้อน: เชิงเส้น (ที่สุด เปรียบเทียบ numElems หรือโทร op() ตามลำดับ)
ตัวอย่างต่อไปนี้สาธิตวิธีการใช้ find() หา subrange เริ่มแรก
องค์ประกอบ มีค่า 4 และการสิ้นสุดหลัง 4 สอง ถ้ามี
การแปล กรุณารอสักครู่..

- รูปแรกส่งกลับตำแหน่งขององค์ประกอบแรกในช่วง [ ขอร้อง จบ ) ซึ่งมีมูลค่าเท่ากับค่า
.
- แบบฟอร์มที่สองคืนตำแหน่งขององค์ประกอบแรกในช่วง [ ขอร้อง จบ ) ซึ่ง
OP ภาคแสดง
นารี ( ใส้ )
อัตราผลตอบแทนที่แท้จริง - รูปที่สาม ( ใช้ได้ตั้งแต่ ซี 11 ) จะได้ค่าตำแหน่งขององค์ประกอบแรกในช่วง
[ ขอร้อง จบ ) ซึ่ง OP ภาคแสดง ( ใส้ )
นารี่ผลผลิตที่เป็นเท็จ
- ใช้คืนจบ ถ้าไม่ตรงกับธาตุที่พบ .
- ทราบว่า OP ไม่ควรเปลี่ยนสถานะของมันในระหว่างการเรียกใช้ฟังก์ชัน ดูส่วน 10.1.4 หน้า 483 , สำหรับ
- รายละเอียด สหกรณ์ไม่ควรปรับเปลี่ยนผ่านอาร์กิวเมนต์ .
- ถ้าช่วงนั้นเยอะ คุณควรใช้ lower_bound() upper_bound() equal_range()
, , , หรือ binary_search() อัลกอริทึม ( ดูมาตรา 11.10 , หน้า 11 ) .
และบริการเชื่อมโยงเรียงลําดับภาชนะให้เทียบเท่าสมาชิกฟังก์ชัน find() ( ดูมาตรา
8.3.3 หน้า 405 ) ซึ่งมีความซับซ้อนกว่า ( ลอการิทึมเพื่อเชื่อมโยงและคงที่
สำหรับเรียงลําดับภาชนะ )
- ความซับซ้อน : เชิงเส้น ( ส่วนใหญ่ numelems เปรียบเทียบหรือโทร
op() ตามลำดับ )ตัวอย่างต่อไปนี้แสดงให้เห็นถึงวิธีการใช้ find() หา subrange เริ่มต้นด้วยองค์ประกอบแรก
ที่มีมูลค่า 4 และสิ้นสุดหลังที่สอง 4 , ถ้าใด ๆ
การแปล กรุณารอสักครู่..
