简体   繁体   English

C ++如何实现std :: is_class

[英]How c++ implement std::is_class

Here is the implementation of std::is_class in mac. 这是mac中std :: is_class的实现。 I don't understand what is the parameter of "int _Tp::*". 我不明白“ int _Tp :: *”的参数是什么。 Can someone explain this? 有人可以解释吗? what is the type of parameter and what is the name of parameter? 参数的类型是什么,参数的名称是什么? Thanks. 谢谢。

And another question is the ellipsis. 另一个问题是省略号。 In C it needs at least one parameter before ellipsis, but in c++ it can be just the ellipsis. 在C语言中,它在省略号之前至少需要一个参数,但是在c ++中,它可以仅是省略号。 Where can I find the standard about this part? 在哪里可以找到有关这部分的标准?

namespace __is_class_imp
{
template <class _Tp> char  __test(int _Tp::*);
template <class _Tp> __two __test(...);
}

template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_class
    : public integral_constant<bool, sizeof(__is_class_imp::__test<_Tp>(0)) == 1 && !is_union<_Tp>::value> {};

To answer one of your questions, the __test(...) function accepts any number of any kind of arguments. 为了回答您的问题之一, __test(...)函数接受任意数量的任何类型的参数。 But they can't be used. 但是它们不能被使用。 The va_start macro needs a previous argument to work, without it one can not get any arguments. va_start需要一个上一个参数才能工作,没有它,就无法获取任何参数。

The reason for it is so that __test can be used with any kind of arguments, but won't actually be implemented. 原因是__test可以与任何类型的参数一起使用,但实际上不会实现。 This works because the function is only used ad compile-time, no actual calling of will happen. 之所以可行,是因为该函数仅在广告编译时使用,不会发生实际的调用。 And since it's overloaded the compiler will do different things depending on the types used. 而且由于过载,编译器将根据所使用的类型执行不同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM