From 501d564eb0fa96eb66b4ad239a2a56e4fa59c95f Mon Sep 17 00:00:00 2001 From: Frantisek Boranek Date: Thu, 18 Oct 2018 17:19:42 +0200 Subject: [PATCH] use std::hash and C++11 --- configure.ac | 3 ++- src/Makefile.am | 2 +- src/tengfilesystem.cc | 20 +++++++++++++------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index d84b558..d56a03a 100644 --- a/configure.ac +++ b/configure.ac @@ -53,6 +53,8 @@ AC_CONFIG_FILES([tests/Makefile]) # check for C++ compiler AC_PROG_CXX +AC_LANG_CPLUSPLUS +AX_CHECK_COMPILE_FLAG([-std=c++11], [],[AC_MSG_ERROR([Compiler without c++11])]) # pkg config PKG_PROG_PKG_CONFIG([0.25]) @@ -145,7 +147,6 @@ AC_CHECK_HEADERS(fenv.h) AC_CHECK_LIB(m, floor) AC_REPLACE_FUNCS([trunc round]) -AC_LANG_CPLUSPLUS AC_CHECK_LIB([pcre++], [_init],,AC_MSG_ERROR([pcre++ not installed])) AX_CHECK_COMPILE_FLAG([-std=c++14], [ diff --git a/src/Makefile.am b/src/Makefile.am index dc2d7c5..d47b41d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -39,7 +39,7 @@ AM_CXXFLAGS = -Wall # extra compiler options -AM_CPPFLAGS = -D_ISOC99_SOURCE -fPIC ${DEPENS_CFLAGS} +AM_CPPFLAGS = -std=c++11 -D_ISOC99_SOURCE -fPIC ${DEPENS_CFLAGS} # these are generated and thus ought to be prepared before anything else BUILT_SOURCES = tenglex2.cc tengsyntax.cc diff --git a/src/tengfilesystem.cc b/src/tengfilesystem.cc index 3ea9444..1fc2700 100644 --- a/src/tengfilesystem.cc +++ b/src/tengfilesystem.cc @@ -20,14 +20,13 @@ #include #include +#include #include #include #include "tengfilesystem.h" -#include "tengutil.h" #include "tengplatform.h" - -#include +#include "tengutil.h" namespace Teng { @@ -42,6 +41,13 @@ static std::string makeFilename(const std::string& root, const std::string& file return filename; } +template +static void hashCombine(std::size_t& seed, S const& value) +{ + std::size_t hash = std::hash{}(value); + seed ^= hash + 0x9e3779b9 + (seed<<6) + (seed>>2); // or use boost::hash_combine +} + Filesystem_t::Filesystem_t(const std::string& root_) : root(root_) { @@ -96,10 +102,10 @@ size_t Filesystem_t::hash(const std::string& filename_) const throw std::runtime_error("File '" + filename + "' is a directory"); } - boost::hash_combine(seed, buf.st_ino); - boost::hash_combine(seed, buf.st_size); - boost::hash_combine(seed, buf.st_mtime); - boost::hash_combine(seed, buf.st_ctime); + hashCombine(seed, buf.st_ino); // unsigned long int - inode number + hashCombine(seed, buf.st_size); // long - total size, in bytes + hashCombine(seed, buf.st_mtime); // long - time of last modification + hashCombine(seed, buf.st_ctime); // long - time of last status change return seed; }