We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

QbProg • 2 years ago

Indeed, for each point I was expecting a before /after example 😀 come on!

fenbf • 2 years ago

I did this for a few samples, I hoped that would be good enough :)
You can try it yourself and run/edit/compile code inside the post.
If you write more samples I'm happy to include them in the main article! :)

luke-guyton • 2 months ago

Hi, what is the purpose of forward<args>(args) in the print and folds example? I replaced it with just args and the example worked.

Paul J. Lucas • 10 months ago

Your fibonacci example doesn't need to be a template function.

Bojan Kverh • 3 months ago

None of the C++17 features is really necessary, everything could be done with C++03 as well.

Eugene Radchenko • 2 years ago

Are there any plans to do this for switch as well? Should make the tuple example even cleaner.

fenbf • 2 years ago

r/programming comments: https://www.reddit.com/r/pr...

brianN2 • 2 years ago

Overall its good - but would like to see the removal of the 'depreciation' of autoptr, not that its good (its not!)

But autoptr isrequired for backwards compatibility with older code, one of the big advantages of C++ and library is forwards compatibility. Yes it can be replaced by the new and better alternatives, but its still there in old tied and tested code that will no longer compile - sheer and utter vandalism by some C++ purist zealot to make a point.

Yes - We know autoptr its not perfect and it really shouldn't be used, just as we know raw pointers are a bad idea - but they are still there for good reasons - compatibility.

fenbf • 2 years ago

auto_ptr is removed, was deprecated in C++11 and now in C++17 it's removed: see http://www.bfilipek.com/201...

brianN2 • 2 years ago

Yes I know and that's what wrong!!!!!
It breaks backwards compatible with legacy code - most silly idea yet to come out of the ISO C++ committees!

A totally unnecessary risk to older C++ code out there, code that has proven itself reliable and good for years now has to be modified.
If the C++ ISO group responsible doesn't understand this, then they really do need to resign and get some real world experience for a while!

The issue is so serious that I know of a number of companies that are saying they are not going to use C++ 17 due to the cost and risk of modifying large amounts of legacy code (not to mention testing etc.).

Yes - crazy to miss out on the new features, but not as crazy as the people that screw up backwards compatibility for legacy code, and for no good reason other than being a C++ 17 purist (and that is not meant to be a complement!).
What next - ban native pointers (a lot bigger source of problems than auto_ptr!)

They could have at least left it in via a separate include file or similar that had to be explicitly defined/included, so it would not be going into new code.

VALERIU SMERICA • 1 year ago

Native pointers cannot be banned because of iterators and future Ranges specifications and memcpy, memmove, memset zoo. If you want to allocate on heap, then you use smart pointers for ownership. There are features that are questionable and sometimes get removed, but there are others that a good developer that knows his C++ should know they won't be removed since they are the best solution for some problem.

HolgerS • 2 years ago

"The issue is so serious that I know of a number of companies that are saying they are not going to use C++ 17 due to the cost and risk of modifying large amounts of legacy code (not to mention testing etc.)."
I can not follow this point. If you really still want to use auto_ptr, you can simply copy the auto_ptr implementation from your pre-C++-17 compiler (which is just a few lines of code), put it into a header file and include this file in your C++ 17 project. Not costly, not risky, no need to modify large amounts of legacy code, not much testing effort... And what etc.?

brianN2 • 2 years ago

That's still called modifying code instead of relying on the QA and testing of compiler and libraries
C++ gives users the ability to shoot themselves in the foot in so many ways (with great power comes great responsibility!) , so why prevent users who need to use the auto_ptr in legacy code.
The recent April Fools prank about removing raw pointers was unfortunately to close to the truth considering some of the self righteous idiots on the ISO committee!

HolgerS • 2 years ago

If you take the auto_ptr implementation of a decent major compiler and use this in your C++ 17 project, which kind of QA issues would you expect? auto_ptr is simple, out in the field for many years, used millions of times and has for sure undergone more QA checks than you can think of.

brianN2 • 1 year ago

That's the point, auto_ptr is QA and well tested so why remove it, even a copy and paste comes with a risk, so why do developers and users have to take a risk to satisfy some self centered ISO committee members already inflated ego.

QbProg • 2 years ago

Indeed I was expecting a before / after example! Come on blogger!

Adam Weingarten • 1 year ago

I tried this out on MS Visual Studio, and unless I misunderstood - C++17 seems FAR MORE LENIENT than described here:

//MyInlineVariablesTest.h

#pragma once

class MyInlineVariablesTest
{
public:
inline MyInlineVariablesTest() = default;
inline ~MyInlineVariablesTest() = default;
inline static int value1_i = 1;
inline static string value2_str = "value_2";
};

// My test function:
#include "MyInlineVariablesTest.h"
void test_InlineVariables(void) {
// Dunno: inline static variables seem FAR MORE FORGIVING/FLEXIBLE than what the article describes.
// I managed to get the entire class into a '.h' file, no accompanying '.cpp', and NO syntactic hassle.

MyInlineVariablesTest myInlineVariablesTest1;
MyInlineVariablesTest myInlineVariablesTest2;

// STATIC INT
cout << "(1) myInlineVariablesTest1.value1_i==" << myInlineVariablesTest1.value1_i <<
" myInlineVariablesTest2.value1_i==" << myInlineVariablesTest2.value1_i << endl;

myInlineVariablesTest1.value1_i = 99;
cout << "assigned 'myInlineVariablesTest1.value1_i = 99;', and now: ..." << endl;
cout << "(2) myInlineVariablesTest1.value1_i==" << myInlineVariablesTest1.value1_i <<
" myInlineVariablesTest2.value1_i==" << myInlineVariablesTest2.value1_i << endl;

MyInlineVariablesTest::value1_i = 100;
cout << "assigned 'MyInlineVariablesTest::value1_i = 100;', and now: ..." << endl;
cout << "(3) myInlineVariablesTest1.value1_i==" << myInlineVariablesTest1.value1_i <<
" myInlineVariablesTest2.value1_i==" << myInlineVariablesTest2.value1_i << endl;

// STATIC STRING
cout << "(1.1) myInlineVariablesTest1.value2_str.c_str()==" << myInlineVariablesTest1.value2_str.c_str() <<
" myInlineVariablesTest2.value2_str.c_str()==" << myInlineVariablesTest2.value2_str.c_str() << endl;

myInlineVariablesTest1.value2_str = "value2_mod1";
cout << "assigned 'myInlineVariablesTest1.value2_str = \"value2_mod1\";', and now: ..." << endl;
cout << "(2.1) myInlineVariablesTest1.value2_str.c_str()==" << myInlineVariablesTest1.value2_str.c_str() <<
" myInlineVariablesTest2.value2_str.c_str()==" << myInlineVariablesTest2.value2_str.c_str() << endl;

MyInlineVariablesTest::value2_str = "value2_mod2";
cout << "assigned 'MyInlineVariablesTest::value2_str = \"value2_mod2\";', and now: ..." << endl;
cout << "(3.1) myInlineVariablesTest1.value2_str.c_str()==" << myInlineVariablesTest1.value2_str.c_str() <<
" myInlineVariablesTest2.value2_str.c_str()==" << myInlineVariablesTest2.value2_str.c_str() << endl;
}

MY OUTPUT:

(1) myInlineVariablesTest1.value1_i==1 myInlineVariablesTest2.value1_i==1
assigned 'myInlineVariablesTest1.value1_i = 99;', and now: ...
(2) myInlineVariablesTest1.value1_i==99 myInlineVariablesTest2.value1_i==99
assigned 'MyInlineVariablesTest::value1_i = 100;', and now: ...
(3) myInlineVariablesTest1.value1_i==100 myInlineVariablesTest2.value1_i==100
(1.1) myInlineVariablesTest1.value2_str.c_str()==value_2 myInlineVariablesTest2.
value2_str.c_str()==value_2
assigned 'myInlineVariablesTest1.value2_str = "value2_mod1";', and now: ...
(2.1) myInlineVariablesTest1.value2_str.c_str()==value2_mod1 myInlineVariablesTe
st2.value2_str.c_str()==value2_mod1
assigned 'MyInlineVariablesTest::value2_str = "value2_mod2";', and now: ...
(3.1) myInlineVariablesTest1.value2_str.c_str()==value2_mod2 myInlineVariablesTe
st2.value2_str.c_str()==value2_mod2

fox123 • 1 year ago

I think the for (auto &p : itemsToAdd) is better by: for (const auto &p : itemsToAdd)