Should this work?

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Jan 10 12:14:14 PST 2014


On Fri, Jan 10, 2014 at 07:32:23PM +0000, Atila Neves wrote:
> I agree that std.algorithm is better than <algorithm>, but let's not
> pretend that C++11 never happened (that happens from time to time on
> this forum). The modern C++ version isn't _that_ different:
> 
>     for(auto& blah: myContainer) { //for-loop condition on one line
>         doSomething(blah->impl->myDataField);
>         if(find(blah->impl->mySubContainer.begin(),
> blah->impl->mySubContainer.end(), key) ==
> blah->impl->mySubContainer.end()) {
>             //decltype is way shorter than std::vector<MyType<Blah>>
>             //and change-resistant
>             return decltype(blah)::iterator{};
>         }
>      }
> 
> Again, I think that std.algorithm is better and that passing a pair
> of iterators to everything when 99.9% of the time they'll be begin()
> and end() anyway is a massive PITA. I'm a D convert. Nobody here
> makes a point of posting D1 code and IMHO there's also no point in
> posting C++98 / C++2003 code.

You're right, my C++ is outdated. I'm not exactly motivated to keep up
with the latest version of C++, though, since D is far better, and my
day job is primarily with C, and what C++ code we have is still in the
dark ages of C++2003 (or perhaps *shudder* even C++98), and is unlikely
to be upgraded to C++11 anytime in the foreseeable future.


[...]
> >	// You can't even write the for-loop conditions in a single
> >	// line!
> >	for (std::vector<MyType<Blah> >::iterator it =
> >		myContainer.start();
> >		it != myContainer.end();
> >		it++)
> >	{
> >		// What's with this (*smartPtr)->x nonsense everywhere?
> >		doSomething((*((*it)->impl)->myDataField);
> >
> >		// What, I can't even write a simple X != Y if-condition
> >		// in a single line?! Not to mention the silly
> >		// redundancy of having to write out the entire chain of
> >		// dereferences to exactly the same object twice.
> >		if (find((*(*it)->impl)->mySubContainer, key) ==
> >			(*(*it)->impl)->mySubContainer.end())
> >		{
> >			// How I long for D's .init!
> >			std::vector<MyTypeBlah> >::iterator empty;
> >			return empty;
> >		}
> >	}


T
-- 
Heuristics are bug-ridden by definition. If they didn't have bugs, they'd be algorithms.


More information about the Digitalmars-d mailing list