April 26, 2025 - Source files that are not intended to also be valid ISO C should not use any of the C headers. With the exception of complex.h, each xxx.h header included in the C++ standard library places in the global namespace each name that the corresponding cxxx header would have placed in the std namespace. These headers are allowed to also declare the same names in the std namespace, and the corresponding cxxx headers are allowed to also declare the same names in the global namespace: including <cstdlib> definitely provides std::malloc and may also provide ::malloc.
From cppreference.com · < cpp · C++ Standard Library header files · The interface of C++ standard library is defined by the following collection of header files.
Discussions
Why are we still dealing with header files?
A couple of weeks ago, I merged C++23's P2465R3 Standard Library Modules into microsoft/STL's main branch, which will ship in VS 2022 17.5 Preview 1. Compiler work to fix various ICEs is still ongoing, and build system work is still necessary, but the library work is done. The PR was microsoft/STL#3108 , which begins with: "I've added over 3,750 occurrences of _EXPORT_STD after auditing over 148,000 lines of headers." (That's my STL-internal macro that expands to export, not for users to use directly.) You can try this right now with the VS 2022 17.4 Preview 2 compiler, by building microsoft/STL main. Here's a quick example comparing #include to import std;: D:\GitHub\STL\out\build\x64>type paleolithic_era.cpp #include int main() { std::cout << "Goodbye, header world!\n"; } D:\GitHub\STL\out\build\x64>cl /EHsc /nologo /W4 /std:c++latest /MTd /Od /Bt paleolithic_era.cpp paleolithic_era.cpp time(C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.34.31823\bin\HostX64\x64\c1xx.dll)=0.513s time(C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.34.31823\bin\HostX64\x64\c2.dll)=0.010s [...linker timings omitted for brevity...] D:\GitHub\STL\out\build\x64>paleolithic_era Goodbye, header world! D:\GitHub\STL\out\build\x64>type new_world_order.cpp import std; int main() { std::cout << "Hello, modules world!\n"; } D:\GitHub\STL\out\build\x64>cl /EHsc /nologo /W4 /std:c++latest /MTd /Od /Bt /c D:\GitHub\STL\out\build\x64\out\modules\std.ixx std.ixx time(C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.34.31823\bin\HostX64\x64\c1xx.dll)=2.564s time(C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.34.31823\bin\HostX64\x64\c2.dll)=0.204s D:\GitHub\STL\out\build\x64>dir std.ifc std.obj | grep -P "\.ifc|\.obj" 10/10/2022 05:31 PM 28,156,007 std.ifc 10/10/2022 05:31 PM 7,211,607 std.obj D:\GitHub\STL\out\build\x64>cl /EHsc /nologo /W4 /std:c++latest /MTd /Od /Bt new_world_order.cpp std.obj new_world_order.cpp time(C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.34.31823\bin\HostX64\x64\c1xx.dll)=0.131s time(C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.34.31823\bin\HostX64\x64\c2.dll)=0.006s [...linker timings omitted for brevity...] D:\GitHub\STL\out\build\x64>new_world_order Hello, modules world! What this shows (as a very quick and dirty benchmark, no attempt to run repeatedly and average timings) is: #include followed by Hello World usage of cout takes 513 ms of compiler front-end time (on my 5950X machine). Building the entire C++ Standard Library into a named module, which needs to be done only once for a given compiler toolset version and project command line, takes 2,564 ms of front-end time (and another 204 ms of back-end time for codegen; this is non-optimized debug mode). This is slightly slower than building a PCH (not depicted here), but not by much. import std; followed by Hello World cout takes only 131 ms of compiler front-end time. That is, importing the entire C++ Standard Library as a named module is 3.9x faster (times, not percent) than classic inclusion of . This speedup will naturally vary depending on what a real program is doing (including more headers will make the classic inclusion scenario much slower - is big but not the biggest - while doing more actual work in the source file will dilute the raw performance difference), but I think this effectively shows how simple (one import!) and fast the Standard Library Modules will be. There are other advantages (macro immunity, not leaking internal names) too. Finally, note that this is very space-efficient - the digested IFC file that allows this rapid importation is only 26.9 MB, plus another 6.9 MB for the OBJ - in previous measurements I've seen that this is about 10x smaller than a PCH. More on reddit.com
r/cpp
61
17
October 11, 2022
Is there a version of C++ STL with well documented header files ?
The libstdc++ one is passable. For instance here is the doc of std::copy : /** * @brief Copy the elements of a sequence for which a predicate is true. * @ingroup mutating_algorithms * @param __first An input iterator. * @param __last An input iterator. * @param __result An output iterator. * @param __pred A predicate. * @return An iterator designating the end of the resulting sequence. * * Copies each element in the range @p [__first,__last) for which * @p __pred returns true to the range beginning at @p __result. * * copy_if() is stable, so the relative order of elements that are * copied is unchanged. */ More on reddit.com
4.1.2 Standard headers · Categories: Pages using deprecated source tags · Pages using deprecated enclose attributes · Support us · Recent changes · FAQ · Offline version · What links here · Related changes · Upload file · Special pages · Printable version ·
From cppreference.com · < cpp · C++ Standard Library header files · The interface of C++ standard library is defined by the following collection of header files · For some of the C standard library headers of the form xxx.h, the C++ standard library both includes an identically-named header and another header of the form cxxx (all meaningful cxxx headers are listed above).
From cppreference.com · < cpp · C++ Standard Library header files · The interface of C++ standard library is defined by the following collection of header files.
Provides functionality to use an abstraction called streams specially designed to perform input and output operations on sequences of character, like files or strings. This functionality is provided through several related classes, as shown in the following relationship map, with the corresponding ...
C Standard Library header files · From cppreference.com · [edit] See also · Retrieved from "http://en.cppreference.com/mwiki/index.php?title=c/header&oldid=71951"
March 5, 2021 - The name of each of these C++ headers is of the form cname, where name is the string that results when the “.h” extension is removed from the name of the equivalent C Standard Library header. For example, the header files <stdlib.h> and <cstdlib> are both provided by the C++ Standard Library and are equivalent in function, with the exception that all declarations in <cstdlib> are located within the std namespace.
We add an #include directive for "my_class.h" file in order to have the my_class declaration inserted at this point in the .cpp file, and we include <iostream> to pull in the declaration for std::cout. Note that quotes are used for header files in the same directory as the source file, and angle brackets are used for standard library headers.
April 12, 2024 - namespace std { class bad_array_new_length : public bad_alloc { public: // see description for the specification of the special member functions constexpr const char* what() const noexcept override; }; } Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/header/new&oldid=170819" Support us · Recent changes · FAQ · Offline version · What links here · Related changes · Upload file ·