From b63079e4933c2013823c54edc04004a52aedf62f Mon Sep 17 00:00:00 2001 From: Lucas Czech Date: Wed, 27 Nov 2024 02:29:27 +0100 Subject: [PATCH] Fix compiler issue in Accession Lookup for Clang 6-8 --- lib/genesis/taxonomy/accession_lookup.hpp | 30 +++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/genesis/taxonomy/accession_lookup.hpp b/lib/genesis/taxonomy/accession_lookup.hpp index a0d67697..364577cf 100644 --- a/lib/genesis/taxonomy/accession_lookup.hpp +++ b/lib/genesis/taxonomy/accession_lookup.hpp @@ -33,6 +33,7 @@ #include "genesis/taxonomy/taxonomy.hpp" #include "genesis/taxonomy/taxon.hpp" +#include "genesis/utils/core/std.hpp" #include "genesis/utils/text/char.hpp" #include "genesis/utils/text/string.hpp" @@ -213,8 +214,13 @@ class AccessionLookup private: + #if GENESIS_CPP_STD > GENESIS_CPP_STD_11 + /** - * @brief Try emplace using SFINAE for maps that have try_emplace (>= C++17) + * @brief Try emplace using SFINAE for maps that have try_emplace (>= C++17). + * + * This works for any map type that supports try_emplace, but we do not activate this + * overload for C++11, as there are some template substitution errors with clang 6-8. */ template typename std::enable_if< decltype( @@ -239,7 +245,7 @@ class AccessionLookup } /** - * @brief Fallback for maps without try_emplace (C++11 and C++14) + * @brief Fallback for maps without try_emplace (C++14) */ template typename std::enable_if< !decltype( @@ -261,6 +267,26 @@ class AccessionLookup } } + #else + + /** + * @brief Fallback for older compilers (C++11) where the above template substitution + * SFINAE might fail to compile; we observe this with Clang 6-8. + */ + inline void add_( std::string const& accession, Taxon* taxon ) + { + auto const result = map_.insert( std::make_pair( accession, taxon )); + if( !result.second ) { + if( result.first->second != taxon ) { + throw std::runtime_error( + "Duplicate entry for accession '" + accession + "' in lookup table" + ); + } + } + } + + #endif + inline ConstIterator find_( std::string const& accession, bool also_look_up_first_word