digitalmars.D.learn - Is my T.init elaborate (eg: Not "0")
- monarch_dodra (10/10) May 05 2014 I'm looking for a way, to *statically* know if my type's ".init"
- Tobias Pankrath (2/13) May 05 2014 Foreach member x of Type X of T, check if T.init.x equals X.init?
- Tobias Pankrath (2/7) May 05 2014 Ah, sorry, didn't read carefully. This is not what you want.
- monarch_dodra (5/14) May 05 2014 Actually, I think you're on to something. I can recursively
I'm looking for a way, to *statically* know if my type's ".init" value is nothing but zeros. I need this to initialize a dynamic array: If the T.init is nothing but 0, then I can just memset the whole array in a single call. Otherwise, I have to memcpy T.init individually N times. Currently, I can (runtime) use "typeid(T).init.ptr": Types that don't have an an elaborate .init will return null. I'm trying to find the same result, without a runtime check. Anybody know how? I'd write a function that tests the bits of a T.init copy, but reinterpreting is not allowed during CTFE...
May 05 2014
On Monday, 5 May 2014 at 20:54:52 UTC, monarch_dodra wrote:I'm looking for a way, to *statically* know if my type's ".init" value is nothing but zeros. I need this to initialize a dynamic array: If the T.init is nothing but 0, then I can just memset the whole array in a single call. Otherwise, I have to memcpy T.init individually N times. Currently, I can (runtime) use "typeid(T).init.ptr": Types that don't have an an elaborate .init will return null. I'm trying to find the same result, without a runtime check. Anybody know how? I'd write a function that tests the bits of a T.init copy, but reinterpreting is not allowed during CTFE...Foreach member x of Type X of T, check if T.init.x equals X.init?
May 05 2014
On Monday, 5 May 2014 at 21:51:14 UTC, Tobias Pankrath wroteAh, sorry, didn't read carefully. This is not what you want.I'm trying to find the same result, without a runtime check. Anybody know how? I'd write a function that tests the bits of a T.init copy, but reinterpreting is not allowed during CTFE...Foreach member x of Type X of T, check if T.init.x equals X.init?
May 05 2014
On Monday, 5 May 2014 at 21:54:33 UTC, Tobias Pankrath wrote:On Monday, 5 May 2014 at 21:51:14 UTC, Tobias Pankrath wroteActually, I think you're on to something. I can recursively iterate on all basic types in my T, and check they are all "0" or NULL. Should work. Thanks!Ah, sorry, didn't read carefully. This is not what you want.I'm trying to find the same result, without a runtime check. Anybody know how? I'd write a function that tests the bits of a T.init copy, but reinterpreting is not allowed during CTFE...Foreach member x of Type X of T, check if T.init.x equals X.init?
May 05 2014