在 C# 中编写 C++ std::反向等效的最接近的方法是什么?
What is the closest way of writing a C++ std::reverse equivalent in C#?
C++标准库中的reverse
算法相当于
template <class BidirectionalIterator>
void reverse (BidirectionalIterator first, BidirectionalIterator last)
{
while ((first!=last)&&(first!=--last)) {
std::iter_swap (first,last);
++first;
}
}
据 http://www.cplusplus.com/reference/algorithm/reverse/说。我想用 C# 编写等效项:
public void Reverse<T> ( T first, T last )
{
// ...
}
首先,你如何传递两个对IEnumerator
的引用,第二个是可以向后移动的引用?有没有一种自然的方法可以做到这一点,还是需要先延长IEnumerable<T>
?
其次,如果上一个问题的答案是否定的,那么是否有一种经过 Skeet 认证的 C# 编写reverse
方式,在通用性和有效性方面与C++方式相当?如果是这样,它是什么?
List<T>
接口提供了一个Reverse()
方法,该方法将与等效C++相同。
看看 https://msdn.microsoft.com/en-us/library/b0axc2h2(v=vs.110).aspx
相关文章:
- 通过JNI传递数据数组的最快方法是什么
- 当无法使用模板和宏时,生成类型变体C++代码的最简单方法是什么?
- 在另一个类视图中添加最多2个图表的正确方法是什么
- 在PostgreSQL中根据它们的ID选择大量行的最快方法是什么?
- 在OSX上使用CMake将Adobe的XMP工具包构建为共享库的最简单方法是什么?
- 将此布尔值传递给此函数的最有效方法是什么?
- 通过比较C++中的行在 txt 文件中搜索的最简单方法是什么?
- 最接近"std::atomic<std::vector>"是什么?
- C++中最接近 Lua 表操作的东西是什么?
- 什么是从最接近线的一组点找到点的最快算法
- C++最接近追溯定义已定义类的超类是什么?
- 是什么让这个二叉搜索更接近最大范围
- 在 C# 中编写 C++ std::反向等效的最接近的方法是什么?
- 与 Ruby's Rack 最接近C++类似物是什么?
- 使用 opencv 和 c++ 找到与复杂形状最接近的匹配的最佳方法是什么?
- 将货币金额四舍五入到最接近的镍、四分之一、1 美元、5 美元等面额的最佳方法是什么?
- 在C++中,最接近.Net NotSupportedException的替代方案是什么
- 最接近 1.0 的双倍是什么,那不是 1.0?
- 在其他语言中,最接近Apache Hadoop的东西是什么
- 循环遍历数组并找到最接近键的数组元素的最佳方法是什么