rationale

What exactly was the rationale behind introducing references in c++?

回眸只為那壹抹淺笑 提交于 2019-12-18 18:24:34
问题 From the discussion that has happened in my recent question (Why is a c++ reference considered safer than a pointer?), it raises another question in my mind: What exactly was the rationale behind introducing references in c++? 回答1: Section 3.7 of Stroustrup's Design and Evolution of C++ describes the introduction of references into the language. If you're interested in the rationale behind any feature of C++, I highly recommend this book. References were introduced primarily to support

What exactly was the rationale behind introducing references in c++?

最后都变了- 提交于 2019-12-18 18:24:20
问题 From the discussion that has happened in my recent question (Why is a c++ reference considered safer than a pointer?), it raises another question in my mind: What exactly was the rationale behind introducing references in c++? 回答1: Section 3.7 of Stroustrup's Design and Evolution of C++ describes the introduction of references into the language. If you're interested in the rationale behind any feature of C++, I highly recommend this book. References were introduced primarily to support

Does C++11 change the behavior of explicitly calling std::swap to ensure ADL-located swap's are found, like boost::swap?

时光总嘲笑我的痴心妄想 提交于 2019-12-17 09:38:34
问题 Background Consider for this question the following code: #include <utility> namespace ns { struct foo { foo() : i(0) {} int i; private: foo(const foo&); // not defined, foo& operator=(const foo&); // non-copyable }; void swap(foo& lhs, foo& rhs) { std::swap(lhs.i, rhs.i); } } template <typename T> void do_swap(T& lhs, T& rhs); // implementation to be determined int main() { ns::foo a, b; do_swap(a, b); } In C++03, this implementation of do_swap would be considered "broken": template

Java constructor is not so intuitive. Or perhaps it's not Java, it's C# that is not intuitive

做~自己de王妃 提交于 2019-12-12 10:39:53
问题 Given this Java code, this outputs 0 and 4 : class A{ A() { print(); } void print() { System.out.println("A"); } } class B extends A{ int i = Math.round(3.5f); public static void main(String[] args){ A a = new B(); a.print(); } void print() { System.out.println(i); } } And with this identical C# code, this outputs 4 and 4 using System; class A{ internal A() { print(); } virtual internal void print() { Console.WriteLine("A"); } } class B : A{ int i = (int) Math.Round(3.5f); public static void

Rationale behind enum access semantics in C++

我的未来我决定 提交于 2019-12-11 04:04:17
问题 Can someone shed some light on the semantics for accessing an enum defined in a class in C++? In particular, why are enum members accessed by the name of the class rather than the enum itself? Given that the enum is the container/scope, just as namespace and class are, why is accessing an element of the container treated differently when it's an enum than when it's a class ? Given namespace mynamespace { class myclass { public: enum myenum { enum1, enum2 }; int myint; }; } Why is the fully

Why does CakePHP use different plural/singular naming conventions?

ぐ巨炮叔叔 提交于 2019-12-06 03:49:36
问题 Can somebody perhaps explain here why on earth CakePHP has a convention of using plural names for db tables and controllers and singular for models? Why not always use singular terms, or always plural? For me it seems confusing to always have to think "now do I use plural or singular here?" (Or is there an easy way to remember??) And then you have the join-tables that use a combination of both! I assume there's a good reason somewhere, but just have not come across it. (I really hope it's not

Why is a template with deduced return type not overloadable with other versions of it?

爷,独闯天下 提交于 2019-12-04 17:39:32
问题 Why are the following two templates incompatible and can't be overloaded? #include <vector> template<typename T> auto f(T t) { return t.size(); } template<typename T> auto f(T t) { return t.foobar(); } int main() { f(std::vector<int>()); } I would think they are (more or less) equivalent with the following which compiles fine (as we cannot do decltype auto(t.size()) I can't give an exact equivalent without some noise..). template<typename T> auto f(T t) -> decltype(t.size() /* plus some decay

Is there a specific reason nested namespace declarations are not allowed in C++?

我的未来我决定 提交于 2019-12-04 16:24:17
问题 The standard does not allow code like this: namespace Hello::World { //Things that are in namespace Hello::World } and instead requires namespace Hello { namespace World { //Things that are in namespace Hello::World }} What is the rationale? Was this simply not thought of at the time, or is there a specific reason it is not included? It seems that the first syntax more directly expresses in which namespace one is supposed to be, as the declaration mimics the actual use of the namespace in

Why does CakePHP use different plural/singular naming conventions?

六眼飞鱼酱① 提交于 2019-12-04 06:59:13
Can somebody perhaps explain here why on earth CakePHP has a convention of using plural names for db tables and controllers and singular for models? Why not always use singular terms, or always plural? For me it seems confusing to always have to think "now do I use plural or singular here?" (Or is there an easy way to remember??) And then you have the join-tables that use a combination of both! I assume there's a good reason somewhere, but just have not come across it. (I really hope it's not just because Ruby-on-Rails works that way.) Simon. CakePHP Conventions CakePHP’s conventions have been

Why is it ill-formed to have multi-line constexpr functions?

心已入冬 提交于 2019-12-03 22:13:20
According to Generalized Constant Expressions—Revision 5 the following is illegal. constexpr int g(int n) // error: body not just ‘‘return expr’’ { int r = n; while (--n > 1) r *= n; return r; } This is because all 'constexpr' functions are required to be of the form { return expression; } . I can't see any reason that this needs to be so. In my mind, the only thing that would really be necessary is that no external state information is read/written and the parameters being passed in are also 'constexpr' statements. This would mean that any call to the function with the same parameters would