|
Boost : |
From: christopher diggins (cdiggins_at_[hidden])
Date: 2005-01-13 10:19:21
----- Original Message -----
From: "Jonathan Turkanis" <technews_at_[hidden]>
>
> It's not that I don't see the benefit of lower complexity; I don't really
> see
> the lower complexity. ;-)
>
> The only noticeable difference is that mine contains "template<typename
> Source>"
> and uses a non-member get function.
And the facts that:
1) ToUpper() is not a non-member function
2) ToUpper() uses cin rather than a passed argument
Nonetheless consider the following psuedo-program (which does model a lot of
software):
void Fu(string s) {
cout << s;
}
string Bar() {
string ret;
cin >> ret;
return ret;
}
string Transform(string s) {
string ret(s);
// do some stuff
return ret;
}
void DoTransform() {
while (!cin.eof()) {
Fu(Transform(Bar()));
}
}
int main() {
DoTransform();
return 0;
}
Now if at a later point I want to refactor and reuse the code from a program
like this in another, I can either rewrite the entire program as an
iostreams filter (which is not trivial), or I can simply write (using my
personal library):
int main() {
fstream("in.txt") > Filter(DoTransform) > fstream("out.txt");
}
Irregardless of the arguments for using iostreams filters (which trust me, I
am very aware of), most of the time I am simply going to opt to use this
syntax, because it require far less work.
Christopher Diggins
Object Oriented Template Library (OOTL)
http://www.ootl.org
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk