Browse Source

Fixed #15 but now regression on cbor 1-7

Optional was the cause and now we get a bunch of bad_optionals
master
Ludovic 'Archivist' Lagouardette 3 years ago
parent
commit
bb802d50a8
2 changed files with 40 additions and 3 deletions
  1. +1
    -0
      include/gp/containers/vector.hpp
  2. +39
    -3
      include/gp/functional/optional.hpp

+ 1
- 0
include/gp/containers/vector.hpp View File

@ -160,6 +160,7 @@ namespace gp{
elem.~T(); elem.~T();
} }
gp_config::assertion(alloc.get().deallocate(ary), "could not deallocate"); gp_config::assertion(alloc.get().deallocate(ary), "could not deallocate");
ary = nullptr;
} }
} }

+ 39
- 3
include/gp/functional/optional.hpp View File

@ -34,7 +34,23 @@ namespace gp{
constexpr optional(T&& value) constexpr optional(T&& value)
: ready{true} : ready{true}
{ {
new(buffer) T(gp::forward<T>(value));
new(buffer) T(gp::move(value));
}
constexpr optional(const optional& oth)
: ready{oth.ready}
{
if(ready) {
new(buffer) T(oth.value());
}
}
constexpr optional(optional&& oth)
: ready{oth.ready}
{
if(ready) {
new(buffer) T(gp::move(oth.value()));
}
} }
~optional() { ~optional() {
@ -63,10 +79,30 @@ namespace gp{
optional& operator=(T&& value) { optional& operator=(T&& value) {
if(ready) { if(ready) {
*(T*)buffer = gp::forward<T>(value);
*(T*)buffer = gp::move(value);
} else {
ready = true;
new(buffer) T(gp::move(value));
}
return *this;
}
optional& operator=(const optional& oth) {
if(ready) {
*(T*)buffer = oth.value();
} else {
ready = true;
new(buffer) T(oth.value());
}
return *this;
}
optional& operator=(optional&& oth) {
if(ready) {
*(T*)buffer = gp::move(oth.value());
} else { } else {
ready = true; ready = true;
new(buffer) T(gp::forward<T>(value));
new(buffer) T(gp::move(oth.value()));
} }
return *this; return *this;
} }

Loading…
Cancel
Save