nullptr_type not supported by simple_type_specifier

nullptr_type not supported by simple_type_specifier

本文关键字:type simple specifier by not nullptr supported      更新时间:2023-10-16

我希望有一个函数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_conststd::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);

现场演示