Ver código fonte

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 anos atrás
pai
commit
bb802d50a8
2 arquivos alterados com 40 adições e 3 exclusões
  1. +1
    -0
      include/gp/containers/vector.hpp
  2. +39
    -3
      include/gp/functional/optional.hpp

+ 1
- 0
include/gp/containers/vector.hpp Ver arquivo

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

+ 39
- 3
include/gp/functional/optional.hpp Ver arquivo

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

Carregando…
Cancelar
Salvar