5 ms·
> I don't have a copy of the standard at hand, can anyone quote the relevant section? The C++ (draft) standard is on GitHub! [0] Compiling it needs Perl and so
by aw1621107 4y ago
> I don't have a copy of the standard at hand, can anyone quote the relevant section?
The C++ (draft) standard is on GitHub! [0] Compiling it needs Perl and some LaTeX packages, but is reasonably straightforwards otherwise. In addition, links to specific draft standards can be found on cppreference [1].
But anyways, in the first C++20 post-publication draft (N4868), the wording you're interested in is in multiple sections. Section 22.2.3 Sequence Containers [sequence.reqmts] has Table 78: Optional sequence container operations [tab:container.seq.opt] (starting on page 815), which states that a precondition of pop_back() is that empty() returns false. Section 16.3.2.4 Detailed Specifications [structure.specifications] (page 481) states:
> Preconditions: the conditions that the function assumes to hold whenever it is called; violation of any preconditions results in undefined behavior.
Therefore, calling pop_back() on an empty vector results in undefined behavior.
> Is this something that in practice is implemented in different (exception-throwing) ways?
Based on a quick glance at the major implementations (libc++ 15.0.7 at [2], MSVC at [3], libstdc++ at [4]), it looks like asserts are used. Whether those result in exceptions probably depends on whether the asserts are compiled in in the first place and how they are implemented, but it's definitely not a guaranteed exception.
[0]: https://github.com/cplusplus/draft https://github.com/cplusplus/draft
[1]: https://en.cppreference.com/w/cpp/links https://en.cppreference.com/w/cpp/links
[2]: https://github.com/llvm/llvm-project/blob/llvmorg-15.0.7/libcxx/include/vector#L1644 https://github.com/llvm/llvm-project/blob/llvmorg-15.0.7/lib...
[3]: https://github.com/llvm/llvm-project/blob/8dfdcc7b7bf66834a761bd8de445840ef68e4d1a/libcxx/include/vector#L1644 https://github.com/llvm/llvm-project/blob/8dfdcc7b7bf66834a7...
[4]: https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libstdc%2B%2B-v3/include/bits/stl_vector.h;h=86ff83d137343ca55a0703bc3d8d6a343468f474;hb=HEAD#l1315 https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libstdc%2B%2B-v3...
- jb1991 4y ago> Compiling it needs Perl this was something that I thought must be a joke at first... a text document that needs ... Perl ... to be read. This does make sense considering the context is C++ though.
- aw1621107 4y agoThe C++ standard is a LaTeX document, not a plain text document. Perl is needed for latexmk [0], which isn't strictly necessary but greatly simplifies the process of compiling LaTeX. [0]: https://mg.readthedocs.io/latexmk.html https://mg.readthedocs.io/latexmk.html
- Karellen 4y agoYou've just been pointed at github. Which hosts git repositories. Which is used to keep track of changes to source files, not published build artifacts. For future reference, lots of other git-hosted projects also require the user to supply build tools to produce the finished product. Sometimes these are programs known as "compilers", but frequently other programs like "parser generators" or "text formatters" are needed too. Or scripting languages (like perl) to help tie the build process together. Might be worth keeping in mind if you ever need to interact with git (or github) again.
- dminik 4y agoYou do know that GitHub has an entire section for each repository called "Releases" right? In fact, you can setup a free pipeline to generate these release for you. Might be worth keeping in mind if you ever need to interact with git (or github) again.
- jb1991 4y agoWhat a snide, unhelpful, and rude remark. This is in the context of a textual language standard, it was reasonable to not consider it something that needs additional steps to view. Fine that it does, but your reply is ridiculous, to suggest that someone talking about the C++ standard doesn't know what a compiler is.
- elteto 4y agoThe final standard document is neither a "text" document, nor do you need Perl to "read" it.