Quote:Original post by Erzengeldeslichtes
That's the same thing as option 2, except not in a single line. With option 2 I could do Array(3, {new bar, new bar2, new bar3}); and have exactly the same result except with my array.
Why do you even bother considering 'options' which are illegal? There is no such thing as an array literal.
Quote:Of course the downside with the overloaded operators is that it then only adds one at a time, requiring the most number of resizes, wheras with varg I'd be able to get the number of elements (I think), size it to that, and add them.
No. Varargs require you to, somehow, tell the compiler when the end of the argument list is reached. printf does it simply by counting the placeholders. Another option is to end the list with a null pointer (as the argv array is).
If you're worried about performance, add an initial parameter that calls std::vector::reserve(). All that an incorrect parameter costs you is some time - you won't have any correctness problem.
Quote:Same deal with static array, I size it to the size you give me and then copy that many from your static array.
Except you still have to find that size, somehow. There are template tricks you can pull to make sure a genuine array is given as parameter (yes, in two steps) and find the number of its elements.
[quote[If I were to switch to std::vector I'd still have to either create a wrapper or derive a new vector because I have functions in the array that work on the members of the array (as I said, it's specialized for my types)
What's wrong with creating wrappers?
STL containers are not designed to be inherited from.
Quote:Original post by Anonymous Poster
Dude, you can only have 2 of elegence, safety and efficiency. Switch to STL
You can have all three, though making code elegant from the user's point of view often requires much work from the implementor's point of view.
Extrarius - You've done function overloads, not template specialisations. I don't think that'll work as you want it to.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan