帮助重载解析的类型。 (如果我没记错的话,标签调度)
当您想在某些函数上使用复杂的模板专门化模式时,您不会尝试直接使用它,而是编写:
template <typename T1, typename T2, other things maybe>
int foo(T1 param1, T2 param2 and so on)
{
using tag = put your complex stuff here, which produces an empty struct
detail::foo_impl(tag, std::forward<T1>(param1), std::forward<T2>(param2) and so on);
}
现在,编译器不必在模板专业化的竞争选择之间做出决定,因为使用不同的标签,您会得到不兼容的函数。
一个基本接口
struct vehicle {
// common members and methods,
// including (pure) virtual ones, e.g.
virtual std::size_t num_maximum_occupants() = 0;
virtual ~vehicle() = default;
};
namespace mixins {
struct named { std::string name; };
struct wheeled { int num_wheels; public: rev() { }; };
} // namespace mixins
struct private_sedan : public vehicle, public wheeled, named {
// I dunno, put some car stuff here
//
// and also an override of `num_maximum_occupants()`
};
将基本结构完全清空可能并不常见,但如果您经常使用 mixins,这当然是可能的。你可以检查继承自vehicle
(虽然我不确定我会这样做)。
模板参数
不确定这意味着什么,但大胆猜测:
template <typename T>
struct foo { };
template <typename T, typename N>
struct foo<std::array<T, N>> {
int value = 1;
};
如果你现在使用foo<T>::value
在一个函数中,只有当T
is int
几乎没有(?)例外。