Why I love C++ so much.

Danilo Turina danilo.turina@alcatel-lucent.it
Fri Feb 22 08:35:00 GMT 2008


Corinna Vinschen wrote:
> On Feb 21 05:26, Warren Young wrote:
>> Corinna Vinschen wrote:
>>> Really?  Show me an example which isn't much harder to understand than
>>> the equivalent C code.
>> template <class T>
>> std::string foo(const T& x)
>> {
>>     std::ostringstream outs;
>>     outs << x << and << maybe << other << stuff;
>>     return outs.str();
>> }
>>
>> (Aside: This looks pointlessly trivial, but it's a simplified version of 
>> real code in MySQL++ (http://tangentsoft.net/mysql++/).  It would just 
>> muddy the waters to talk about the reason MySQL++ does this.)
>>
>> To do that with C functions (maybe strto*() instead of printf()) you'd have 
>> to create a set of template specializations for every T you know about to 
>> call the right C function with the right arguments.  Any time you add to 
>> the list of supported T's, you have to add template specializations.
> 
> Argh.  Using templates as an example for simplicity is somewhat daring.
> Templates, liberally used, are a good way to make code unreadable.
> 
> IMHO.
> 
> FWIW.
> 
> YMMV.
> 
> YMCA.
> 
> 
> Corinna
> 

C++ is like Unix, people that don't like it is because they don't 
understand it.

Cheers,
		Danilo



More information about the Cygwin-talk mailing list