Increasing performance with static polymorphism (and other neat tricks) in D(atilanevesoncode.wordpress.com)
atilanevesoncode.wordpress.com
Increasing performance with static polymorphism (and other neat tricks) in D
http://atilanevesoncode.wordpress.com/2014/03/31/increasing-performance-with-static-polymorphism-and-other-neat-tricks/
1 comments
> Is there a way in D to check at compile time if a type is a POD type ?
http://dlang.org/phobos/std_traits#hasElaborateDestructor
I believe this is what you're looking for. Mayhap you need to combine it with hasElaborateCopyConstructor and/or other functions in std.traits.
http://dlang.org/phobos/std_traits#hasElaborateDestructor
I believe this is what you're looking for. Mayhap you need to combine it with hasElaborateCopyConstructor and/or other functions in std.traits.
scopebuffer's inclusion in Phobos was controversial. Many felt that its unusual design (such as lack of destructor), and ease of misuse, meant it shouldn't be there.
Can't the destructor issue be mitigated by
EDIT: To clarify, one could have two versions one with a destructor for non POD and the current one. The compiler dispatches to the appropriate one at compile time.
hasElaborateDestructor( )
that biotronic pointed me to ?EDIT: To clarify, one could have two versions one with a destructor for non POD and the current one. The compiler dispatches to the appropriate one at compile time.
No, as that doesn't convert anything to POD.
Is there a way in D to check at compile time if a type is a POD type ?
Strangely enough I had to implement something similar in C++ very recently. I went with a solution that uses alloca if the size is lower than some limit, else falls back to new. I was torn between whether to allocate an array statically or use alloca, eventually went with alloca although that is usually frowned upon. I expected this function to be called from multiple threads not all of which would need to allocate space, using an array on stack would have wasted space.
Wish C++ committee approved the proposal to have variable sized arrays like the ones C has now.