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

QbProg • 1 year ago

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

fenbf • 1 year 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! :)

fox123 • 5 months ago

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

Eugene Radchenko • 12 months ago

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

fenbf • 1 year ago

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

brianN2 • 1 year 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 • 1 year 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 • 1 year 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.

QbProg • 1 year ago

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

Adam Weingarten • 4 months 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