Why is libc++’s vector::const_reference not bool?

The motivation for this extension, which is detectable by a conforming program, and thus non-conforming, is to make vector<bool> behave more like vector<char> with respect to references (const and otherwise). Introduction Since 1998, vector<bool> has been derided as “not quite a container.” LWG 96, one of the very first LWG issues, launched the debate. Today, … Read more

Are the experimental features of modern C++ reliable for long-term projects?

Is it guaranteed that all compliant compilers have the same experimental features? No, experimental features are optional. Are experimental features prone to big changes that make them unreliable? Yes, the C++ committee might even decide to abandon a feature or in the process of standardization a defect might come up that would force a feature … Read more

How to get the file size in bytes with C++17

<filesystem> (added in C++17) makes this very straightforward. #include <cstdint> #include <filesystem> // … std::uintmax_t size = std::filesystem::file_size(“c:\\foo\\bar.txt”); As noted in comments, if you’re planning to use this function to decide how many bytes to read from the file, keep in mind that… …unless the file is exclusively opened by you, its size can be … Read more

Why is there no transform_if in the C++ standard library?

The standard library favours elementary algorithms. Containers and algorithms should be independent of each other if possible. Likewise, algorithms that can be composed of existing algorithms are only rarely included, as shorthand. If you require a transform if, you can trivially write it. If you want it /today/, composing of ready-mades and not incur overhead, … Read more

What are the mechanics of short string optimization in libc++?

The libc++ basic_string is designed to have a sizeof 3 words on all architectures, where sizeof(word) == sizeof(void*). You have correctly dissected the long/short flag, and the size field in the short form. what value would __min_cap, the capacity of short strings, take for different architectures? In the short form, there are 3 words to … Read more

Writing your own STL Container

Here’s a sequence pseudo-container I pieced together from ยง 23.2.1\4 Note that the iterator_category should be one of std::input_iterator_tag, std::output_iterator_tag,std::forward_iterator_tag,std::bidirectional_iterator_tag,std::random_access_iterator_tag. Also note that the below is technically more strict than required, but this is the idea. Note that the vast majority of the “standard” functions are technically optional, due to the awesomeness that is iterators. … Read more

Deleting elements from std::set while iterating

This is implementation dependent: Standard 23.1.2.8: The insert members shall not affect the validity of iterators and references to the container, and the erase members shall invalidate only iterators and references to the erased elements. Maybe you could try this — this is standard conforming: for (auto it = numbers.begin(); it != numbers.end(); ) { … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)