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
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 dal programmatore utente 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 Hello world allora il programma sarà scritto:
#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
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] | Unknown | Commercial | Unknown |
Cray C++ Standard Library | [8] | Unknown | Commercial | Unknown |
Header standard
I file seguenti contengono le dichiarazioni della libreria standard C++.
Generici
<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 nuovità 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, realazzate per l'uso con algoritrmi standard.
<memory>
- Fornisce facilities for memory management in C++, including the class 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 class template
std::optional
, an optional type. <stacktrace>
- Novità in C++23. Fornisce stack trace operations.
<tuple>
- Novità in C++11 e TR1. Fornisce a class template
std::tuple
, a tuple. <type_traits>
- Novità in C++11. Fornisce metaprogramming facilities working with types.
<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 a class template
std::variant
, a tagged union type.
Supporto del linguaggio
<compare>
- Novità in C++20. Fornisce three-way comparison operator support.
<coroutine>
- Novità in C++20. Fornisce coroutine support.
<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 initializer list support.
<limits>
- Fornisce the class template
std::numeric_limits
, used for describing properties of fundamental numeric types. <new>
- Fornisce operators
new
anddelete
and other functions and types composing the fundamentals of C++ memory management. <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
<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
<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
<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. This header is deprecated since C++17.
Stringhe
<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
<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 C++ input and output fundamentals. See iostream.
<istream>
- Fornisce
std::istream
and other supporting classes for input. <ostream>
- Fornisce
std::ostream
and other supporting classes for 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
<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 facitility for shared mutual exclusion.
<semaphore>
- Novità in C++20. Fornisce semaphore that models non-negative resource count.
<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
Components that C++ programs may use to perform seminumerical operations.
<bit>
- Novità in C++20. Fornisce bit manipulation facility.
<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. Facility for generating (pseudo-)random numbers and distributions.
<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>
- Generalized numeric operations.
Libreria standard del C
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
- ^ 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.
- ^ (EN) Working Draft, Standard for Programming Language C++ (PDF), in ISO/IEC, 1º aprile 2020, p. 492. URL consultato il 30 aprile 2021.