#pragma once
#include "type_info.h"
namespace utils {
//template for iterable hashes, where iteration is independannt result
template<typename IN, typename OUT> constexpr inline
OUT iterable_hash(const IN* in, size_t in_size, auto iterable_hash_lamda) {
static_assert(
!(sizeof(OUT) < sizeof(IN)),
"iterable_hash can`t generate output type smaller than input type"
);
static_assert(
!type_in_type_wholes<IN, OUT>(),
"iterable_hash can`t input type must fil entirely output type"
);
//to do "static warning", when sizeof(in)*in_size=OUT
OUT result;
IN* out_pointer = (IN*)&result;
//make result = 0, supports arrays with constant legth (like int[2])
size_t i = type_in_type_capasity<IN, OUT>(), ii = 0;
while (i) {
out_pointer[--i] = 0;
}
//calculate hash, IN size is already a STEP size
i = type_in_type_capasity<IN, OUT>();
while (in_size) {
out_pointer[ii] = iterable_hash_lamda(out_pointer[ii], in[--in_size]);
if (++ii == i) {
ii = 0;
}
}
return result;
}
template<typename IN, typename OUT> constexpr inline
OUT pearson_hash(const IN* in, size_t in_size) {
return iterable_hash<IN, OUT>(
in, in_size,
[](IN& out_step, const IN& in_step) {
return out_step ^ in_step;
}
);
};
}
#pragma once
#include "utils/include/hash.h"
#include <stdint.h>
#include <xstring>
namespace tokenoperator::dte_token {
#define TOKEN_NAME(lpwstr) token_name(lpwstr, std::char_traits<wchar_t>::length(lpwstr))
struct object {
public:
object(uint64_t ID) : ID(ID){}
virtual ~object() {}
uint64_t getID() const {
return ID;
}
protected:
uint64_t ID;
};
constexpr inline uint64_t token_name(const wchar_t* wstr, size_t wstr_len) {
return utils::pearson_hash<wchar_t, uint64_t>(wstr, wstr_len);
}
}
#pragma once
#include "type.h"
namespace tokenoperator::dte_token::data {
template<typename T>
struct value : object {
template <typename U> friend struct value;
public:
value(uint64_t ID = 0) : object(ID), t(ID) {}
template<typename U>
value(const U& v, uint64_t ID = 0) : object(ID), t(ID), v(v) {}
value(const T& v, uint64_t ID = 0) : object(ID), t(ID), v(v) {}
T& get_value() {
return v;
}
type<T> get_type() const {
return t;
}
protected:
T v;
type<T> t;
};
}
constexpr inline uint64_t token_name(const wchar_t* wstr, size_t wstr_len) {
return utils::pearson_hash<wchar_t, uint64_t>(wstr, wstr_len);
}
template<typename IN, typename OUT> constexpr inline
OUT pearson_hash(const IN* in, size_t in_size) {
return iterable_hash<IN, OUT>(
in, in_size,
[](IN& out_step, const IN& in_step) {
return out_step ^ in_step;
}
);
};
using namespace tokenoperator::dte_token::stream;
не работает? И оно выдает другую функцию? Вот это место я и просил прояснить. Покажи код, который не работает.