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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:59:01+00:00 2026-06-02T04:59:01+00:00

Reading templates-revisited : struct S(T : T*) { T t; // t is supposed

  • 0

Reading templates-revisited:

struct S(T : T*) {
  T t;  // t is supposed to be of type 'int*', but it's of type 'int', why?
}

void main() {

  int x = 123;
  S!(int*) s;
  static assert(is(typeof(s.t) == typeof(&x)));
}

The above code doesn’t compile.

Strangely enough, the following does compile:

struct S(T : int*) {
  T t;
}

void main() {

  int x = 123;
  S!(int*) s;
  static assert(is(typeof(s.t) == typeof(&x)));
}

I don’t understand this behavior. An explanation would be appreciated.

  • 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-02T04:59:01+00:00Added an answer on June 2, 2026 at 4:59 am

    When a type specialization (the type after the colon) is dependent on the parameter identifier, such as T : T*, the resulting identifier refers to the role of the identifier (T) in the type specialization (the deduced type) if there was a match.

    Otherwise, if the specialization is independent, such as T : int*, the resulting identifier is an alias of the type specialization.

    Examples:

    =========================================================
    Argument T        | Specialization     | Result
    =========================================================
    void              | T : void           | void
    char              | T : void           | <no match>
    int*              | T : T*             | int
    immutable(char)[] | T : T[]            | immutable(char)
    immutable(char)[] | T : immutable(T)[] | char
    =========================================================
    

    When there is a mismatch for an argument passed to a template parameter, the template is dropped from the overload set. An error is raised if the overload set becomes empty before a match is found.

    When there is a mismatch in an IsExpression (the is(...) primary expression), the result is false and no symbols are introduced into scope.

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

Sidebar

Related Questions

I am reading C++ Templates Complete Guide and came across this non-type function template
Reading about Kohana templates and saw something I've never seen before: $this->template->title = __('Welcome
I am reading the chapter function templates of C++ Primer 3rd edition , and
I have been reading templates,functors,callback function for the past week and have referred some
I was reading http://technet.microsoft.com/en-us/library/aa834376(AX.50).aspx about creating email templates, and I was wondering if there
I've been reading the official docs about sending emails from Plone using some templates,
Reading C++ Templates: The Complete Guide and it says Note that templates cannot be
I was reading a book on templates and found the following piece of code:
Are C++ Templates just Macros in disguise? I was reading the above topic, and
Possible Duplicate: What are the disadvantages of using templates? Reading about templates I found

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.