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

  • SEARCH
  • Home
  • 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 6926789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:57:50+00:00 2026-05-27T10:57:50+00:00

I was fishing around in D’s standard library looking for a Set implementation, and

  • 0

I was fishing around in D’s standard library looking for a Set implementation, and I only found these:

  • BinaryHeap
  • RedBlackTree

These both would work fine, if I could only figure out how to use them. I started with the RedBlackTree (because I’m already familiar with how they work), and this is what I came up with:

auto rbt = redBlackTree!string();
foreach(s; setOfStrings) {
    rbt.insert(s);
}

foreach(s; rbt) {
    if (s[0 .. 3] == "sth") {
        rbt.removeKey(s);
    }
}

I know I could have done the condition in the first foreach, but it’s just an example showing that I need to add and remove elements from the Set. This would work, but I get compile errors:

Error: template std.container.RedBlackTree!(string).RedBlackTree.removeKey(U) if (isImplicitlyConvertible!(U,Elem)) does not match any function template declaration

Error: template std.container.RedBlackTree!(string).RedBlackTree.removeKey(U) if (isImplicitlyConvertible!(U,Elem)) cannot deduce template function from argument types !()(string

I don’t need a red-black tree (anything without duplicates), and speed isn’t too important. I could do something like this:

string[] arr;
foreach(s; setOfStrings) {
    // check for duplicate code here...

    arr ~= s;
}
for(int i = 0; i < arr.length; i++) {
    if (s[0 .. 3] == "sth") {
        arr = arr[0 .. i] ~ arr[i + 1 .. $];
        i++;
    }
}

Is there anything in the standard library for a simple Set?

  • 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-27T10:57:51+00:00Added an answer on May 27, 2026 at 10:57 am

    RedBlackTree is Phobos’ set implementation. The problem that you’re running into with removeKey is the fact that it’s variadic. It will take either an array of keys to remove or multiple keys (e.g. removeKey(arr) or removeKey(key1, key2, key3)). string is an array of immmutable chars, so it tries to instantiate removeKey with char instead of string, which doesn’t work, because your tree holds strings, not chars. You wouldn’t have this sort of problem if you were dealing with a RedBlackTree of ints or any other non-array type.

    What you need to do is either give it an array of strings or to instantiate it directly i.e. removeKey([s]) or removeKey!string(s).

    By the way, std.container has gone the route of naming its container types based on their data structure rather than what they’re used for. So, when you say that you don’t need a red-black tree, that’s not quite right. You want a set. You just don’t care how it’s implemented. The two typical ways to implement sets involve using either a red-black tree or a hash table. So, RedBlackTree gives you one way to have a set. It’s just that its named after its data structure, not how you might use it, so if you’re looking for a container name Set in std.container, you’re not going to find it.

    EDIT: A bug report exists for this, and a fix has been submitted. So, in a future release of dmd, it should be possible to pass a string to removeKey without having to directly instantiate it or pass the string in inside an array.

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

Sidebar

Related Questions

i am working on a fishing app these days and i am getting a
I have successfully set up this plugin before so I am curious as to
For example, given a string: Bob went fishing with his friend Jim Smith. Bob
I have 4 select boxes, each containing the exact same data: Riding Fishing Smoking
I'm developing a reusable library and have been creating abstract classes, so the client
So I have some code here that takes user input from a standard web
Warning! I'm on a bit of a fishing trip here, and I'm not even
I am writing a little shop administration software for my uncles fishing shop. It
I have an xml feed, say: http://gdata.youtube.com/feeds/api/videos/-/bass/fishing/ I want to get the list of
I see the following options when I want to set up a new In-App

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.