【发布时间】:2019-03-14 11:21:57
【问题描述】:
是否存在您无法正确使用std::conjunction/std::disjunction 并且不使用更“基本”(即语言功能而不是库功能)折叠表达式而不是&&/|| 的特定情况?
例子:
// func is enabled if all Ts... have the same type
template<typename T, typename... Ts>
std::enable_if_t<std::conjunction_v<std::is_same<T, Ts>...> >
func(T, Ts...) {
// TODO something to show
}
对
// func is enabled if all Ts... have the same type
template<typename T, typename... Ts>
std::enable_if_t<(std::is_same<T, Ts> &&...)>
func(T, Ts...) {
// TODO something to show
}
使用折叠表达式的版本更简洁,通常更具可读性(尽管意见可能不同)。所以我不明白为什么将它与折叠表达式一起添加到库中。
【问题讨论】:
-
conjunction和disjunction的“内部”实现在 C++17 折叠表达式不可用(无论出于何种原因)的项目中仍然有用。
标签: c++ c++17 variadic-templates fold-expression