c++-standard-library

POD implications for a struct which holds an standard library container

天大地大妈咪最大 提交于 2020-01-14 19:37:59
问题 I came across this question recently. My goal is to understand how the C++ compiler views struct definitions which hold standard library containers such as std::vector. Ben Voigt's answer to the linked question cites the following from the C++0x standard: .... A trivial class is a class that has a trivial default constructor (12.1) and is trivially copyable. [ Note: In particular, a trivially copyable or trivial class does not have virtual functions or virtual base classes. — end note ] A

When could std::priority_queue::pop throw an exception

我怕爱的太早我们不能终老 提交于 2020-01-14 12:44:49
问题 The pop() method of std::priority_queue is not declared noexcept , so in theory could throw an exception. But when might it throw an exception, and what might those exceptions be? 回答1: It could be marked nothrow , but isn't. Why std::priority_queue::pop could * not throw void pop(); Removes the top element from the priority queue. Effectively calls std::pop_heap(c.begin(), c.end(), comp); c.pop_back(); c is by default an std::vector . [vector.modifiers]/4&5 void pop_back(); 4/ Complexity :

std::stoi not recognized by eclipse

核能气质少年 提交于 2020-01-13 19:50:59
问题 On my system, running Windows 7 x64, Eclipse Luna, and g++ 4.9.2 (installed via cygwin), it seems std::stoi was never declared by g++. According to the documentation, stoi is part of the string library, so obviously I have #include <string> . In addition, I know that stoi was introduced in C++11, and I have set the appropriate flags for my compiler (g++), even though this seems like an IDE error , rather than a compiler error. Still, I would get one of the following error messages when

std::stoi not recognized by eclipse

两盒软妹~` 提交于 2020-01-13 19:50:12
问题 On my system, running Windows 7 x64, Eclipse Luna, and g++ 4.9.2 (installed via cygwin), it seems std::stoi was never declared by g++. According to the documentation, stoi is part of the string library, so obviously I have #include <string> . In addition, I know that stoi was introduced in C++11, and I have set the appropriate flags for my compiler (g++), even though this seems like an IDE error , rather than a compiler error. Still, I would get one of the following error messages when

Is there any drawbacks in providing operator+ or operator- to bidirectional iterators?

夙愿已清 提交于 2020-01-13 12:08:28
问题 The bidirectional iterators have no luxuries like random access iterators, and hence need to depend upon the std::next and std::prev, when someone needs to do operations like std::set<int> s{ 1, 2, 3, 4, 5 }; //std::set<int> s2(s.cbegin(), s.cbegin() + 2); // won't work as there is no operator+ for std::set::const_iterator std::set<int> s2(s.cbegin(), std::next(s.cbegin(), 2)); //std::set<int> s3(s.cbegin(), s.cend() - 2); // won't work as there is no operator- for std::set::const_iterator

Is there any drawbacks in providing operator+ or operator- to bidirectional iterators?

你说的曾经没有我的故事 提交于 2020-01-13 12:08:15
问题 The bidirectional iterators have no luxuries like random access iterators, and hence need to depend upon the std::next and std::prev, when someone needs to do operations like std::set<int> s{ 1, 2, 3, 4, 5 }; //std::set<int> s2(s.cbegin(), s.cbegin() + 2); // won't work as there is no operator+ for std::set::const_iterator std::set<int> s2(s.cbegin(), std::next(s.cbegin(), 2)); //std::set<int> s3(s.cbegin(), s.cend() - 2); // won't work as there is no operator- for std::set::const_iterator

Standard library facilities which allocate but don't use an Allocator

别等时光非礼了梦想. 提交于 2020-01-10 14:15:15
问题 In most places where the C++ standard library allocates memory, the user is able to customise this by providing a class which meets the Allocator requirements. For example, almost all containers take an allocator template argument, and std::allocate_shared returns a shared_ptr whose contained element and control block are both allocated via a provided Allocator. However, there are a few places where the standard library can (potentially) allocate memory, but no Allocator support is provided.

std::atomic | compare_exchange_weak vs. compare_exchange_strong

好久不见. 提交于 2020-01-09 12:30:25
问题 I'm unsure if it's me not understanding or the documentation isn't clearly formulated. The following excerpt has been taken from the newest draft (N3126, section 29.6): bool atomic_compare_exchange_weak(volatile A* object, C * expected, C desired); bool atomic_compare_exchange_weak(A* object, C * expected, C desired); bool atomic_compare_exchange_strong(volatile A* object, C * expected, C desired); bool atomic_compare_exchange_strong(A* object, C * expected, C desired); bool atomic_compare

std::atomic | compare_exchange_weak vs. compare_exchange_strong

↘锁芯ラ 提交于 2020-01-09 12:28:51
问题 I'm unsure if it's me not understanding or the documentation isn't clearly formulated. The following excerpt has been taken from the newest draft (N3126, section 29.6): bool atomic_compare_exchange_weak(volatile A* object, C * expected, C desired); bool atomic_compare_exchange_weak(A* object, C * expected, C desired); bool atomic_compare_exchange_strong(volatile A* object, C * expected, C desired); bool atomic_compare_exchange_strong(A* object, C * expected, C desired); bool atomic_compare

std::atomic | compare_exchange_weak vs. compare_exchange_strong

泪湿孤枕 提交于 2020-01-09 12:28:08
问题 I'm unsure if it's me not understanding or the documentation isn't clearly formulated. The following excerpt has been taken from the newest draft (N3126, section 29.6): bool atomic_compare_exchange_weak(volatile A* object, C * expected, C desired); bool atomic_compare_exchange_weak(A* object, C * expected, C desired); bool atomic_compare_exchange_strong(volatile A* object, C * expected, C desired); bool atomic_compare_exchange_strong(A* object, C * expected, C desired); bool atomic_compare