How to use structured binding in an array passed as arg to some function?Using std NamespaceIs there a max array length limit in C++?Autocompletion in VimFunction passed as template argumentWhat is the copy-and-swap idiom?How do I use arrays in C++?Image Processing: Algorithm Improvement for 'Coca-Cola Can' Recognitionc++ passing Pointers into a function, for passing int arrays out of and into a functionReplacing a 32-bit loop counter with 64-bit introduces crazy performance deviationspassing character arrays to a functionStructure Binding : binding to public data members (inherited base class )
Rushed passport - does my reason qualify?
Square spiral in Mathematica
Can a person still be an Orthodox Jew and believe that the Torah contains narratives that are not scientifically correct?
What are the effects of eating many berries from the Goodberry spell per day?
How come Arya Stark didn't burn in Game of Thrones Season 8 Episode 5
Given 0s on Assignments with suspected and dismissed cheating?
Why does the U.S military use mercenaries?
Canadian citizen who is presently in litigation with a US-based company
Why does string strummed with finger sound different from the one strummed with pick?
Pedaling at different gear ratios on flat terrain: what's the point?
Can I pay my credit card?
How to handle professionally if colleagues has referred his relative and asking to take easy while taking interview
Why doesn't Iron Man's action affect this person in Endgame?
What color to choose as "danger" if the main color of my app is red
Why is so much ransomware breakable?
He is the first man to arrive here
How can we delete item permanently without storing in Recycle Bin?
Usage of the relative pronoun "dont"
Why would you put your input amplifier in front of your filtering for and ECG signal?
Does a non-singular matrix have a large minor with disjoint rows and columns and full rank?
How to continually and organically let my readers know what time it is in my story?
Why would company (decision makers) wait for someone to retire, rather than lay them off, when their role is no longer needed?
Capital gains on stocks sold to take initial investment off the table
How could it be that 80% of townspeople were farmers during the Edo period in Japan?
How to use structured binding in an array passed as arg to some function?
Using std NamespaceIs there a max array length limit in C++?Autocompletion in VimFunction passed as template argumentWhat is the copy-and-swap idiom?How do I use arrays in C++?Image Processing: Algorithm Improvement for 'Coca-Cola Can' Recognitionc++ passing Pointers into a function, for passing int arrays out of and into a functionReplacing a 32-bit loop counter with 64-bit introduces crazy performance deviationspassing character arrays to a functionStructure Binding : binding to public data members (inherited base class )
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm trying to decompose an array of 2 integers given to a function into x, y
It doesn't work when using int init[2]
as a parameter. But it does when I change it to int (&init)[2]
.
vector<vector<State>> Search(vector<vector<State>> board,
int init[2], int goal[2])
auto [x, y] = init;
What does (&init)
mean here? And why it doesn't work when using int init[2]
?
c++ c++17
add a comment |
I'm trying to decompose an array of 2 integers given to a function into x, y
It doesn't work when using int init[2]
as a parameter. But it does when I change it to int (&init)[2]
.
vector<vector<State>> Search(vector<vector<State>> board,
int init[2], int goal[2])
auto [x, y] = init;
What does (&init)
mean here? And why it doesn't work when using int init[2]
?
c++ c++17
Don't dousing namespace std;
.
– Williham Totland
May 11 at 19:50
add a comment |
I'm trying to decompose an array of 2 integers given to a function into x, y
It doesn't work when using int init[2]
as a parameter. But it does when I change it to int (&init)[2]
.
vector<vector<State>> Search(vector<vector<State>> board,
int init[2], int goal[2])
auto [x, y] = init;
What does (&init)
mean here? And why it doesn't work when using int init[2]
?
c++ c++17
I'm trying to decompose an array of 2 integers given to a function into x, y
It doesn't work when using int init[2]
as a parameter. But it does when I change it to int (&init)[2]
.
vector<vector<State>> Search(vector<vector<State>> board,
int init[2], int goal[2])
auto [x, y] = init;
What does (&init)
mean here? And why it doesn't work when using int init[2]
?
c++ c++17
c++ c++17
edited May 11 at 17:35
StoryTeller
108k16227290
108k16227290
asked May 11 at 17:10
BrunoBruno
14414
14414
Don't dousing namespace std;
.
– Williham Totland
May 11 at 19:50
add a comment |
Don't dousing namespace std;
.
– Williham Totland
May 11 at 19:50
Don't do
using namespace std;
.– Williham Totland
May 11 at 19:50
Don't do
using namespace std;
.– Williham Totland
May 11 at 19:50
add a comment |
1 Answer
1
active
oldest
votes
int (&init)[2]
is a reference to an array of two integers. int init[2]
as a function parameter is a leftover from C++'s C heritage. It doesn't declare the function as taking an array. The type of the parameter is adjusted to int*
and all size information for an array being passed into the function is lost.
A function taking int init[2]
can be called with an array of any size, on account of actually taking a pointer. It may even be passed nullptr
. While a function taking int(&)[2]
may only be given a valid array of two as an argument.
Since in the working version init
refers to a int[2]
object, structured bindings can work with that array object. But a decayed pointer cannot be the subject of structured bindings, because the static type information available only gives access to a single element being pointed at.
1
Thanks!! I got it :)
– Bruno
May 11 at 17:25
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56092567%2fhow-to-use-structured-binding-in-an-array-passed-as-arg-to-some-function%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
int (&init)[2]
is a reference to an array of two integers. int init[2]
as a function parameter is a leftover from C++'s C heritage. It doesn't declare the function as taking an array. The type of the parameter is adjusted to int*
and all size information for an array being passed into the function is lost.
A function taking int init[2]
can be called with an array of any size, on account of actually taking a pointer. It may even be passed nullptr
. While a function taking int(&)[2]
may only be given a valid array of two as an argument.
Since in the working version init
refers to a int[2]
object, structured bindings can work with that array object. But a decayed pointer cannot be the subject of structured bindings, because the static type information available only gives access to a single element being pointed at.
1
Thanks!! I got it :)
– Bruno
May 11 at 17:25
add a comment |
int (&init)[2]
is a reference to an array of two integers. int init[2]
as a function parameter is a leftover from C++'s C heritage. It doesn't declare the function as taking an array. The type of the parameter is adjusted to int*
and all size information for an array being passed into the function is lost.
A function taking int init[2]
can be called with an array of any size, on account of actually taking a pointer. It may even be passed nullptr
. While a function taking int(&)[2]
may only be given a valid array of two as an argument.
Since in the working version init
refers to a int[2]
object, structured bindings can work with that array object. But a decayed pointer cannot be the subject of structured bindings, because the static type information available only gives access to a single element being pointed at.
1
Thanks!! I got it :)
– Bruno
May 11 at 17:25
add a comment |
int (&init)[2]
is a reference to an array of two integers. int init[2]
as a function parameter is a leftover from C++'s C heritage. It doesn't declare the function as taking an array. The type of the parameter is adjusted to int*
and all size information for an array being passed into the function is lost.
A function taking int init[2]
can be called with an array of any size, on account of actually taking a pointer. It may even be passed nullptr
. While a function taking int(&)[2]
may only be given a valid array of two as an argument.
Since in the working version init
refers to a int[2]
object, structured bindings can work with that array object. But a decayed pointer cannot be the subject of structured bindings, because the static type information available only gives access to a single element being pointed at.
int (&init)[2]
is a reference to an array of two integers. int init[2]
as a function parameter is a leftover from C++'s C heritage. It doesn't declare the function as taking an array. The type of the parameter is adjusted to int*
and all size information for an array being passed into the function is lost.
A function taking int init[2]
can be called with an array of any size, on account of actually taking a pointer. It may even be passed nullptr
. While a function taking int(&)[2]
may only be given a valid array of two as an argument.
Since in the working version init
refers to a int[2]
object, structured bindings can work with that array object. But a decayed pointer cannot be the subject of structured bindings, because the static type information available only gives access to a single element being pointed at.
answered May 11 at 17:16
StoryTellerStoryTeller
108k16227290
108k16227290
1
Thanks!! I got it :)
– Bruno
May 11 at 17:25
add a comment |
1
Thanks!! I got it :)
– Bruno
May 11 at 17:25
1
1
Thanks!! I got it :)
– Bruno
May 11 at 17:25
Thanks!! I got it :)
– Bruno
May 11 at 17:25
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56092567%2fhow-to-use-structured-binding-in-an-array-passed-as-arg-to-some-function%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Don't do
using namespace std;
.– Williham Totland
May 11 at 19:50