c++-standard-library

Where are the headers of the C++ standard library

谁说胖子不能爱 提交于 2019-12-31 10:31:46
问题 I wonder where on my file system I find the headers of the C++ Standard library. In particular I am looking for the definition of the vector template. I searched in /usr/include/ and various subdirectories. I also tried 'locate vector.h' which brought up many implementations of vectors, but not the standard one. What am I missing? (The distribution is Gentoo) Background: I'm profiling a library that iterates over vector's most of the time and gprof shows that most of the time is spent in std:

Why doesn't N3421 provide the noexcept qualifier?

て烟熏妆下的殇ゞ 提交于 2019-12-30 09:52:23
问题 In N3421 - Making Operator Functors greater<>, the new specialization for the std function objects is: template <> struct plus<void> { template <class T, class U> auto operator()(T&& t, U&& u) const -> decltype(std::forward<T>(t) + std::forward<U>(u)); }; instead of template <> struct plus<void> { template <class T, class U> auto operator()(T&& t, U&& u) const noexcept(noexcept(decltype(std::forward<T>(t) + std::forward<U>(u)) (std::move(std::forward<T>(t) + std::forward<U>(u))))) -> decltype

Qt: Qt classes vs. standard C++

半城伤御伤魂 提交于 2019-12-30 08:30:12
问题 A large amount of functionality is duplicated between standard c++ and Qt. At some point it seems logical but many times it looks foolish. Like I feel like doing a new programming language, learning things which I already know. e.g. using QFile. Also if I do it all Qt way and suppose now I want to move out of Qt framework it will be too much tedious to rewrite that code. OTOH I like Qt because it provides me with libraries which otherwise I would have to fish myself like webkit, database

Qt: Qt classes vs. standard C++

柔情痞子 提交于 2019-12-30 08:30:08
问题 A large amount of functionality is duplicated between standard c++ and Qt. At some point it seems logical but many times it looks foolish. Like I feel like doing a new programming language, learning things which I already know. e.g. using QFile. Also if I do it all Qt way and suppose now I want to move out of Qt framework it will be too much tedious to rewrite that code. OTOH I like Qt because it provides me with libraries which otherwise I would have to fish myself like webkit, database

C++ valarray vs. vector

三世轮回 提交于 2019-12-27 16:32:45
问题 I like vectors a lot. They're nifty and fast. But I know this thing called a valarray exists. Why would I use a valarray instead of a vector? I know valarrays have some syntactic sugar, but other than that, when are they useful? 回答1: Valarrays (value arrays) are intended to bring some of the speed of Fortran to C++. You wouldn't make a valarray of pointers so the compiler can make assumptions about the code and optimise it better. (The main reason that Fortran is so fast is that there is no

Is it reasonable to overload std functions such as std::distance?

早过忘川 提交于 2019-12-24 15:47:55
问题 I have a custom iterator class conforming to the bidirectional iterator requirements (but not random access). However, the distance of two iterators can also be found in constant time. Conceptually, it2 - it1 is efficient, but it += n is not (neither of these operator overloads is actually implemented). Is it reasonable to overload std::distance() to allow standard library algorithms to compute distances efficiently with this iterator? I found conflicting information about the appropriateness

How do I get the current “localized pattern” for the date and time of an std::locale

不羁的心 提交于 2019-12-23 10:28:25
问题 So far, I'm able to get the current locale, but I want to get the date format for that particular locale. Can this be done with the standard library. #include <locale> int _tmain(int argc, _TCHAR* argv[]) { // Print the current locale std::cout << std::locale("").name().c_str() << "\n"; // TODO: get the locale's date pattern, example for US it's (mm/dd/yyyy) std::cout << "date pattern: \n"; } 回答1: If you just want to cast a date to the corresponding string you can use std::time_put<char> :

Transitioning away from std::string, std::ostream, etc. in a library's public API

狂风中的少年 提交于 2019-12-23 09:00:25
问题 For API/ABI compatibility across many toolchains with the same binary, it is well known that STL containers, std::string , and other standard library classes like iostreams are verboten in public headers. (Exceptions to this are if one is distributing one build for each version of supported toolchains; one delivers source with no binaries for end-user compilation, which are not preferred options in the present case; or one translates to some other container inline so that a differing std

why do std::sort and partial_sort require random-access iterators?

我是研究僧i 提交于 2019-12-23 07:12:12
问题 I was wondering why does the c++ standard require that std::sort should only take random-access iterators? I don't see the advantage, since both std::sort and std::list::sort have a complexity of N*log(N) . Restricting std::sort to random-access iterators (RAI) seems to have made it necessary to write a separate function for lists with the same complexity. The same applies to partial_sort , where the non-RAI counter-part for list is simply missing to this day. Is this design because people

Why calling shared_from_this calls std::terminate

纵饮孤独 提交于 2019-12-22 12:19:30
问题 Consider this code: class A : public std::enable_shared_from_this<A> { public: std::shared_ptr<A> f() { return shared_from_this(); } }; int main() { A a; std::shared_ptr<A> ptr = a.f(); } This code terminated in Visual Studio 2017. I guess I am doing something wrong here. Can anyone help me with this? I want a shared_ptr on a created by shared_from_this(). 回答1: Because a is not a owned by a shared pointer. From cppreference: It is permitted to call shared_from_this only on a previously shared