String and opBinary
Zhenya
zheny at list.ru
Fri Jun 1 12:37:36 PDT 2012
This code work
import std.stdio;
struct String
{
string data;
alias data this;
this(string s)
{
data = s;
}
String opBinary(string op : "*")(string word)
{
string temp;
foreach(letter; word)
{
temp ~= data;
}
return String(temp);
}
};
string opBinary(string op : "*")(string data, string word)
{
string temp;
foreach(letter; word)
{
temp ~= data;
}
return temp;
}
void main()
{
String word = "foo";
String secretword = String("_") * word;
//string secretword = "_".opBinary!"*"(word); // compile
writeln(secretword); // output : ___
}
More information about the Digitalmars-d-learn
mailing list