Ownership of internal resources can be transferred, and emplace_back even allows constructing your object in place.
As others said, the O(n) really becomes more like pseudo-O(1) due to cache effects unless you have elements the size of your cache lines (in which case prefetching still helps) or you're only fetching one element at a time and then triggering a context switch (as in a scheduler).
I'm not bashing your library, and if you prefer to use C then that's great, but it's kind of unfair to blame it on the language in the first place.
This is just inertia and only true on UNIX world due to how C is tied to UNIX.
BeOS, Symbian, Genode -> C++
Mac OS X -> drivers are done in C++ (IOKit)
Windows -> C is now official deprecated and C++ is the way to go. (http://herbsutter.com/2012/05/03/reader-qa-what-about-vc-and... && Herb's remarks at BUILD 2012)
Now C++ comes with new/delete, dynamic_cast<>, throw/catch/etc, RAII, always export "C" interface (to avoid mangling) - While all of these are useful, due to the constraint where the language has to be used they can be forbidden. It's no longer functions that you are restricting from being called (as in "C"), you are forbidding to use parts of the language that are considered by many as vital, and it's basically a different language at this point.
Even if that's the only C++ feature that a project were to use, I'd still consider it a net gain. Anything that makes your program less susceptible to manual resource management bugs in "goto cleanup"-style C is worth using. This doesn't just include memory leaks, but more insidious problems like unclear ownership of various system resources (sockets, file handles...). Things not even a GC would help you with in a long-running server process.
There are several popular "C" libraries that use them - jpeglib comes to mind, but there are others. Also certain language's runtime environment uses it. There is a way to handle it, but you need to take care.
To get defined behaviour with regards to destructors, you simply have to make sure that the function calling setjmp doesn't internally use RAII. Call a wrapper function to do the setjmp and you're safe.
Of course it's a whole other question whether using setjmp/longjmp to implement "exception handling in C" is a good idea in the first place.
1) https://developer.apple.com/library/mac/documentation/Device...
Yes, it is true it wasn't well accepted in the community and never really took off.
Still it is a C++ subset, not C, which is what this discussion is all about, regarding the use of C++ in kernel space.
1) He can solve the issue by requiring C++11 (!!)
2) Just rely on cache-effects making it pseudo-O(1), unless (insert various cases where it might blow).
Sure, he can jump through 200 hoops to use C++, special features, rely on CPU cache behavior, finetune to death, etc -- or, you know, he can use C and be done with it...
2) You missed the part where there's nothing preventing anyone from using intrusive lists in C++.
template <typename T>
void remove(std::vector<T>& v, std::size_t i)
{
std::swap(v[i], v.back());
v.resize(v.size() - 1);
}That wasn't an option for ZeroMQ which was started in 2007.
For the use case required by ZeroMQ, it's faster in all cases, because swap-with-last and shrink is O(1). Sure, if CPUs didn't have caches, a list might be faster.
Do you see where this is going? The C way of solving problems consists of adding one more level of indirection (ever heard of 3-star C programmers?), because it becomes more efficient asymptotically that way. Nevermind the hidden factor of 100-1000 due to pipeline stalls and cache misses.
Fortunately not all C programmers think that way.
Removal with intrusive containers: flip two pointers.
Removal with std::vector<>: copy all the subsequent items in the vector one position backwards.
A vector will still give you better cache-locality and also amortize the number of allocations.
I've probably spent more years writing C++ code than C code, but I'm all with him on this - if what you need to do for whatever reason don't need/benefit all that much from C++ when accounting for all constraints, then choosing C as being the lowest common denominator between other languages is a very good choice for a library.