Skip to content
Home · Sonraki hedefe 100 XP
Son hareketler
Henüz bir öğrenme hareketi yok. İlk derse başlayın.

Programming Fundamentals

C++ set: Uniqueness and ordering contract

The set holds unique keys based on the comparison rule. If uniqueness is not consistent with the meaning of the application, visually similar records may still be considered different.

Bu derste neler var?

SIBERSALDIRI.COM · FOCUSED LESSON

What you will learn

  • Explain the relationship between Key and Comparison.
  • “How does the set determine non-repeatability?” To give a reasoned answer to the question.
  • Changing the example and comparing expected and observed behavior.

How it works and where the trust boundary lies

insert reports the re-insert status. The comparator should provide a consistent tight weak ranking. Business rules such as case and Unicode normalization in usernames are separate from the container's default string comparison. Don't try to break the sorting rule by changing the key in place.

C++ set: Uniqueness and sorting convention flow: Key → Comparison → Unique set
Key → Comparison → Unique set. The diagram shows the relationship; It does not replace the entire application.

Worked example

The following passage makes the concept visible. Evaluate samples containing commands or code in your own separate testing environment, not in the production system. Architectural diagrams and policy examples are not executable programs.

#include <set>
#include <iostream>
int main(){
 std::set<int> ids{4,2,4};
 std::cout<<ids.size();
}

Expected result and interpretation

Since the repeated 4 are combined, the size becomes 2.

Compare the scenarios

StatusRecommended approachWhy?
repeating numbersingle recordUniqueness is preserved
letter differenceDepends on comparisonJob equality can be separate
key replacementMaintain rankContainer immutable condition should not be broken

Practice task

Add alpha and alpha texts; Discuss whether your business rule considers these two records to be the same.

  1. Write down the expected outcome and acceptance condition before the action.
  2. Change a single variable; Record the observation and the medium you used.
  3. Evaluate the result with the comparison table above. Explain which assumption might be wrong if it does not fit.

Common mistake and how to correct it

Do not equate default text comparison with language username parity.

Test your understanding

How does the set determine non-repeatability?

Answer explained: It determines the comparison relationship it uses according to the equivalence rule.

Continue with related lessons

Technical reference

The explanation and examples of this course have been re-prepared for the academy. The link below is a technical reference to verify details of the technology or security approach used.

Bir adım daha ilerlediniz.

Dersi bitirdiyseniz tamamlandı olarak işaretleyin. İlerlemeniz bu cihazda saklanır.

Academy menu

Akademide ara

En az 2 karakter yazın.