Merge pull request #76 from lioncash/dependent

DNAOp: Make use of template keyword for dependent templates
This commit is contained in:
Luke Street 2021-04-18 21:26:12 -04:00 committed by GitHub
commit ec43f653a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 29 deletions

View File

@ -147,18 +147,20 @@ struct BinarySize {
}
template <class T, Endian DNAE>
static std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& s) {
for (auto& v : var)
BinarySize<PropOp>::Do<std::remove_reference_t<decltype(v)>, DNAE>(id, v, s);
for (auto& v : var) {
BinarySize<PropOp>::template Do<std::remove_reference_t<decltype(v)>, DNAE>(id, v, s);
}
}
template <class T, Endian DNAE>
static void DoSize(const PropId& id, T& var, StreamT& s) {
BinarySize<PropOp>::Do<T, DNAE>(id, var, s);
BinarySize<PropOp>::template Do<T, DNAE>(id, var, s);
}
template <class T, class S, Endian DNAE>
static std::enable_if_t<!std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
StreamT& s) {
for (T& v : vector)
BinarySize<PropOp>::Do<T, DNAE>(id, v, s);
for (T& v : vector) {
BinarySize<PropOp>::template Do<T, DNAE>(id, v, s);
}
}
template <class T, class S, Endian DNAE>
static std::enable_if_t<std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
@ -255,7 +257,7 @@ struct PropCount {
}
template <class T, Endian DNAE>
static void DoSize(const PropId& id, T& var, StreamT& s) {
PropCount<PropOp>::Do<T, DNAE>(id, var, s);
PropCount<PropOp>::template Do<T, DNAE>(id, var, s);
}
template <class T, class S, Endian DNAE>
static void Do(const PropId& id, std::vector<T>& vector, const S& count, StreamT& s) {
@ -327,12 +329,13 @@ struct Read {
}
template <class T, Endian DNAE>
static std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& s) {
for (auto& v : var)
Read<PropOp>::Do<std::remove_reference_t<decltype(v)>, DNAE>(id, v, s);
for (auto& v : var) {
Read<PropOp>::template Do<std::remove_reference_t<decltype(v)>, DNAE>(id, v, s);
}
}
template <class T, Endian DNAE>
static void DoSize(const PropId& id, T& var, StreamT& s) {
Read<PropOp>::Do<T, DNAE>(id, var, s);
Read<PropOp>::template Do<T, DNAE>(id, var, s);
}
template <class T, class S, Endian DNAE>
static std::enable_if_t<!std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
@ -341,7 +344,7 @@ struct Read {
vector.reserve(count);
for (size_t i = 0; i < static_cast<size_t>(count); ++i) {
vector.emplace_back();
Read<PropOp>::Do<T, DNAE>(id, vector.back(), r);
Read<PropOp>::template Do<T, DNAE>(id, vector.back(), r);
}
}
template <class T, class S, Endian DNAE>
@ -483,18 +486,20 @@ struct Write {
}
template <class T, Endian DNAE>
static std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& s) {
for (auto& v : var)
Write<PropOp>::Do<std::remove_reference_t<decltype(v)>, DNAE>(id, v, s);
for (auto& v : var) {
Write<PropOp>::template Do<std::remove_reference_t<decltype(v)>, DNAE>(id, v, s);
}
}
template <class T, Endian DNAE>
static void DoSize(const PropId& id, T& var, StreamT& s) {
Write<PropOp>::Do<T, DNAE>(id, var, s);
Write<PropOp>::template Do<T, DNAE>(id, var, s);
}
template <class T, class S, Endian DNAE>
static std::enable_if_t<!std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
StreamT& w) {
for (T& v : vector)
Write<PropOp>::Do<T, DNAE>(id, v, w);
for (T& v : vector) {
Write<PropOp>::template Do<T, DNAE>(id, v, w);
}
}
template <class T, class S, Endian DNAE>
static std::enable_if_t<std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
@ -596,9 +601,11 @@ struct ReadYaml {
template <class T, Endian DNAE>
static std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& r) {
size_t _count;
if (auto __v = r.enterSubVector(id.name, _count))
for (size_t i = 0; i < _count && i < std::extent_v<T>; ++i)
ReadYaml<PropOp>::Do<std::remove_reference_t<decltype(var[i])>, DNAE>({}, var[i], r);
if (auto __v = r.enterSubVector(id.name, _count)) {
for (size_t i = 0; i < _count && i < std::extent_v<T>; ++i) {
ReadYaml<PropOp>::template Do<std::remove_reference_t<decltype(var[i])>, DNAE>({}, var[i], r);
}
}
}
template <class T, Endian DNAE>
static void DoSize(const PropId& id, T& var, StreamT& s) {
@ -613,7 +620,7 @@ struct ReadYaml {
vector.reserve(_count);
for (size_t i = 0; i < _count; ++i) {
vector.emplace_back();
ReadYaml<PropOp>::Do<T, DNAE>({}, vector.back(), r);
ReadYaml<PropOp>::template Do<T, DNAE>({}, vector.back(), r);
}
}
/* Horrible reference abuse (but it works) */
@ -712,9 +719,11 @@ struct WriteYaml {
}
template <class T, Endian DNAE>
static std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& w) {
if (auto __v = w.enterSubVector(id.name))
for (auto& v : var)
WriteYaml<PropOp>::Do<std::remove_reference_t<decltype(v)>, DNAE>({}, v, w);
if (auto __v = w.enterSubVector(id.name)) {
for (auto& v : var) {
WriteYaml<PropOp>::template Do<std::remove_reference_t<decltype(v)>, DNAE>({}, v, w);
}
}
}
template <class T, Endian DNAE>
static void DoSize(const PropId& id, T& var, StreamT& s) {
@ -723,9 +732,11 @@ struct WriteYaml {
template <class T, class S, Endian DNAE>
static std::enable_if_t<!std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
StreamT& w) {
if (auto __v = w.enterSubVector(id.name))
for (T& v : vector)
WriteYaml<PropOp>::Do<T, DNAE>(id, v, w);
if (auto __v = w.enterSubVector(id.name)) {
for (T& v : vector) {
WriteYaml<PropOp>::template Do<T, DNAE>(id, v, w);
}
}
}
template <class T, class S, Endian DNAE>
static std::enable_if_t<std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,

View File

@ -21,7 +21,7 @@ MemoryReader::MemoryReader(const void* data, atUint64 length, bool takeOwnership
MemoryReader::~MemoryReader() {
if (m_owns)
delete[] reinterpret_cast<const atUint8*>(m_data);
delete[] static_cast<const atUint8*>(m_data);
}
MemoryCopyReader::MemoryCopyReader(const void* data, atUint64 length) : MemoryReader(data, length, false) {
@ -111,7 +111,7 @@ atUint64 MemoryReader::readUBytesToBuf(void* buf, atUint64 length) {
}
length = std::min(length, m_length - m_position);
memmove(buf, reinterpret_cast<const atUint8*>(m_data) + m_position, length);
memmove(buf, static_cast<const atUint8*>(m_data) + m_position, length);
m_position += length;
return length;
}

View File

@ -233,7 +233,7 @@ void MemoryWriter::writeUBytes(const atUint8* data, atUint64 length) {
return;
}
memmove(reinterpret_cast<atInt8*>(m_data + m_position), data, length);
memmove(m_data + m_position, data, length);
m_position += length;
}
@ -248,7 +248,7 @@ void MemoryCopyWriter::writeUBytes(const atUint8* data, atUint64 length) {
if (m_position + length > m_length)
resize(m_position + length);
memmove(reinterpret_cast<atInt8*>(m_data + m_position), data, length);
memmove(m_data + m_position, data, length);
m_position += length;
}