Saturday, August 15, 2015

Digest for comp.lang.c++@googlegroups.com - 2 updates in 2 topics

Gareth Owen <gwowen@gmail.com>: Aug 15 12:50PM +0100


> Man, that is unnecessarly complicated for such a simple problem. Just
> use the interators directly and dump the unreadable auto/lamda parts.
 
That's not Stefan's style. His code is the poster child for how to
turn idioms into incomprensibility.
Nobody <nobody@nowhere.invalid>: Aug 15 01:40AM +0100

On Fri, 14 Aug 2015 02:57:31 -0700, Paul wrote:
 
> Please could someone tell me the simplest way to count the number of
> unique values in a container when the values are not necessarily
> consecutive?
 
First of all, the objects must support some form of equality comparison,
otherwise any talk of uniqueness is meaningless.
 
If they additionally support total ordering (i.e. for any elements a and b
then either a==b, a<b or b<a, and for any elements a, b and c then if a<b
and b<c then a<c), you can first sort them; then you only need to check
whether adjacent elements are equal.
 
Personally, I'd suggest that copying to an unordered_set and measuring its
size is likely to be about as efficient as it gets (anything more
efficient would basically amount to optimising unordered_set) and
(although this is subjective) perfectly elegant.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: