Ver código fonte

made variant more practical

cbor
Ludovic 'Archivist' Lagouardette 4 anos atrás
pai
commit
4caf7f2d21
1 arquivos alterados com 10 adições e 3 exclusões
  1. +10
    -3
      include/gp/variant.hpp

+ 10
- 3
include/gp/variant.hpp Ver arquivo

@ -18,7 +18,7 @@ namespace gp{
class fixed_variant{
std::size_t index = std::numeric_limits<std::size_t>::max();
char buffer[max_size<T...>()];
gp::function<void(void*)p">, dummy_allocator> dtor = [](void*){};
gp::function<void(void*)> dtor = [](void*){};
static_assert(all_of_fixed_size<T...>::value, "not fixed");
public:
template<typename U, typename std::enable_if<list_contains_class<U,T...>::value,int>::type>
@ -26,7 +26,7 @@ namespace gp{
: index{r_index_of<U, T...>::value}
{
new(buffer) U(value);
dtor = gp::function<void(void*)p">, dummy_allocator>([](void* thing){((U*)thing)->~U();});
dtor = gp::function<void(void*)>([](void* thing){((U*)thing)->~U();});
}
template<typename U, typename std::enable_if<list_contains_class<U,T...>::value,int>::type>
@ -34,10 +34,17 @@ namespace gp{
: index{r_index_of<U, T...>::value}
{
new(buffer) U(std::move(value));
dtor = gp::function<void(void*)p">, dummy_allocator>([](void* thing){((U*)thing)->~U();});
dtor = gp::function<void(void*)>([](void* thing){((U*)thing)->~U();});
}
template<typename U>
constexpr size_t alt() const {
return r_index_of<U, T...>::value;
}
size_t type() const {
return index;
}
template<typename U, typename std::enable_if<list_contains_class<U,T...>::value,int>::type>
void operator=(U& value)

Carregando…
Cancelar
Salvar