Comments (6)
This is modeled after p<> where a conversion operator for a non-const reference would require a snapshot. Such approach would probably lead to many unnecessary snapshots, that's why there are explicit getters.
For consistency sake, v<> behaves the same, and to get a mutable reference, you have to call get()
. But... I guess returning a reference would make more sense in this case, since there's no snapshot.
Can we have both though? How would the compiler choose between a conversion to T and T&?
from libpmemobj-cpp.
I don't think you can have both. The compiler cannot do overload resolution for you based on the return type and that is what you are suggesting, right? I'm not up to date on the topic, so sorry if I'm far off with my comment.
There is syntax where the compiler can behave differently for rvalues, but that is not the case here, right?
from libpmemobj-cpp.
Return type is not part of function signature. But if you would like to have both we can have const and non-const versions of the conversion operator:
`operator T &() noexcept
{
return this->get();
}
operator const T&() const noexcept
{
return this->get();
}`
Note, that in my example even const version does not return by value. I am using const reference. It helps to avoid unnecessary copy. Furthermore, type T might have no copy-constructor.
from libpmemobj-cpp.
I think in case of conversion to T&
it will be ok to have just one non-const conversion operator. After all, T&
can be used in context where const T&
is required, right?
from libpmemobj-cpp.
@igchor I agree with you. This changes already part of #40
from libpmemobj-cpp.
We have already merged this change to master. We also fixed some other issues with v which we found while testing operator T& so you should probably rebase.
from libpmemobj-cpp.
Related Issues (20)
- [doc] Update comments in atomic_persistent_aware_ptr to hide implementation details HOT 1
- gcc-12 radix_tree fail: no decltype matches HOT 7
- redefinitions in ebr.hpp
- libpmemobj-cpp as a cmake submodule HOT 1
- make error! HOT 9
- Valgrind not found, but flag TESTS_USE_VALGRIND was set. HOT 6
- fails to build with tbb→onetbb
- concurrent_hash_map HOT 6
- Read garbled code HOT 6
- using hashmap_type = concurrent_hash_map<string, p<int>>; HOT 3
- Why do not make install? HOT 3
- concurrent_hash_map HOT 3
- pmem::transaction_out_of_memory HOT 6
- ndctl create-namespace HOT 3
- avx access beyond end of string HOT 1
- Possible atomic_persistent_aware_ptr_pmreorder failures with FullReorder engine
- radix-tree HOT 3
- Can it be used and built with Mingw64 in MSYS2 HOT 2
- Does libpmemobj or libpmemobj-cpp support dev-dax mode? HOT 5
- multiple definition of pmem::detail::ebr HOT 1
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 libpmemobj-cpp.