std::declval vs crtp, cannot deduce method return type from incomplete typeSpecial behavior for decltype of...
UTC timestamp format for launch vehicles
Why can I traceroute to this IP address, but not ping?
Why was this person allowed to become Grand Maester?
Proving that a Russian cryptographic standard is too structured
Does the new finding on "reversing a quantum jump mid-flight" rule out any interpretations of QM?
Can all groups be thought of as the symmetries of a geometrical object?
Separate SPI data
How creative should the DM let an artificer be in terms of what they can build?
New bike, tubeless tire will not inflate
Origin of "boor"
Live action TV show where High school Kids go into the virtual world and have to clear levels
How can I use String in enum for Apex?
How can I remove material from this wood beam?
Fermat's statement about the ancients: How serious was he?
60s or 70s novel about Empire of Man making 1st contact with 1st discovered alien race
Are inverted question and exclamation mark supposed to be symmetrical to the "normal" counter-parts?
Is an entry level DSLR going to shoot nice portrait pictures?
Why am I Seeing A Weird "Notch" on the Data Line For Some Logical 1s?
Why can my keyboard only digest 6 keypresses at a time?
How to hide rifle during medieval town entrance inspection?
A map of non-pathological topology?
Electricity free spaceship
Is it possible to have 2 different but equal size real number sets that have the same mean and standard deviation?
Non-aqueous eyes?
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 7 hours ago
formerlyknownas_463035818
asked 10 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
10 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
10 hours ago
1
@Evg: true, but you can still use it like this: gcc.godbolt.org/z/fHUxO5
– Vittorio Romeo
9 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
10 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
10 hours ago
1
@Evg: true, but you can still use it like this: gcc.godbolt.org/z/fHUxO5
– Vittorio Romeo
9 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
10 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
10 hours ago
1
@Evg: true, but you can still use it like this: gcc.godbolt.org/z/fHUxO5
– Vittorio Romeo
9 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 10 hours ago
Vittorio RomeoVittorio Romeo
61.5k17171318
61.5k17171318
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
10 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
10 hours ago
1
@Evg: true, but you can still use it like this: gcc.godbolt.org/z/fHUxO5
– Vittorio Romeo
9 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
10 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
10 hours ago
1
@Evg: true, but you can still use it like this: gcc.godbolt.org/z/fHUxO5
– Vittorio Romeo
9 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
10 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
10 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
10 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
10 hours ago
1
1
@Evg: true, but you can still use it like this: gcc.godbolt.org/z/fHUxO5
– Vittorio Romeo
9 hours ago
@Evg: true, but you can still use it like this: gcc.godbolt.org/z/fHUxO5
– Vittorio Romeo
9 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