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 1023709
In Process

The Archive Base Latest Questions

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

interface I1 { … } interface I2 { … } struct List(T) { …

  • 0
interface I1 { ... }
interface I2 { ... }
struct List(T) { ... }

How do I specialize my List to operate only on classes that implement both I1 and I2? One interface is easy:

struct List(T : I1)

Other languages. In C# it’s:

struct List<T> where T : I1, I2

And in Java I’d say:

class List<T extends I1 & I2>

One catch: I don’t want an if template constraint because I want reasonable auto-completion from a non-state-of-the-art IDEs. I think it’ll be long before IDEs for D do things like reverse-engineering template constraints to deduce a list possible T’s methods. And even if, that doesn’t sound like cheap performance-wise.

  • 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-16T11:40:05+00:00Added an answer on May 16, 2026 at 11:40 am

    If you don’t want to constrain template by if statement, only way is this:

    struct List(T : I1, U : I2 = T) {  }
    

    that means that you can instantiate List with one or two arguments, if you instantiate only with one – List!(C), then the U will be by default assigned value C, and checked if it implements I2. You can then ignore parameter U in the struct. The problem with this method is that you instantiate the List with two parameters – List!(C1, C2)…

    Here is version with if constraint, which doesn’t have this problem:

    struct List2(T) if ( is(T : I1) && is(T : I2)) {  }
    

    There is no practical performance overhead in using if template constraint – or any compile time technique – if you are not calculating lot of data (like ct raytracer or look-up tables)

    I would really suggest you to not limit your code to what the IDE supports – there sure will be many things that your IDE is not supporting well and you may find yourself having much less fun than using simple text editor with only sintax highlight, but with full potential of D.

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

Sidebar

Related Questions

In Interface Builder, I have set the dataCell of one of the columns of
In interface builder there is a control in the struts and springs inspector that
public interface Person { String getName(); void setName(String name); List<PersonFriend> getFriends(); } public interface
Interface methods in C# can be implemented explicitly, so that their implementation is invoked
interface Receiver { public <T extends HasId> void doSomethingWithList(List<T> list); } also, class SubClass
@interface Foo { Bar *bar[12][8][2]; } And I am wondering what that means and
Interface IView { List<string> Names {get; set;} } public class Presenter { public List<string>
The Interface Segregation Principle (ISP) says that many client specific interfaces are better than
What interface must i implement to be able to create wpf event when some
Following interface and classes are successfully compiled. Problem is mentioned in the output below

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.