浏览代码

enable_if issue

cbor
Ludovic 'Archivist' Lagouardette 3 年前
父节点
当前提交
b4d47633d8
共有 9 个文件被更改,包括 70 次插入33 次删除
  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 查看文件

@ -75,7 +75,7 @@ namespace gp {
template< class T >
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 >

+ 1
- 1
include/gp/array.hpp 查看文件

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

+ 1
- 1
include/gp/bloomfilter.hpp 查看文件

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

+ 19
- 7
include/gp/enveloppe/cbor.hpp 查看文件

@ -76,13 +76,13 @@ namespace gp {
template<typename T>
using cbor_composite = gp::fixed_variant<
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>>,
c1">//gp::nullopt_t,
undefined_tc1">//,
c1">//cbor_floating_point
n">gp::nullopt_t,
undefined_tp">,
n">cbor_floating_point
>;
class cbor_value {
@ -101,7 +101,7 @@ namespace gp {
, alloc(alloc_v)
{}
cbor_value(cbor_value& oth)
cbor_value(k">const cbor_value& oth)
: contents(oth.contents)
, alloc(oth.alloc)
{}
@ -128,6 +128,18 @@ namespace gp {
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() {
return gp::vector<cbor_value>{alloc};

+ 14
- 7
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<typename U1, typename U2>
pair(U1&& a, U2&& b)
: first(gp::forward<U1>(a))
, second(gp::forward<U2>(b))
{}
template<typename U1, typename U2>
pair(pair<U1, U2>&& v)
: first(gp::move(v.first))

+ 21
- 14
include/gp/variant.hpp 查看文件

@ -31,27 +31,34 @@ namespace gp{
mvtor(oth.buffer, tmp);
}
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}
{
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}
{
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}
, dtor{oth.dtor}
, cpytor{oth.cpytor}
@ -60,7 +67,7 @@ namespace gp{
cpytor(oth.buffer, buffer);
}
k">constexpr fixed_variant(fixed_variant&& oth)
fixed_variant(fixed_variant&& oth)
{
mvtor(buffer, oth.buffer);
gp::swap(dtor, oth.dtor);

+ 2
- 2
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();

+ 10
- 0
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;

+ 1
- 0
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;
}
};

正在加载...
取消
保存