From 02b6cedd14baacf0dee534d952a89197e9a7d3f3 Mon Sep 17 00:00:00 2001 From: Olivier Parcollet Date: Tue, 10 Dec 2013 11:52:53 +0100 Subject: [PATCH] callback: move to std::chrono instead of boost - and rm boost::function clashing with std:function (detected by new clang). --- triqs/utility/callbacks.cpp | 54 ++++++++++++++++++++++++++----------- triqs/utility/callbacks.hpp | 4 +-- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/triqs/utility/callbacks.cpp b/triqs/utility/callbacks.cpp index 06f5f8ef..b56fecdd 100644 --- a/triqs/utility/callbacks.cpp +++ b/triqs/utility/callbacks.cpp @@ -1,4 +1,3 @@ - /******************************************************************************* * * TRIQS: a Toolbox for Research in Interacting Quantum Systems @@ -22,24 +21,47 @@ #include "callbacks.hpp" #include "signal_handler.hpp" + +// switch to std. Remove old boost code when ok on several compilers +#ifndef TRIQS_USE_BOOST_CHRONO +#include + +namespace triqs { +namespace utility { + + std::function clock_callback(int time_in_seconds) { + if (time_in_seconds <= 0) + return []() { return (!triqs::signal_handler().empty()); }; + + // auto end_time = boost::posix_time::second_clock::local_time() + boost::posix_time::seconds(time_in_seconds); + // return [end_time]() { return (!triqs::signal_handler().empty()) || boost::posix_time::second_clock::local_time() > end_time + + auto end_time = std::chrono::system_clock::now() + std::chrono::seconds(time_in_seconds); + return [end_time]() { return (!triqs::signal_handler().empty()) || (std::chrono::system_clock::now() > end_time); }; + } +} +} + +#else + #include #include -namespace triqs { - namespace utility { - - bool clock_callback_impl(boost::posix_time::ptime const & end_time) { - return (!triqs::signal_handler().empty()) || boost::posix_time::second_clock::local_time() > end_time; - } - - bool false_callback_impl() { return (!triqs::signal_handler().empty());} - - boost::function clock_callback(int time_in_seconds) { - return (time_in_seconds>0 ? - boost::bind(&clock_callback_impl, boost::posix_time::second_clock::local_time() + boost::posix_time::seconds(time_in_seconds)) : - boost::function (&false_callback_impl)); - } +namespace triqs { +namespace utility { + bool clock_callback_impl(boost::posix_time::ptime const& end_time) { + return (!triqs::signal_handler().empty()) || boost::posix_time::second_clock::local_time() > end_time; } -}; + + bool false_callback_impl() { return (!triqs::signal_handler().empty()); } + + std::function clock_callback(int time_in_seconds) { + return (time_in_seconds > 0 ? boost::bind(&clock_callback_impl, boost::posix_time::second_clock::local_time() + + boost::posix_time::seconds(time_in_seconds)) + : std::function(&false_callback_impl)); + } +} +} +#endif diff --git a/triqs/utility/callbacks.hpp b/triqs/utility/callbacks.hpp index 92655e5f..2e2cde12 100644 --- a/triqs/utility/callbacks.hpp +++ b/triqs/utility/callbacks.hpp @@ -23,11 +23,11 @@ #ifndef TRIQS_TOOLS_MC_CALLBACKS_H #define TRIQS_TOOLS_MC_CALLBACKS_H #include -#include +#include namespace triqs { namespace utility { - boost::function clock_callback(int time_in_seconds); + std::function clock_callback(int time_in_seconds); }} #endif