From 0469526276fc815b27692e64e2db591cc0fec126 Mon Sep 17 00:00:00 2001 From: Oleg Sh Date: Sat, 10 Apr 2021 15:41:27 +0200 Subject: [PATCH] Fix compilation error for case when we use std::unordered_map inside map_type for g++ or Mac. Fix should work for C++17. For example: bootstrap::standard_library::map_type>("StringInt_Map") --- .../chaiscript/dispatchkit/bootstrap_stl.hpp | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index bc3c0869..9d63aeba 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -37,6 +37,15 @@ namespace chaiscript { namespace standard_library { + template + struct isUnorderedMap { + static constexpr bool value = false; + }; + + template + struct isUnorderedMap> { + static constexpr bool value = true; + }; /// Bidir_Range, based on the D concept of ranges. /// \todo Update the Range code to base its capabilities on @@ -71,7 +80,14 @@ namespace chaiscript { throw std::range_error("Range empty"); } - --m_end; + if constexpr (!isUnorderedMap::type>::value) + { + --m_end; + } + else + { + throw std::range_error("Cannot call pop_back for unordered_map"); + } } decltype(auto) front() const @@ -90,7 +106,14 @@ namespace chaiscript throw std::range_error("Range empty"); } auto pos = m_end; - --pos; + if constexpr (!isUnorderedMap::type>::value) + { + --pos; + } + else + { + throw std::range_error("Cannot call back for unordered_map"); + } return (*(pos)); }