C# to D
Dennis Ritchie via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Mar 25 12:32:41 PDT 2015
On Wednesday, 25 March 2015 at 19:01:43 UTC, bearophile wrote:
> One solution:
Thanks.
On Wednesday, 25 March 2015 at 19:03:27 UTC, bearophile wrote:
> But calling "count" for each item is not efficient (in both C#
> and D). If your array is largish, then you need a more
> efficient solution.
A more effective solution for C ++:
#include <iostream>
#include <vector>
#include <range/v3/all.hpp>
int main() {
using namespace ranges;
auto rng = istream<int>( std::cin )
| to_vector
| action::sort
| view::group_by( std::equal_to<int>() )
| copy
| action::stable_sort( []( const auto& e1, const auto&
e2 ) { return distance( e1 ) < distance( e2 ); } );
std::cout << ( rng );
}
More information about the Digitalmars-d-learn
mailing list