-4

Why is a struct consume defined without using template type?
What is the difference between consume_t and delegate_t?

template <typename T>
struct consume;

template <typename D, typename I = D>
using consume_t = typename consume<I>::template type<D>;

template <typename T>
struct delegate;

template <typename T, typename H>
using delegate_t = typename delegate<T>::template type<H>;
mopodafordeya
  • 635
  • 1
  • 9
  • 26
  • 1
    The second half of your question is answered [here](https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords) – NathanOliver Sep 13 '19 at 16:35
  • You should ask the person who wrote it. A shame they did not leave any documenting comments. – Lightness Races in Orbit Sep 13 '19 at 16:51
  • 2
    Is this from the Windows runtime? Did you get it from MSDN? Trying to determine the relevance of your tags but it's hard as you gave no context for this question. – Lightness Races in Orbit Sep 13 '19 at 16:52
  • 1
    I do not see a definition of `struct consume` (with or without a template type). I only see a declaration. – Yunnosch Sep 13 '19 at 17:07
  • 1
    The difference between consume_t and delegate_t is that one is based on consume and one on delegate. Both are defined elsewhere and could be very different. – Yunnosch Sep 13 '19 at 17:08
  • @LightnessRacesinOrbit you are right, it is quoted from WinSDK cppwinrt/winrt/base.h. Because I am having hard time recognizing this pattern therefore I associated it with ambiguous tags. – mopodafordeya Sep 13 '19 at 20:09
  • Your edit has really focused the question, i.e. turned it into a single one. Because I consider the second question mark to be a specification detail of what puzzles you about the first one. Good work. – Yunnosch Sep 13 '19 at 20:25

1 Answers1

2

The shown code does not contain a definition of struct consume, neither with nor without a template type.

This however is a (forward) declaration of it

template <typename T>
struct consume;

It only states that such a type does exist and that it takes a template parameter.

Same for struct delegate.

So it is clear that both exist, but the definition (elsewhere) is probably different.

That in turn means that delegate_t and consume_t are based on different templated types and hence also are (most probably) different, even though they seem to be so similarily defined.

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
  • The source is from the standard WinSDK path, for example: C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\cppwinrt\winrt\base.h Would you please help to quote the path of "struct consume" definition? I could find other dependent types inherited from consume, for example "struct require_one" – mopodafordeya Sep 13 '19 at 20:04
  • Could you instead use a tool which searches your drive for that? The unix tool grep comes to mind, there are windows versions of that. Otherwise consider making a separate question please, because I consider this one answered. Finding the definition is a new one. – Yunnosch Sep 13 '19 at 20:08
  • I have rephrased the question a bit, but still I could not find the definition of the consumer/delegate template using my tools, too many dependent types inherited from these two templates. Thanks for the linked resource, it is very helpful. – mopodafordeya Sep 13 '19 at 20:16
  • I need to know the difference between these two forward declared types, maybe someone could find the actual interface/type declaration. – mopodafordeya Sep 13 '19 at 20:18
  • 1
    Be careful with editing questions after they got answers. People do not like "moving target questions". In this case however, the edited question actually fits better to the major part of my answer, so that is fine, don't worry. And thanks for the accept. That is good style. – Yunnosch Sep 13 '19 at 20:20
  • Concerning what you still need to know: Please make another, separate question about that. Link to this one for background if you like. – Yunnosch Sep 13 '19 at 20:21