Merge pull request #72 from lioncash/constexpr

DNAYaml: Make use of if constexpr where applicable
This commit is contained in:
Phillip Stephens 2019-10-20 18:40:14 -07:00 committed by GitHub
commit 9a2277091f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 13 deletions

View File

@ -1,7 +1,6 @@
#pragma once
#include <string>
#include <type_traits>
#include "athena/DNA.hpp"
#include "athena/FileReader.hpp"
@ -12,14 +11,13 @@
namespace athena::io {
template <class T>
inline std::string_view __GetDNAName(const T& dna, std::enable_if_t<athena::io::__IsDNAVRecord_v<T>>* = nullptr) {
std::string_view __GetDNAName(const T& dna) {
if constexpr (__IsDNAVRecord_v<T>) {
return dna.DNATypeV();
}
template <class T>
inline std::string_view __GetDNAName(const T& dna, std::enable_if_t<!athena::io::__IsDNAVRecord_v<T>>* = nullptr) {
} else {
return dna.DNAType();
}
}
template <class T>
std::string ToYAMLString(const T& dna) {

View File

@ -2,6 +2,7 @@
#include <cctype>
#include <cstdlib>
#include <type_traits>
#include "athena/YAMLCommon.hpp"
@ -138,21 +139,23 @@ std::unique_ptr<YAMLNode> ValToNode(double val) {
template <typename RETURNTYPE>
RETURNTYPE NodeToVec(const YAMLNode* node) {
constexpr bool isDouble = std::is_same<RETURNTYPE, atVec2d>::value || std::is_same<RETURNTYPE, atVec3d>::value ||
std::is_same<RETURNTYPE, atVec4d>::value;
constexpr bool isDouble =
std::is_same_v<RETURNTYPE, atVec2d> || std::is_same_v<RETURNTYPE, atVec3d> || std::is_same_v<RETURNTYPE, atVec4d>;
RETURNTYPE retval = {};
auto it = node->m_seqChildren.begin();
simd_values<std::conditional_t<isDouble, double, float>> f;
for (size_t i = 0; i < 4 && it != node->m_seqChildren.end(); ++i, ++it) {
YAMLNode* snode = it->get();
if (snode->m_type == YAML_SCALAR_NODE) {
if (isDouble)
if constexpr (isDouble) {
f[i] = NodeToVal<double>(snode);
else
} else {
f[i] = NodeToVal<float>(snode);
} else
}
} else {
f[i] = 0.0;
}
}
retval.simd.copy_from(f);
return retval;
}