你也许知道,在 pb_ds 库里面有一种神奇的类叫 priority_queue(不是 std 库里面的那个)。
在声明的时候,形式大概是:
__gnu_pbds ::priority_queue<T, Compare, Tag, Allocator>
问题在于其中的 tag。如何制作一个 tag 类?
我的想法是,写一个仿函数,就像 less 和 greater 一样。但是我发现这个 tag 并没有带模板。那么它是如何匹配类型的呢?
比如说这是一个声明:
__gnu_pbds ::priority_queue<int,less<int>,pairing_heap_tag> Q;
我们发现仿函数 less 带了一个 int 的模板。但是 pairing_heap_tag 没有。
谁能告诉我,这个 tag 是怎么实现的?