std::tuple的遍历

//
/// <元组遍历>
enum EFOREACHTUPLE_RUNSTATE
{
	OVER = 1, // 结束执行
	NEXT	  // 继续执行下一个
};
// 递归编译终点
template<std::size_t index = 0, typename FuncHandle, typename... TupleParam>
inline typename std::enable_if<index == sizeof...(TupleParam), void>::type ForEachTuple(std::tuple<TupleParam...>&, FuncHandle)
{
}
/*example CContainer*的类型可以换成任意,具体要和tuple定义的对应
::ForEachTuple(m_tPlayerGoodsContainer, [&](std::size_t index, CContainer* pContainer) {
		// pContainer不会为空 还是加下判断 预防下
		if (!pContainer)
			return ::EFOREACHTUPLE_RUNSTATE::NEXT;
		...
		return ::EFOREACHTUPLE_RUNSTATE::NEXT;
	});
*/
template<std::size_t index = 0, typename FuncHandle, typename... TupleParam>
inline typename std::enable_if < index < sizeof...(TupleParam), void>::type ForEachTuple(std::tuple<TupleParam...>& tp, FuncHandle funcHandle)
{
	// funcHandle参数(下标I, 存储的值)
	::EFOREACHTUPLE_RUNSTATE runState = funcHandle(index, &std::get<index>(tp));
	// 是否遍历结束
	if (::EFOREACHTUPLE_RUNSTATE::OVER == runState)
		return;
	ForEachTuple<index + 1, FuncHandle, TupleParam...>(tp, funcHandle);
}
/// </元组遍历>
//
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页