c++-standard-library

Why is operator!= removed in C++20 for many standard library types?

折月煮酒 提交于 2020-03-13 03:50:42
问题 According to cppreference, std::type_info::operator!= gets removed with C++20, however, std::type_info::operator== apparently remains. What's the reasoning behind? I might agree on comparing for inequality being meaningless, but then comparing for equality would be just as meaningless as well, wouldn't it? Similarly, operator!= of many other standard library types, including containers such as std::unordered_map::operator!= and std::unordered_set::operator!= will be removed in C++20 according

Why is operator!= removed in C++20 for many standard library types?

僤鯓⒐⒋嵵緔 提交于 2020-03-13 03:49:54
问题 According to cppreference, std::type_info::operator!= gets removed with C++20, however, std::type_info::operator== apparently remains. What's the reasoning behind? I might agree on comparing for inequality being meaningless, but then comparing for equality would be just as meaningless as well, wouldn't it? Similarly, operator!= of many other standard library types, including containers such as std::unordered_map::operator!= and std::unordered_set::operator!= will be removed in C++20 according

Why is operator!= removed in C++20 for many standard library types?

偶尔善良 提交于 2020-03-13 03:48:49
问题 According to cppreference, std::type_info::operator!= gets removed with C++20, however, std::type_info::operator== apparently remains. What's the reasoning behind? I might agree on comparing for inequality being meaningless, but then comparing for equality would be just as meaningless as well, wouldn't it? Similarly, operator!= of many other standard library types, including containers such as std::unordered_map::operator!= and std::unordered_set::operator!= will be removed in C++20 according

Why do people seem to insinuate I would rather not use Boost? [closed]

旧街凉风 提交于 2020-02-01 00:34:06
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . Very often here on SO I see notes about boost such as If you are fine with using Boost... or If you can use Boost... And I wonder, what's that all about? What should I be weary of? When can't I use boost? What are the reasons not to use boost? In my opinion boost is a great

Why does cout.precision() affect the whole stream?

时光怂恿深爱的人放手 提交于 2020-01-24 16:33:45
问题 I feel I'm asking a very basic question, but I haven't been able to find an answer here or in Google. I recall we were taught this at school, but alas it has vanished over years. Why does cout.precision() ( std::ios_base::precision() ) affect the whole stream when called in the middle of the output list? I know the rule that std::setprecision() should be used to change precision on the fly, and that cout.precision() is going to spoil the output with the value it returns. But what is the

How to portably compare std::system_error exceptions to std::errc values?

↘锁芯ラ 提交于 2020-01-24 08:41:52
问题 As far as I've understood, one of the best practices to check system_error conditions in a portable manner is to compare their code() value with values in the std::errc enumeration. However, when I try to run the following code, this does not seem to work. #include <cassert> #include <cerrno> #include <system_error> int main() { try { throw std::system_error(ENOENT, std::system_category()); } catch (std::system_error const & e) { assert(e.code() == std::errc::no_such_file_or_directory); // <-

Setting a std::function variable to refer to the std::sin function

こ雲淡風輕ζ 提交于 2020-01-22 19:38:29
问题 I've got a question about how to properly use the new C++11 std::function variable. I've seen several examples from searching the Internet, but they don't seem to cover the usage case I'm considering. Take this minimum example, where the function fdiff is an implementation of the finite forward differencing algorithm defined in numerical.hxx (which isn't the problem, I just wanted to give a contextual reason why I'd want to take an arbitrary function and pass it around). #include <functional>

Why operator void*() conversion function added to the C++ stream classes?

此生再无相见时 提交于 2020-01-22 17:30:29
问题 There is a conversion function operator void*() const in C++ stream classes. so that all stream objects can be implicitly converted to void* . During the interaction with programmers on SO they suggest me to don't use void* unless you've a good reason to use it. void* is a technique of removing type safety & error checking. So, due to the existance of this conversion function following program is perfectly valid. This is a flaw in the C++ standard library. #include <iostream> int main() {

Visual C++ 10.0 bug in std::reference_wrapper?

て烟熏妆下的殇ゞ 提交于 2020-01-21 06:20:07
问题 Code: #include <functional> struct Foo { virtual void mf() = 0; }; struct Bar: Foo { virtual void mf() {} }; int main() { Bar o; std::reference_wrapper<Foo const> wrapper( o ); } Result with MinGW g++ 4.6.1: [d:\dev\test] > g++ foo.cpp -std=c++0x [d:\dev\test] > _ Result with Visual C++ 10.0: [d:\dev\test] > cl foo.cpp foo.cpp C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xxcallwrap(8) : error C2259: 'Foo' : cannot instantiate abstract class due to following members: 'void

Parameter induction with std::variant

ⅰ亾dé卋堺 提交于 2020-01-15 03:15:09
问题 Recenty I am working on an ORM which accepts registration of functions by doing the following: orm->register_func("NAME", &User::set_name); So basically when the database returns the column NAME , the ORM will use the function set_name in User . During the development I learned more about std::variant and here is a little example of how I use it: template<typename RET, typename T, typename ...Args> using FPTR = RET(T::*)(Args...); template<typename T> using VARIANT_FPTR = std::variant<FPTR