standards

Why is std::for_each a non-modifying sequence operation?

百般思念 提交于 2019-11-27 02:55:20
问题 I just read in the C++ standard that std::for_each is a non-modifying sequence operation, along with find , search and so on. Does that mean that the function applied to each element should not modify them? Why is that? What could possibly go wrong? Here is a sample code, where the sequence is modified. Can you see anything wrong with it? void foo(int & i) { i = 12; } int main() { std::vector<int> v; v.push_back(0); std::for_each(v.begin(), v.end(), foo); // v now contains 12 } I suspect this

Pointer to member conversion

∥☆過路亽.° 提交于 2019-11-27 02:41:14
问题 I just found the following paragraphs in c++03 standard draft relevant to pointer to member conversion. 4.11/2 Pointer to member conversions An rvalue of type “pointer to member of B of type cv T,” where B is a class type, can be converted to an rvalue of type “pointer to member of D of type cv T,” where D is a derived class (clause 10) of B. If B is an inaccessible (clause 11), ambiguous (10.2) or virtual (10.1) base class of D, a program that necessitates this conversion is ill-formed. The

Why not enforce 2's complement in C++?

橙三吉。 提交于 2019-11-27 02:31:55
问题 The new C++ standard still refuses to specify the binary representation of integer types. Is this because there are real-world implementations of C++ that don't use 2's complement arithmetic? I find that hard to believe. Is it because the committee feared that future advances in hardware would render the notion of 'bit' obsolete? Again hard to believe. Can anyone shed any light on this? Background: I was surprised twice in one comment thread (Benjamin Lindley's answer to this question). First

Undefined behavior on reading object using non-character type when last written using character type

穿精又带淫゛_ 提交于 2019-11-27 02:09:01
问题 Assuming unsigned int has no trap representations, do either or both of the statements marked (A) and (B) below provoke undefined behavior, why or why not, and (especially if you think one of them is well-defined but the other isn't), do you consider that a defect in the standard? I am primarily interested in the current version of the C standard (i.e. C2011), but if this is different in older versions of the standard, or in C++, I would also like to know about that. ( _Alignas is used in

What should happen to template class static member variables with definition in the .h file

爷,独闯天下 提交于 2019-11-27 01:56:47
问题 If a template class definition contains a static member variable that depends on the template type, I'm unsure of what the reliable behavior should be? In my case it is desirable to place the definition of that static member in the same .h file as the class definition, since I want the class to be general for many template data types that I don't currently know. I want only one instance of the static member to be shared throughout my program for each given template type. ( one for all MyClass

Overloading global swap for user-defined type

↘锁芯ラ 提交于 2019-11-27 01:55:17
问题 The C++ standard prohibits declaring types or defining anything in namespace std , but it does allow you to specialize standard STL templates for user-defined types. Usually, when I want to specialize std::swap for my own custom templated type, I just do: namespace std { template <class T> void swap(MyType<T>& t1, MyType<T>& t2) { t1.swap(t2); } } ...and that works out fine. But I'm not entirely sure if my usual practice is standard compliant. Am I doing this correctly? 回答1: What you have is

Name database design notation you prefer and why?

人盡茶涼 提交于 2019-11-27 01:05:02
Which notation , methodology and tools for database designing, modeling, diagraming you prefer and why? Which notation, standards , methodology are the most broadly used and covered by different vendors? Which are standard and which are not ? i.e. which are to stick with and which to avoid And personal question to PerformaneDBA: Why do you prefer IDEF1X? Is not it more comfortable to stick with tools, notations built-in into used client tools of RDBMS? Update: I just read What are some of your most useful database standards? . I am quite surprised - dozen of answers there and absolutely no

Preparation for std::iterator Being Deprecated

故事扮演 提交于 2019-11-27 00:30:28
On March 21 st the standards committee voted to approve the deprecation of std::iterator proposed in P0174 : The long sequence of void arguments is much less clear to the reader than simply providing the expected typedef s in the class definition itself, which is the approach taken by the current working draft, following the pattern set in c++14 Before c++17 inheritance from std::iterator was encouraged to remove the tedium from iterator boilerplate implementation. But the deprecation will require one of these things: An iterator boilerplate will now need to include all required typedef s

C++11 and the lack of polymorphic lambdas - why?

℡╲_俬逩灬. 提交于 2019-11-27 00:21:18
问题 I've been reviewing the draft version of the C++11 standard. Specifically the section on lambdas, and I am confused as to the reasoning for not introducing polymorphic lambdas. For example, amongst the 100001 ways polymorphic lambdas could be used, I had hoped we could use code such as the following: template<typename Container> void foo(Container c) { for_each(c.begin(), c.end(), [](T& t) { ++t; }); } What were the reasons: Was it that the committee ran out of time? That polymorphic lambdas

When to use ellipsis after menu items

旧城冷巷雨未停 提交于 2019-11-27 00:13:36
问题 In pretty much all applications that have a menu bar, some of the items have an ellipsis (...) after them, and some don't. Is there a well known convention on when to put that ellipsis there and when not to? When do you do it? Do you do it? I have looked at various windows applications, and this is what I have come to: Ellipsis Menu items which opens a form that require user input to do something (Replace, Go to, Font) No ellipsis Menu items which just does something (Cut, Paste, Exit, Save)