From f3fe5dafa900f5ade6b8e25ca7d1ad6d32265967 Mon Sep 17 00:00:00 2001 From: rekrutik Date: Mon, 20 Jan 2025 23:02:48 +0300 Subject: [PATCH 1/2] Fix copy construction of LRU cache --- include/boost/compute/detail/lru_cache.hpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/boost/compute/detail/lru_cache.hpp b/include/boost/compute/detail/lru_cache.hpp index fe1a56f74..ca29ff583 100644 --- a/include/boost/compute/detail/lru_cache.hpp +++ b/include/boost/compute/detail/lru_cache.hpp @@ -39,6 +39,28 @@ class lru_cache { } + // in case of default copying list iterators would be invalidated + lru_cache(const lru_cache& other) + : m_list(other.m_list), + m_capacity(other.m_capacity) + { + for(typename list_type::iterator i = m_list.begin(); i != m_list.end(); ++i){ + m_map[*i] = std::make_pair(other.m_map.at(*i).first, i); + } + } + + lru_cache& operator=(const lru_cache& other) + { + if(this != &other){ + m_list = other.m_list; + m_capacity = other.m_capacity; + for(typename list_type::iterator i = m_list.begin(); i != m_list.end(); ++i){ + m_map[*i] = std::make_pair(other.m_map.at(*i).first, i); + } + } + return *this; + } + ~lru_cache() { } From e3d18802256327d25605dc9491f2930b3184fab6 Mon Sep 17 00:00:00 2001 From: rekrutik Date: Mon, 20 Jan 2025 23:16:58 +0300 Subject: [PATCH 2/2] Comply with code style from different sources --- include/boost/compute/detail/lru_cache.hpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/include/boost/compute/detail/lru_cache.hpp b/include/boost/compute/detail/lru_cache.hpp index ca29ff583..cfce86094 100644 --- a/include/boost/compute/detail/lru_cache.hpp +++ b/include/boost/compute/detail/lru_cache.hpp @@ -41,12 +41,8 @@ class lru_cache // in case of default copying list iterators would be invalidated lru_cache(const lru_cache& other) - : m_list(other.m_list), - m_capacity(other.m_capacity) { - for(typename list_type::iterator i = m_list.begin(); i != m_list.end(); ++i){ - m_map[*i] = std::make_pair(other.m_map.at(*i).first, i); - } + lru_cache::operator=(other); } lru_cache& operator=(const lru_cache& other) @@ -61,6 +57,21 @@ class lru_cache return *this; } + lru_cache(const lru_cache&& other) BOOST_NOEXCEPT + { + lru_cache::operator=(std::move(other)); + } + + lru_cache& operator==(lru_cache&& other) BOOST_NOEXCEPT + { + if(this != &other){ + m_map = std::move(other.m_map); + m_list = std::move(other.m_list); + m_capacity = other.m_capacity; + } + return *this; + } + ~lru_cache() { }