Comments (5)
This post got the wrong qualifier. It's actually two suggested enhancement
s and one bug
(or major inefficiency at least, since move
won't guarantee a move but may very well copy when dealing with legacy code or something that doesn't satisfy Movable
).
Please re-read my post, or, if it's too long, just re-read your code I cited above and keep in mind that deque::emplace_back
should never ever change the memory locations of elements already in the container.
from eastl.
For emplace_back, its not clear to me what change you are suggesting? I'd agree this code is subtle and I'm not exactly sure what guarantee the standards give for moving elements that originate from within the container. I'd have to read up on that.
from eastl.
I'm not exactly sure what guarantee standards give for moving elements that originate from within the container. I'd have to read up on that.
<cite, from the second link to stackoverflow given above>
ยง23.2.1.3 guarantees that while iterators into the dequeue are invalidated, pointers and references to the elements are still valid: An insert in the middle of the deque invalidates all the iterators and references to elements of the deque. An insert at either end of the deque invalidates all the iterators to the deque, but has no effect on the validity of references to elements of the deque.
</cite>
So there would be the paragraph to verify.
This means that deque::emplace_back
must never reallocate the objects, it may have to do so for the bookkeeping data, but that's about how far it goes (other than std::vector::emplace_back
which will eventually relocate the objects).
For emplace_back, its not clear to me what change you are suggesting?
Get rid of that subtle and inefficient dance and just go
if need be {
grow container
}
call placement new with the reference which must still be valid, no matter what
In fact, I guess you can just delete the overload and let the variadic version do the right thing :-).
from eastl.
This reallocation issue has become even more relevant since C++17's emplace_back
finally returns a reference to the inserted object.
template< class... Args >
reference emplace_back( Args&&... args );
It is unfortunate that vagaries such as this (and I'm not referring to your library here, I had an issue with MSVC's std::unordered_map changing references) have led to me habitually using a std::list to store data when I need to be sure the reference will remain unchanged, and using (e.g.) std::unordered_map as an index into std::list.
My only suggestion would be that it be strongly documented that your class does not comply with (as phrased at http://en.cppreference.com/w/cpp/container/deque/emplace_back) - "No references are invalidated." (If this is indeed the case).
from eastl.
It seems interest hasn't picked up on this ticket. Please re-open with additional information and/or provide a PR for specific changes you would like to see.
from eastl.
Related Issues (20)
- Incorrect behaviour of vector (and other) with switched off exceptions HOT 1
- [MSVC][std:c++latest] EASTL failed to build with msvc due to error C2338 on Windows
- Eastl is susport windows kernel? HOT 1
- Building EASTL HOT 1
- [MSVC][std:c++latest] EASTL build failed due to error C2666: 'TestLruCacheInternal::Foo::operator ==': overloaded functions have similar conversions HOT 2
- intrusive_slist is not implemented
- No signed tarball for releases
- Build with Clang15 results in warnings about deprecated builtins HOT 1
- Inquiry about the expected behavior of the comparison operators in RingBuffer HOT 1
- compilation error due to `std::remove_reference` HOT 5
- Tests fail to compile: error: use of undeclared identifier 'getpid'
- Tests fail to compile: error: use of undeclared identifier 'pthread_attr_get_np'
- Tests fail to link: ld: error: undefined symbol: EA::EAMain::InitializeSignalHandler()
- Consider using reset() for fast container teardown - Best pratices HOT 2
- emscripten support? HOT 1
- [Question] Should eastl::unordered_set.reserve not check if a change is required?
- Error of RBTreeDecrement function HOT 3
- Move semantic dosn't work with eastl::list HOT 2
- Critical silent bug: vector push back of an own element moves it and calls a copy constructor on the invalidated reference HOT 1
- Overriding make_unique and default_delete HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eastl.