From b4d47633d81fd9dcc1e811c61317faaf491c6aac Mon Sep 17 00:00:00 2001 From: Ludovic 'Archivist' Lagouardette Date: Mon, 12 Oct 2020 09:03:14 +0200 Subject: [PATCH] enable_if issue --- include/gp/algorithm/modifiers.hpp | 2 +- include/gp/array.hpp | 2 +- include/gp/bloomfilter.hpp | 2 +- include/gp/enveloppe/cbor.hpp | 26 ++++++++++++++++------ include/gp/pair.hpp | 21 ++++++++++++------ include/gp/variant.hpp | 35 ++++++++++++++++++------------ include/gp/vector.hpp | 4 ++-- tests/bloomfilter.cpp | 10 +++++++++ tests/cbor_test.cpp | 1 + 9 files changed, 70 insertions(+), 33 deletions(-) diff --git a/include/gp/algorithm/modifiers.hpp b/include/gp/algorithm/modifiers.hpp index b8d8706..8fd440c 100644 --- a/include/gp/algorithm/modifiers.hpp +++ b/include/gp/algorithm/modifiers.hpp @@ -75,7 +75,7 @@ namespace gp { template< class T > struct remove_cvref { - typedef std::remove_cv_t> type; + using type = std::remove_cv_t>; }; template< class T > diff --git a/include/gp/array.hpp b/include/gp/array.hpp index 1c93cbd..e6f55ee 100644 --- a/include/gp/array.hpp +++ b/include/gp/array.hpp @@ -30,7 +30,7 @@ namespace gp{ template array(U&& ...values) - : ary{gp::move((T&&)values)...} + : ary{gp::forward((T&&)values)...} {} array(array&& values) diff --git a/include/gp/bloomfilter.hpp b/include/gp/bloomfilter.hpp index c3bc4d6..2bd663e 100644 --- a/include/gp/bloomfilter.hpp +++ b/include/gp/bloomfilter.hpp @@ -17,7 +17,7 @@ namespace gp { uint32_t >::type, phys_size - > data; + > data{}; template static void set_bit(T* value, const int v_pos) { diff --git a/include/gp/enveloppe/cbor.hpp b/include/gp/enveloppe/cbor.hpp index cc2f425..95b79a4 100644 --- a/include/gp/enveloppe/cbor.hpp +++ b/include/gp/enveloppe/cbor.hpp @@ -76,13 +76,13 @@ namespace gp { template using cbor_composite = gp::fixed_variant< cbor_number, - //gp::buffer, - //bool, - //gp::vector, + gp::buffer, + bool, + gp::vector, gp::vector>, - //gp::nullopt_t, - undefined_t//, - //cbor_floating_point + gp::nullopt_t, + undefined_t, + cbor_floating_point >; class cbor_value { @@ -101,7 +101,7 @@ namespace gp { , alloc(alloc_v) {} - cbor_value(cbor_value& oth) + cbor_value(const cbor_value& oth) : contents(oth.contents) , alloc(oth.alloc) {} @@ -128,6 +128,18 @@ namespace gp { return *this; } + template + cbor_value& operator=(T& value) { + contents = value; + return *this; + } + + template + cbor_value& operator=(T&& value) { + contents = gp::move(value); + return *this; + } + auto new_array() { return gp::vector{alloc}; diff --git a/include/gp/pair.hpp b/include/gp/pair.hpp index 341063f..a662646 100644 --- a/include/gp/pair.hpp +++ b/include/gp/pair.hpp @@ -10,19 +10,26 @@ namespace gp{ 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) : first(gp::move(v.first)) , second(gp::move(v.second)) {} - template - pair(U1&& a, U2&& b) - : first(gp::forward(a)) - , second(gp::forward(b)) - {} - template pair(pair&& v) : first(gp::move(v.first)) diff --git a/include/gp/variant.hpp b/include/gp/variant.hpp index 3d8609c..d39d78a 100644 --- a/include/gp/variant.hpp +++ b/include/gp/variant.hpp @@ -31,27 +31,34 @@ namespace gp{ mvtor(oth.buffer, tmp); } public: - template//, typename std::enable_if::value,int>::type> - constexpr fixed_variant(U& value) + template,T...>::value,int>> + fixed_variant(U& value) : index{r_index_of::value} { - new(buffer) U(value); - dtor = gp::function([](void* thing){((U*)thing)->~U();}, nullopt); - cpytor = gp::function([](void* src, void* dest){new(dest) U(*(U*)src);}, nullopt); - mvtor = gp::function([](void* src, void* dest){new(dest) U(gp::move(*(U*)src));}, nullopt); + using actual = gp::remove_cvref_t; + new(buffer) actual(value); + dtor = gp::function([](void* thing){((actual*)thing)->~actual();}, nullopt); + cpytor = gp::function([](void* src, void* dest){new(dest) actual(*(actual*)src);}, nullopt); + mvtor = gp::function([](void* src, void* dest){new(dest) actual(gp::move(*(actual*)src));}, nullopt); } - template//, typename std::enable_if::value,int>::type> - constexpr fixed_variant(U&& value) + static_assert(list_contains_class::value, "list_contains_class doesn't work properly"); + static_assert(list_contains_class::value, "list_contains_class doesn't work properly"); + static_assert(list_contains_class::value, "list_contains_class doesn't work properly"); + static_assert(list_contains_class::value, "list_contains_class doesn't work properly"); + + template,T...>::value,int>> + fixed_variant(U&& value) : index{r_index_of::value} { - new(buffer) U(std::move(value)); - dtor = gp::function([](void* thing){((U*)thing)->~U();}, nullopt); - cpytor = gp::function([](void* src, void* dest){new(dest) U(*(U*)src);}, nullopt); - mvtor = gp::function([](void* src, void* dest){new(dest) U(gp::move(*(U*)src));}, nullopt); + using actual = gp::remove_cvref_t; + new(buffer) actual(std::move(value)); + dtor = gp::function([](void* thing){((actual*)thing)->~actual();}, nullopt); + cpytor = gp::function([](void* src, void* dest){new(dest) actual(*(actual*)src);}, nullopt); + mvtor = gp::function([](void* src, void* dest){new(dest) actual(gp::move(*(actual*)src));}, nullopt); } - constexpr fixed_variant(fixed_variant& oth) + fixed_variant(fixed_variant& oth) : index{oth.index} , dtor{oth.dtor} , cpytor{oth.cpytor} @@ -60,7 +67,7 @@ namespace gp{ cpytor(oth.buffer, buffer); } - constexpr fixed_variant(fixed_variant&& oth) + fixed_variant(fixed_variant&& oth) { mvtor(buffer, oth.buffer); gp::swap(dtor, oth.dtor); diff --git a/include/gp/vector.hpp b/include/gp/vector.hpp index c404f6c..2ea73f2 100644 --- a/include/gp/vector.hpp +++ b/include/gp/vector.hpp @@ -23,12 +23,12 @@ namespace gp{ , alloc(v) {} - vector(const vector& oth) + vector(vector& oth) + : alloc(oth.alloc) { sz = 0; cap = 0; ary = nullptr; - alloc = oth.alloc; gp_config::assertion(reserve(oth.size()), "could not reserve space on building"); sz = oth.size(); cap = oth.size(); diff --git a/tests/bloomfilter.cpp b/tests/bloomfilter.cpp index 66f0284..9ce784b 100644 --- a/tests/bloomfilter.cpp +++ b/tests/bloomfilter.cpp @@ -55,6 +55,15 @@ struct bfilter2_test : public test_scaffold { 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() { cheap_rand setter(seedA); @@ -83,6 +92,7 @@ struct bfilter2_test : public test_scaffold { }; append_test dummy_r2gflu3(new bfilter2_test{}); +append_test dummy_rsdgueiu3(new bfilter2_test{3780040561, 79423740}); struct bfilter3_test : public test_scaffold { uint32_t seed; diff --git a/tests/cbor_test.cpp b/tests/cbor_test.cpp index 744c947..fb1c726 100644 --- a/tests/cbor_test.cpp +++ b/tests/cbor_test.cpp @@ -16,6 +16,7 @@ struct cbor_test : public test_scaffold { 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(13), alloc}, gp::cbor_value{uint32_t(98), alloc}); + data = gen; return 0; } };