Compile with g++-4.7

g++-4.7 lacks thread_local, which can be workaround by
--disable-threads.  What left remaining is std::map::emplace, which is
what this change deals with.  First check availability of
std::map::emplace, if there is none, use std::map::insert.
This commit is contained in:
Tatsuhiro Tsujikawa 2015-01-17 15:32:49 +09:00
parent 13a14ecda8
commit 3817798905
2 changed files with 21 additions and 0 deletions

View File

@ -197,6 +197,22 @@ std::vector<std::future<int>> 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 <map>
]],
[[
std::map<int, int>().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.

View File

@ -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;
}