Comments (9)
I don't think we've ever hit upon that specific use case.
Have you looked at absl::Span
? It isn't exactly what you are looking for, but you can use it as a function parameter to accept a view into generic array data. It isn't specific to vector (so there is no push_back()
method, for instance), but it might work depending on your use case.
from abseil-cpp.
That would only work if the objet is read only. In my example, foo() could grow the vector to size beyond the initial capacity, moving data from the stack to the heap.A span would definitely not apply here.
from abseil-cpp.
I feared that was the case. Sounds like something @JonathanDCohen could consider as an enhancement to InlinedVector.
from abseil-cpp.
The contents of Span are mutable - if you need to grow beyond the input Span into a vector (moving data from stack to heap) that's doable, no?
Or is the point that you want to actually resize the underlying vector/InlineVector?
from abseil-cpp.
The content is mutable ok, but all the capability of InlinedVector, like resizing are lost. I don't see how the function using the Span is able to grow it safely, given that if it goes over the threshold that data is moved around. And all while keeping the InlinedVector object valid?
from abseil-cpp.
You can't grow the vector through a Span. However, I'll pint out that even if we used a proxy template Impl class, we make no guarantees about the stability of internal APIs and wouldn't support clients making functions with the kind of signature you suggest.
Typically for this I'll do something like
template <typename Vector>
void foo(Vector* v) {}
if you need push_back, emplace_back, etc, or just
void foo(Span<int> v) {}
if you just need access to the data.
from abseil-cpp.
Johathan,
You seems to suggest that because I refered to an "Impl" class, that is it part of the internal API, but that does not have to be the case. I should have you a different name ;-) Check what llvm has to say about SmallVectorImpl:
Even though it has "
Impl
" in the name, this is so widely used that it really isn't "private to the implementation" anymore. A name likeSmallVectorHeader
would be more appropriate.
As for:
template <typename Vector>
void foo(Vector* v) {}
I fail to see how the implementation of foo can compile without knowing about Vector, which would be "impossible" if foo is provided as an API/library.
The more I think about it the more I see that if I was to write new code, I would not need that feature that much. But what I,m trying to do is switching from std::vector/llvm::SmallVector to InlinedVector, with as little change as possible in existing code. It's when the InlinedVector is passed by referenced as an output that I hit a wall.
I'm mostly surprise that no one ever saw the need for this in something like absl, which makes me doubt my own sanity, lol!
Thanks for the feedback!
from abseil-cpp.
Let me make sure we're on the same page -- you're worried about if foo() was provided as an interface in a precompiled library. Then there's no way the compiler could generate foo<InlinedVector<MyType, N>>.
That's a case we don't really hit at Google because we compile everything from source and use static linking for most of our binaries.
from abseil-cpp.
There is that, yet but most importantly for me, don't want to force anyone using InlineVector in their API to force usage of template on their user.
Also, unfortunately we don't have access to a compiler farm to build stuff quickly, so cutting down on recompile, dependancies and stuff is of importance.
Thanks.
from abseil-cpp.
Related Issues (20)
- [Bug]: btree_multiset memory leak with ASAN enabled HOT 6
- [Bug]: Uninitialized value in AnyInvocable.
- [Bug]: Build failure MSVC x86 with /arch:AVX2 HOT 4
- [Bug]: ABSL_ATTRIBUTE_NORETURN doesn't work in all contexts HOT 1
- [Bug]: Compilation issue on Windows 2022 with Ninja and CMake
- [Bug]: Can't link using riscv64 toolchain
- use vcpkg install absl dll lib link error HOT 1
- [Bug]: Sanitizer options may disagree between library and user leading to ODR violations
- Can't link to MSVC built abseil with clang/LLVM
- improvement : keep cmakelists clean, remove unneeded policy activations that are already active HOT 2
- [Bug]: container test_allocator should be skipped if testing is disabled HOT 3
- [Bug]: Build error during cmake quick start HOT 1
- [Bug]: 20240722.rc1 can not be built for android ndk r25b / r25c HOT 3
- [Bug]: Can't build C++20 project without .bazelrc HOT 2
- [Bug]: absl::Log Initialization in DLL Fails When Called Using ctypes on Windows
- [Bug]: Flag "-Wnon-virtual-dtor" is added to pkg-config files
- [Bug]: error while loading shared libraries: libabsl_cord_internal.so.2401.0.0: cannot open shared object file: No such file or directory
- [Bug]: asan failure in absl::Status::ToString() HOT 3
- [Bug]: Compilation regression in version update: "...incomplete type 'absl::container_internal::HashEq..." HOT 2
- Have Bazel rules for creating shared libraries 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 abseil-cpp.