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 )

Does Lawful Interception of 4G / the proposed 5G provide a back door for hackers as well?

Why in a Ethernet LAN, a packet sniffer can obtain all packets sent over the LAN?

List software from restricted, multiverse separately

On studying Computer Science vs. Software Engineering to become a proficient coder

Why was the Ancient One so hesitant to teach Dr. Strange the art of sorcery?

Meaning of「〜てみたいと思います」

When a land becomes a creature, is it untapped?

Speculative Biology of a Haplodiploid Humanoid Species

Why is this int array not passed as an object vararg array?

tikz: not so precise graphic

Two researchers want to work on the same extension to my paper. Who to help?

How are one-time password generators like Google Authenticator different from having two passwords?

Exception propagation: When should I catch exceptions?

How to pronounce "r" after a "g"?

What does i386 mean on macOS Mojave?

Find the cipher used

Can the sorting of a list be verified without comparing neighbors?

Would an 8% reduction in drag outweigh the weight addition from this custom CFD-tested winglet?

How to use structured binding in an array passed as arg to some function?

Was this character’s old age look CGI or make-up?

How to cope with regret and shame about not fully utilizing opportunities during PhD?

Can 'sudo apt-get remove [write]' destroy my Ubuntu?

What to do if SUS scores contradict qualitative feedback?

iMac 27" 2017 memory upgrade question



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;








8















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]?










share|improve this question
























  • Don't do using namespace std;.

    – Williham Totland
    1 hour ago


















8















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]?










share|improve this question
























  • Don't do using namespace std;.

    – Williham Totland
    1 hour ago














8












8








8


1






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]?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 3 hours ago









StoryTeller

108k16227290




108k16227290










asked 4 hours ago









BrunoBruno

14414




14414












  • Don't do using namespace std;.

    – Williham Totland
    1 hour ago


















  • Don't do using namespace std;.

    – Williham Totland
    1 hour ago

















Don't do using namespace std;.

– Williham Totland
1 hour ago






Don't do using namespace std;.

– Williham Totland
1 hour ago













1 Answer
1






active

oldest

votes


















8














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.






share|improve this answer


















  • 1





    Thanks!! I got it :)

    – Bruno
    3 hours ago











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
);



);













draft saved

draft discarded


















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









8














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.






share|improve this answer


















  • 1





    Thanks!! I got it :)

    – Bruno
    3 hours ago















8














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.






share|improve this answer


















  • 1





    Thanks!! I got it :)

    – Bruno
    3 hours ago













8












8








8







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










answered 4 hours ago









StoryTellerStoryTeller

108k16227290




108k16227290







  • 1





    Thanks!! I got it :)

    – Bruno
    3 hours ago












  • 1





    Thanks!! I got it :)

    – Bruno
    3 hours ago







1




1





Thanks!! I got it :)

– Bruno
3 hours ago





Thanks!! I got it :)

– Bruno
3 hours ago



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Siegen Nawigatsjuun

Log på Navigationsmenu

Log på Navigationsmenu