diff --git a/configure.ac b/configure.ac index 76bcabe5..7d007c7e 100644 --- a/configure.ac +++ b/configure.ac @@ -197,6 +197,22 @@ std::vector> v; [have_std_future=no AC_MSG_RESULT([no])]) +# Check that std::map::emplace is available for g++-4.7. +AC_MSG_CHECKING([whether std::map::emplace is available]) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM( +[[ +#include +]], +[[ +std::map().emplace(1, 2); +]])], + [AC_DEFINE([HAVE_STD_MAP_EMPLACE], [1], + [Define to 1 if you have the `std::map::emplace`.]) + have_std_map_emplace=yes + AC_MSG_RESULT([yes])], + [have_std_map_emplace=no + AC_MSG_RESULT([no])]) + AC_LANG_POP() # Checks for libraries. diff --git a/src/shrpx_downstream_queue.cc b/src/shrpx_downstream_queue.cc index e89c57b9..1393aafa 100644 --- a/src/shrpx_downstream_queue.cc +++ b/src/shrpx_downstream_queue.cc @@ -55,7 +55,12 @@ DownstreamQueue::HostEntry & DownstreamQueue::find_host_entry(const std::string &host) { auto itr = host_entries_.find(host); if (itr == std::end(host_entries_)) { +#ifdef HAVE_STD_MAP_EMPLACE std::tie(itr, std::ignore) = host_entries_.emplace(host, HostEntry()); +#else // !HAVE_STD_MAP_EMPLACE + // for g++-4.7 + std::tie(itr, std::ignore) = host_entries_.insert({host, HostEntry()}); +#endif // !HAVE_STD_MAP_EMPLACE } return (*itr).second; }