c++-standard-library

Error C2676: std::set::const_iterator doesn't have operator+ function?

巧了我就是萌 提交于 2021-02-10 20:08:38
问题 std::set<int> s = { 1,2,3,4,5 }; std::set<int> s2(s.begin(), s.begin() + 2); I want to assgin several values of s into s2 . But got below compile error: Error C2676 binary ' + ': ' std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>> ' does not define this operator or a conversion to a type acceptable to the predefined It seems std::set::const_iterator doesn't have operator+ method. 回答1: It seems std::set::const_iterator doesn't have operator+ method. You are right about

ref-qualifiers for the assignment operator of standard library types

本秂侑毒 提交于 2021-02-09 10:55:43
问题 I was wondering, is there a reason the assignment operator of standard types is not lvalue ref-qualified? None of them are. Because of that, we can write things such as this: std::string{} = "42"; std::string s = "hello " + std::string{"world"} = "oops!"; std::vector<int> v = { 1,2,3 }; std::move(v) = { 4,5,6 }; If the assignment operator was lvalue ref-qualified all of these examples would not compile. Is it because there's a lot of things to modify (but then so it was for noexcept) and

ref-qualifiers for the assignment operator of standard library types

牧云@^-^@ 提交于 2021-02-09 10:54:09
问题 I was wondering, is there a reason the assignment operator of standard types is not lvalue ref-qualified? None of them are. Because of that, we can write things such as this: std::string{} = "42"; std::string s = "hello " + std::string{"world"} = "oops!"; std::vector<int> v = { 1,2,3 }; std::move(v) = { 4,5,6 }; If the assignment operator was lvalue ref-qualified all of these examples would not compile. Is it because there's a lot of things to modify (but then so it was for noexcept) and

Why has std::accumulate not been made constexpr in C++20?

懵懂的女人 提交于 2021-02-08 12:16:59
问题 In C++20, many (most?) C++-standard-library algorithms have been made constexpr . Yet - std::accumulate has not. It seems like it could have been: template<class InputIt, class T> constexpr T accumulate(InputIt first, InputIt last, T init) { for (; first != last; ++first) { init = std::move(init) + *first; } return init; } So - is there a reason it wasn't constexpr 'ed as well? Note: This question was motivated by my answer to this question on compile-time accumulation. 回答1: P1645R1 was

Will std::experimental::optional<> support references?

三世轮回 提交于 2021-02-07 11:49:18
问题 At the moment, boost::optional<> supports references but the std::experimental::optional<> on my system from libstdc++ does not. Is this reflective of what might make it into the standard? I know that the optional proposal author spun off optional references as a separate proposal so that the main optional proposal would have a better chance of being accepted. Was the proposal for optional references rejected or did work on it stop? 回答1: Is this reflective of what might make it into the

Will std::experimental::optional<> support references?

孤街醉人 提交于 2021-02-07 11:49:04
问题 At the moment, boost::optional<> supports references but the std::experimental::optional<> on my system from libstdc++ does not. Is this reflective of what might make it into the standard? I know that the optional proposal author spun off optional references as a separate proposal so that the main optional proposal would have a better chance of being accepted. Was the proposal for optional references rejected or did work on it stop? 回答1: Is this reflective of what might make it into the

How to (and who can) implement the standard library features defined by the C++ committee?

隐身守侯 提交于 2021-02-07 06:54:10
问题 When the C++ committee publish a new feature that will be part of the standard library in the next standard of the language, they also release some source code or some kind of guidance on how to implement that feature? Let's take unique_ptr as an example. The language committee just defines an interface for that class template and let the compiler vendor implement it as it wants? How exactly this process of implementation of the standard library features occurs. Can anyone implement parts of

How to (and who can) implement the standard library features defined by the C++ committee?

泪湿孤枕 提交于 2021-02-07 06:54:10
问题 When the C++ committee publish a new feature that will be part of the standard library in the next standard of the language, they also release some source code or some kind of guidance on how to implement that feature? Let's take unique_ptr as an example. The language committee just defines an interface for that class template and let the compiler vendor implement it as it wants? How exactly this process of implementation of the standard library features occurs. Can anyone implement parts of

Standard experimental latch and barrier use ptrdiff_t

独自空忆成欢 提交于 2021-02-05 07:37:51
问题 I was looking at the C++ experimental extensions for concurrency and noticed the new synchronization classes latch , barrier , and flex_barrier . They all implement a standard barrier, either single-use or reusable. The current documentation states the following signature for their constructors: explicit latch( ptrdiff_t value ); explicit barrier( std::ptrdiff_t num_threads ); explicit flex_barrier( std::ptrdiff_t num_threads ); With the following explanation for the value or num_threads

istream_iterator copy example keeps waiting for input

我怕爱的太早我们不能终老 提交于 2021-02-04 08:15:06
问题 I tried implementing an example of stream iterators from page 107 of "The C++ Standard Library". I get stuck on this line: copy (istream_iterator<string>(cin), istream_iterator<string>(), back_inserter(coll)); The program keeps reading data from the console here, but does not pass on to the next line. How do I continue past this point? 回答1: take for instance, if you would have made an input stream of int then you would have given input like - 45 56 45345 555 ....., so in all those cases, the