From 8aa4a027bbe91aec7af044bb4becc5715758b3f6 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Thu, 20 Nov 2014 05:51:47 -0800 Subject: [PATCH] Template abstract_clock on Clock: The abstract_clock is now templated on a type meeting the requirements of the Clock concept. It inherits the nested types of the Clock on which it is based. This resolves a problem with the original design which broke the type-safety of time_point from different abstract clocks. --- beast/chrono/abstract_clock.h | 125 +++------ beast/chrono/abstract_clock_io.h | 37 --- beast/chrono/basic_seconds_clock.h | 107 ++++--- beast/chrono/chrono_io.h | 14 +- beast/chrono/manual_clock.h | 113 ++++---- beast/chrono/tests/abstract_clock.test.cpp | 30 +- beast/container/aged_map.h | 4 +- beast/container/aged_multimap.h | 4 +- beast/container/aged_multiset.h | 4 +- beast/container/aged_set.h | 4 +- beast/container/aged_unordered_map.h | 4 +- beast/container/aged_unordered_multimap.h | 4 +- beast/container/aged_unordered_multiset.h | 4 +- beast/container/aged_unordered_set.h | 4 +- .../container/detail/aged_ordered_container.h | 221 +++++++-------- .../detail/aged_unordered_container.h | 264 +++++++++--------- .../tests/aged_associative_container.test.cpp | 63 +++-- 17 files changed, 448 insertions(+), 558 deletions(-) delete mode 100644 beast/chrono/abstract_clock_io.h diff --git a/beast/chrono/abstract_clock.h b/beast/chrono/abstract_clock.h index d085825c5d..6f2c830388 100644 --- a/beast/chrono/abstract_clock.h +++ b/beast/chrono/abstract_clock.h @@ -27,12 +27,12 @@ namespace beast { /** Abstract interface to a clock. - The abstract clock interface allows a dependency injection to take - place so that the choice of implementation can be made at run-time - instead of compile time. The trade-off is that the Duration used to - represent the clock must be chosen at compile time and cannot be - changed. This includes both the choice of representation (integers - for example) and the period in ticks corresponding to one second. + This makes now() a member function instead of a static member, so + an instance of the class can be dependency injected, facilitating + unit tests where time may be controlled. + + An abstract_clock inherits all the nested types of the Clock + template parameter. Example: @@ -40,56 +40,37 @@ namespace beast { struct Implementation { - abstract_clock & m_clock; - - // Dependency injection - // - explicit Implementation ( - abstract_clock & clock) - : m_clock (clock) + using clock_type = abstract_clock ; + clock_type& clock_; + explicit Implementation (clock_type& clock) + : clock_(clock) { } }; @endcode - @tparam The length of time, in seconds, corresponding to one tick. + @tparam Clock A type meeting these requirements: + http://en.cppreference.com/w/cpp/concept/Clock */ -template +template class abstract_clock { public: - typedef typename Duration::rep rep; - typedef typename Duration::period period; - typedef Duration duration; - typedef std::chrono::time_point < - abstract_clock, duration> time_point; + using rep = typename Clock::rep; + using period = typename Clock::period; + using duration = typename Clock::duration; + using time_point = typename Clock::time_point; - virtual ~abstract_clock () { } + static bool const is_steady = Clock::is_steady; - /** Returns `true` if this is a steady clock. */ - virtual bool is_steady () const = 0; + virtual ~abstract_clock() = default; /** Returns the current time. */ - virtual time_point now () const = 0; - -#if 0 - /** Convert the specified time point to a string. */ - /** @{ */ - //virtual std::string to_string (time_point const& tp) const = 0; - - template - std::string to_string ( - std::chrono::time_point const& tp) const - { - return to_string ( - std::chrono::time_point_cast (tp)); - } - /** @} */ -#endif + virtual time_point now() const = 0; /** Returning elapsed ticks since the epoch. */ - rep elapsed () const + rep elapsed() { return now().time_since_epoch().count(); } @@ -99,68 +80,34 @@ public: namespace detail { -template -struct basic_abstract_clock_wrapper : public abstract_clock -{ - using typename abstract_clock ::duration; - using typename abstract_clock ::time_point; - - bool is_steady () const - { - return TrivialClock::is_steady; - } - - time_point now () const - { - return time_point (duration ( - std::chrono::duration_cast ( - TrivialClock::now().time_since_epoch ()).count ())); - } -}; - -template +template struct abstract_clock_wrapper - : public basic_abstract_clock_wrapper + : public abstract_clock { - // generic conversion displays the duration - /* - std::string to_string (typename basic_abstract_clock_wrapper < - TrivialClock, Duration>::time_point const& tp) const - { - std::stringstream ss; - ss << tp.time_since_epoch(); - return ss.str (); - } - */ -}; + using typename abstract_clock::duration; + using typename abstract_clock::time_point; -/* -template -struct abstract_clock_wrapper - : public basic_abstract_clock_wrapper -{ - typedef std::chrono::system_clock clock_type; - std::string to_string (time_point const& tp) + time_point + now() const override { - std::stringstream ss; - ss << clock_type::time_point (tp.time_since_epoch ()); - return ss.str (); + return Clock::now(); } }; -*/ } //------------------------------------------------------------------------------ -/** Retrieve a discrete clock for a type implementing the Clock concept. - The interface is created as an object with static storage duration. +/** Returns a global instance of an abstract clock. + @tparam Facade A type meeting these requirements: + http://en.cppreference.com/w/cpp/concept/Clock + @tparam Clock The actual concrete clock to use. */ -template -abstract_clock & get_abstract_clock () +template +abstract_clock& +get_abstract_clock() { - static detail::abstract_clock_wrapper < - TrivialClock, Duration> clock; + static detail::abstract_clock_wrapper clock; return clock; } diff --git a/beast/chrono/abstract_clock_io.h b/beast/chrono/abstract_clock_io.h deleted file mode 100644 index 45f9dd8154..0000000000 --- a/beast/chrono/abstract_clock_io.h +++ /dev/null @@ -1,37 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#ifndef BEAST_CHRONO_ABSTRACT_CLOCK_IO_H_INCLUDED -#define BEAST_CHRONO_ABSTRACT_CLOCK_IO_H_INCLUDED - -#include - -namespace beast { - -template -std::basic_ostream & -operator<< (std::basic_ostream & os, - std::chrono::time_point , Duration> const& tp) -{ - return os << tp.time_since_epoch() << " since epoch"; -} - -} - -#endif diff --git a/beast/chrono/basic_seconds_clock.h b/beast/chrono/basic_seconds_clock.h index 227e3de439..6247935b61 100644 --- a/beast/chrono/basic_seconds_clock.h +++ b/beast/chrono/basic_seconds_clock.h @@ -45,25 +45,25 @@ public: class seconds_clock_thread { public: - typedef std::mutex mutex; - typedef std::condition_variable cond_var; - typedef std::lock_guard lock_guard; - typedef std::unique_lock unique_lock; - typedef std::chrono::steady_clock clock_type; - typedef std::chrono::seconds seconds; - typedef std::thread thread; - typedef std::vector workers; + using mutex = std::mutex; + using cond_var = std::condition_variable; + using lock_guard = std::lock_guard ; + using unique_lock = std::unique_lock ; + using clock_type = std::chrono::steady_clock; + using seconds = std::chrono::seconds; + using thread = std::thread; + using workers = std::vector ; - bool m_stop; - mutex m_mutex; - cond_var m_cond; - workers m_workers; - thread m_thread; + bool stop_; + mutex mutex_; + cond_var cond_; + workers workers_; + thread thread_; seconds_clock_thread () - : m_stop (false) + : stop_ (false) { - m_thread = thread (std::bind( + thread_ = thread (std::bind( &seconds_clock_thread::run, this)); } @@ -74,37 +74,37 @@ public: void add (seconds_clock_worker& w) { - lock_guard lock (m_mutex); - m_workers.push_back (&w); + lock_guard lock (mutex_); + workers_.push_back (&w); } void remove (seconds_clock_worker& w) { - lock_guard lock (m_mutex); - m_workers.erase (std::find ( - m_workers.begin (), m_workers.end(), &w)); + lock_guard lock (mutex_); + workers_.erase (std::find ( + workers_.begin (), workers_.end(), &w)); } void stop() { - if (m_thread.joinable()) + if (thread_.joinable()) { { - lock_guard lock (m_mutex); - m_stop = true; + lock_guard lock (mutex_); + stop_ = true; } - m_cond.notify_all(); - m_thread.join(); + cond_.notify_all(); + thread_.join(); } } void run() { - unique_lock lock (m_mutex);; + unique_lock lock (mutex_);; for (;;) { - for (auto iter : m_workers) + for (auto iter : workers_) iter->sample(); clock_type::time_point const when ( @@ -112,7 +112,7 @@ public: clock_type::now().time_since_epoch()) + seconds (1)); - if (m_cond.wait_until (lock, when, [this]{ return m_stop; })) + if (cond_.wait_until (lock, when, [this]{ return stop_; })) return; } } @@ -143,24 +143,26 @@ basic_seconds_clock_main_hook() } /** A clock whose minimum resolution is one second. + The purpose of this class is to optimize the performance of the now() member function call. It uses a dedicated thread that wakes up at least once per second to sample the requested trivial clock. - @tparam TrivialClock The clock to sample. + + @tparam Clock A type meeting these requirements: + http://en.cppreference.com/w/cpp/concept/Clock */ -template +template class basic_seconds_clock { public: - typedef std::chrono::seconds resolution; - typedef typename resolution::rep rep; - typedef typename resolution::period period; - typedef std::chrono::duration duration; - typedef std::chrono::time_point time_point; + using rep = typename Clock::rep; + using period = typename Clock::period; + using duration = typename Clock::duration; + using time_point = typename Clock::time_point; - static bool const is_steady = TrivialClock::is_steady; + static bool const is_steady = Clock::is_steady; - static time_point now () + static time_point now() { // Make sure the thread is constructed before the // worker otherwise we will crash during destruction @@ -176,45 +178,36 @@ public: struct worker : detail::seconds_clock_worker { - typedef std::mutex mutex; - typedef std::lock_guard lock_guard; - time_point m_now; - mutex m_mutex; + std::mutex mutex_; - static time_point get_now () + worker() + : m_now(Clock::now()) { - return time_point (floor ( - TrivialClock::now().time_since_epoch())); + detail::seconds_clock_thread::instance().add(*this); } - worker () - : m_now (get_now ()) + ~worker() { - detail::seconds_clock_thread::instance().add (*this); - } - - ~worker () - { - detail::seconds_clock_thread::instance().remove (*this); + detail::seconds_clock_thread::instance().remove(*this); } time_point now() { - lock_guard lock (m_mutex); + std::lock_guard lock (mutex_); return m_now; } - void sample () + void sample() { - lock_guard lock (m_mutex); - m_now = get_now (); + std::lock_guard lock (mutex_); + m_now = Clock::now(); } }; static worker w; - return w.now (); + return w.now(); } }; diff --git a/beast/chrono/chrono_io.h b/beast/chrono/chrono_io.h index a17cd4aea8..939be44e37 100644 --- a/beast/chrono/chrono_io.h +++ b/beast/chrono/chrono_io.h @@ -856,15 +856,15 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, tz = f.get_timezone(); } time_t __t = system_clock::to_time_t(__tp); - tm __tm; + tm* __tm; if (tz == local) { - if (localtime_r(&__t, &__tm) == 0) + if (! (__tm = localtime(&__t))) failed = true; } else { - if (gmtime_r(&__t, &__tm) == 0) + if (! (__tm = gmtime(&__t))) failed = true; } if (!failed) @@ -875,11 +875,11 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT pattern[] = {'%', 'F', 'T', '%', 'H', ':', '%', 'M', ':'}; pb = pattern; pe = pb + sizeof(pattern) / sizeof(_CharT); - failed = tp.put(__os, __os, __os.fill(), &__tm, pb, pe).failed(); + failed = tp.put(__os, __os, __os.fill(), __tm, pb, pe).failed(); if (!failed) { duration __d = __tp - system_clock::from_time_t(__t) + - seconds(__tm.tm_sec); + seconds(__tm->tm_sec); if (__d.count() < 10) __os << _CharT('0'); ios::fmtflags __flgs = __os.flags(); @@ -891,7 +891,7 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT sub_pattern[] = {' ', '%', 'z'}; pb = sub_pattern; pe = pb + + sizeof(sub_pattern) / sizeof(_CharT); - failed = tp.put(__os, __os, __os.fill(), &__tm, pb, pe).failed(); + failed = tp.put(__os, __os, __os.fill(), __tm, pb, pe).failed(); } else { @@ -901,7 +901,7 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, } } else - failed = tp.put(__os, __os, __os.fill(), &__tm, pb, pe).failed(); + failed = tp.put(__os, __os, __os.fill(), __tm, pb, pe).failed(); } } catch (...) diff --git a/beast/chrono/manual_clock.h b/beast/chrono/manual_clock.h index 24dd9ddd8f..0c31d5812e 100644 --- a/beast/chrono/manual_clock.h +++ b/beast/chrono/manual_clock.h @@ -25,68 +25,73 @@ namespace beast { /** Manual clock implementation. + This concrete class implements the @ref abstract_clock interface and allows the time to be advanced manually, mainly for the purpose of providing a clock in unit tests. - @tparam The length of time, in seconds, corresponding to one tick. + + @tparam Clock A type meeting these requirements: + http://en.cppreference.com/w/cpp/concept/Clock */ -template -class manual_clock : public abstract_clock +template +class manual_clock + : public abstract_clock { public: - using typename abstract_clock ::rep; - using typename abstract_clock ::duration; - using typename abstract_clock ::time_point; - - explicit manual_clock (time_point const& t = time_point (Duration (0))) - : m_now (t) - { - } - - bool is_steady () const - { - return IsSteady; - } - - time_point now () const - { - return m_now; - } - -#if 0 - std::string to_string (time_point const& tp) const - { - std::stringstream ss; - ss << tp.time_since_epoch() << " from start"; - return ss.str (); - } -#endif - - /** Set the current time of the manual clock. - Precondition: - ! IsSteady || t > now() - */ - void set (time_point const& t) - { - //if (IsSteady) - m_now = t; - } - - /** Convenience for setting the time using a duration in @ref rep units. */ - void set (rep v) - { - set (time_point (duration (v))); - } - - /** Convenience for advancing the clock by one. */ - manual_clock& operator++ () - { - m_now += duration (1); - return *this; - } + using typename abstract_clock::rep; + using typename abstract_clock::duration; + using typename abstract_clock::time_point; private: - time_point m_now; + time_point now_; + +public: + explicit + manual_clock (time_point const& now = time_point(duration(0))) + : now_(now) + { + } + + time_point + now() const override + { + return now_; + } + + /** Set the current time of the manual clock. */ + void + set (time_point const& when) + { + assert(! Clock::is_steady || when >= now_); + now_ = when; + } + + /** Convenience for setting the time in seconds from epoch. */ + template + void + set(Integer seconds_from_epoch) + { + set(time_point(duration( + std::chrono::seconds(seconds_from_epoch)))); + } + + /** Advance the clock by a duration. */ + template + void + advance(std::chrono::duration const& elapsed) + { + assert(! Clock::is_steady || + (now_ + elapsed) >= now_); + now_ += elapsed; + } + + /** Convenience for advancing the clock by one second. */ + manual_clock& + operator++ () + { + advance(std::chrono::seconds(1)); + return *this; + } }; } diff --git a/beast/chrono/tests/abstract_clock.test.cpp b/beast/chrono/tests/abstract_clock.test.cpp index 5bf4493ab9..1e5e3b0fc9 100644 --- a/beast/chrono/tests/abstract_clock.test.cpp +++ b/beast/chrono/tests/abstract_clock.test.cpp @@ -20,11 +20,8 @@ // MODULES: ../impl/chrono_io.cpp #include -#include #include - #include - #include #include #include @@ -34,7 +31,8 @@ namespace beast { class abstract_clock_test : public unit_test::suite { public: - void test (abstract_clock & c) + template + void test (abstract_clock& c) { { auto const t1 (c.now ()); @@ -53,18 +51,18 @@ public: void test_manual () { - typedef manual_clock clock_type; + using clock_type = manual_clock; clock_type c; std::stringstream ss; - ss << "now() = " << c.now () << std::endl; + ss << "now() = " << c.now().time_since_epoch() << std::endl; - c.set (clock_type::time_point (std::chrono::seconds (1))); - ss << "now() = " << c.now () << std::endl; + c.set (clock_type::time_point (std::chrono::seconds(1))); + ss << "now() = " << c.now().time_since_epoch() << std::endl; - c.set (clock_type::time_point (std::chrono::seconds (2))); - ss << "now() = " << c.now () << std::endl; + c.set (clock_type::time_point (std::chrono::seconds(2))); + ss << "now() = " << c.now().time_since_epoch() << std::endl; log << ss.str(); } @@ -72,16 +70,16 @@ public: void run () { log << "steady_clock"; - test (get_abstract_clock ()); + test (get_abstract_clock< + std::chrono::steady_clock>()); log << "system_clock"; - test (get_abstract_clock ()); + test (get_abstract_clock< + std::chrono::system_clock>()); log << "high_resolution_clock"; - test (get_abstract_clock ()); + test (get_abstract_clock< + std::chrono::high_resolution_clock>()); log << "manual_clock"; test_manual (); diff --git a/beast/container/aged_map.h b/beast/container/aged_map.h index f9d0470fdc..680aad49de 100644 --- a/beast/container/aged_map.h +++ b/beast/container/aged_map.h @@ -31,12 +31,12 @@ namespace beast { template < class Key, class T, - class Duration = std::chrono::seconds, + class Clock = std::chrono::steady_clock, class Compare = std::less , class Allocator = std::allocator > > using aged_map = detail::aged_ordered_container < - false, true, Key, T, Duration, Compare, Allocator>; + false, true, Key, T, Clock, Compare, Allocator>; } diff --git a/beast/container/aged_multimap.h b/beast/container/aged_multimap.h index c66ff227d8..55807388fd 100644 --- a/beast/container/aged_multimap.h +++ b/beast/container/aged_multimap.h @@ -31,12 +31,12 @@ namespace beast { template < class Key, class T, - class Duration = std::chrono::seconds, + class Clock = std::chrono::steady_clock, class Compare = std::less , class Allocator = std::allocator > > using aged_multimap = detail::aged_ordered_container < - true, true, Key, T, Duration, Compare, Allocator>; + true, true, Key, T, Clock, Compare, Allocator>; } diff --git a/beast/container/aged_multiset.h b/beast/container/aged_multiset.h index 620270d2ec..aeb083fec2 100644 --- a/beast/container/aged_multiset.h +++ b/beast/container/aged_multiset.h @@ -30,12 +30,12 @@ namespace beast { template < class Key, - class Duration = std::chrono::seconds, + class Clock = std::chrono::steady_clock, class Compare = std::less , class Allocator = std::allocator > using aged_multiset = detail::aged_ordered_container < - true, false, Key, void, Duration, Compare, Allocator>; + true, false, Key, void, Clock, Compare, Allocator>; } diff --git a/beast/container/aged_set.h b/beast/container/aged_set.h index a5ef922d5c..076e4830a4 100644 --- a/beast/container/aged_set.h +++ b/beast/container/aged_set.h @@ -30,12 +30,12 @@ namespace beast { template < class Key, - class Duration = std::chrono::seconds, + class Clock = std::chrono::steady_clock, class Compare = std::less , class Allocator = std::allocator > using aged_set = detail::aged_ordered_container < - false, false, Key, void, Duration, Compare, Allocator>; + false, false, Key, void, Clock, Compare, Allocator>; } diff --git a/beast/container/aged_unordered_map.h b/beast/container/aged_unordered_map.h index b6031bc976..b632312660 100644 --- a/beast/container/aged_unordered_map.h +++ b/beast/container/aged_unordered_map.h @@ -31,13 +31,13 @@ namespace beast { template < class Key, class T, - class Duration = std::chrono::seconds, + class Clock = std::chrono::steady_clock, class Hash = std::hash , class KeyEqual = std::equal_to , class Allocator = std::allocator > > using aged_unordered_map = detail::aged_unordered_container < - false, true, Key, T, Duration, Hash, KeyEqual, Allocator>; + false, true, Key, T, Clock, Hash, KeyEqual, Allocator>; } diff --git a/beast/container/aged_unordered_multimap.h b/beast/container/aged_unordered_multimap.h index 7512392923..c257700601 100644 --- a/beast/container/aged_unordered_multimap.h +++ b/beast/container/aged_unordered_multimap.h @@ -31,13 +31,13 @@ namespace beast { template < class Key, class T, - class Duration = std::chrono::seconds, + class Clock = std::chrono::steady_clock, class Hash = std::hash , class KeyEqual = std::equal_to , class Allocator = std::allocator > > using aged_unordered_multimap = detail::aged_unordered_container < - true, true, Key, T, Duration, Hash, KeyEqual, Allocator>; + true, true, Key, T, Clock, Hash, KeyEqual, Allocator>; } diff --git a/beast/container/aged_unordered_multiset.h b/beast/container/aged_unordered_multiset.h index c1f3ef353a..7d033cacc3 100644 --- a/beast/container/aged_unordered_multiset.h +++ b/beast/container/aged_unordered_multiset.h @@ -30,13 +30,13 @@ namespace beast { template < class Key, - class Duration = std::chrono::seconds, + class Clock = std::chrono::steady_clock, class Hash = std::hash , class KeyEqual = std::equal_to , class Allocator = std::allocator > using aged_unordered_multiset = detail::aged_unordered_container < - true, false, Key, void, Duration, Hash, KeyEqual, Allocator>; + true, false, Key, void, Clock, Hash, KeyEqual, Allocator>; } diff --git a/beast/container/aged_unordered_set.h b/beast/container/aged_unordered_set.h index 83b37de041..cf98970bb9 100644 --- a/beast/container/aged_unordered_set.h +++ b/beast/container/aged_unordered_set.h @@ -30,13 +30,13 @@ namespace beast { template < class Key, - class Duration = std::chrono::seconds, + class Clock = std::chrono::steady_clock, class Hash = std::hash , class KeyEqual = std::equal_to , class Allocator = std::allocator > using aged_unordered_set = detail::aged_unordered_container < - false, false, Key, void, Duration, Hash, KeyEqual, Allocator>; + false, false, Key, void, Clock, Hash, KeyEqual, Allocator>; } diff --git a/beast/container/detail/aged_ordered_container.h b/beast/container/detail/aged_ordered_container.h index 38830aa375..4c8cc9f73d 100644 --- a/beast/container/detail/aged_ordered_container.h +++ b/beast/container/detail/aged_ordered_container.h @@ -22,15 +22,11 @@ #include #include - #include - #include #include - #include #include - #include // #include #include @@ -75,7 +71,7 @@ template < bool IsMap, class Key, class T, - class Duration = std::chrono::seconds, + class Clock = std::chrono::steady_clock, class Compare = std::less , class Allocator = std::allocator < typename std::conditional clock_type; - typedef typename clock_type::time_point time_point; - typedef typename clock_type::duration duration; - typedef Key key_type; - typedef T mapped_type; - typedef typename std::conditional < - IsMap, - std::pair , - Key>::type value_type; - typedef std::size_t size_type; - typedef std::ptrdiff_t difference_type; + using clock_type = abstract_clock; + using time_point = typename clock_type::time_point; + using duration = typename clock_type::duration; + using key_type = Key; + using mapped_type = T; + using value_type = typename std::conditional < + IsMap, std::pair , Key>::type; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; // Introspection (for unit tests) - typedef std::false_type is_unordered; - typedef std::integral_constant is_multi; - typedef std::integral_constant is_map; - - // VFALCO TODO How can we reorder the declarations to keep - // all the public things together contiguously? + using is_unordered = std::false_type; + using is_multi = std::integral_constant ; + using is_map = std::integral_constant ; private: static Key const& extract (value_type const& value) @@ -1237,8 +1228,8 @@ private: //------------------------------------------------------------------------------ template -aged_ordered_container :: + class Clock, class Compare, class Allocator> +aged_ordered_container :: aged_ordered_container ( clock_type& clock) : m_config (clock) @@ -1246,8 +1237,8 @@ aged_ordered_container ( } template -aged_ordered_container :: + class Clock, class Compare, class Allocator> +aged_ordered_container :: aged_ordered_container ( clock_type& clock, Compare const& comp) @@ -1256,8 +1247,8 @@ aged_ordered_container ( } template -aged_ordered_container :: + class Clock, class Compare, class Allocator> +aged_ordered_container :: aged_ordered_container ( clock_type& clock, Allocator const& alloc) @@ -1266,8 +1257,8 @@ aged_ordered_container ( } template -aged_ordered_container :: + class Clock, class Compare, class Allocator> +aged_ordered_container :: aged_ordered_container ( clock_type& clock, Compare const& comp, @@ -1277,9 +1268,9 @@ aged_ordered_container ( } template + class Clock, class Compare, class Allocator> template -aged_ordered_container :: +aged_ordered_container :: aged_ordered_container (InputIt first, InputIt last, clock_type& clock) : m_config (clock) @@ -1288,9 +1279,9 @@ aged_ordered_container (InputIt first, InputIt last, } template + class Clock, class Compare, class Allocator> template -aged_ordered_container :: +aged_ordered_container :: aged_ordered_container (InputIt first, InputIt last, clock_type& clock, Compare const& comp) @@ -1300,9 +1291,9 @@ aged_ordered_container (InputIt first, InputIt last, } template + class Clock, class Compare, class Allocator> template -aged_ordered_container :: +aged_ordered_container :: aged_ordered_container (InputIt first, InputIt last, clock_type& clock, Allocator const& alloc) @@ -1312,9 +1303,9 @@ aged_ordered_container (InputIt first, InputIt last, } template + class Clock, class Compare, class Allocator> template -aged_ordered_container :: +aged_ordered_container :: aged_ordered_container (InputIt first, InputIt last, clock_type& clock, Compare const& comp, @@ -1325,8 +1316,8 @@ aged_ordered_container (InputIt first, InputIt last, } template -aged_ordered_container :: + class Clock, class Compare, class Allocator> +aged_ordered_container :: aged_ordered_container (aged_ordered_container const& other) : m_config (other.m_config) { @@ -1334,8 +1325,8 @@ aged_ordered_container (aged_ordered_container const& other) } template -aged_ordered_container :: + class Clock, class Compare, class Allocator> +aged_ordered_container :: aged_ordered_container (aged_ordered_container const& other, Allocator const& alloc) : m_config (other.m_config, alloc) @@ -1344,8 +1335,8 @@ aged_ordered_container (aged_ordered_container const& other, } template -aged_ordered_container :: + class Clock, class Compare, class Allocator> +aged_ordered_container :: aged_ordered_container (aged_ordered_container&& other) : m_config (std::move (other.m_config)) , m_cont (std::move (other.m_cont)) @@ -1354,8 +1345,8 @@ aged_ordered_container (aged_ordered_container&& other) } template -aged_ordered_container :: + class Clock, class Compare, class Allocator> +aged_ordered_container :: aged_ordered_container (aged_ordered_container&& other, Allocator const& alloc) : m_config (std::move (other.m_config), alloc) @@ -1365,8 +1356,8 @@ aged_ordered_container (aged_ordered_container&& other, } template -aged_ordered_container :: + class Clock, class Compare, class Allocator> +aged_ordered_container :: aged_ordered_container (std::initializer_list init, clock_type& clock) : m_config (clock) @@ -1375,8 +1366,8 @@ aged_ordered_container (std::initializer_list init, } template -aged_ordered_container :: + class Clock, class Compare, class Allocator> +aged_ordered_container :: aged_ordered_container (std::initializer_list init, clock_type& clock, Compare const& comp) @@ -1386,8 +1377,8 @@ aged_ordered_container (std::initializer_list init, } template -aged_ordered_container :: + class Clock, class Compare, class Allocator> +aged_ordered_container :: aged_ordered_container (std::initializer_list init, clock_type& clock, Allocator const& alloc) @@ -1397,8 +1388,8 @@ aged_ordered_container (std::initializer_list init, } template -aged_ordered_container :: + class Clock, class Compare, class Allocator> +aged_ordered_container :: aged_ordered_container (std::initializer_list init, clock_type& clock, Compare const& comp, @@ -1409,17 +1400,17 @@ aged_ordered_container (std::initializer_list init, } template -aged_ordered_container :: + class Clock, class Compare, class Allocator> +aged_ordered_container :: ~aged_ordered_container() { clear(); } template + class Clock, class Compare, class Allocator> auto -aged_ordered_container :: +aged_ordered_container :: operator= (aged_ordered_container const& other) -> aged_ordered_container& { @@ -1433,9 +1424,9 @@ operator= (aged_ordered_container const& other) -> } template + class Clock, class Compare, class Allocator> auto -aged_ordered_container :: +aged_ordered_container :: operator= (aged_ordered_container&& other) -> aged_ordered_container& { @@ -1447,9 +1438,9 @@ operator= (aged_ordered_container&& other) -> } template + class Clock, class Compare, class Allocator> auto -aged_ordered_container :: +aged_ordered_container :: operator= (std::initializer_list init) -> aged_ordered_container& { @@ -1461,10 +1452,10 @@ operator= (std::initializer_list init) -> //------------------------------------------------------------------------------ template + class Clock, class Compare, class Allocator> template typename std::conditional ::type& -aged_ordered_container :: +aged_ordered_container :: at (K const& k) { auto const iter (m_cont.find (k, @@ -1475,10 +1466,10 @@ at (K const& k) } template + class Clock, class Compare, class Allocator> template typename std::conditional ::type const& -aged_ordered_container :: +aged_ordered_container :: at (K const& k) const { auto const iter (m_cont.find (k, @@ -1489,10 +1480,10 @@ at (K const& k) const } template + class Clock, class Compare, class Allocator> template typename std::conditional ::type& -aged_ordered_container :: +aged_ordered_container :: operator[] (Key const& key) { typename cont_type::insert_commit_data d; @@ -1511,10 +1502,10 @@ operator[] (Key const& key) } template + class Clock, class Compare, class Allocator> template typename std::conditional ::type& -aged_ordered_container :: +aged_ordered_container :: operator[] (Key&& key) { typename cont_type::insert_commit_data d; @@ -1536,9 +1527,9 @@ operator[] (Key&& key) //------------------------------------------------------------------------------ template + class Clock, class Compare, class Allocator> void -aged_ordered_container :: +aged_ordered_container :: clear() { for (auto iter (chronological.list.begin()); @@ -1550,10 +1541,10 @@ clear() // map, set template + class Clock, class Compare, class Allocator> template auto -aged_ordered_container :: +aged_ordered_container :: insert (value_type const& value) -> typename std::enable_if >::type @@ -1573,10 +1564,10 @@ insert (value_type const& value) -> // multimap, multiset template + class Clock, class Compare, class Allocator> template auto -aged_ordered_container :: +aged_ordered_container :: insert (value_type const& value) -> typename std::enable_if ::type @@ -1591,10 +1582,10 @@ insert (value_type const& value) -> // set template + class Clock, class Compare, class Allocator> template auto -aged_ordered_container :: +aged_ordered_container :: insert (value_type&& value) -> typename std::enable_if >::type @@ -1614,10 +1605,10 @@ insert (value_type&& value) -> // multiset template + class Clock, class Compare, class Allocator> template auto -aged_ordered_container :: +aged_ordered_container :: insert (value_type&& value) -> typename std::enable_if ::type @@ -1634,10 +1625,10 @@ insert (value_type&& value) -> // map, set template + class Clock, class Compare, class Allocator> template auto -aged_ordered_container :: +aged_ordered_container :: insert (const_iterator hint, value_type const& value) -> typename std::enable_if ::type @@ -1657,10 +1648,10 @@ insert (const_iterator hint, value_type const& value) -> // map, set template + class Clock, class Compare, class Allocator> template auto -aged_ordered_container :: +aged_ordered_container :: insert (const_iterator hint, value_type&& value) -> typename std::enable_if ::type @@ -1680,10 +1671,10 @@ insert (const_iterator hint, value_type&& value) -> // map, set template + class Clock, class Compare, class Allocator> template auto -aged_ordered_container :: +aged_ordered_container :: emplace (Args&&... args) -> typename std::enable_if >::type @@ -1707,10 +1698,10 @@ emplace (Args&&... args) -> // multiset, multimap template + class Clock, class Compare, class Allocator> template auto -aged_ordered_container :: +aged_ordered_container :: emplace (Args&&... args) -> typename std::enable_if ::type @@ -1726,10 +1717,10 @@ emplace (Args&&... args) -> // map, set template + class Clock, class Compare, class Allocator> template auto -aged_ordered_container :: +aged_ordered_container :: emplace_hint (const_iterator hint, Args&&... args) -> typename std::enable_if >::type @@ -1752,10 +1743,10 @@ emplace_hint (const_iterator hint, Args&&... args) -> } template + class Clock, class Compare, class Allocator> template detail::aged_container_iterator -aged_ordered_container :: +aged_ordered_container :: erase (detail::aged_container_iterator pos) { unlink_and_delete_element(&*((pos++).iterator())); @@ -1764,10 +1755,10 @@ erase (detail::aged_container_iterator pos) } template + class Clock, class Compare, class Allocator> template detail::aged_container_iterator -aged_ordered_container :: +aged_ordered_container :: erase (detail::aged_container_iterator first, detail::aged_container_iterator last) { @@ -1779,10 +1770,10 @@ erase (detail::aged_container_iterator first, } template + class Clock, class Compare, class Allocator> template auto -aged_ordered_container :: +aged_ordered_container :: erase (K const& k) -> size_type { @@ -1805,9 +1796,9 @@ erase (K const& k) -> } template + class Clock, class Compare, class Allocator> void -aged_ordered_container :: +aged_ordered_container :: swap (aged_ordered_container& other) noexcept { swap_data (other); @@ -1818,10 +1809,10 @@ swap (aged_ordered_container& other) noexcept //------------------------------------------------------------------------------ template + class Clock, class Compare, class Allocator> template auto -aged_ordered_container :: +aged_ordered_container :: touch (K const& k) -> size_type { @@ -1839,11 +1830,11 @@ touch (K const& k) -> //------------------------------------------------------------------------------ template + class Clock, class Compare, class Allocator> template bool -aged_ordered_container :: +aged_ordered_container :: operator== ( aged_ordered_container + class Clock, class Compare, class Allocator> template void -aged_ordered_container :: +aged_ordered_container :: touch (detail::aged_container_iterator < is_const, Iterator, Base> pos, typename clock_type::time_point const& now) @@ -1881,10 +1872,10 @@ touch (detail::aged_container_iterator < } template + class Clock, class Compare, class Allocator> template typename std::enable_if ::type -aged_ordered_container :: +aged_ordered_container :: swap_data (aged_ordered_container& other) noexcept { std::swap (m_config.key_compare(), other.m_config.key_compare()); @@ -1893,10 +1884,10 @@ swap_data (aged_ordered_container& other) noexcept } template + class Clock, class Compare, class Allocator> template typename std::enable_if ::type -aged_ordered_container :: +aged_ordered_container :: swap_data (aged_ordered_container& other) noexcept { std::swap (m_config.key_compare(), other.m_config.key_compare()); @@ -1908,9 +1899,9 @@ swap_data (aged_ordered_container& other) noexcept //------------------------------------------------------------------------------ template + class Clock, class Compare, class Allocator> struct is_aged_container > + IsMulti, IsMap, Key, T, Clock, Compare, Allocator>> : std::true_type { }; @@ -1918,22 +1909,22 @@ struct is_aged_container + class Clock, class Compare, class Allocator> void swap ( detail::aged_ordered_container & lhs, + Key, T, Clock, Compare, Allocator>& lhs, detail::aged_ordered_container & rhs) noexcept + Key, T, Clock, Compare, Allocator>& rhs) noexcept { lhs.swap (rhs); } /** Expire aged container items past the specified age. */ template std::size_t expire (detail::aged_ordered_container < - IsMulti, IsMap, Key, T, Duration, Compare, Allocator>& c, + IsMulti, IsMap, Key, T, Clock, Compare, Allocator>& c, std::chrono::duration const& age) { std::size_t n (0); diff --git a/beast/container/detail/aged_unordered_container.h b/beast/container/detail/aged_unordered_container.h index b1c44f7c93..6ae3f4cfd6 100644 --- a/beast/container/detail/aged_unordered_container.h +++ b/beast/container/detail/aged_unordered_container.h @@ -22,15 +22,11 @@ #include #include - #include - #include #include - #include #include - #include // #include #include @@ -80,7 +76,7 @@ template < bool IsMap, class Key, class T, - class Duration = std::chrono::seconds, + class Clock = std::chrono::steady_clock, class Hash = std::hash , class KeyEqual = std::equal_to , class Allocator = std::allocator < @@ -91,24 +87,20 @@ template < class aged_unordered_container { public: - typedef abstract_clock clock_type; - typedef typename clock_type::time_point time_point; - typedef typename clock_type::duration duration; - typedef Key key_type; - typedef T mapped_type; - typedef typename std::conditional , - Key>::type value_type; - typedef std::size_t size_type; - typedef std::ptrdiff_t difference_type; + using clock_type = abstract_clock; + using time_point = typename clock_type::time_point; + using duration = typename clock_type::duration; + using key_type = Key; + using mapped_type = T; + using value_type = typename std::conditional , Key>::type; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; // Introspection (for unit tests) - typedef std::true_type is_unordered; - typedef std::integral_constant is_multi; - typedef std::integral_constant is_map; - - // VFALCO TODO How can we reorder the declarations to keep - // all the public things together contiguously? + using is_unordered = std::true_type; + using is_multi = std::integral_constant ; + using is_map = std::integral_constant ; private: static Key const& extract (value_type const& value) @@ -1504,8 +1496,8 @@ private: //------------------------------------------------------------------------------ template -aged_unordered_container +aged_unordered_container :: aged_unordered_container ( clock_type& clock) @@ -1517,8 +1509,8 @@ aged_unordered_container ( } template -aged_unordered_container +aged_unordered_container :: aged_unordered_container ( clock_type& clock, @@ -1531,8 +1523,8 @@ aged_unordered_container ( } template -aged_unordered_container +aged_unordered_container :: aged_unordered_container ( clock_type& clock, @@ -1545,8 +1537,8 @@ aged_unordered_container ( } template -aged_unordered_container +aged_unordered_container :: aged_unordered_container ( clock_type& clock, @@ -1560,8 +1552,8 @@ aged_unordered_container ( } template -aged_unordered_container +aged_unordered_container :: aged_unordered_container ( clock_type& clock, @@ -1575,8 +1567,8 @@ aged_unordered_container ( } template -aged_unordered_container +aged_unordered_container :: aged_unordered_container ( clock_type& clock, @@ -1591,8 +1583,8 @@ aged_unordered_container ( } template -aged_unordered_container +aged_unordered_container :: aged_unordered_container ( clock_type& clock, @@ -1607,8 +1599,8 @@ aged_unordered_container ( } template -aged_unordered_container +aged_unordered_container :: aged_unordered_container ( clock_type& clock, @@ -1624,9 +1616,9 @@ aged_unordered_container ( } template + class Clock, class Hash, class KeyEqual, class Allocator> template -aged_unordered_container :: aged_unordered_container (InputIt first, InputIt last, clock_type& clock) @@ -1639,9 +1631,9 @@ aged_unordered_container (InputIt first, InputIt last, } template + class Clock, class Hash, class KeyEqual, class Allocator> template -aged_unordered_container :: aged_unordered_container (InputIt first, InputIt last, clock_type& clock, @@ -1655,9 +1647,9 @@ aged_unordered_container (InputIt first, InputIt last, } template + class Clock, class Hash, class KeyEqual, class Allocator> template -aged_unordered_container :: aged_unordered_container (InputIt first, InputIt last, clock_type& clock, @@ -1671,9 +1663,9 @@ aged_unordered_container (InputIt first, InputIt last, } template + class Clock, class Hash, class KeyEqual, class Allocator> template -aged_unordered_container :: aged_unordered_container (InputIt first, InputIt last, clock_type& clock, @@ -1688,9 +1680,9 @@ aged_unordered_container (InputIt first, InputIt last, } template + class Clock, class Hash, class KeyEqual, class Allocator> template -aged_unordered_container :: aged_unordered_container (InputIt first, InputIt last, clock_type& clock, @@ -1705,9 +1697,9 @@ aged_unordered_container (InputIt first, InputIt last, } template + class Clock, class Hash, class KeyEqual, class Allocator> template -aged_unordered_container :: aged_unordered_container (InputIt first, InputIt last, clock_type& clock, @@ -1723,9 +1715,9 @@ aged_unordered_container (InputIt first, InputIt last, } template + class Clock, class Hash, class KeyEqual, class Allocator> template -aged_unordered_container :: aged_unordered_container (InputIt first, InputIt last, clock_type& clock, @@ -1741,9 +1733,9 @@ aged_unordered_container (InputIt first, InputIt last, } template + class Clock, class Hash, class KeyEqual, class Allocator> template -aged_unordered_container :: aged_unordered_container (InputIt first, InputIt last, clock_type& clock, @@ -1760,8 +1752,8 @@ aged_unordered_container (InputIt first, InputIt last, } template -aged_unordered_container +aged_unordered_container :: aged_unordered_container (aged_unordered_container const& other) : m_config (other.m_config) @@ -1774,8 +1766,8 @@ aged_unordered_container (aged_unordered_container const& other) } template -aged_unordered_container +aged_unordered_container :: aged_unordered_container (aged_unordered_container const& other, Allocator const& alloc) @@ -1789,8 +1781,8 @@ aged_unordered_container (aged_unordered_container const& other, } template -aged_unordered_container +aged_unordered_container :: aged_unordered_container (aged_unordered_container&& other) : m_config (std::move (other.m_config)) @@ -1801,8 +1793,8 @@ aged_unordered_container (aged_unordered_container&& other) } template -aged_unordered_container +aged_unordered_container :: aged_unordered_container (aged_unordered_container&& other, Allocator const& alloc) @@ -1817,8 +1809,8 @@ aged_unordered_container (aged_unordered_container&& other, } template -aged_unordered_container +aged_unordered_container :: aged_unordered_container (std::initializer_list init, clock_type& clock) @@ -1831,8 +1823,8 @@ aged_unordered_container (std::initializer_list init, } template -aged_unordered_container +aged_unordered_container :: aged_unordered_container (std::initializer_list init, clock_type& clock, @@ -1846,8 +1838,8 @@ aged_unordered_container (std::initializer_list init, } template -aged_unordered_container +aged_unordered_container :: aged_unordered_container (std::initializer_list init, clock_type& clock, @@ -1861,8 +1853,8 @@ aged_unordered_container (std::initializer_list init, } template -aged_unordered_container +aged_unordered_container :: aged_unordered_container (std::initializer_list init, clock_type& clock, @@ -1877,8 +1869,8 @@ aged_unordered_container (std::initializer_list init, } template -aged_unordered_container +aged_unordered_container :: aged_unordered_container (std::initializer_list init, clock_type& clock, @@ -1893,8 +1885,8 @@ aged_unordered_container (std::initializer_list init, } template -aged_unordered_container +aged_unordered_container :: aged_unordered_container (std::initializer_list init, clock_type& clock, @@ -1910,8 +1902,8 @@ aged_unordered_container (std::initializer_list init, } template -aged_unordered_container +aged_unordered_container :: aged_unordered_container (std::initializer_list init, clock_type& clock, @@ -1927,8 +1919,8 @@ aged_unordered_container (std::initializer_list init, } template -aged_unordered_container +aged_unordered_container :: aged_unordered_container (std::initializer_list init, clock_type& clock, @@ -1945,8 +1937,8 @@ aged_unordered_container (std::initializer_list init, } template -aged_unordered_container +aged_unordered_container :: ~aged_unordered_container() { @@ -1954,9 +1946,9 @@ aged_unordered_container + class Clock, class Hash, class KeyEqual, class Allocator> auto -aged_unordered_container :: operator= (aged_unordered_container const& other) -> aged_unordered_container& @@ -1974,9 +1966,9 @@ operator= (aged_unordered_container const& other) } template + class Clock, class Hash, class KeyEqual, class Allocator> auto -aged_unordered_container :: operator= (aged_unordered_container&& other) -> aged_unordered_container& @@ -1992,9 +1984,9 @@ operator= (aged_unordered_container&& other) -> } template + class Clock, class Hash, class KeyEqual, class Allocator> auto -aged_unordered_container :: operator= (std::initializer_list init) -> aged_unordered_container& @@ -2007,10 +1999,10 @@ operator= (std::initializer_list init) -> //------------------------------------------------------------------------------ template + class Clock, class Hash, class KeyEqual, class Allocator> template typename std::conditional ::type& -aged_unordered_container :: at (K const& k) { @@ -2023,10 +2015,10 @@ at (K const& k) } template + class Clock, class Hash, class KeyEqual, class Allocator> template typename std::conditional ::type const& -aged_unordered_container :: at (K const& k) const { @@ -2039,10 +2031,10 @@ at (K const& k) const } template + class Clock, class Hash, class KeyEqual, class Allocator> template typename std::conditional ::type& -aged_unordered_container :: operator[] (Key const& key) { @@ -2065,10 +2057,10 @@ operator[] (Key const& key) } template + class Clock, class Hash, class KeyEqual, class Allocator> template typename std::conditional ::type& -aged_unordered_container :: operator[] (Key&& key) { @@ -2093,9 +2085,9 @@ operator[] (Key&& key) //------------------------------------------------------------------------------ template + class Clock, class Hash, class KeyEqual, class Allocator> void -aged_unordered_container :: clear() { @@ -2109,10 +2101,10 @@ clear() // map, set template + class Clock, class Hash, class KeyEqual, class Allocator> template auto -aged_unordered_container :: insert (value_type const& value) -> typename std::enable_if // multimap, multiset template + class Clock, class Hash, class KeyEqual, class Allocator> template auto -aged_unordered_container :: insert (value_type const& value) -> typename std::enable_if // map, set template + class Clock, class Hash, class KeyEqual, class Allocator> template auto -aged_unordered_container :: insert (value_type&& value) -> typename std::enable_if // multimap, multiset template + class Clock, class Hash, class KeyEqual, class Allocator> template auto -aged_unordered_container :: insert (value_type&& value) -> typename std::enable_if #if 1 // Use insert() instead of insert_check() insert_commit() // set, map template + class Clock, class Hash, class KeyEqual, class Allocator> template auto -aged_unordered_container :: emplace (Args&&... args) -> typename std::enable_if #else // As original, use insert_check() / insert_commit () pair. // set, map template + class Clock, class Hash, class KeyEqual, class Allocator> template auto -aged_unordered_container :: emplace (Args&&... args) -> typename std::enable_if // multiset, multimap template + class Clock, class Hash, class KeyEqual, class Allocator> template auto -aged_unordered_container :: emplace (Args&&... args) -> typename std::enable_if // set, map template + class Clock, class Hash, class KeyEqual, class Allocator> template auto -aged_unordered_container :: emplace_hint (const_iterator /*hint*/, Args&&... args) -> typename std::enable_if } template + class Clock, class Hash, class KeyEqual, class Allocator> template detail::aged_container_iterator -aged_unordered_container :: erase (detail::aged_container_iterator < is_const, Iterator, Base> pos) @@ -2316,10 +2308,10 @@ erase (detail::aged_container_iterator < } template + class Clock, class Hash, class KeyEqual, class Allocator> template detail::aged_container_iterator -aged_unordered_container :: erase (detail::aged_container_iterator < is_const, Iterator, Base> first, @@ -2334,10 +2326,10 @@ erase (detail::aged_container_iterator < } template + class Clock, class Hash, class KeyEqual, class Allocator> template auto -aged_unordered_container :: erase (K const& k) -> size_type @@ -2361,9 +2353,9 @@ erase (K const& k) -> } template + class Clock, class Hash, class KeyEqual, class Allocator> void -aged_unordered_container :: swap (aged_unordered_container& other) noexcept { @@ -2373,10 +2365,10 @@ swap (aged_unordered_container& other) noexcept } template + class Clock, class Hash, class KeyEqual, class Allocator> template auto -aged_unordered_container :: touch (K const& k) -> size_type @@ -2393,7 +2385,7 @@ touch (K const& k) -> } template + class Clock, class Hash, class KeyEqual, class Allocator> template < bool OtherIsMap, class OtherKey, @@ -2405,7 +2397,7 @@ template < > typename std::enable_if ::type aged_unordered_container < - IsMulti, IsMap, Key, T, Duration, Hash, KeyEqual, Allocator>:: + IsMulti, IsMap, Key, T, Clock, Hash, KeyEqual, Allocator>:: operator== ( aged_unordered_container + class Clock, class Hash, class KeyEqual, class Allocator> template < bool OtherIsMap, class OtherKey, @@ -2436,7 +2428,7 @@ template < > typename std::enable_if ::type aged_unordered_container < - IsMulti, IsMap, Key, T, Duration, Hash, KeyEqual, Allocator>:: + IsMulti, IsMap, Key, T, Clock, Hash, KeyEqual, Allocator>:: operator== ( aged_unordered_container + class Clock, class Hash, class KeyEqual, class Allocator> template auto -aged_unordered_container :: insert_unchecked (value_type const& value) -> typename std::enable_if // multimap, multiset template + class Clock, class Hash, class KeyEqual, class Allocator> template auto -aged_unordered_container :: insert_unchecked (value_type const& value) -> typename std::enable_if //------------------------------------------------------------------------------ template + class Clock, class Hash, class KeyEqual, class Allocator> struct is_aged_container > + IsMulti, IsMap, Key, T, Clock, Hash, KeyEqual, Allocator>> : std::true_type { }; // Free functions -template void swap ( detail::aged_unordered_container & lhs, + Key, T, Clock, Hash, KeyEqual, Allocator>& lhs, detail::aged_unordered_container & rhs) noexcept + Key, T, Clock, Hash, KeyEqual, Allocator>& rhs) noexcept { lhs.swap (rhs); } /** Expire aged container items past the specified age. */ template std::size_t expire (detail::aged_unordered_container < - IsMulti, IsMap, Key, T, Duration, Hash, KeyEqual, Allocator>& c, + IsMulti, IsMap, Key, T, Clock, Hash, KeyEqual, Allocator>& c, std::chrono::duration const& age) noexcept { std::size_t n (0); diff --git a/beast/container/tests/aged_associative_container.test.cpp b/beast/container/tests/aged_associative_container.test.cpp index 49b43f479a..b282da733c 100644 --- a/beast/container/tests/aged_associative_container.test.cpp +++ b/beast/container/tests/aged_associative_container.test.cpp @@ -302,7 +302,7 @@ public: > using Cont = detail::aged_ordered_container < Base::is_multi::value, Base::is_map::value, typename Base::Key, - typename Base::T, typename Base::Dur, Compare, Allocator>; + typename Base::T, typename Base::Clock, Compare, Allocator>; }; // unordered @@ -318,7 +318,7 @@ public: > using Cont = detail::aged_unordered_container < Base::is_multi::value, Base::is_map::value, - typename Base::Key, typename Base::T, typename Base::Dur, + typename Base::Key, typename Base::T, typename Base::Clock, Hash, KeyEqual, Allocator>; }; @@ -327,8 +327,8 @@ public: struct TestTraitsBase { typedef std::string Key; - typedef std::chrono::seconds Dur; - typedef manual_clock Clock; + typedef std::chrono::steady_clock Clock; + typedef manual_clock ManualClock; }; template @@ -744,12 +744,12 @@ testConstructEmpty () typedef typename Traits::Value Value; typedef typename Traits::Key Key; typedef typename Traits::T T; - typedef typename Traits::Dur Dur; + typedef typename Traits::Clock Clock; typedef typename Traits::Comp Comp; typedef typename Traits::Alloc Alloc; typedef typename Traits::MyComp MyComp; typedef typename Traits::MyAlloc MyAlloc; - typename Traits::Clock clock; + typename Traits::ManualClock clock; //testcase (Traits::name() + " empty"); testcase ("empty"); @@ -789,14 +789,14 @@ testConstructEmpty () typedef typename Traits::Value Value; typedef typename Traits::Key Key; typedef typename Traits::T T; - typedef typename Traits::Dur Dur; + typedef typename Traits::Clock Clock; typedef typename Traits::Hash Hash; typedef typename Traits::Equal Equal; typedef typename Traits::Alloc Alloc; typedef typename Traits::MyHash MyHash; typedef typename Traits::MyEqual MyEqual; typedef typename Traits::MyAlloc MyAlloc; - typename Traits::Clock clock; + typename Traits::ManualClock clock; //testcase (Traits::name() + " empty"); testcase ("empty"); @@ -859,12 +859,12 @@ testConstructRange () typedef typename Traits::Value Value; typedef typename Traits::Key Key; typedef typename Traits::T T; - typedef typename Traits::Dur Dur; + typedef typename Traits::Clock Clock; typedef typename Traits::Comp Comp; typedef typename Traits::Alloc Alloc; typedef typename Traits::MyComp MyComp; typedef typename Traits::MyAlloc MyAlloc; - typename Traits::Clock clock; + typename Traits::ManualClock clock; auto const v (Traits::values()); //testcase (Traits::name() + " range"); @@ -922,14 +922,14 @@ testConstructRange () typedef typename Traits::Value Value; typedef typename Traits::Key Key; typedef typename Traits::T T; - typedef typename Traits::Dur Dur; + typedef typename Traits::Clock Clock; typedef typename Traits::Hash Hash; typedef typename Traits::Equal Equal; typedef typename Traits::Alloc Alloc; typedef typename Traits::MyHash MyHash; typedef typename Traits::MyEqual MyEqual; typedef typename Traits::MyAlloc MyAlloc; - typename Traits::Clock clock; + typename Traits::ManualClock clock; auto const v (Traits::values()); //testcase (Traits::name() + " range"); @@ -1002,12 +1002,12 @@ testConstructInitList () typedef typename Traits::Value Value; typedef typename Traits::Key Key; typedef typename Traits::T T; - typedef typename Traits::Dur Dur; + typedef typename Traits::Clock Clock; typedef typename Traits::Comp Comp; typedef typename Traits::Alloc Alloc; typedef typename Traits::MyComp MyComp; typedef typename Traits::MyAlloc MyAlloc; - typename Traits::Clock clock; + typename Traits::ManualClock clock; //testcase (Traits::name() + " init-list"); testcase ("init-list"); @@ -1027,14 +1027,14 @@ testConstructInitList () typedef typename Traits::Value Value; typedef typename Traits::Key Key; typedef typename Traits::T T; - typedef typename Traits::Dur Dur; + typedef typename Traits::Clock Clock; typedef typename Traits::Hash Hash; typedef typename Traits::Equal Equal; typedef typename Traits::Alloc Alloc; typedef typename Traits::MyHash MyHash; typedef typename Traits::MyEqual MyEqual; typedef typename Traits::MyAlloc MyAlloc; - typename Traits::Clock clock; + typename Traits::ManualClock clock; //testcase (Traits::name() + " init-list"); testcase ("init-list"); @@ -1057,7 +1057,7 @@ testCopyMove () typedef TestTraits Traits; typedef typename Traits::Value Value; typedef typename Traits::Alloc Alloc; - typename Traits::Clock clock; + typename Traits::ManualClock clock; auto const v (Traits::values()); //testcase (Traits::name() + " copy/move"); @@ -1139,7 +1139,7 @@ testIterator() typedef TestTraits Traits; typedef typename Traits::Value Value; typedef typename Traits::Alloc Alloc; - typename Traits::Clock clock; + typename Traits::ManualClock clock; auto const v (Traits::values()); //testcase (Traits::name() + " iterators"); @@ -1202,7 +1202,7 @@ testReverseIterator() typedef TestTraits Traits; typedef typename Traits::Value Value; typedef typename Traits::Alloc Alloc; - typename Traits::Clock clock; + typename Traits::ManualClock clock; auto const v (Traits::values()); //testcase (Traits::name() + " reverse_iterators"); @@ -1357,7 +1357,7 @@ aged_associative_container_test_base:: testModifiers() { typedef TestTraits Traits; - typename Traits::Clock clock; + typename Traits::ManualClock clock; auto const v (Traits::values()); auto const l (make_list (v)); @@ -1418,7 +1418,7 @@ testChronological () { typedef TestTraits Traits; typedef typename Traits::Value Value; - typename Traits::Clock clock; + typename Traits::ManualClock clock; auto const v (Traits::values()); //testcase (Traits::name() + " chronological"); @@ -1484,7 +1484,7 @@ aged_associative_container_test_base:: testArrayCreate() { typedef TestTraits Traits; - typename Traits::Clock clock; + typename Traits::ManualClock clock; auto v (Traits::values()); //testcase (Traits::name() + " array create"); @@ -1522,8 +1522,9 @@ reverseFillAgedContainer (Container& c, Values const& values) c.clear(); // c.clock() returns an abstract_clock, so dynamic_cast to manual_clock. - typedef TestTraitsBase::Clock Clock; - Clock& clk (dynamic_cast (c.clock ())); + // VFALCO NOTE This is sketchy + typedef TestTraitsBase::ManualClock ManualClock; + ManualClock& clk (dynamic_cast (c.clock())); clk.set (0); Values rev (values); @@ -1626,8 +1627,8 @@ testElementErase () testcase ("element erase"); // Make and fill the container - typename Traits::Clock ck; - typename Traits::template Cont <> c {ck}; + typename Traits::ManualClock clock; + typename Traits::template Cont <> c {clock}; reverseFillAgedContainer (c, Traits::values()); { @@ -1756,8 +1757,8 @@ testRangeErase () testcase ("range erase"); // Make and fill the container - typename Traits::Clock ck; - typename Traits::template Cont <> c {ck}; + typename Traits::ManualClock clock; + typename Traits::template Cont <> c {clock}; reverseFillAgedContainer (c, Traits::values()); // Not bothering to test range erase with reverse iterators. @@ -1785,7 +1786,7 @@ testCompare () { typedef TestTraits Traits; typedef typename Traits::Value Value; - typename Traits::Clock clock; + typename Traits::ManualClock clock; auto const v (Traits::values()); //testcase (Traits::name() + " array create"); @@ -1819,7 +1820,7 @@ aged_associative_container_test_base:: testObservers() { typedef TestTraits Traits; - typename Traits::Clock clock; + typename Traits::ManualClock clock; //testcase (Traits::name() + " observers"); testcase ("observers"); @@ -1838,7 +1839,7 @@ aged_associative_container_test_base:: testObservers() { typedef TestTraits Traits; - typename Traits::Clock clock; + typename Traits::ManualClock clock; //testcase (Traits::name() + " observers"); testcase ("observers");