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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:46:09+00:00 2026-05-26T15:46:09+00:00

I have been learning D, and am in particular very excited for it’s Generic

  • 0

I have been learning D, and am in particular very excited for it’s Generic programming capabilities. Delegates are wonderful, and apparently they have completely replaced member-function-pointers, so I was stuck when I wanted to implement something like the following:

template <typename T>
void DispatchMethodForAll(std::vector<T*> & container, void (T::* func)(void))
{
  for(typename std::vector<T*>::iterator it = container.begin(); it != container.end(); ++it)
      (*it)->*func();
}

According to what I have learned of function pointers and delegates in D, is that neither of them can do this, since function pointers can only be declared for global functions, and delegates have to be bound to an object, there is no “partial delegate” that I can find. As seen here, I cannot use a delegate, since there is no single object that can be bound to the method that is to be called.

I know that I could do it with mixins, and essentially make it a macro. However this really doesn’t sound D-like, and I figured there should be “The correct way”

  • 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-26T15:46:10+00:00Added an answer on May 26, 2026 at 3:46 pm

    You could still use a delegate here.

    void DispatchMethodForAll(T)(T*[] container, void delegate(T*) action)
    {
        foreach (it; container)
            action(it);
    }
    
    ...
    
    DispatchMethodForAll(container, (Foo* foo) { foo.func(); });
    

    Example: http://www.ideone.com/9HUJa

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

Sidebar

Related Questions

I have been learning about Delegation and Data Sources for iOS programming and need
I have been learning functional programming and I come to idea, to assemble mathematical
I have been learning the Factor and J languages to experiment with point-free programming.
I have been learning NodeJS recently. It seems to be standard in the Node
I have been learning css & jquery. <!DOCTYPE html> <html> <head> <style type=text/css> #box
I have been learning Hibernate for the past few weeks, I have gotten most
I have been learning Scala for the past couple of months and now I
I have been learning the mapreduce algorithm and how it can potentially scale to
I have been learning a bit of Python 2 and Python 3 and it
I have been learning python for some time now. While starting this learning python

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.