I'd like to overload the '*' operator to work with string arguments. Is
it possible? I tried the following, but apparently operator overloading
doesn't work at the package level?

        string opBinary(string op)(string repeatMe, int thisManyTimes)
                if (op=="*")
        {
                auto app = appender!string();
                while (thisManyTimes > 0) {
                        app.put(repeatMe);
                        thisManyTimes--;
                }
                return app.data;
        }

        void main() {
                writeln("spam" * 3);    // compile error
        }

Or is this just a very bad idea? ;-)


T

-- 
Старый друг лучше новых двух.

Reply via email to