nullptr_type not supported by simple_type_specifier
nullptr_type not supported by simple_type_specifier
我希望有一个函数fn
,它接受指向const
和非const
对象的指针集。我正在编写一个模板来执行此操作。
template<typename T1,
typename T2,
std::enable_if<std::is_same<T1,NodeType *>::value && std::is_same<T2,EdgeType *>::value, std::nullptr_t>::type = nullptr>
static void fn(unordered_set<T1> &nodeSet, unordered_set<T2>& edgeSet);
在上面的例子中,我希望能够传递unordered_set<const NodeType *>
和unordered_set<NodeType *>
(与EdgeType
相似)。但是,我收到一个错误: ‘nullptr_type’ not supported by simple_type_specifier
.有人可以帮忙吗?
除了您缺少的某些typename
之外,要实现这一点,您应该使用std::remove_const
并std::remove_pointer
类型特征,如下所示:
template<typename T1, typename T2,
typename std::enable_if<
std::is_same<typename std::remove_const<typename std::remove_pointer<T1>::type>::type, NodeType>::value &&
std::is_same<typename std::remove_const<typename std::remove_pointer<T2>::type>::type, EdgeType>::value,
typename std::nullptr_t>::type = nullptr>
static void fn(std::unordered_set<T1> &nodeSet, std::unordered_set<T2>& edgeSet);
现场演示
相关文章:
- 使用 [] 运算符时"binding reference of type discards qualifiers"
- 在 QVector<std::unique_ptr 上使用 std::find<Type>>
- 在类型和包装器之间reinterpret_cast是否安全<Type>?
- 使用 cmake 的 Linux 终端上的"Conversion to non-scalar type is requested"错误
- 控制到达非空函数clang(-Wreturn-type)的末尾
- std::unordered_map 类型对象声明期间出现"field has incomplete type"错误
- 将系数存储在头文件的数组中("does not name a type"错误)
- 尝试打开 ifstream 时出现"Incomplete type"错误
- 将成员函数作为构造函数参数调用时出错 "Variable is not a type name"
- 在"结构提升::enable_if<提升::is_pod<T>,无效>"中没有名为"type"的类型
- "Missing type specifier - int assumed"无法通过向主函数添加"return 0"来解决
- OpenCV CV_16F type
- C++ "错误:在'类 std::result_of< ... >"中没有名为'type'的类型"
- 将内存分配返回值强制转换为 TYPE 数组
- C++ 一个lambda浅拷贝const Type&如果它被赋予一个命名捕获,如[copy=val](){}?
- reference_wrapper导致"incomplete type is not allowed"
- 为什么别名声明不是有效的 init 语句(/simple-declaration)?
- 继承类时"invalid use of incomplete type ‘class tree_node_t’"
- 由于"error C4430: missing type specifier - int assumed. Note: C++ does not support default-int",我现在无法编
- 如何声明和使用"one writer, many readers, one process, simple type"变量?