Aller au contenu

C++

Si Wikipedia, tasanayt tilellit.
C++
langage de programmation orienté objet (fr) Suqel, langage de programmation multi-paradigme (fr) Suqel, langage procédural (fr) Suqel, langage de programmation fonctionnel (fr) Suqel, langage de programmation générique (fr) Suqel, tutlayt n usihel, langage à forme libre (fr) Suqel d langage compilé (fr) Suqel
Isefka
Adu-smil nlangage compilé (fr) Suqel
Azemz n ubeddi d unulfu1983
AsemresProgrammation système (fr) Suqel
Nom en kanas (fr) Suqelシープラスプラス
Développé par (fr) SuqelBjarne Stroustrup (fr) Suqel
Paradigme (fr) Suqelprogrammation orientée objet (fr) Suqel, programmation fonctionnelle (fr) Suqel, programmation procédurale (fr) Suqel, généricité (fr) Suqel d programmation à paradigmes multiples (fr) Suqel
Conçu par (fr) SuqelBjarne Stroustrup (fr) Suqel
Akufi n tengalt taɣbaluthttps://github.com/cplusplus/draft
Identifiant de version logicielle (fr) SuqelC++23, C++98, C++03, C++11, C++14, C++17 d C++20
Asmel web unṣibisocpp.org d open-std.org…
Hashtag (mul) Suqelcpp d cplusplus
Yettubeggen sTuring-complet (fr) Suqel
Type MIME (fr) Suqeltext/x-c++src d text/x-c++hdr
Organisme de normalisation (fr) SuqelOrganisation internationale de normalisation (fr) Suqel d Commission électrotechnique internationale (fr) Suqel
Système de typage (fr) Suqeltypage statique (fr) Suqel, système nominatif de types (fr) Suqel d partial inference typing (en) Suqel
Alugu n C++.

Tutlayt n usihel C++ Yesnulfa-tt-id Bjarne Stroustrup deg useggas n 1979 deg Bell Laboratories. Deg tazwara, semman-as "C s tserkam", acku tella d asiɣzef n tutlayt C s tmerna n tserkam. Deg useggas n 1983, beddlen isem-is ɣer C++. Deg useggas n 1998, teffeɣ-d tizeɣt tamezwarut s waggaz ISO/IEC 14882.

C++ tella d tutlayt n usihel i d-yufraren ɣef C acku terni-yas :

  • Asihel s tɣawsiwin
  • Asihel s tserkam
  • Asihel imcettel (Generic Programming) s templates
  • Asefrek n tkatut s ufus

Tutlayt-a tettwaseqdec deg :

Asnulfu n yisiɣẓanen n unagraw d usihel n yinagrawen yettwaselɣen, arnu asnulfu n wuraren akked deg uḥric n tussna n isefka d tigzi taragmawant. arnu daɣen deg iseggasen-a ineggura C++ nezmer ad t-nesseqdec deg weḥric n Web seg tama n umsaɣ s tallelt n WebAssembly.

Tutlayt n usihel C++ tella d yiwet seg tutlayin timeqranin akk deg umaḍal n tsenselkimt. Seg wasmi i d-tlul deg useggas n 1979 ar ass-a, C++ temhaz-d s waṭas, tessaweḍ ad tili d allal agejdan deg waṭas n yiḥricen : seg usnulfu n yinagrawen n wammud ar usihel n yiselkimen, seg wuraren ar tigzi taragmawant. Aḍris-agi ad d-yezzuɣɣer amezruy-is, amhaz-is, d wazal-is deg yal tallit n tselkimt.

1. Tilalin : Seg C ar C s Tserkam (1979–1983)

[ẓreg | ẓreg aɣbalu]

1.1 Asenti

[ẓreg | ẓreg aɣbalu]

Deg useggas n 1979, Bjarne Stroustrup, yiwen n unelmad n PhD deg Bell Laboratories (AT&T) deg Marikan, yebda yettmahal ɣef usnulfu n tutlayt tamaynut. Stroustrup yella yesseqdac s tutlayt C, maca yebɣa ad yernu fell-as tarrayin n usihel s tɣawsiwin (object-oriented programming) i d-yellan seg tutlayt Simula.

Iswi-ines amezwaru d ad yessers tamṣukt n usihel s tserkam ɣef tutlayt C, i wakken ad yessers isefka d twsitin n tserkam deg yiwen n umkan. Deg tazwara, isem n tutlayt-a yella d "C with Classes" (C s Tserkam).

1.2 Ismawen d Tarrayin Timezwura

[ẓreg | ẓreg aɣbalu]

Deg tallit-a tamezwarut, Stroustrup yerni-yas i C :

  • Tiserkam (classes) s tmahilin-nsent (member functions)
  • Tukkest (inheritance) : taserkemt ad tawi isefka d twsitin seg tserkemt nniḍen
  • Timselɣutin (references)
  • Asenqed n tewsatin (type checking) iǧehden

Deg useggas n 1983, beddlen isem n tutlayt seg "C with Classes" ar "C++". Azamul ++ deg C yettawwi-d anerni n wazal s yiwen, d tinnaṭ i d-yemmalen belli C++ d asiɣzef n C.

2. Tallit n Umhaz Amezwaru (1983–1998)

[ẓreg | ẓreg aɣbalu]

2.1 Tizeɣt Tamezwarut

[ẓreg | ẓreg aɣbalu]

Deg tallit-a, C++ terna aṭas n tɣawsiwin timaynutin :

1985 : Tiffeɣ-d Tizeɣt tamezwarut n C++ s uzwel "The C++ Programming Language" n Stroustrup. Tizeɣt-a tesɛa tiserkam, tukkest, tiseɣnin tuhlistin, d tseɣnin n tserkam (member functions).

1989 : Yerna-yas agettalɣa (polymorphism) s twsitin timenyafin, akwbal (encapsulation) s wawalen private, public, d protected, d tamadwant (abstraction).

1990 : Timerna n "templates" i usihel imcettel (generic programming), tisuraf (exceptions) i uselmed n tuccḍiwin, d ismawen n tallunin (namespaces).

2.2 C++ deg Tselkimt n Tallit-a

[ẓreg | ẓreg aɣbalu]

Deg tallit-a, C++ tettwaseqdec aṭas deg :

  • Usnulfu n yinagrawen n wammud am Windows d Unix
  • Usihel n yinagrawen yettwaselɣen
  • Usnulfu n isiɣẓanen n tnarit
  • Asihel n yinagrawen n taffa n isefka

C++ tella d tutlayt i yesɛan tanezmart meqqren deg uselkem, acku tettaǧǧa asefrek asmussaw n tkatut s ufus, s useqdec n new d delete.

3. Tallit n Tizeɣt (1998–2011)

[ẓreg | ẓreg aɣbalu]

3.1 Tizeɣt Tamezwarut : C++98

[ẓreg | ẓreg aɣbalu]

Deg useggas n 1998, teffeɣ-d tizeɣt tamezwarut n C++ s waggaz ISO/IEC 14882:1998. Tizeɣt-a tesbedd ilugan n tutlayt s wudem unṣib, tefka-yas i C++ tamṣukt tusliḍt i yettwaqbalen deg umaḍal meṛṛa.

C++98 tesɛa :

  • STL (Standard Template Library) : tamkarḍit n temudmin timcettelt (generic templates) am vector, list, map, set
  • allusen (iterators) i ulḥu deg yimgraden
  • Tiwsatin timatuyin (algorithms) am sort, find, for_each
  • Tusrufin (exceptions) s try, catch, throw

3.2 C++03

[ẓreg | ẓreg aɣbalu]

Deg useggas n 2003, yeffeɣ-d lqem wis sin n tizeɣt (ISO/IEC 14882:2003). Lqem-a ur yerni ara aṭas n tɣawsiwin timaynutin, maca yesseɣti kra n tuccḍiwin yellan deg C++98, yesbedd ilugan s wudem uḥric.

3.3 C++ deg Tallit-a

[ẓreg | ẓreg aɣbalu]

Deg tallit n 1998 ar 2011, C++ tettwaseqdec aṭas deg :

  • Usnulfu n wuraren : s tallelt n imuturen n wuraren am Unreal Engine, CryEngine
  • Usihel n yiselkimen : afreɣẓan, inuḍaf, anagraw n wammud
  • Tasnallunt d tmhelt n tkeṛṛusin
  • Taɣult n tedrimt : inagrawen n lbanka d tenzzut

4. Tallit n Imaynuten n C++ (2011–Ass-a)

[ẓreg | ẓreg aɣbalu]

4.1 C++11 : Tagrawla Tameqqrant

[ẓreg | ẓreg aɣbalu]

Deg useggas n 2011, teffeɣ-d C++11, i yettwaḥsben d tagrawla tameqqrant deg umezruy n tutlayt-a. C++11 terna aṭas n tɣawsiwin timaynutin i yessahlen asihel :

  • auto : tawsit yettwafra s wudem awurman
  • Lambda expressions : tiwsitin tuffirin i yettwarun deg umkan
  • Range-based for : tineddict ɣef yal aferdis n umegrad
  • Move semantics : asmutti n tɣawsiwin bla anɣal, i usnerni n tmellit
  • Smart pointers (unique_ptr, shared_ptr) : isewwaṛen iuḥricen i yettḥerzen takatut s wudem awurman
  • constexpr : azalen yettwaḥesben deg wakud n lqem
  • nullptr : azal amaynut i usewwaṛ ilem, yettbeddilen NULL
  • enum class : inumriyen iǧehden

4.2 C++14

[ẓreg | ẓreg aɣbalu]

Deg 2014, yeffeɣ-d lqem i d-yernan :

Generic lambdas : lambdas s tewsatin timcettelt, akeed "Return type deduction" i twsitin, "constexpr" iǧehden, arnu timudmin s wudem amutti "Variable templates".

4.3 C++17

[ẓreg | ẓreg aɣbalu]

Deg 2017, C++17 terna :

if constexpr : tiwtilin deg wakud n lqem, optional, variant, any : tiwsatin n isefka imatuyen, Fold expressions : i timudmin, Parallel algorithms : tiwsatin timatuyin s uselmed n ukala afessas.

4.4 C++20

[ẓreg | ẓreg aɣbalu]

Deg 2020, C++20 terna tɣawsiwin timeqranin :

Concepts : tilisa ɣef timudmin, i wakken ad yili useqqer n tuccḍiwin drus, Modules : anagraw amaynut n uskecm n ifuyla, yettbeddilen #include, Coroutines : tiwsitin i izemren ad ḥebsent rnu ad kemmlent, Ranges : allalen imaynuten n umahil ɣef yimgraden, <format> : tamṣukt n usformat am Python, Kraḍ n iberdan n userwes (<=>)

4.5 C++23

[ẓreg | ẓreg aɣbalu]

Deg 2023, C++23 terna :

std::expected : i uselmed n tuccḍiwin bla tasureft, Deducing this : i twsitin n tserkam.

Tamṣukt n Wahil C++

[ẓreg | ẓreg aɣbalu]

Yal ahil n C++ yesɛa tamṣukt taseddast. Aḥric amezwaru i yessefken ad yili deg yal ahil d tawsit n tesɣent "main()", d nettat i d iḥdar agejdan amezwer n uselkem.

#include <iostream>
using namespace std;

int main() {
    cout << "Azul, a ddunit!" << endl;
    return 0;
}

Deg uḍris-agi :

#include <iostream> : d taladna n uzarsekkar i d-yesskecmen tamkarḍit n unekcum d usuffeɣ.

using namespace std; : d alɣu i d-yemmalen belli nseqdac tallunt n yismawen (namespace) std.

int main() : d tawsit n tesɣent tagejdant ideg yebda uselkem.

cout : d allal n usuffeɣ ɣer wegdil.

return 0; : d tinnaṭ n tuɣalin i d-yemmalen belli ahil yemmed akken iwata.

Tewsatin n Isefka d Imuttiyen

[ẓreg | ẓreg aɣbalu]

1 Tewsatin tigejdanin

[ẓreg | ẓreg aɣbalu]

C++ tesɛa aṭas n tewsatin n isefka tigejdanin :

Tawsit Aglam Tiddi
int Ummid (entier) 4 ibitten
float Amḍan s ticcert yettifliwen (réel simple précision) 4 ibitten
double Amḍan s ticcert yettifliwen (réel double précision) 8 ibitten
char Asekkil 1 n ubit
void Ulac 0

2 Imuttiyen

[ẓreg | ẓreg aɣbalu]

Amutti d isem i yettunefken i wadeg di tkatut (mémoire) ideg yettwasekles wazal. Asebded (tabadut) n umutti yettili s tewsit, isem, d wazal amezwaru :

int amḍan = 10;
double azal = 3.14;
char asekkil = 'A';
bool tidett = true;

3 Ismawen d Yilugan-nsen

[ẓreg | ẓreg aɣbalu]

Ismawen n yimuttiyen deg C++ ilaq ad ḍefren ilugan-agi :

  • Zemren ad bdun s usekkil neɣ s ujerriḍ n wadda (_)
  • Ur zmiren ara ad bdun s umḍan
  • Ur zmiren ara ad sqedcen awalen yettwaḥerzen (reserved keywords)
  • C++ txedem amgired gar usekkil ameqran d umeẓyan

4 Imahalen

[ẓreg | ẓreg aɣbalu]

Imahalen deg C++ d izamulen i yettunefken i tmhelt ɣef wazalen.

4.1 Imahalen imsnamḍanen

[ẓreg | ẓreg aɣbalu]
Azamul Tamhelt Amedya
+ Timernit 5 + 3 = 8
- Tukkssit 5 - 3 = 2
* Asegat 5 * 3 = 15
/ Taẓunt 6 / 3 = 2
% Tasagert 7 % 3 = 1

4.2 Imahalen n usemyif

[ẓreg | ẓreg aɣbalu]
Azamul Anamek
== Yugda (égal à)
!= Ur yugdi ara
< Amazdar
> Imineg
<= Amazdar neɣ yugda
>= Imineg neɣ yugda

4.3 Imahalen imeẓẓulen

[ẓreg | ẓreg aɣbalu]
Azamul Anamek
&& D (ET logique)
! Ur (NON logique)

4.4 Imahalen n usemdukel

[ẓreg | ẓreg aɣbalu]
int x = 10;    // Asemdukel asentan
x += 5;        // x = x + 5
x -= 3;        // x = x - 3
x *= 2;        // x = x * 2
x /= 4;        // x = x / 4

5. Tamṣukt n Usenqed

[ẓreg | ẓreg aɣbalu]

5.1 Tiwtilin

[ẓreg | ẓreg aɣbalu]

if / else if / else

if (azal > 100) {
    cout << "Azal meqqeṛ" << endl;
} else if (azal > 50) {
    cout << "Azal alemmas" << endl;
} else {
    cout << "Azal meẓẓi" << endl;
}

switch

switch (ass) {
    case 1: cout << "Aram" << endl; break;
    case 2: cout << "Aram" << endl; break;
    case 3: cout << "Aram" << endl; break;
    default: cout << "Ass nniḍen" << endl;
}

5.2 Tineddicin

[ẓreg | ẓreg aɣbalu]

Tineddict for

for (int i = 0; i < 10; i++) {
    cout << i << " ";
}

Tineddict while

int azal = 0;
do {
    cout << azal << endl;
    azal++;
} while (azal < 5);

Tinnaḍin n usenqed n tneddict

break : ad teffeɣ seg tneddict neɣ seg switch

continue : ad tezgel tikkelt-a, ad teddu ɣer tikkelt i d-iteddun

6. Tiseɣnin

[ẓreg | ẓreg aɣbalu]

6.1 Asebded n Tasɣent

[ẓreg | ẓreg aɣbalu]

Tasɣent deg C++ tesɛa :

  • Tawsit n tuɣalin
  • Isem n tasɣent
  • Iɣewwaṛen
  • Tafekka s tinnaḍin
tawsit_n_tuɣalin isem_n_tasɣent(iɣewwaṛen) {
    // tinnaḍin
    return azal;
}

6.2 Amedya

[ẓreg | ẓreg aɣbalu]
int smerni_sin(int a, int b) {
    return a + b;
}

// Aseɣṛi (appel)
int ugmuḍ = smerni_sin(5, 3);  // ugmuḍ = 8

6.3 Aɛeddi n Yiɣewwaṛen

[ẓreg | ẓreg aɣbalu]

C++ tesɛa kraḍ n tarrayin n uɛeddi n yiɣewwaṛen :

  • Aɛeddi s wazal (pass by value) : ad yettwaneɣl wazal
  • Aɛeddi s tamselɣut (pass by reference) : ad yettwafk unekcam srid ɣer umutti
  • Aɛeddi s usewwaṛ (pass by pointer) : ad yettwafk wazal n tkatut
// S wazal
void s_wazal(int x) { x = x + 1; }

// S tamselɣut
void s_tamselɣut(int& x) { x = x + 1; }

// S usewwaṛ
void s_usewwaṛ(int* x) { *x = *x + 1; }

7. Isewwaṛen d Timselɣutin

[ẓreg | ẓreg aɣbalu]

7.1 Isewwaṛen (Pointers)

[ẓreg | ẓreg aɣbalu]

Asewwaṛ d amutti i yessekles adɣar (ideg/tansa) n umutti nniḍen di tkatut.

int azal = 42;
int* asewwaṛ = &azal;  // asewwaṛ yesseklas adɣar n "azal"

cout << *asewwaṛ << endl;  // ad yesken 42

Imahalen imenza :

  • & : amahal n tansa (address-of operator)
  • * : amahal n tukksa n tmselɣut (dereference operator)

7.2 Timselɣutin

[ẓreg | ẓreg aɣbalu]

Tamselɣut (reference) d isem nniḍen i umutti yellan. Ur yezmirt ara ad ibeddel ɣer umutti nniḍen :

int azal = 10;
int& tamselɣut = azal;  // tamselɣut d isem nniḍen i "azal"
tamselɣut = 20;          // azal yuɣal 20

8. Tifelwiyin d Izraren

[ẓreg | ẓreg aɣbalu]

8.1 Tifelwiyin

[ẓreg | ẓreg aɣbalu]

Tafelwit d tagrumma n wazalen n tewsit yiwen, yettwaskelsen deg tkatut s wudem amezdi

int tifelwiyin[5] = {10, 20, 30, 40, 50};

// Anekcum ɣer uferdis
cout << tifelwiyin[0] << endl;  // 10
cout << tifelwiyin[4] << endl;  // 50

8.2 Tifelwiyin s uget n tsektiwin

[ẓreg | ẓreg aɣbalu]
int tafelwit[3][4] = {
    {1, 2, 3, 4},
    {5, 6, 7, 8},
    {9, 10, 11, 12}
};

8.3 Izraren

[ẓreg | ẓreg aɣbalu]

Deg C++, azrar (string) yezmer ad yili :

// Azrar s tewsit C
char azrar_c[] = "Azul";

// Azrar s tewsit C++ (tamkarḍit <string>)
#include <string>
string azrar_cpp = "Azul, a ddunit!";

9. Asihel s Tɣawsiwin

[ẓreg | ẓreg aɣbalu]

Asihel s tɣawsiwin (OOP) d tarrayt n usihel i yessebdaden ahil ɣef tɣawsiwin i yesɛan isefka d tarrayin.

9.1 Taserkemt

[ẓreg | ẓreg aɣbalu]

Taserkemt d tamudemt (template) i d-yessnulfuyen tiɣawsiwin. Tesɛa :

Imuttiyen n tserkemt (imuttiyen-ines / imyaren-ines)

Tiwsatin n tserkemt (tiseɣnin-ines / tarrayin-ines)

class Aɣersiw {
private:
    string isem;
    int leɛmeṛ;

public:
    // Amakras (constructor)
    Aɣersiw(string i, int l) {
        isem = i;
        leɛmeṛ = l;
    }

    // Tawsit n tserkemt
    void sken() {
        cout << "Isem: " << isem << ", Leɛmeṛ: " << leɛmeṛ << endl;
    }

    // Asemmatay (destructor)
    ~Aɣersiw() {
        cout << "Aɣersiw yettwakkes" << endl;
    }
};

9.2 Taɣawsa

[ẓreg | ẓreg aɣbalu]

Taɣawsa d tummant n tserkemt :

int main() {
    Aɣersiw aɣyu1("Muc", 3);
    aɣyu1.sken();  // Isem: Muc, Leɛmeṛ: 3
    return 0;
}

9.3 Akwbal

[ẓreg | ẓreg aɣbalu]

Akwbal d amenzay i yettḥerzen isefka n tserkemt s useqdec n wawalen :

private : anekcum kan seg twsitin n tserkemt

public : anekcum seg yal amkan

protected : anekcum seg tserkemt akked tserkam i d-yufraren seg-s s uzellum

9.4 Tukkest

[ẓreg | ẓreg aɣbalu]

Tukkest tettajǧa taserkemt ad tawi isefka d twsitin seg tserkemt nniḍen :

class Amɣar : public Aɣersiw {
private:
    string tawuri;

public:
    Amɣar(string i, int l, string t) : Aɣersiw(i, l) {
        tawuri = t;
    }

    void sken_tawuri() {
        cout << "Tawuri: " << tawuri << endl;
    }
};

Tawsitin n tukkest deg C++ :

  • Tukkest tasufut
  • Tukkest tusgit
  • Tukkest s waṭas n yiswiren

9.5 Agettalɣa (Polymorphism)

[ẓreg | ẓreg aɣbalu]

Agettalɣa d amenzay i yettǧǧan tiwsitin yemgaraden ad sɛunt isem yiwen maca ad xedmen tigawin yemgaraden.

Tiseɣnin tuhlisin:

class Aɣersiw {
public:
    virtual void imesli() {
        cout << "Imesli n uɣersiw" << endl;
    }
};

class Amcic : public Aɣersiw {
public:
    void imesli() override {
        cout << "Miyaw!" << endl;
    }
};

class Aydi : public Aɣersiw {
public:
    void imesli() override {
        cout << "Waw!" << endl;
    }
};

9.6 Tamadwant

[ẓreg | ẓreg aɣbalu]

Tamadwant d amenzay i yettḥerzen isefka n daxel, ad yesken kan ayen ilaqen i useqdac :

class Talɣa {
public:
    virtual double tajumma() = 0;  // Tasɣent tadwant tamenyafit
};

10. Asihel Amatu s Leqwaleb

[ẓreg | ẓreg aɣbalu]

Leqwaleb neɣ "Templates" ttajǧan ad naru tangalt ara ixedmen s uget n tewsatin n isefka bla ma naru-tt yal tikkelt.

10.1 Tiseɣnin n Leqwaleb

[ẓreg | ẓreg aɣbalu]
template <typename T>
T ameqqran(T a, T b) {
    return (a > b) ? a : b;
}

// Aseqdec
int x = ameqqran(5, 3);       // x = 5
double y = ameqqran(3.14, 2.71);  // y = 3.14

Tiserkam Timatuyin

template <typename T>
class Akufi {
private:
    T iferdisen[100];
    int uṭṭun;

public:
    Akufi() : uṭṭun(0) {}

    void rnu(T azal) {
        iferdisen[uṭṭun++] = azal;
    }

    T kkes() {
        return iferdisen[--uṭṭun];
    }
};

11. Asefrek n Tkatut

[ẓreg | ẓreg aɣbalu]

11.1 Aḥeṛṛi Asmussaw

[ẓreg | ẓreg aɣbalu]

C++ tettaǧǧa aḥeṛṛi asmussaw n tkatut s wawalen new d delete :

// Aḥeṛṛi n wazal yiwen
int* p = new int;
*p = 42;
delete p;

// Aḥeṛṛi n tfelwit
int* arr = new int[10];
delete[] arr;

11.2 Isewwaṛen Uḥricen

[ẓreg | ẓreg aɣbalu]

Deg imaynuten n C++, llan isewwaṛen uḥricen i yettḥerzen tkatut s wudem awurman :

#include <memory>

// unique_ptr : yezmer kan yiwen n usewwaṛ ad yesɛu taɣawsa
unique_ptr<int> p1 = make_unique<int>(42);

// shared_ptr : aṭas n isewwaṛen zemren ad bḍun taɣawsa
shared_ptr<int> p2 = make_shared<int>(100);

12. Asefrek n Tsuraf

[ẓreg | ẓreg aɣbalu]

Tsuraf d tarrayt n usefrek n tuccḍiwin deg wakud n uselkem :

#include <stdexcept>

double beṭṭu(int a, int b) {
    if (b == 0) {
        throw invalid_argument("Ur yezmir ara ad yebḍu ɣef 0");
    }
    return (double)a / b;
}

int main() {
    try {
        double ugmuḍ = beṭṭu(10, 0);
    } catch (const invalid_argument& e) {
        cout << "Tuccḍa: " << e.what() << endl;
    }
    return 0;
}

Imawalen imenza :

try : ɛreḍ tangalt i izemren ad teg tuccḍa

throw : zzuzer tasureft

catch : ṭṭef tasureft

13. Tamkarḍit Tizeɣtant n Temudmin (STL)

[ẓreg | ẓreg aɣbalu]

STL (Standard Template Library) d tagrumma n tserkam d twsitin timatuyin i yettwasqedcen aṭas deg C++.

13.1 Imagbaren

[ẓreg | ẓreg aɣbalu]
Amagbar anamek-is
vector Tafelwit tamussawt (dynamic array)
list Tabdart tamsuddast (doubly linked list)
map Amawal n tsuraf (key-value pairs)
set Tagrumma n wazalen ur nelli ara d imenza
queue Adras FIFO
stack Akufi LIFO

13.2 Imedyaten

[ẓreg | ẓreg aɣbalu]
#include <vector>
#include <algorithm>

vector<int> imḍanen = {5, 2, 8, 1, 9};

// Af ran (sorting)
sort(imḍanen.begin(), imḍanen.end());

// Anadi (searching)
auto it = find(imḍanen.begin(), imḍanen.end(), 8);

13.3 Tineddicin

[ẓreg | ẓreg aɣbalu]

Tineddicin d allalen i yettǧǧan ad nelḥu deg yimagbaren :

for (auto it = imḍanen.begin(); it != imḍanen.end(); ++it) {
    cout << *it << " ";
}

13.4 Tiwsatin Timatuyin (Algorithms)

[ẓreg | ẓreg aɣbalu]
#include <algorithm>

// Af ran
sort(v.begin(), v.end());

// Anadi
auto it = find(v.begin(), v.end(), 42);

// Asmekti n yal aferdis
for_each(v.begin(), v.end(), [](int x) { cout << x << " "; });

Tutlayt n usihel C++ d yiwet seg tutlayin timeqranin deg umaḍal n tsenselkimt. Seg usihel n yinagrawen n wammud ar usnulfu n yisiɣẓanen n tigzi taragmawant, C++ tezmer ad tili deg yal aḥric.

Tamudemt-agi n tutlayt-a tbedd ɣef :

Tazmert : C++ tettaǧǧa asefrek asmussaw n tkatut d uselkem

Taflest : tawala n yilɣa imaynuten (C++11 ar C++23)

Taseddi : tanezmart deg uselkem

Tagttilɣa : tettaǧǧa asihel s tɣawsiwin, asihel imcettel(amatu), d usihel amesɣan

I useqdac amaynut, yewwid ad yebdu s yilugan tseddast, syin ad yelmed asihel s tɣawsiwin, rnu ad yesnerni tamusni-is s templates d STL.