std::declval vs crtp, cannot deduce method return type from incomplete typeSpecial behavior for decltype of call operator for incomplete typesC++11 does not deduce type when std::function or lambda functions are involvedgcc 4.7 about Variadic Templates/ decltype /std::forwardstd::declval() firing assertion error with warnings in GCCInferring return type of templated member functions in CRTPWhy doesn't std::shared_ptr need to know complete type if it's constructed from non-null?Specialize function template with decltype trailing return typeCan you declare a member variable with decltype on an object function?Invalid use of incomplete type struct std::hash with unordered_map with std::pair of enum class as keymixing CRTP with SFINAEno type named “type” in “std::result_of” ; get return type from overloading functions
Is it possible to have 2 different but equal size real number sets that have the same mean and standard deviation?
Why was this person allowed to become Grand Maester?
Is it possible to have a wealthy country without a middle class?
What does 思ってやっている mean?
Origin of "boor"
Why am I Seeing A Weird "Notch" on the Data Line For Some Logical 1s?
What are some really overused phrases in French that are common nowadays?
What is the color of artificial intelligence?
Why are MBA programs closing?
Russian word for a male zebra
Excel division by 0 error when trying to average results of formulas
How to safely destroy (a large quantity of) valid checks?
Does putting salt first make it easier for attacker to bruteforce the hash?
Has there been a multiethnic Star Trek character?
Can the removal of a duty-free sales trolley result in a measurable reduction in emissions?
How do photos of the same subject compare between the Nikon D700 and D70?
Explain the ending of Black Mirror's "Smithereens"
Longest bridge/tunnel that can be cycled over/through?
Is it possible to fly backward if you have really strong headwind?
Are polynomials with the same roots identical?
color rows on table (Tabu package)
std::declval vs crtp, cannot deduce method return type from incomplete type
A word that means "blending into a community too much"
If I leave the US through an airport, do I have to return through the same airport?
std::declval vs crtp, cannot deduce method return type from incomplete type
Special behavior for decltype of call operator for incomplete typesC++11 does not deduce type when std::function or lambda functions are involvedgcc 4.7 about Variadic Templates/ decltype /std::forwardstd::declval() firing assertion error with warnings in GCCInferring return type of templated member functions in CRTPWhy doesn't std::shared_ptr need to know complete type if it's constructed from non-null?Specialize function template with decltype trailing return typeCan you declare a member variable with decltype on an object function?Invalid use of incomplete type struct std::hash with unordered_map with std::pair of enum class as keymixing CRTP with SFINAEno type named “type” in “std::result_of” ; get return type from overloading functions
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to do something like this (in c++11):
#include <utility>
template <typename T>
struct base
using type = decltype( std::declval<T>().foo() );
;
struct bar : base<bar>
int foo() return 42;
;
int main()
bar::type x;
which fails with
prog.cc: In instantiation of 'struct base<bar>':
prog.cc:8:14: required from here
prog.cc:5:46: error: invalid use of incomplete type 'struct bar'
using type = decltype( std::declval<T>().foo() );
~~~~~~~~~~~~~~~~~~^~~
prog.cc:8:8: note: forward declaration of 'struct bar'
struct bar : base<bar> {
^~~
How can I declare an alias to the return type of bar::foo
in base
? Is it not possible?
This question seems to be rather related: Special behavior for decltype of call operator for incomplete types, though I couldnt manage to apply the answer given there to my case.
c++ c++11 decltype crtp declval
add a comment |
I am trying to do something like this (in c++11):
#include <utility>
template <typename T>
struct base
using type = decltype( std::declval<T>().foo() );
;
struct bar : base<bar>
int foo() return 42;
;
int main()
bar::type x;
which fails with
prog.cc: In instantiation of 'struct base<bar>':
prog.cc:8:14: required from here
prog.cc:5:46: error: invalid use of incomplete type 'struct bar'
using type = decltype( std::declval<T>().foo() );
~~~~~~~~~~~~~~~~~~^~~
prog.cc:8:8: note: forward declaration of 'struct bar'
struct bar : base<bar> {
^~~
How can I declare an alias to the return type of bar::foo
in base
? Is it not possible?
This question seems to be rather related: Special behavior for decltype of call operator for incomplete types, though I couldnt manage to apply the answer given there to my case.
c++ c++11 decltype crtp declval
add a comment |
I am trying to do something like this (in c++11):
#include <utility>
template <typename T>
struct base
using type = decltype( std::declval<T>().foo() );
;
struct bar : base<bar>
int foo() return 42;
;
int main()
bar::type x;
which fails with
prog.cc: In instantiation of 'struct base<bar>':
prog.cc:8:14: required from here
prog.cc:5:46: error: invalid use of incomplete type 'struct bar'
using type = decltype( std::declval<T>().foo() );
~~~~~~~~~~~~~~~~~~^~~
prog.cc:8:8: note: forward declaration of 'struct bar'
struct bar : base<bar> {
^~~
How can I declare an alias to the return type of bar::foo
in base
? Is it not possible?
This question seems to be rather related: Special behavior for decltype of call operator for incomplete types, though I couldnt manage to apply the answer given there to my case.
c++ c++11 decltype crtp declval
I am trying to do something like this (in c++11):
#include <utility>
template <typename T>
struct base
using type = decltype( std::declval<T>().foo() );
;
struct bar : base<bar>
int foo() return 42;
;
int main()
bar::type x;
which fails with
prog.cc: In instantiation of 'struct base<bar>':
prog.cc:8:14: required from here
prog.cc:5:46: error: invalid use of incomplete type 'struct bar'
using type = decltype( std::declval<T>().foo() );
~~~~~~~~~~~~~~~~~~^~~
prog.cc:8:8: note: forward declaration of 'struct bar'
struct bar : base<bar> {
^~~
How can I declare an alias to the return type of bar::foo
in base
? Is it not possible?
This question seems to be rather related: Special behavior for decltype of call operator for incomplete types, though I couldnt manage to apply the answer given there to my case.
c++ c++11 decltype crtp declval
c++ c++11 decltype crtp declval
edited 5 hours ago
formerlyknownas_463035818
asked 8 hours ago
formerlyknownas_463035818formerlyknownas_463035818
21.4k43075
21.4k43075
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can make type
a template type alias, so that users can instantiate it after the definition of bar
is available. This will change the final syntax from bar::type
to bar::type<>
.
template <typename T>
struct base
template <typename G = T>
using type = decltype( std::declval<G>().foo() );
;
struct bar : base<bar>
int foo() return 42;
;
int main()
bar::type<> x;
live example on godbolt.org
I think now I also understand the reasoning in the answer I linked :) I dont like thebar::type<>
too much but I could live with that
– formerlyknownas_463035818
7 hours ago
Unfortunately,type<>
is not that useful inside a class scope. E.g., you can't writetype<> foo2();
for abase
's ofbar
's member function without using similarG = T
trick.
– Evg
7 hours ago
1
@Evg: true, but you can still use it like this: gcc.godbolt.org/z/fHUxO5
– Vittorio Romeo
7 hours ago
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%2f56497888%2fstddeclval-vs-crtp-cannot-deduce-method-return-type-from-incomplete-type%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
You can make type
a template type alias, so that users can instantiate it after the definition of bar
is available. This will change the final syntax from bar::type
to bar::type<>
.
template <typename T>
struct base
template <typename G = T>
using type = decltype( std::declval<G>().foo() );
;
struct bar : base<bar>
int foo() return 42;
;
int main()
bar::type<> x;
live example on godbolt.org
I think now I also understand the reasoning in the answer I linked :) I dont like thebar::type<>
too much but I could live with that
– formerlyknownas_463035818
7 hours ago
Unfortunately,type<>
is not that useful inside a class scope. E.g., you can't writetype<> foo2();
for abase
's ofbar
's member function without using similarG = T
trick.
– Evg
7 hours ago
1
@Evg: true, but you can still use it like this: gcc.godbolt.org/z/fHUxO5
– Vittorio Romeo
7 hours ago
add a comment |
You can make type
a template type alias, so that users can instantiate it after the definition of bar
is available. This will change the final syntax from bar::type
to bar::type<>
.
template <typename T>
struct base
template <typename G = T>
using type = decltype( std::declval<G>().foo() );
;
struct bar : base<bar>
int foo() return 42;
;
int main()
bar::type<> x;
live example on godbolt.org
I think now I also understand the reasoning in the answer I linked :) I dont like thebar::type<>
too much but I could live with that
– formerlyknownas_463035818
7 hours ago
Unfortunately,type<>
is not that useful inside a class scope. E.g., you can't writetype<> foo2();
for abase
's ofbar
's member function without using similarG = T
trick.
– Evg
7 hours ago
1
@Evg: true, but you can still use it like this: gcc.godbolt.org/z/fHUxO5
– Vittorio Romeo
7 hours ago
add a comment |
You can make type
a template type alias, so that users can instantiate it after the definition of bar
is available. This will change the final syntax from bar::type
to bar::type<>
.
template <typename T>
struct base
template <typename G = T>
using type = decltype( std::declval<G>().foo() );
;
struct bar : base<bar>
int foo() return 42;
;
int main()
bar::type<> x;
live example on godbolt.org
You can make type
a template type alias, so that users can instantiate it after the definition of bar
is available. This will change the final syntax from bar::type
to bar::type<>
.
template <typename T>
struct base
template <typename G = T>
using type = decltype( std::declval<G>().foo() );
;
struct bar : base<bar>
int foo() return 42;
;
int main()
bar::type<> x;
live example on godbolt.org
answered 7 hours ago
Vittorio RomeoVittorio Romeo
61.4k17171318
61.4k17171318
I think now I also understand the reasoning in the answer I linked :) I dont like thebar::type<>
too much but I could live with that
– formerlyknownas_463035818
7 hours ago
Unfortunately,type<>
is not that useful inside a class scope. E.g., you can't writetype<> foo2();
for abase
's ofbar
's member function without using similarG = T
trick.
– Evg
7 hours ago
1
@Evg: true, but you can still use it like this: gcc.godbolt.org/z/fHUxO5
– Vittorio Romeo
7 hours ago
add a comment |
I think now I also understand the reasoning in the answer I linked :) I dont like thebar::type<>
too much but I could live with that
– formerlyknownas_463035818
7 hours ago
Unfortunately,type<>
is not that useful inside a class scope. E.g., you can't writetype<> foo2();
for abase
's ofbar
's member function without using similarG = T
trick.
– Evg
7 hours ago
1
@Evg: true, but you can still use it like this: gcc.godbolt.org/z/fHUxO5
– Vittorio Romeo
7 hours ago
I think now I also understand the reasoning in the answer I linked :) I dont like the
bar::type<>
too much but I could live with that– formerlyknownas_463035818
7 hours ago
I think now I also understand the reasoning in the answer I linked :) I dont like the
bar::type<>
too much but I could live with that– formerlyknownas_463035818
7 hours ago
Unfortunately,
type<>
is not that useful inside a class scope. E.g., you can't write type<> foo2();
for a base
's of bar
's member function without using similar G = T
trick.– Evg
7 hours ago
Unfortunately,
type<>
is not that useful inside a class scope. E.g., you can't write type<> foo2();
for a base
's of bar
's member function without using similar G = T
trick.– Evg
7 hours ago
1
1
@Evg: true, but you can still use it like this: gcc.godbolt.org/z/fHUxO5
– Vittorio Romeo
7 hours ago
@Evg: true, but you can still use it like this: gcc.godbolt.org/z/fHUxO5
– Vittorio Romeo
7 hours ago
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%2f56497888%2fstddeclval-vs-crtp-cannot-deduce-method-return-type-from-incomplete-type%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