Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4614248
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:40:16+00:00 2026-05-22T01:40:16+00:00

In order to find out which element occurs most often in a given array,

  • 0

In order to find out which element occurs most often in a given array, I’ve been using the group function from std.algorithm. First I would sort the array (that doesn’t seem to be necessary anymore), then pass it to group, and sort the tuple array, so that I could take the first element. It used to work, but now I get the error: overlapping array copy. I’m using version 2.053 for win32. I know that D2 and Phobos are under construction so I’m not really surprised. Just a little puzzled about what’s causing the problem.

import std.stdio, std.algorithm, std.array;

void main() {
    int[] arr = [ 1, 2, 2, 2, 2, 3, 4, 4, 4, 5 ];
    auto a = sort!("a[1] > b[1]")(array(group(arr)))[0];
}

The error I’m getting:

object.Exception@src\rt\arraycat.d(40): overlapping array copy
----------------
42EB58
42E9CF
4061F8
4060A0
406166
405EE8
402072
408898
4088D7
4084D3
4532C9
----------------

The content of the array makes a lot of difference. The following code compiles and prints the correct result:

import std.stdio, std.algorithm, std.array;

void main() {
    int[] arr = [ 1, 2, 3, 4, 4, 4, 5 ];
    auto a = sort!("a[1] > b[1]")(array(group(arr)))[0];
    writeln(a);
}
// prints: Tuple!(int,uint)(4, 3)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:40:16+00:00Added an answer on May 22, 2026 at 1:40 am

    This looks to be related to Bug 4789. Your code is correct. See http://d.puremagic.com/issues/show_bug.cgi?id=4789 .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to find out the z-order of all active windows in
I cannot find out how to obtain destination element with jQuery UI sortable. $(#pages).sortable({
I have a function which creates HTML elements out of a select box in
In most RDBMS, the meta-model is self contained, which means that I can find
I would like to find out if a particular python datetime object is older
I want to parse some HTML in order to find the values of some
I'm looking for a profiler in order to find the bottleneck in my C++
I am trying to find the best way to design the database in order
I'm writing a semi-generic form plugin using jQuery in order to speed up the
I have a webpage from the Fogbugz bug tracking system, and using a plugin

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.