具有 volatile 的 C++ 类型特征
C++ type trait with volatile
我试图理解以下类型特征,它检查 T
是来自类型 container
还是派生自这种类型。我的问题与 aux_iscontainer
及其参数有关。
为什么参数前面需要有 CV 限定符?
为什么我们甚至需要传递一个指向类型的指针而不仅仅是类型本身?
虽然 std::declval<T>
只允许我们使用 T
的类型,但它没有构造 std::declval<T*>
在这种情况下意味着什么?
template< typename T>
std::true_type aux_iscontainer( const volatile container<T> *);
std::false_type aux_iscontainer(... ) ;
template< typename T >
struct iscontainer : public decltype( aux_iscontainer(std::declval<T*>() ) )
{};
//
template< typename T >
struct iscontainer <T&>
: public std::false_type
{};
Why does it need to have the CV qualifier in front of the argument.?
标准隐式转换之一是向表达式添加 cv 限定符,因此const volatile T*
可以绑定到T*
、[=12= 中的任何一个], volatile T*
和 const volatile T*
.
Why do we even need to pass a pointer to the type and not just the type itself?
另一个标准隐式转换是从派生指针到基址指针。
While std::declval does just allow us to use the type of T without it constructing what does std::declval<T*> mean in this case?
一样,是T*
类型的表达式,没有T*
类型的值。
我试图理解以下类型特征,它检查 T
是来自类型 container
还是派生自这种类型。我的问题与 aux_iscontainer
及其参数有关。
为什么参数前面需要有 CV 限定符?
为什么我们甚至需要传递一个指向类型的指针而不仅仅是类型本身?
虽然 std::declval<T>
只允许我们使用 T
的类型,但它没有构造 std::declval<T*>
在这种情况下意味着什么?
template< typename T>
std::true_type aux_iscontainer( const volatile container<T> *);
std::false_type aux_iscontainer(... ) ;
template< typename T >
struct iscontainer : public decltype( aux_iscontainer(std::declval<T*>() ) )
{};
//
template< typename T >
struct iscontainer <T&>
: public std::false_type
{};
Why does it need to have the CV qualifier in front of the argument.?
标准隐式转换之一是向表达式添加 cv 限定符,因此const volatile T*
可以绑定到T*
、[=12= 中的任何一个], volatile T*
和 const volatile T*
.
Why do we even need to pass a pointer to the type and not just the type itself?
另一个标准隐式转换是从派生指针到基址指针。
While std::declval does just allow us to use the type of T without it constructing what does std::declval<T*> mean in this case?
一样,是T*
类型的表达式,没有T*
类型的值。