rationale

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

假如想象 提交于 2019-11-27 08:35:44
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 <typename T> void do_swap(T& lhs, T& rhs) { std::swap(lhs, rhs); } By explicitly specifying std:: , it

C++: rationale behind hiding rule

假装没事ソ 提交于 2019-11-26 17:48:05
What's the rationale behind the hiding rule in C++? class A { void f(int); } class B : public A { void f(double); } // B::f(int) is hidden If it is a meaningful feature I think it should also be possible to hide functions without defining new functions with the same name: something like this: class B : public A { hide void f(double); } but this is not possible. I don't think it simplifies compilers job, since compilers must anyway be able to unhide functions when you explicitly use the using directive: class B : public A { using A::f; void f(double); } // B::f(int) NOT hidden So, how come

C++14 Variable Templates: what is their purpose? Any usage example?

馋奶兔 提交于 2019-11-26 09:27:46
问题 C++14 will allow the creation of variables that are templated. The usual example is a variable \'pi\' that can be read to get the value of the mathematical constant π for various types (3 for int ; the closest value possible with float , etc.) Besides that we can have this feature just by wrapping a variable within a templated struct or class, how does this mix with type conversions? I see some overlapping. And other than the pi example, how would it work with non-const variables? Any usage

C++: rationale behind hiding rule

此生再无相见时 提交于 2019-11-26 09:03:21
问题 What\'s the rationale behind the hiding rule in C++? class A { void f(int); } class B : public A { void f(double); } // B::f(int) is hidden If it is a meaningful feature I think it should also be possible to hide functions without defining new functions with the same name: something like this: class B : public A { hide void f(double); } but this is not possible. I don\'t think it simplifies compilers job, since compilers must anyway be able to unhide functions when you explicitly use the

What is the point of DBNull?

百般思念 提交于 2019-11-26 01:56:40
In .NET there is the null reference, which is used everywhere to denote that an object reference is empty, and then there is the DBNull , which is used by database drivers (and few others) to denote... pretty much the same thing. Naturally, this creates a lot of confusion and conversion routines have to be churned out, etc. So why did the original .NET authors decide to make this? To me it makes no sense. Their documentation makes no sense either: The DBNull class represents a nonexistent value. In a database, for example, a column in a row of a table might not contain any data whatsoever.

What is the point of DBNull?

我是研究僧i 提交于 2019-11-26 00:59:57
问题 In .NET there is the null reference, which is used everywhere to denote that an object reference is empty, and then there is the DBNull , which is used by database drivers (and few others) to denote... pretty much the same thing. Naturally, this creates a lot of confusion and conversion routines have to be churned out, etc. So why did the original .NET authors decide to make this? To me it makes no sense. Their documentation makes no sense either: The DBNull class represents a nonexistent