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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:40:18+00:00 2026-06-11T23:40:18+00:00

/** This is struct S. */ struct S(T) { static if(isFloatingPoint!T) { /// This

  • 0
/** This is struct S. */
struct S(T) {

  static if(isFloatingPoint!T)
  {
    /// This version works well with floating-point numbers.
    void fun() { }
  }
  else
  {
    /// This version works well with everything else.
    void fun() { }
    /// We also provide extra functionality.
    void du() { }
  }
}

Compiling with dmd -D, documentation is generated for the first block only. How do I get it to generate for the else block as well ?

  • 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-11T23:40:19+00:00Added an answer on June 11, 2026 at 11:40 pm

    For version blocks, it’s only the version which is used which ends up in the documentation (be it the first one or the last one or whichever in between). So, for instance, if you have a version block for Linux and one for Windows, only the one which matches the system that you compile on will end up in the docs.

    static if blocks outside of templates seem to act the same way. If they’re compiled in, then their ddoc comments end up in the docs, whereas if they’re not compiled in, they don’t.

    However, static if blocks inside templates appear to always grab the documentation from the first static if block, even if it’s always false. But considering that those static ifs can end up being both true and false (from different instantiations of the template) and that the compiler doesn’t actually require that the template be instantiated for its ddoc comments to end up in the generated docs, that makes sense. It doesn’t have one right answer like static if blocks outside of templates do.

    Regardless, it’s generally a bad idea to put documentation inside of a version block or static if, precisely because they’re using conditional compilation and may or may not be compiled in. The solution is to use a version(D_Ddoc) block. So, you’d end up with something like this:

    /// This is struct S
    struct S(T)
    {
        version(D_Ddoc)
        {
            /// Function foo.
            void fun();
    
            /// Extra functionality. Exists only when T is not a floating point type.
            void du();
        }
        else
        {
            static if(isFloatingPoint!T)
                void fun() { }
            else
            {
                void fun() { }
                void du() { }
            }
        }
    }
    

    I would also note that even if what you were trying to do had worked, it would look very bizarre in the documentation, because you would have ended up with foo in there twice with the exact same signature but different comments. static if doesn’t end up in the docs at all, so there’d be no way to know under what circumstances foo existed. It would just look like you somehow declared foo twice.

    The situation is similar with template constraints. The constraints don’t end up in the docs, so it doesn’t make sense to document each function overload when you’re dealing with templated functions which are overloaded only by the their constraints.

    One place where you don’t need version(D_Ddoc), however, is when you have the same function in a series of version blocks. e.g.

    /// foo!
    version(linux)
        void foo() {}
    else version(Windows)
        void foo() {}
    else
        static assert(0, "Unsupported OS.");
    

    The ddoc comment will end up in the generated documentation regardless of which version block is compiled in.

    It should be noted that the use of version(D_Ddoc) blocks tends to make it so when using -D, it makes no sense to compile your code for anything other than generating the documentation and that the actual executable that you run should be generated by a separate build which doesn’t use -D. You can put the full code in the version(D_Ddoc) blocks to avoid that, but that would mean duplicating code, and it wouldn’t really work with static if. Phobos uses version(StdDdoc) (which it defines for itself) instead of version(D_Ddoc) so that if you don’t use version(D_Ddoc) blocks, you can still compile with -D and have Phobos work, but once you start using version(D_Ddoc), you’re going to have to generate your documentation separately from your normal build.

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

Sidebar

Related Questions

I tried this struct Foo(T) { align(8) void[T.sizeof] data; } but static assert(Foo!(int).data.alignof ==
I have something like this: struct D { virtual void operator() {...}; } struct
This code compiles (as I would expect): typedef void __stdcall (*Func)(); struct A {
I defined a static struct in C like this: typedef static struct { int
I'm trying to use a lambda as a static member, like this: struct A
How to use this method: public static void DFT (Complex[] data, Direction direction) if
I currently have a class like this: struct Rgb { static const int NUM_CHANNELS
static struct K { int x; }; Is this valid in C and C++?
I have a struct like this: static struct F_t { char *_1; char *_2;
I have this struct; #define BUFSIZE 10 struct shared_data { pthread_mutex_t th_mutex_queue; int count;

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.