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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:52:29+00:00 2026-05-23T08:52:29+00:00

Reading TDPL about function and delegate literals (5.6.1) auto f = (int i) {};

  • 0

Reading TDPL about function and delegate literals (5.6.1)

auto f = (int i) {}; 
assert(is(f == function));

I’ve got an assertion failure. Is this assertion correct?

I tried the following:

int z = 5;
auto f = (int i) { return i < 5; };
auto d = (int i) { return i < z; };
assert(is(typeof(f) == typeof(d)));

Assertion is valid there. Actually f is a delegate, not a function even if it doesn’t need a frame pointer to access local variables. Is this a bug?

Also, I do not understand how assert(is(f == function)); should work.

I tried assert(is(f == delegate)); but it was failed also. What’s wrong?

I use DMD32 D Compiler v2.053

UPDATE

auto f = (int i) {};
assert(is(typeof(f) == delegate))

Works correct, although there is no reason to be a delegate

But

auto f = function (int i) {};
assert(is(typeof(f) == void function(int))); // correct
assert(is(typeof(f) == function));           // failed!!!!!

Miracle. It seems D2 is not ready for production use yet.

  • 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-23T08:52:29+00:00Added an answer on May 23, 2026 at 8:52 am

    “f” is a variable. The is expression compares types. This should work:

    assert(is(typeof(f) == delegate));
    

    If you want to create a function instead of a delegate, you can use the function literal syntax:

    auto f = function (int i) { ... };
    assert(is(typeof(f) == function));    // should be true
    

    If the function literal syntax is not used, the literal is assumed to be delegate (Expressions, look under “Function Literals”. This makes sense because D should not change the type based on the whether the body of the literal needs the stack frame (this would be super screwy). EDIT: TDPL does actually specify that the compiler will infer a function instead of a delegate if it can, regardless of the “function” keyword. This seems like a poor idea to me, so this might be something that has been dropped.

    As to why the is(f == function) doesn’t work, this looks like a regression.

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

Sidebar

Related Questions

Reading over the responses to this question Disadvantages of Test Driven Development? I got
Reading about how Google solves the translation problem got me thinking. Would it be
Reading online about this topic is confusing. Is there a way to cut around
Reading a post about redis I saw this word: REPL . Can someone tell
Reading about the G.729 codec , I found this interesting tidbit about Comfort Noise
Reading this blog post about HttpOnly cookies made me start thinking, is it possible
Reading through this , I came to the bit on default values for function
Reading through the C specs I found this function: double remquo(double x, double y,
Reading this question I found this as (note the quotation marks) code to solve
Reading MSDN (and other sources) about custom report items (CRI) for reporting services 2005.

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.