Is it possible to use function output in declaration of another function in C++
Clash 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) ¶ms);
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> ¶ms);
Is it possible to do so?
c++ c++11 decltype
add a comment |Â
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) ¶ms);
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> ¶ms);
Is it possible to do so?
c++ c++11 decltype
add a comment |Â
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) ¶ms);
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> ¶ms);
Is it possible to do so?
c++ c++11 decltype
I want something like this:
std::tuple<int, bool, double> MyFunction_1 (void);
void MyFunction_2 (decltype (MyFunction_1) ¶ms);
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> ¶ms);
Is it possible to do so?
c++ c++11 decltype
c++ c++11 decltype
edited 24 mins ago
songyuanyao
86k9163224
86k9163224
asked 37 mins ago
Dmitrii Motorygin
555
555
add a comment |Â
add a comment |Â
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()) ¶ms);
// ^^
1 The expression is evaluated at compile-time, the function won't be called at run-time.
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 thedecltype()
" 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
add a comment |Â
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.
1
Thanks for the help!
– Dmitrii Motorygin
3 mins ago
add a comment |Â
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()) ¶ms);
// ^^
1 The expression is evaluated at compile-time, the function won't be called at run-time.
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 thedecltype()
" 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
add a comment |Â
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()) ¶ms);
// ^^
1 The expression is evaluated at compile-time, the function won't be called at run-time.
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 thedecltype()
" 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
add a comment |Â
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()) ¶ms);
// ^^
1 The expression is evaluated at compile-time, the function won't be called at run-time.
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()) ¶ms);
// ^^
1 The expression is evaluated at compile-time, the function won't be called at run-time.
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 thedecltype()
" 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
add a comment |Â
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 thedecltype()
" 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
add a comment |Â
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.
1
Thanks for the help!
– Dmitrii Motorygin
3 mins ago
add a comment |Â
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.
1
Thanks for the help!
– Dmitrii Motorygin
3 mins ago
add a comment |Â
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.
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.
answered 17 mins ago


Bathsheba
170k26239360
170k26239360
1
Thanks for the help!
– Dmitrii Motorygin
3 mins ago
add a comment |Â
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
add a comment |Â
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
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
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
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
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