Is it possible to use function output in declaration of another function in C++

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
7
down vote

favorite












I want something like this:



std::tuple<int, bool, double> MyFunction_1 (void);

void MyFunction_2 (decltype (MyFunction_1) &params);


Obviously in this example code pointer to function would be passed



What I want is to have equivalent of this:



void MyFunction_2 (std::tuple<int, bool, double> &params);


Is it possible to do so?










share|improve this question



























    up vote
    7
    down vote

    favorite












    I want something like this:



    std::tuple<int, bool, double> MyFunction_1 (void);

    void MyFunction_2 (decltype (MyFunction_1) &params);


    Obviously in this example code pointer to function would be passed



    What I want is to have equivalent of this:



    void MyFunction_2 (std::tuple<int, bool, double> &params);


    Is it possible to do so?










    share|improve this question

























      up vote
      7
      down vote

      favorite









      up vote
      7
      down vote

      favorite











      I want something like this:



      std::tuple<int, bool, double> MyFunction_1 (void);

      void MyFunction_2 (decltype (MyFunction_1) &params);


      Obviously in this example code pointer to function would be passed



      What I want is to have equivalent of this:



      void MyFunction_2 (std::tuple<int, bool, double> &params);


      Is it possible to do so?










      share|improve this question















      I want something like this:



      std::tuple<int, bool, double> MyFunction_1 (void);

      void MyFunction_2 (decltype (MyFunction_1) &params);


      Obviously in this example code pointer to function would be passed



      What I want is to have equivalent of this:



      void MyFunction_2 (std::tuple<int, bool, double> &params);


      Is it possible to do so?







      c++ c++11 decltype






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 24 mins ago









      songyuanyao

      86k9163224




      86k9163224










      asked 37 mins ago









      Dmitrii Motorygin

      555




      555






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          9
          down vote













          decltype (MyFunction_1) will give the type of MyFunction_1 (i.e. the function type std::tuple<int, bool, double> ()), you need to emulate a function calling 1 (via adding ()) to get the return type (i.e. std::tuple<int, bool, double>), e.g.



          void MyFunction_2 (decltype (MyFunction_1()) &params);
          // ^^



          1 The expression is evaluated at compile-time, the function won't be called at run-time.






          share|improve this answer


















          • 1




            Because....? FGITWing is nice and all, but an answer should explain to the OP and future readers why adding two characters solves the problem here.
            – StoryTeller
            24 mins ago






          • 1




            Would "you need to emulate a function call in the decltype()" be a better wording? :P
            – Rerito
            13 mins ago










          • Another approach (maybe more straightforward): std::result_of
            – Ptaq666
            10 mins ago






          • 2




            Thanks for the help!
            – Dmitrii Motorygin
            3 mins ago

















          up vote
          6
          down vote













          The type of MyFunction_1 is not std::tuple<int, bool, double> - informally you can think of it as a function pointer. In fact &MyFunction_1 decays to itself and is certainly a pointer.



          So decltype(MyFunction_1) is not what you want.



          The solution is to write decltype(MyFunction_1()). The type of MyFunction_1() is std::tuple<int, bool, double>. Note that this doesn't actually call the function; it's rather like sizeof in that respect.






          share|improve this answer
















          • 1




            Thanks for the help!
            – Dmitrii Motorygin
            3 mins 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',
          convertImagesToLinks: true,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          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%2f52811378%2fis-it-possible-to-use-function-output-in-declaration-of-another-function-in-c%23new-answer', 'question_page');

          );

          Post as a guest






























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          9
          down vote













          decltype (MyFunction_1) will give the type of MyFunction_1 (i.e. the function type std::tuple<int, bool, double> ()), you need to emulate a function calling 1 (via adding ()) to get the return type (i.e. std::tuple<int, bool, double>), e.g.



          void MyFunction_2 (decltype (MyFunction_1()) &params);
          // ^^



          1 The expression is evaluated at compile-time, the function won't be called at run-time.






          share|improve this answer


















          • 1




            Because....? FGITWing is nice and all, but an answer should explain to the OP and future readers why adding two characters solves the problem here.
            – StoryTeller
            24 mins ago






          • 1




            Would "you need to emulate a function call in the decltype()" be a better wording? :P
            – Rerito
            13 mins ago










          • Another approach (maybe more straightforward): std::result_of
            – Ptaq666
            10 mins ago






          • 2




            Thanks for the help!
            – Dmitrii Motorygin
            3 mins ago














          up vote
          9
          down vote













          decltype (MyFunction_1) will give the type of MyFunction_1 (i.e. the function type std::tuple<int, bool, double> ()), you need to emulate a function calling 1 (via adding ()) to get the return type (i.e. std::tuple<int, bool, double>), e.g.



          void MyFunction_2 (decltype (MyFunction_1()) &params);
          // ^^



          1 The expression is evaluated at compile-time, the function won't be called at run-time.






          share|improve this answer


















          • 1




            Because....? FGITWing is nice and all, but an answer should explain to the OP and future readers why adding two characters solves the problem here.
            – StoryTeller
            24 mins ago






          • 1




            Would "you need to emulate a function call in the decltype()" be a better wording? :P
            – Rerito
            13 mins ago










          • Another approach (maybe more straightforward): std::result_of
            – Ptaq666
            10 mins ago






          • 2




            Thanks for the help!
            – Dmitrii Motorygin
            3 mins ago












          up vote
          9
          down vote










          up vote
          9
          down vote









          decltype (MyFunction_1) will give the type of MyFunction_1 (i.e. the function type std::tuple<int, bool, double> ()), you need to emulate a function calling 1 (via adding ()) to get the return type (i.e. std::tuple<int, bool, double>), e.g.



          void MyFunction_2 (decltype (MyFunction_1()) &params);
          // ^^



          1 The expression is evaluated at compile-time, the function won't be called at run-time.






          share|improve this answer














          decltype (MyFunction_1) will give the type of MyFunction_1 (i.e. the function type std::tuple<int, bool, double> ()), you need to emulate a function calling 1 (via adding ()) to get the return type (i.e. std::tuple<int, bool, double>), e.g.



          void MyFunction_2 (decltype (MyFunction_1()) &params);
          // ^^



          1 The expression is evaluated at compile-time, the function won't be called at run-time.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 4 mins ago

























          answered 35 mins ago









          songyuanyao

          86k9163224




          86k9163224







          • 1




            Because....? FGITWing is nice and all, but an answer should explain to the OP and future readers why adding two characters solves the problem here.
            – StoryTeller
            24 mins ago






          • 1




            Would "you need to emulate a function call in the decltype()" be a better wording? :P
            – Rerito
            13 mins ago










          • Another approach (maybe more straightforward): std::result_of
            – Ptaq666
            10 mins ago






          • 2




            Thanks for the help!
            – Dmitrii Motorygin
            3 mins ago












          • 1




            Because....? FGITWing is nice and all, but an answer should explain to the OP and future readers why adding two characters solves the problem here.
            – StoryTeller
            24 mins ago






          • 1




            Would "you need to emulate a function call in the decltype()" be a better wording? :P
            – Rerito
            13 mins ago










          • Another approach (maybe more straightforward): std::result_of
            – Ptaq666
            10 mins ago






          • 2




            Thanks for the help!
            – Dmitrii Motorygin
            3 mins ago







          1




          1




          Because....? FGITWing is nice and all, but an answer should explain to the OP and future readers why adding two characters solves the problem here.
          – StoryTeller
          24 mins ago




          Because....? FGITWing is nice and all, but an answer should explain to the OP and future readers why adding two characters solves the problem here.
          – StoryTeller
          24 mins ago




          1




          1




          Would "you need to emulate a function call in the decltype()" be a better wording? :P
          – Rerito
          13 mins ago




          Would "you need to emulate a function call in the decltype()" be a better wording? :P
          – Rerito
          13 mins ago












          Another approach (maybe more straightforward): std::result_of
          – Ptaq666
          10 mins ago




          Another approach (maybe more straightforward): std::result_of
          – Ptaq666
          10 mins ago




          2




          2




          Thanks for the help!
          – Dmitrii Motorygin
          3 mins ago




          Thanks for the help!
          – Dmitrii Motorygin
          3 mins ago












          up vote
          6
          down vote













          The type of MyFunction_1 is not std::tuple<int, bool, double> - informally you can think of it as a function pointer. In fact &MyFunction_1 decays to itself and is certainly a pointer.



          So decltype(MyFunction_1) is not what you want.



          The solution is to write decltype(MyFunction_1()). The type of MyFunction_1() is std::tuple<int, bool, double>. Note that this doesn't actually call the function; it's rather like sizeof in that respect.






          share|improve this answer
















          • 1




            Thanks for the help!
            – Dmitrii Motorygin
            3 mins ago














          up vote
          6
          down vote













          The type of MyFunction_1 is not std::tuple<int, bool, double> - informally you can think of it as a function pointer. In fact &MyFunction_1 decays to itself and is certainly a pointer.



          So decltype(MyFunction_1) is not what you want.



          The solution is to write decltype(MyFunction_1()). The type of MyFunction_1() is std::tuple<int, bool, double>. Note that this doesn't actually call the function; it's rather like sizeof in that respect.






          share|improve this answer
















          • 1




            Thanks for the help!
            – Dmitrii Motorygin
            3 mins ago












          up vote
          6
          down vote










          up vote
          6
          down vote









          The type of MyFunction_1 is not std::tuple<int, bool, double> - informally you can think of it as a function pointer. In fact &MyFunction_1 decays to itself and is certainly a pointer.



          So decltype(MyFunction_1) is not what you want.



          The solution is to write decltype(MyFunction_1()). The type of MyFunction_1() is std::tuple<int, bool, double>. Note that this doesn't actually call the function; it's rather like sizeof in that respect.






          share|improve this answer












          The type of MyFunction_1 is not std::tuple<int, bool, double> - informally you can think of it as a function pointer. In fact &MyFunction_1 decays to itself and is certainly a pointer.



          So decltype(MyFunction_1) is not what you want.



          The solution is to write decltype(MyFunction_1()). The type of MyFunction_1() is std::tuple<int, bool, double>. Note that this doesn't actually call the function; it's rather like sizeof in that respect.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 17 mins ago









          Bathsheba

          170k26239360




          170k26239360







          • 1




            Thanks for the help!
            – Dmitrii Motorygin
            3 mins ago












          • 1




            Thanks for the help!
            – Dmitrii Motorygin
            3 mins ago







          1




          1




          Thanks for the help!
          – Dmitrii Motorygin
          3 mins ago




          Thanks for the help!
          – Dmitrii Motorygin
          3 mins ago

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52811378%2fis-it-possible-to-use-function-output-in-declaration-of-another-function-in-c%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          List of Gilmore Girls characters

          One-line joke