Libreria standard C++
Nel C++, la libreria standard C++ è una collezione di classi e funzioni, che sono scritte nel linguaggio stesso e sono a loro volta parte dello Standard ISO C++ [1].
La libreria standard C++ fornisce una serie di contenitori generici e di funzioni strutturate per manipolarli, insieme a funzioni oggetti, stringhe e stream generici (utili anche per l'input/output su file o a video), funzioni di supporto alla programmazione e matematiche. La libreria standard C++ incorpora anche la libreria standard ISO C90. Tutte le funzioni e le classi sono dichiarate all'interno del namespace std
.
Gli header file nella libreria standard del C++ non hanno l'estensione ".h". Tuttavia, la Libreria Standard del C++ include 18 header file dalla libreria standard del C, che terminano con il ".h". Il loro uso è deprecato e mantenuto solo per retrocompatibilità[2].
Esempi[modifica | modifica wikitesto]
Il linguaggio di programmazione C++ è un linguaggio OOP (object-oriented programming) derivato dal linguaggio C. Il linguaggio C++ ha ereditato dal C la caratteristica che le sue funzioni possono essere definite dall'utente programmatore ed inserite in una libreria. Buona parte delle più importanti funzioni del C++, per esempio quelle di ingresso e uscita, sono contenute in una libreria "standard", suscettibile però di modifica. Per esempio se il programma scritto in C++ deve ricevere e stampare su schermo dei dati esso dovrà contenere nelle definizioni iniziali il file di header iostream
; cioè supponendo di voler scrivere il programma Hello world allora bisognerà scrivere:
#include <iostream>
// richiama dalla libreria standard il file header iostream
using namespace std;
//direttiva propria del c++ per dichiarare l'uso dello spazio dei nomi della libreria standard
int main () { //int è un identificatore che indica che
cout << "Hello world " << endl; //la funzione main, anch'essa presente
return 0; //nella libreria standard del c/c++,
} //restituisce un valore intero, zero
//se il programma è stato eseguito correttamente.
//In particolare main rappresenta il corpo
//del programma principale.
Implementazioni[modifica | modifica wikitesto]
Nome | Sito web | Acronimo | Licenza | Ultima versione |
---|---|---|---|---|
GNU C++ Standard Library | [1] | libstdc++ | GPLv3 | 11/15/2021 |
LLVM C++ Standard Library | [2] | libc++ | Apache License v2.0 with LLVM Exceptions | 9/30/2021 |
NVIDIA C++ Standard Library | [3] | libcu++ | Apache License v2.0 with LLVM Exceptions | 8/9/2021 |
Microsoft C++ Standard Library | [4] | MSVC STL | Apache License v2.0 with LLVM Exceptions | 12/16/2021 |
HPX C++ Standard Library for Parallelism and Concurrency | [5] | HPX | Boost Software License 1.0 | 8/12/2021 |
Electronic Arts Standard Template Library | [6] | EASTL | BSD 3-Clause License | 10/20/2021 |
Dinkum C++ Library | [7] | Commerciale | ||
Cray C++ Standard Library | [8] | Commerciale |
Header standard[modifica | modifica wikitesto]
I file seguenti contengono le dichiarazioni della libreria standard C++.
Generici[modifica | modifica wikitesto]
<any>
- Novità in C++17. Fornisce una classe senza tipo
std::any
. <atomic>
- Novità in C++11. Fornisce la classe template
std::atomic
, le sue diverse specializzazioni di modelli e più operazioni atomiche. <chrono>
- Fornisce funzioni per le temporizzazioni, come
std::chrono::duration
,std::chrono::time_point
e orologi. A partire da C++20, le novità aggiunte sono calendari, fusi orari, nuovi orologi e stringhe di formattazione per orari e intervalli. <concepts>
- Novità in C++20. Fornisce la libreria per le concepts.
<functional>
- Fornisce diverse funzioni oggetto, realizzate per l'uso con algoritmi standard.
<memory>
- Fornisce funzioni per la gestione della memoria in C++, includendo la classe template
std::unique_ptr
. <memory_resource>
- Novità in C++17. Fornisce facilities for creating polymorphic memory allocators whose behaviors can change at runtime.[3]
<scoped_allocator>
- Novità in C++11. Fornisce
std::scoped_allocator_adaptor
. <stdexcept>
- Contains standard exception classes such as
std::logic_error
andstd::runtime_error
, both derived fromstd::exception
. <system_error>
- Novità in C++11. Definisce
std::error_code
<optional>
- Novità in C++17. Fornisce la classe template
std::optional
per i tipi opzionali. <stacktrace>
- Novità in C++23. Fornisce le operazioni stack trace.
<tuple>
- Novità in C++11 e TR1. Fornisce la classe template
std::tuple
, una tupla. <type_traits>
- Novità in C++11. Fornisce funzioni di metaprogrammazione per lavorare con i tipi.
<utility>
- Fornisce various utilities: class template
std::pair
(two-member tuples), compile-time integer sequences, helpers in constructing vocabulary types, functions such asstd::move
andstd::forward
, and many more. The namespacestd::rel_ops
for automatically generating comparison operators is deprecated in C++20 in favor of new defaulted comparison operators. <variant>
- Novità in C++17. Fornisce la classe template
std::variant
, a tagged union type.
Supporto del linguaggio[modifica | modifica wikitesto]
<compare>
- Novità in C++20. Fornisce il supporto al nuovo operatore a tre vie.
<coroutine>
- Novità in C++20. Fornisce il supporto alle coroutine.
<exception>
- Fornisce several types and functions related to exception handling, including
std::exception
, the base class of all exceptions thrown by the Standard Library. <initializer_list>
- Novità in C++11. Fornisce il supporto alle liste di inizializzatori.
<limits>
- Fornisce la classe template
std::numeric_limits
, used for describing properties of fundamental numeric types. <new>
- Fornisce gli operatori
new
edelete
oltre che altre funzioni e tipi, i quali compongono i fondamenti della gestione della memoria in C++. <source_location>
- Novità in C++20. Fornisce capturing source location information as alternative to predefined macros such as
__LINE__
. <typeinfo>
- Fornisce facilities for working with C++ run-time type information.
<version>
- Novità in C++20. Fornisce informazioni riguardo l'implementazione corrente della libreria standard C++.[4]
Strutture dati[modifica | modifica wikitesto]
<array>
- Novità in C++11 and TR1. Fornisce the container class template
std::array
, a container for a fixed sized array. <bitset>
- Fornisce the specialized container class
std::bitset
, a bit array. <deque>
- Fornisce the container class template
std::deque
, a double-ended queue. <forward_list>
- Novità in C++11 and TR1. Fornisce the container class template
std::forward_list
, a singly linked list. <list>
- Fornisce the container class template
std::list
, a doubly linked list. <map>
- Fornisce the container class templates
std::map
andstd::multimap
, sorted associative array and multimap. <queue>
- Fornisce the container adapter class
std::queue
, a single-ended queue, andstd::priority_queue
, a priority queue. <set>
- Fornisce the container class templates
std::set
andstd::multiset
, sorted associative containers or sets. <span>
- Novità in C++20. Fornisce the container adapter class template
std::span
, a mutable non-owning view that refers to any contiguous range. <stack>
- Fornisce the container adapter class
std::stack
, a stack. <unordered_map>
- Novità in C++11 and TR1. Fornisce the container class template
std::unordered_map
andstd::unordered_multimap
, hash tables. <unordered_set>
- Novità in C++11 and TR1. Fornisce the container class template
std::unordered_set
andstd::unordered_multiset
. <vector>
- Fornisce the container class template
std::vector
, a dynamic array.
Iteratori e intervalli[modifica | modifica wikitesto]
<algorithm>
- Fornisce definitions of many container algorithms.
<execution>
- Fornisce execution policies for parallelized algorithms.
<iterator>
- Fornisce classes and templates for working with iterators.
<ranges>
- Novità in C++20. Fornisce ranges facilities and lazy evaluated adaptors.
Localizzazione[modifica | modifica wikitesto]
<locale>
- Definisce classes and declares functions that encapsulate and manipulate the information peculiar to a locale.
<codecvt>
- Fornisce code conversion facets for various character encodings. Questo header è deprecato a partire da C++17.
Stringhe[modifica | modifica wikitesto]
<charconv>
- Novità in C++17. Fornisce a locale-independent, non-allocating, and non-throwing string conversion utilities from/to integers and floating points.
<format>
- Novità in C++20. Fornisce a modern way of formatting strings including
std::format
. <string>
- Fornisce the C++ standard string classes and templates.
<string_view>
- Novità in C++17. Fornisce class template
std::basic_string_view
, an immutable non-owning view to any string. <regex>
- Novità in C++11. Fornisce utilities for pattern matching strings using regular expressions.
Streams, Files, e Input/Output[modifica | modifica wikitesto]
<filesystem>
- Novità in C++17. Fornisce facilities for file system operations and their components.
<fstream>
- Fornisce facilities for file-based input and output. See fstream.
<iomanip>
- Fornisce facilities to manipulate output formatting, such as the base used when formatting integers and the precision of floating point values.
<ios>
- Fornisce several types and functions basic to the operation of iostreams.
<iosfwd>
- Fornisce forward declarations of several I/O-related class templates.
<iostream>
- Fornisce le basi per gestire l'input e l'output in C++. Vedere iostream.
<istream>
- Fornisce
std::istream
e altre classi di support per l'input. <ostream>
- Fornisce
std::ostream
e altre classi di supporto per l'output. <spanstream>
- Novità in C++23. Fornisce
std::spanstream
and other fixed character buffer I/O streams. <sstream>
- Fornisce
std::stringstream
and other supporting classes for string manipulation. <streambuf>
- Fornisce reading and writing functionality to/from certain types of character sequences, such as external files or strings.
<syncstream>
- Novità in C++20. Fornisce
std::osyncstream
and other supporting classes for synchronized output streams.
Libreria di supporto dei thread[modifica | modifica wikitesto]
<barrier>
- Novità in C++20. Fornisce
std::barrier
, a reusable thread barrier. <condition_variable>
- Novità in C++11. In 32.6-1, condition variables provide synchronization primitives used to block a thread until notified by some other thread that some condition is met or until a system time is reached.
<future>
- Novità in C++11. In 32.9.1-1, this section describes components that a C++ program can use to retrieve in one thread the result (value or exception) from a function that has run in the same thread or another thread.
<latch>
- Novità in C++20. Fornisce
std::latch
, a single-use thread barrier. <mutex>
- Novità in C++11. In 32.5-1, this section Fornisce mechanisms for mutual exclusion: mutexes, locks, and call once.
<shared_mutex>
- Novità in C++14. Fornisce funzioni per la mutua esclusione condivisa.
<semaphore>
- Novità in C++20. Fornisce semafori che modellano un conteggio non negativo delle risorse.
<stop_token>
- Novità in C++20. In 32.3.1-1, this section describes components that can be used to asynchronously request that an operation stops execution in a timely manner, typically because the result is no longer required. Such a request is called a stop request.
<thread>
- Novità in C++11. Provide class and namespace for working with threads.
Libreria numerica[modifica | modifica wikitesto]
Components that C++ programs may use to perform seminumerical operations.
<bit>
- Novità in C++20. Fornisce funzioni per la manipolazione dei bit.
<complex>
- Definisce a class template
std::complex
, and numerous functions for representing and manipulating complex numbers. <numbers>
- Novità in C++20. Fornisce mathematical constants defined in namespace
std::numbers
. <random>
- Novità in C++11. Contiene funzioni per generare numeri e ripartizioni (pseudo-)casuali.
<ratio>
- Novità in C++11. Fornisce compile-time rational arithmetic based on class templates.
<valarray>
- Definisce five class templates (
std::valarray
,std::slice_array
,std::gslice_array
,std::mask_array
, andstd::indirect_array
), two classes (std::slice
andstd::gslice
), and a series of related function templates for representing and manipulating arrays of values. <numeric>
- Per le operazioni numeriche generalizzate.
Libreria standard del C[modifica | modifica wikitesto]
Ogni intestazione della libreria standard C è inclusa nella libreria standard C++ con un nome diverso, generata rimuovendo il .h e aggiungendo una "c" all'inizio; ad esempio, 'time.h' diventa 'ctime'. L'unica differenza tra queste intestazioni e le tradizionali intestazioni della Libreria standard C è che, ove possibile, le funzioni dovrebbero essere collocate nello spazio dei nomi std::
. In ISO C, le funzioni nella libreria standard possono essere implementate da macro, cosa che non è consentita da ISO C++.
Note[modifica | modifica wikitesto]
- ^ ISO/IEC 14882:2003(E) Programming Languages — C++ §17-27
- ^ ISO/IEC 14882:2003(E) Programming Languages — C++ §D.5
- ^ (EN) Bartlomiej Filipek, Polymorphic Allocators, std::vector Growth and Hacking, su bfilipek.com. URL consultato il 30 aprile 2021.
- ^ (EN) Working Draft, Standard for Programming Language C++ (PDF), in ISO/IEC, 1º aprile 2020, p. 492. URL consultato il 30 aprile 2021.