浏览代码

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 年前
父节点
当前提交
bb802d50a8
共有 2 个文件被更改,包括 40 次插入3 次删除
  1. +1
    -0
      include/gp/containers/vector.hpp
  2. +39
    -3
      include/gp/functional/optional.hpp

+ 1
- 0
include/gp/containers/vector.hpp 查看文件

@ -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 查看文件

@ -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;
}

正在加载...
取消
保存