【发布时间】:2023-03-06 06:32:02
【问题描述】:
在 bgl iteration_makros.hpp 中,它说
当图形类型是模板参数或 依赖于模板参数。否则使用非 _T 版本。
例如:
#define BGL_FORALL_EDGES_T(ENAME, GNAME, GraphType) \
for (std::pair<typename boost::graph_traits<GraphType>::edge_iterator, \
typename boost::graph_traits<GraphType>::edge_iterator> BGL_RANGE(__LINE__) = edges(GNAME); \
BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \
for (typename boost::graph_traits<GraphType>::edge_descriptor ENAME; \
BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (ENAME = *BGL_FIRST(__LINE__), true):false; \
++BGL_FIRST(__LINE__))
对比
#define BGL_FORALL_EDGES(ENAME, GNAME, GraphType) \
for (std::pair<boost::graph_traits<GraphType>::edge_iterator, \
boost::graph_traits<GraphType>::edge_iterator> BGL_RANGE(__LINE__) = edges(GNAME); \
BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \
for (boost::graph_traits<GraphType>::edge_descriptor ENAME; \
BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (ENAME = *BGL_FIRST(__LINE__), true):false; \
++BGL_FIRST(__LINE__))
我看到的唯一区别 - stackoverflow 足以在代码中突出显示这一点 - 是 _T 版本中的 typename 修饰符。
现在,我对整个类型名和模板这件事不是很了解,但为什么要提供两个版本呢?为什么 _T 版本不够用?谁能给我一个我不能使用 _T 版本的例子吗?
或者如果没有这样的例子,这背后的原因是什么?
在相关说明中,使用 BGL 的捆绑属性是否算作 Graph 的“依赖于模板参数”?
【问题讨论】: