Where are the headers of the C++ standard library

GCC typically has the standard C++ headers installed in /usr/include/c++/<version>/. You can run gcc -v to find out which version you have installed. At least in my version, there is no vector.h; the public header is just vector (with no extension), and most of the implementation is in bits/stl_vector.h. That’s the case on my Ubuntu … Read more

Bug in the C++ standard library in std::poisson_distribution?

My system is set up as follows (Debian testing): libstdc++-7-dev: Installed: 7.2.0-16 libc++-dev: Installed: 3.5-2 clang: Installed: 1:3.8-37 g++: Installed: 4:7.2.0-1d1 I can confirm the bug when using libstdc++: g++ -o pois_gcc -std=c++11 pois.cpp clang++ -o pois_clang -std=c++11 -stdlib=libstdc++ pois.cpp clang++ -o pois_clang_libc -std=c++11 -stdlib=libc++ pois.cpp Result:

Does it make sense to combine optional with reference_wrapper?

Is there any conceptual difference between std::optional<std::reference_wrapper<T>> and T*? std::optional<>, as the name already suggest, is meant to be used when we could have a value or might not have any value at all. The equivalent of having no value for a T* object would be assigning nullptr to it, i.e.: the pointer will point … Read more

How do I iterate equal values with the standard library?

This is basically Range v3’s group_by: group_by(v, std::equal_to{}). It doesn’t exist in the C++17 standard library, but we can write our own rough equivalent: template <typename FwdIter, typename BinaryPred, typename ForEach> void for_each_equal_range(FwdIter first, FwdIter last, BinaryPred is_equal, ForEach f) { while (first != last) { auto next_unequal = std::find_if_not(std::next(first), last, [&] (auto const& element) … Read more

what is difference between fgetpos/fsetpos and ftell/fseek

None of the above answers are correct – in fact if you use fsetpos interchangeably with fseek you could introduce a security flaw (https://www.securecoding.cert.org/confluence/pages/viewpage.action?pageId=20087255). The reason is that the fpos_t *pos argument to fsetpos isn’t actually an integer so it can’t be used to seek to arbitrary locations in a file. The only valid values … Read more

Does the C standard guarantee buffers are not touched past their null terminator?

The C99 draft standard does not explicitly state what should happen in those cases, but by considering multiple variations, you can show that it must work a certain way so that it meets the specification in all cases. The standard says: %s – Matches a sequence of non-white-space characters.252) If no l length modifier is … Read more

Assign a nullptr to a std::string is safe?

Interesting little question. According to the C++11 standard, sect. 21.4.2.9, basic_string(const charT* s, const Allocator& a = Allocator()); Requires: s shall not be a null pointer. Since the standard does not ask the library to throw an exception when this particular requirement is not met, it would appear that passing a null pointer provoked undefined … Read more

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