« first day (1495 days earlier)      last day (1341 days later) » 

5:12 AM
0
Q: std::pair<> equivalent of a node in a linked list

d4rk4ng31Consider the following code: class LinkedList { struct Node { int ivar = 0; Node* next = nullptr; } //functions, ctors and dtor }; Is there an std::pair equivalent for the struct? Something like: class LinkedList { std::pair<int, <what goes here??>> node; };

Help guys please
 
5:33 AM
Also, will struct Node { std::pair<int, Node*> pair; }; too cause infinite recursion?
 
 
2 hours later…
nwp
8:02 AM
@d4rk4ng31 Seems to be deleted.
@d4rk4ng31 It doesn't.
 
 
16 hours later…
11:53 PM
I have written an allocator for fixed block memory. For instance, you may pass in a mapped memory page, or you may pass in a buffer, and it will doll out memory from that.
The problem is that I am trying to comply with the allocator template, and I also have an allocator that by necessity must keep state.
I have written my copy constructor, along with my move-assignment operator, to carefully copy in the state of the origin instance so that the state (a single block of memory) can be transferred safely.
However, I'm not sure how to handle the rebind template I need to support.
Or rather, I'm not sure how the rebind actually will construct new instances of the allocator.
Can anyone perhaps give some insight on how that mechanism works? The allocator can allocate memory for different types, but some state needs to be transferred.
tl;dr: allocator template classes should be stateless, but I'm trying to design one that can share the memory pool given when rebound, and I'm not sure how. I know it's kind of an abuse of the template, but I am interested in being able to use the convenience of providing my own allocator. Open to other approaches too!
 

« first day (1495 days earlier)      last day (1341 days later) »