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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:31:40+00:00 2026-06-15T14:31:40+00:00

I have a professor that wrote all his examples for D templates in shorthand:

  • 0

I have a professor that wrote all his examples for D templates in shorthand:

T exec(alias f,T)(T t) {
    return f(t);
}

I can’t find any examples that explain what this means. Can someone here explain it?

  • 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-06-15T14:31:42+00:00Added an answer on June 15, 2026 at 2:31 pm

    In a function template, the first set of parens hold the template arguments and the second set holds the function arguments.

    http://dlang.org/template.html#function-templates

    You could rewrite that as:

    template exec(alias f, T) {
        T exec(T t) {
             return f(t);
        }
    }
    

    At the usage point, if a template member has the same name as the template itself, you don’t have to write it twice. This is called the eponymous trick. http://www.bing.com/search?q=eponymous+trick+d+programming+language&qs=n&form=QBRE&pq=eponymous+trick+d+programming+languag&sc=0-0&sp=-1&sk=

    Though most D code I’ve seen uses the shorter format – the long template syntax is pretty rare for functions, classes, or structs, which can do it too: struct Foo(T) { } is a struct template with argument T.

    The arguments themselves in this exec template are “alias f”, which is any symbol you decide to pass it, e.g., a function or variable name, and “T”, just any generic type. The repeated T are references to that type.

    At the usage point, you’ll most likely see it like this:

    int foo(int a) { return a; } // just a regular function
    exec!(foo)(10); // instantiates the template with arguments (foo, int), and then calls the function.
    

    The second template argument here is figured out implicitly by the function arguments. This is very common with function templates: a lot of the template arguments are implicit so you rarely see them written out. You might see this referenced in D discussions as “IFTI”, which means “implicit function template instantiation”.

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

Sidebar

Related Questions

I have a processor component that can process a single File, InputStream, Reader, or
I have a question regarding caches that I'm not quite understanding Consider all the
My professor wrote this median function and I don't understand it very well. Can
I have a professor that doesn't understand source control very well. He asked us
Let's assume below scenario: In the multi-processor system we have, PIT that interrupt any
I have a requirement to create a background processor that works only when the
I have a Perl script that launches 2 threads,one for each processor. I need
There are some processors out there that don't have commercially released documents explaining what
I have two tables Department Professor in which Department has an attribute called HeadID
I have been taking a few graduate classes with a professor I like alot

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.