Skip to main content

Timeline for A vector implementation

Current License: CC BY-SA 3.0

19 events
when toggle format what by license comment
S Nov 15, 2017 at 12:21 history suggested Vladislavs Burakovs CC BY-SA 3.0
"constructible be" -> "constructible from" and "unamed" -> "unnamed"
Nov 15, 2017 at 8:54 review Suggested edits
S Nov 15, 2017 at 12:21
Nov 15, 2017 at 8:34 comment added Loki Astari @Vladislavs Burakovs Please don't fix my code without asking. Especially if you get it wrong. Next time make a comment of what you think is wrong and I will validate. Please feel free to fix grammer and spelling.
Nov 15, 2017 at 8:31 review Suggested edits
Nov 15, 2017 at 8:32
Nov 14, 2017 at 8:46 vote accept Yukine Tokisaki
Nov 11, 2017 at 5:08 comment added Peter Cordes One recommendation I've read is that it would be better in this case to write reserved_size(n + n / 2 + 1), storage(new T[n + n / 2 + 1]) and recalculate in terms of constructor parameters.
Nov 11, 2017 at 5:06 comment added Peter Cordes IIRC, it's considered risky / poor style to read member variables in the initializer list, because initialization order depends on declaration order, not the order they appear in the initializer list. e.g. reserved_size(n + n / 2 + 1), storage(new T[reserved_size]) works not because you wrote them in that order there, but because they're declared in that order in the class. Your initializer list order doesn't match declaration order (you swap vector_size with reserved_size); if you're going to depend on that order, copy it exactly so you can enable compiler options to check it.
Nov 11, 2017 at 2:59 comment added Loki Astari @Yakk You can get that with T* which is the next step after char*. The type aligned_storage_t is when your buffer is a local object.
Nov 10, 2017 at 22:47 comment added Yakk @LokiAstari Well, you get [] for free and it is an actual array instead of a buffer with objects created in it. /shrug.
Nov 10, 2017 at 22:29 comment added Loki Astari @Yakk as I explained in a previous comment (its not necessary)
Nov 10, 2017 at 21:53 comment added Yakk Instead of char* why not std::aligned_storage_t< sizeof(T), alignof(T) >*?
Nov 10, 2017 at 18:59 comment added Incomputable @LokiAstari, as I noted above, it never copies elements. It doesn't matter how you pass it. It also seems like one cannot copy it anyway.
Nov 10, 2017 at 16:52 comment added WorldSEnder @LokiAstari where I was getting at was to separate size and capacity which is, I realize now, something you have not put explicitly in your answer. Constructing objects in advance as in new T[reserved_size] is not allowed if the constructor of T has side effects.
Nov 10, 2017 at 16:37 history edited Loki Astari CC BY-SA 3.0
deleted 1 character in body
Nov 10, 2017 at 16:33 comment added Loki Astari @Incomputable: What about std::initializer_list<int> data{1,2,3,4};std::vector v(data); As far as I can tell std::initializer_list has no intrinsic magic properties that make it work differently (apart from syntax helping). Its just that normal use case is highly optimized.
Nov 10, 2017 at 16:32 comment added Loki Astari @WorldSEnder char* can point at any location. Also if you ask for (dynamically allocate with new) a block larger than size T then it is automatically aligned for objects of type T. Note: if memory is aligned for objects of size 2^n then it is also aligned for objects of size 2^(n+1) and all alignment is done on 2^m boundaries. The use of std::aligned_storage is when you are allocating the memory locally (ie automatic storage duration) or inside another object (ie automatic storage duration).
Nov 10, 2017 at 10:59 comment added Incomputable std::initializer_list never copies elements, it is meant to be passed by value.
Nov 10, 2017 at 8:55 comment added WorldSEnder instead of using char[] as your storage class, you might want to use std::aligned_storage<sizeof(T), alignof(T)>::type
Nov 10, 2017 at 6:57 history answered Loki Astari CC BY-SA 3.0