In JavaScript ES6, there is a language feature known as destructuring. It exists across many other languages as well.
In JavaScript ES6, it looks like this:
var animal = {
species: 'dog',
weight: 23,
sound: 'woof'
}
//Destructuring
var {species, sound} = animal
//The dog says woof!
console.log('The ' + species + ' says ' + sound + '!')
What can I do in C++ to get a similar syntax and emulate this kind of functionality?
structure
and overload its assignment operator accordingly, maybe you can achieve what you are aiming for. Not sure thought. But you could maybe research into that direction. – DissimilationC++
essentially already has this in the form ofusing
statements. The novel bit is the extension to allow import members of objects as well as members of namespaces. e.g. if someone saidusing animal.species;
was in c++1z, what do you think it would do? – Counteroffensiveusing
. It's a new variable declaration. – Hurley