From 120b3d12817bb8396d834936db9aee54fb68a0c2 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 19 Oct 2019 07:09:24 -0400 Subject: [PATCH 1/2] DNAYaml: Collapse SFINAE functions into single function We can leverage if constexpr here to determine which branch of code to instantiate, eliminating the need for the use of SFINAE. --- include/athena/DNAYaml.hpp | 14 ++++++-------- src/athena/DNAYaml.cpp | 1 + 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/include/athena/DNAYaml.hpp b/include/athena/DNAYaml.hpp index 5d11f29..e7ba501 100644 --- a/include/athena/DNAYaml.hpp +++ b/include/athena/DNAYaml.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include "athena/DNA.hpp" #include "athena/FileReader.hpp" @@ -12,13 +11,12 @@ namespace athena::io { template -inline std::string_view __GetDNAName(const T& dna, std::enable_if_t>* = nullptr) { - return dna.DNATypeV(); -} - -template -inline std::string_view __GetDNAName(const T& dna, std::enable_if_t>* = nullptr) { - return dna.DNAType(); +std::string_view __GetDNAName(const T& dna) { + if constexpr (__IsDNAVRecord_v) { + return dna.DNATypeV(); + } else { + return dna.DNAType(); + } } template diff --git a/src/athena/DNAYaml.cpp b/src/athena/DNAYaml.cpp index c8d7d59..2f2f077 100644 --- a/src/athena/DNAYaml.cpp +++ b/src/athena/DNAYaml.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "athena/YAMLCommon.hpp" From e7f7867f323c37e2ab429ffffef9df124d77d054 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 19 Oct 2019 07:13:48 -0400 Subject: [PATCH 2/2] DNAYaml: Make use of if constexpr within NodeToVec() Only the constexpr isDouble variable is tested within the conditional, so we can make use of if constexpr here. --- src/athena/DNAYaml.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/athena/DNAYaml.cpp b/src/athena/DNAYaml.cpp index 2f2f077..b7db0be 100644 --- a/src/athena/DNAYaml.cpp +++ b/src/athena/DNAYaml.cpp @@ -139,20 +139,22 @@ std::unique_ptr ValToNode(double val) { template RETURNTYPE NodeToVec(const YAMLNode* node) { - constexpr bool isDouble = std::is_same::value || std::is_same::value || - std::is_same::value; + constexpr bool isDouble = + std::is_same_v || std::is_same_v || std::is_same_v; RETURNTYPE retval = {}; auto it = node->m_seqChildren.begin(); simd_values> 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(snode); - else + } else { f[i] = NodeToVal(snode); - } else + } + } else { f[i] = 0.0; + } } retval.simd.copy_from(f); return retval;