X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsupport%2FCache.h;h=f1738c7147a0bc669d1fafb61c58224ffbe24726;hb=3561caa3a171a5984ee7a10b7ea82f7f4b7226e8;hp=75427809b40e2442d1bc622124d6a4dc327196d6;hpb=33b696c8acf2e64b44d449180781de6dbc203709;p=lyx.git diff --git a/src/support/Cache.h b/src/support/Cache.h index 75427809b4..f1738c7147 100644 --- a/src/support/Cache.h +++ b/src/support/Cache.h @@ -33,11 +33,15 @@ namespace lyx { */ template class Cache : private QCache { +#if !(defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 6)) static_assert(std::is_copy_constructible::value, "lyx::Cache only stores copyable objects!"); static_assert(std::is_default_constructible::value, "lyx::Cache only stores default-constructible objects!"); using Q = QCache; +#else + typedef QCache Q; +#endif public: /// @@ -47,15 +51,17 @@ public: { return Q::insert(key, new Val(std::move(object)), cost); } - // Returns the default value (e.g. null pointer) before using the result. If - // this is not convenient for your type, check if it exists beforehand with - // Cache::contains. + // Returns the default value (e.g. null pointer) if not found in the + // cache. If this is not convenient for your class Val, check if it exists + // beforehand with Cache::contains. Val object(Key const & key) const { if (Val * obj = Q::object(key)) return *obj; return Val(); } + /// Synonymous for object, same remark as above. + Val operator[](Key const & key) const { return object(key); } /// Everything from QCache except QCache::take. using Q::clear; using Q::contains; @@ -67,7 +73,6 @@ public: int max_cost() const { return Q::maxCost(); } void set_max_cost(int cost) { Q::setMaxCost(cost); } int total_cost() const { return Q::totalCost(); } - Val operator[](Key const & key) const { return object(key); } }; } // namespace lyx