digitalmars.D.learn - How can I check to see if template type is an array?
- Tim (6/6) Jan 19 2021 Hi all,
- Dennis (3/6) Jan 19 2021 `if(is(T == E[], E))` or `isDynamicArray!T` is you `import
- Paul Backus (3/9) Jan 19 2021 You've almost got it. The correct syntax is `is(T == U[], U)`.
- Tim (2/5) Jan 19 2021 Thanks! Do I need to specify U in the template function?
- Paul Backus (2/7) Jan 19 2021 No, only inside the is(...) expression.
- Tim (2/10) Jan 19 2021 What if it is a static array i.e. double[3]?
- Paul Backus (2/14) Jan 19 2021 is(T == U[n], U, size_t n)
- Tim (2/17) Jan 19 2021 Easy, thanks a lot!
Hi all, I need to be able to check in a template whether the type given is an array type so that I can do some different logic. How can I do this? I would have thought that if(is(T == [])) would work, but no. Thanks in advance
Jan 19 2021
On Tuesday, 19 January 2021 at 22:26:52 UTC, Tim wrote:I need to be able to check in a template whether the type given is an array type so that I can do some different logic. How can I do this?`if(is(T == E[], E))` or `isDynamicArray!T` is you `import std.traits;`
Jan 19 2021
On Tuesday, 19 January 2021 at 22:26:52 UTC, Tim wrote:Hi all, I need to be able to check in a template whether the type given is an array type so that I can do some different logic. How can I do this? I would have thought that if(is(T == [])) would work, but no. Thanks in advanceYou've almost got it. The correct syntax is `is(T == U[], U)`. You can read it as "there exists some type U such that T == U[]".
Jan 19 2021
On Tuesday, 19 January 2021 at 22:31:47 UTC, Paul Backus wrote:You've almost got it. The correct syntax is `is(T == U[], U)`. You can read it as "there exists some type U such that T == U[]".Thanks! Do I need to specify U in the template function?
Jan 19 2021
On Tuesday, 19 January 2021 at 22:34:04 UTC, Tim wrote:On Tuesday, 19 January 2021 at 22:31:47 UTC, Paul Backus wrote:No, only inside the is(...) expression.You've almost got it. The correct syntax is `is(T == U[], U)`. You can read it as "there exists some type U such that T == U[]".Thanks! Do I need to specify U in the template function?
Jan 19 2021
On Tuesday, 19 January 2021 at 22:36:47 UTC, Paul Backus wrote:On Tuesday, 19 January 2021 at 22:34:04 UTC, Tim wrote:What if it is a static array i.e. double[3]?On Tuesday, 19 January 2021 at 22:31:47 UTC, Paul Backus wrote:No, only inside the is(...) expression.You've almost got it. The correct syntax is `is(T == U[], U)`. You can read it as "there exists some type U such that T == U[]".Thanks! Do I need to specify U in the template function?
Jan 19 2021
On Tuesday, 19 January 2021 at 22:38:41 UTC, Tim wrote:On Tuesday, 19 January 2021 at 22:36:47 UTC, Paul Backus wrote:is(T == U[n], U, size_t n)On Tuesday, 19 January 2021 at 22:34:04 UTC, Tim wrote:What if it is a static array i.e. double[3]?On Tuesday, 19 January 2021 at 22:31:47 UTC, Paul Backus wrote:No, only inside the is(...) expression.You've almost got it. The correct syntax is `is(T == U[], U)`. You can read it as "there exists some type U such that T == U[]".Thanks! Do I need to specify U in the template function?
Jan 19 2021
On Tuesday, 19 January 2021 at 22:45:19 UTC, Paul Backus wrote:On Tuesday, 19 January 2021 at 22:38:41 UTC, Tim wrote:Easy, thanks a lot!On Tuesday, 19 January 2021 at 22:36:47 UTC, Paul Backus wrote:is(T == U[n], U, size_t n)On Tuesday, 19 January 2021 at 22:34:04 UTC, Tim wrote:What if it is a static array i.e. double[3]?On Tuesday, 19 January 2021 at 22:31:47 UTC, Paul Backus wrote:No, only inside the is(...) expression.You've almost got it. The correct syntax is `is(T == U[], U)`. You can read it as "there exists some type U such that T == U[]".Thanks! Do I need to specify U in the template function?
Jan 19 2021