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;








8















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.










share|improve this question






























    8















    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.










    share|improve this question


























      8












      8








      8


      0






      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.










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 5 hours ago







      formerlyknownas_463035818

















      asked 8 hours ago









      formerlyknownas_463035818formerlyknownas_463035818

      21.4k43075




      21.4k43075






















          1 Answer
          1






          active

          oldest

          votes


















          10














          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






          share|improve this answer























          • 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







          • 1





            @Evg: true, but you can still use it like this: gcc.godbolt.org/z/fHUxO5

            – Vittorio Romeo
            7 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%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









          10














          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






          share|improve this answer























          • 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







          • 1





            @Evg: true, but you can still use it like this: gcc.godbolt.org/z/fHUxO5

            – Vittorio Romeo
            7 hours ago















          10














          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






          share|improve this answer























          • 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







          • 1





            @Evg: true, but you can still use it like this: gcc.godbolt.org/z/fHUxO5

            – Vittorio Romeo
            7 hours ago













          10












          10








          10







          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






          share|improve this answer













          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







          share|improve this answer












          share|improve this answer



          share|improve this answer










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







          • 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











          • 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





            @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



















          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%2f56497888%2fstddeclval-vs-crtp-cannot-deduce-method-return-type-from-incomplete-type%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

          Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

          Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

          199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單