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 )
Is "cool" appropriate or offensive to use in IMs?
Parallel fifths in the orchestra
Which European Languages are not Indo-European?
Convert Byte array into collection of items of different types
Is the Unsullied name meant to be ironic? How did it come to be?
Why does the hash of infinity have the digits of π?
Do I need full recovery mode when I have multiple daily backup?
Website returning plaintext password
Where have Brexit voters gone?
Does this strict reading of the rules allow both Extra Attack and the Thirsting Blade warlock invocation to be used together?
Why does this if-statement combining assignment and an equality check return true?
bash regexp matching fails in [[ ]]
What happened to boiled-off gases from the storage tanks at Launch Complex 39?
NIntegrate doesn't evaluate
How did NASA Langley end up with the first 737?
Can my floppy disk still work without a shutter spring?
How to politely tell someone they did not hit "reply to all" in an email?
Find the three digit Prime number P from the given unusual relationships
Is it truly impossible to tell what a CPU is doing?
How to let other coworkers know that I don't share my coworker's political views?
How to cut a climbing rope?
Why are GND pads often only connected by four traces?
Is Jon Snow the last of his House?
How to reverse input order?
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
109k16229293
109k16229293
asked May 11 at 17:10
BrunoBruno
14315
14315
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
109k16229293
109k16229293
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