5.2.21 · D1 · HinglishC++ Programming

FoundationsIterators — input, output, forward, bidirectional, random access, contiguous

2,338 words11 min read↑ Read in English

5.2.21 · D1 · Coding › C++ Programming › Iterators — input, output, forward, bidirectional, random ac

parent note mein chhah iterator categories samajhne se pehle, aapko kuch chote symbols mein fluent hona padega. Yeh page unhe ek-ek karke bilkul zero se build karta hai. Hum dheere chalte hain aur ek aisi order mein jahan har idea sirf upar wale ideas par lean karta hai.


0. Ek collection aur uske elements

Sabse concrete picture se shuru karte hain: boxes ki ek row, jisme har ek mein ek value hai.

Figure — Iterators — input, output, forward, bidirectional, random access, contiguous

Hum abhi yeh nahi bol rahe ki boxes memory mein kaise laid out hain. Yahi difference (sab-ek-line-mein vs. bikre hue) aage categories ko separate karega. Abhi ke liye: boxes, values, bas.


1. Ungli: it ka matlab kya hai

Figure — Iterators — input, output, forward, bidirectional, random access, contiguous

Finger box se ek alag object hai. Aap ek hi row par do fingers rakh sakte ho, ek ko move kar sakte ho, aur doosri wahin rahi — yeh idea (multi-pass) baad mein important ho jaata hai.


2. *it — star ka matlab hai "finger ke neeche ki value"


3. ++it — plus-plus ka matlab hai "next box par step karo"

Figure — Iterators — input, output, forward, bidirectional, random access, contiguous

--it (figure mein, gray arrow jo baayein jaata hai) mirror move hai: ek box baayein. Notice karo yeh faded drawn hai — har finger ko peechhe jaane ki ijazat nahi hoti. Yahi restriction exactly bidirectional vs forward define karegi baad mein.


4. begin, end, aur sentinel


5. == aur != — do fingers ki comparison

Note karo yeh positions compare karta hai, kabhi values nahi. Do alag boxes par do fingers jo same number hold karti hon equal nahi hain.


6. it + n, it - n, it[n] — ek saath kai boxes jump karna

Figure — Iterators — input, output, forward, bidirectional, random access, contiguous

7. <, > — do fingers ka ordering


8. Contiguous memory: &*(it+n) == &*it + n

Yeh parent mein sabse dense symbol hai, toh hum ise letter by letter unpack karte hain.

Ab &*(it + n) ko right-to-left, ek symbol at a time padho:

  1. it + n — finger boxes daayein (needs random access, §6).
  2. *(...) — us finger ke neeche ki value (§2).
  3. &(...) — us value ka address.

Toh &*(it+n) hai "box ka house number jo steps aage hai". Claim &*(it+n) == &*it + n kehta hai:

Figure — Iterators — input, output, forward, bidirectional, random access, contiguous

9. Subset aur refinement chain

Isliye parent ki operation table kabhi bhi daayein jaate waqt ✓ nahi hatati: jab ek power aati hai, toh saari rich categories use inherit karti hain.


10. Tag types (std::..._iterator_tag)


Foundations topic ko kaise feed karti hain

Container = row of boxes

Iterator it = finger on one box

star it = read or write the value

plus plus it = step forward

begin end and the stop post

equals and not equals compare positions

it plus n = jump many boxes fast

less than orders fingers

address of gives contiguous line

Refinement chain of six categories

Category tags select fast code at compile time


Equipment checklist

Daayein side cover karo aur zor se jawab do. Agar koi jawab fuzzy lage, toh parent note se pehle woh section dobara padho.

Ek word mein it (ek iterator) kya represent karta hai?
Ek collection ke ek element par point karti hui finger.
it aur *it mein kya farq hai?
it position hai (finger); *it uske neeche ki value hai.
++it kya change karta hai — boxes ya finger?
Sirf finger; woh ek box daayein slide karti hai.
end() kahan point karta hai, aur last element par kyun nahi?
Last se ek box aage, taaki loops it != end se cleanly ruk sakein.
Kya it1 == it2 positions compare karta hai ya values?
Positions — same box hai ya nahi, value chahe kuch bhi ho.
it + n ++it ko n baar press karne se aage kya extra promise karta hai?
Yeh target tak ek constant-time leap mein pahunchta hai, chahe n kitna bhi bada ho.
&*(it + n) ko plain words mein right-to-left padho.
Us value ka address jo us finger ke neeche hai jo n boxes daayein hai.
Categories ke liye A ⊂ B ka kya matlab hai?
A ki har capability B mein rakhi jaati hai, aur B aur zyada add karta hai (refinement).
Ek deque it + n kar sakta hai lekin contiguous test fail kyun karta hai?
Uske boxes alag chunks mein rehte hain, isliye addresses ek even line mein nahi badhte.
Category tag kya hai aur kab padha jaata hai?
Ek empty label-struct jo category ka naam batata hai, compile time par fastest code choose karne ke liye padha jaata hai.