Browse Source

enable_if issue

cbor
Ludovic 'Archivist' Lagouardette 4 years ago
parent
commit
b4d47633d8
9 changed files with 70 additions and 33 deletions
  1. +1
    -1
      include/gp/algorithm/modifiers.hpp
  2. +1
    -1
      include/gp/array.hpp
  3. +1
    -1
      include/gp/bloomfilter.hpp
  4. +19
    -7
      include/gp/enveloppe/cbor.hpp
  5. +14
    -7
      include/gp/pair.hpp
  6. +21
    -14
      include/gp/variant.hpp
  7. +2
    -2
      include/gp/vector.hpp
  8. +10
    -0
      tests/bloomfilter.cpp
  9. +1
    -0
      tests/cbor_test.cpp

+ 1
- 1
include/gp/algorithm/modifiers.hpp View File

@ -75,7 +75,7 @@ namespace gp {
template< class T > template< class T >
struct remove_cvref { struct remove_cvref {
typedef std::remove_cv_t<std::remove_reference_t<T>> type;
using type = std::remove_cv_t<std::remove_reference_t<T>>;
}; };
template< class T > template< class T >

+ 1
- 1
include/gp/array.hpp View File

@ -30,7 +30,7 @@ namespace gp{
template<typename ...U> template<typename ...U>
array(U&& ...values) array(U&& ...values)
: ary{gp::move((T&&)values)...}
: ary{gp::forward<U>((T&&)values)...}
{} {}
array(array&& values) array(array&& values)

+ 1
- 1
include/gp/bloomfilter.hpp View File

@ -17,7 +17,7 @@ namespace gp {
uint32_t uint32_t
>::type, >::type,
phys_size phys_size
> data;
> data{};
template<typename T> template<typename T>
static void set_bit(T* value, const int v_pos) { static void set_bit(T* value, const int v_pos) {

+ 19
- 7
include/gp/enveloppe/cbor.hpp View File

@ -76,13 +76,13 @@ namespace gp {
template<typename T> template<typename T>
using cbor_composite = gp::fixed_variant< using cbor_composite = gp::fixed_variant<
cbor_number, cbor_number,
c1">//gp::buffer<std::byte>,
c1">//bool,
c1">//gp::vector<T>,
n">gp::buffer<std::byte>,
kt">bool,
n">gp::vector<T>,
gp::vector<gp::pair<T, T>>, gp::vector<gp::pair<T, T>>,
c1">//gp::nullopt_t,
undefined_tc1">//,
c1">//cbor_floating_point
n">gp::nullopt_t,
undefined_tp">,
n">cbor_floating_point
>; >;
class cbor_value { class cbor_value {
@ -101,7 +101,7 @@ namespace gp {
, alloc(alloc_v) , alloc(alloc_v)
{} {}
cbor_value(cbor_value& oth)
cbor_value(k">const cbor_value& oth)
: contents(oth.contents) : contents(oth.contents)
, alloc(oth.alloc) , alloc(oth.alloc)
{} {}
@ -128,6 +128,18 @@ namespace gp {
return *this; return *this;
} }
template<typename T>
cbor_value& operator=(T& value) {
contents = value;
return *this;
}
template<typename T>
cbor_value& operator=(T&& value) {
contents = gp::move(value);
return *this;
}
auto new_array() { auto new_array() {
return gp::vector<cbor_value>{alloc}; return gp::vector<cbor_value>{alloc};

+ 14
- 7
include/gp/pair.hpp View File

@ -10,19 +10,26 @@ namespace gp{
pair() : first(), second() {} pair() : first(), second() {}
pair(const T1& a, const T2& b) : first(a), second(b) {}
pair(T1& a, T2& b) : first(a), second(b) {}
pair(T1& a, T2&& b) : first(a), second(gp::move(b)) {}
pair(T1&& a, T2& b) : first(gp::move(a)), second(b) {}
pair(T1&& a, T2&& b) : first(gp::move(a)), second(gp::move(b)) {}
pair(const pair& v)
: first(v.first)
, second(v.second)
{}
pair(pair& v)
: first(v.first)
, second(v.second)
{}
pair(pair&& v) pair(pair&& v)
: first(gp::move(v.first)) : first(gp::move(v.first))
, second(gp::move(v.second)) , second(gp::move(v.second))
{} {}
template<typename U1, typename U2>
pair(U1&& a, U2&& b)
: first(gp::forward<U1>(a))
, second(gp::forward<U2>(b))
{}
template<typename U1, typename U2> template<typename U1, typename U2>
pair(pair<U1, U2>&& v) pair(pair<U1, U2>&& v)
: first(gp::move(v.first)) : first(gp::move(v.first))

+ 21
- 14
include/gp/variant.hpp View File

@ -31,27 +31,34 @@ namespace gp{
mvtor(oth.buffer, tmp); mvtor(oth.buffer, tmp);
} }
public: public:
template<typename Uo">>//, typename std::enable_if<list_contains_class<U,T...>::value,int>::type>
k">constexpr fixed_variant(U& value)
template<typename Up">, typename = std::enable_if_t<list_contains_class<gp::remove_cvref_t<U>,T...>::value,int>>
fixed_variant(U& value)
: index{r_index_of<U, T...>::value} : index{r_index_of<U, T...>::value}
{ {
new(buffer) U(value);
dtor = gp::function<void(void*)>([](void* thing){((U*)thing)->~U();}, nullopt);
cpytor = gp::function<void(void*, void*)>([](void* src, void* dest){new(dest) U(*(U*)src);}, nullopt);
mvtor = gp::function<void(void*, void*)>([](void* src, void* dest){new(dest) U(gp::move(*(U*)src));}, nullopt);
using actual = gp::remove_cvref_t<U>;
new(buffer) actual(value);
dtor = gp::function<void(void*)>([](void* thing){((actual*)thing)->~actual();}, nullopt);
cpytor = gp::function<void(void*, void*)>([](void* src, void* dest){new(dest) actual(*(actual*)src);}, nullopt);
mvtor = gp::function<void(void*, void*)>([](void* src, void* dest){new(dest) actual(gp::move(*(actual*)src));}, nullopt);
} }
template<typename U>//, typename std::enable_if<list_contains_class<U,T...>::value,int>::type>
constexpr fixed_variant(U&& value)
static_assert(list_contains_class<int, int>::value, "list_contains_class doesn't work properly");
static_assert(list_contains_class<int, char, int>::value, "list_contains_class doesn't work properly");
static_assert(list_contains_class<int, int, char>::value, "list_contains_class doesn't work properly");
static_assert(list_contains_class<int, char, int, char>::value, "list_contains_class doesn't work properly");
template<typename U, typename = std::enable_if_t<list_contains_class<gp::remove_cvref_t<U>,T...>::value,int>>
fixed_variant(U&& value)
: index{r_index_of<U, T...>::value} : index{r_index_of<U, T...>::value}
{ {
new(buffer) U(std::move(value));
dtor = gp::function<void(void*)>([](void* thing){((U*)thing)->~U();}, nullopt);
cpytor = gp::function<void(void*, void*)>([](void* src, void* dest){new(dest) U(*(U*)src);}, nullopt);
mvtor = gp::function<void(void*, void*)>([](void* src, void* dest){new(dest) U(gp::move(*(U*)src));}, nullopt);
using actual = gp::remove_cvref_t<U>;
new(buffer) actual(std::move(value));
dtor = gp::function<void(void*)>([](void* thing){((actual*)thing)->~actual();}, nullopt);
cpytor = gp::function<void(void*, void*)>([](void* src, void* dest){new(dest) actual(*(actual*)src);}, nullopt);
mvtor = gp::function<void(void*, void*)>([](void* src, void* dest){new(dest) actual(gp::move(*(actual*)src));}, nullopt);
} }
k">constexpr fixed_variant(fixed_variant& oth)
fixed_variant(fixed_variant& oth)
: index{oth.index} : index{oth.index}
, dtor{oth.dtor} , dtor{oth.dtor}
, cpytor{oth.cpytor} , cpytor{oth.cpytor}
@ -60,7 +67,7 @@ namespace gp{
cpytor(oth.buffer, buffer); cpytor(oth.buffer, buffer);
} }
k">constexpr fixed_variant(fixed_variant&& oth)
fixed_variant(fixed_variant&& oth)
{ {
mvtor(buffer, oth.buffer); mvtor(buffer, oth.buffer);
gp::swap(dtor, oth.dtor); gp::swap(dtor, oth.dtor);

+ 2
- 2
include/gp/vector.hpp View File

@ -23,12 +23,12 @@ namespace gp{
, alloc(v) , alloc(v)
{} {}
vector(const vector& oth)
vector(vector& oth)
: alloc(oth.alloc)
{ {
sz = 0; sz = 0;
cap = 0; cap = 0;
ary = nullptr; ary = nullptr;
alloc = oth.alloc;
gp_config::assertion(reserve(oth.size()), "could not reserve space on building"); gp_config::assertion(reserve(oth.size()), "could not reserve space on building");
sz = oth.size(); sz = oth.size();
cap = oth.size(); cap = oth.size();

+ 10
- 0
tests/bloomfilter.cpp View File

@ -55,6 +55,15 @@ struct bfilter2_test : public test_scaffold {
name += std::to_string(seedB); name += std::to_string(seedB);
} }
bfilter2_test(uint32_t a, uint32_t b) {
seedA = a;
seedB = b;
name = __FILE__ ":2_seedA";
name += std::to_string(seedA);
name += "&seedB";
name += std::to_string(seedB);
}
virtual int run() { virtual int run() {
cheap_rand setter(seedA); cheap_rand setter(seedA);
@ -83,6 +92,7 @@ struct bfilter2_test : public test_scaffold {
}; };
append_test dummy_r2gflu3(new bfilter2_test{}); append_test dummy_r2gflu3(new bfilter2_test{});
append_test dummy_rsdgueiu3(new bfilter2_test{3780040561, 79423740});
struct bfilter3_test : public test_scaffold { struct bfilter3_test : public test_scaffold {
uint32_t seed; uint32_t seed;

+ 1
- 0
tests/cbor_test.cpp View File

@ -16,6 +16,7 @@ struct cbor_test : public test_scaffold {
auto gen = data.new_object(); auto gen = data.new_object();
gen.emplace_back(gp::cbor_value{uint8_t(12), alloc}, gp::cbor_value{int32_t(-98), alloc}); gen.emplace_back(gp::cbor_value{uint8_t(12), alloc}, gp::cbor_value{int32_t(-98), alloc});
gen.emplace_back(gp::cbor_value{uint8_t(13), alloc}, gp::cbor_value{uint32_t(98), alloc}); gen.emplace_back(gp::cbor_value{uint8_t(13), alloc}, gp::cbor_value{uint32_t(98), alloc});
data = gen;
return 0; return 0;
} }
}; };

Loading…
Cancel
Save