iteratorの無いSTL

・・・は、あり得ない。STLのalgorithmをC#にどーやって持ってこようかと考えていたのですが、iterator(SLTの方)が無いことにはどうにもならないです。もちろん、C#iteratorを用意する手もあるのですが、それだとBCLとは別のコレクションを一セット用意することになってしまうか、少なくともIEnumeratorやIEnumerable、IListあたりでやり取りするようにしておかないと、基本ライブラリと相性が悪くなりすぎます。

試しにちょっと書いてみましたが、どうにもしっくり来ないです。

namespace Pseudo.Std
{
    public delegate void Action<T>(T obj);
    public delegate bool Predicate<T>(T obj);

    public static class Algorithm
    {
        public static T Max<T>(T lhs, T rhs) where T : IComparable<T>
        {
            return lhs.CompareTo(rhs) > 0 ? lhs : rhs;
        }

        public static T Min<T>(T lhs, T rhs) where T : IComparable<T>
        {
            return lhs.CompareTo(rhs) < 0 ? lhs : rhs;
        }

        public static void Swap<T>(ref T lhs, ref T rhs)
        {
            T tmp = lhs;
            lhs = rhs;
            rhs = tmp;
        }

        public static T MaxElement<T>(IEnumerable<T> objs) where T : IComparable<T>
        {
            IEnumerator<T> it = objs.GetEnumerator();
            if (!it.MoveNext())
                throw new ArgumentException();
            T max = it.Current;
            while (it.MoveNext())
                if (it.Current != null && it.Current.CompareTo(max) > 0)
                    max = it.Current;
            return max;
        }

        public static T MinElement<T>(IEnumerable<T> objs) where T : IComparable<T>
        {
            IEnumerator<T> it = objs.GetEnumerator();
            if (!it.MoveNext())
                throw new ArgumentException();
            T min = it.Current;
            while (it.MoveNext())
                if (it.Current != null && it.Current.CompareTo(min) < 0)
                    min = it.Current;
            return min;
        }

        public static Action<T> ForEach<T>(IEnumerable<T> objs, Action<T> action)
        {
            foreach (T t in objs)
                action(t);
            return action;
        }

        public static IEnumerable<T> Find<T>(IEnumerable<T> objs, T value) where T : IComparable<T>
        {
            foreach(T t in objs)
                if (t.Equals(value)) 
                    yield return t;
        }

        public static IEnumerable<T> Find<T>(IEnumerable<T> objs, Predicate<T> pred)
        {
            foreach (T t in objs)
                if (pred(t))
                    yield return t;
        }
    }
}

Peter Golde - PowerCollections (and more?)
こんなプロジェクトもあるらしいし、偉い人にお任せした方がいい気がしてきた。csharpllでもεπιστημη氏がやりそーなこと言ってたし。(^^;