[
  {
    "path": ".clang-format",
    "content": "Language: Cpp\nStandard: Cpp11\nBasedOnStyle: Google\n\nAllowAllParametersOfDeclarationOnNextLine: true\nAllowShortBlocksOnASingleLine: false\nAllowShortCaseLabelsOnASingleLine: true\nAllowShortFunctionsOnASingleLine: false\nAllowShortIfStatementsOnASingleLine: true\nAllowShortLoopsOnASingleLine: true\n\nAlignOperands: true\nAlignConsecutiveAssignments: false\n\nBinPackArguments: false\nBinPackParameters: false\nBreakConstructorInitializersBeforeComma: true\nConstructorInitializerAllOnOneLineOrOnePerLine: true\nConstructorInitializerIndentWidth: 0\nContinuationIndentWidth: 4\nCpp11BracedListStyle: true\nDerivePointerAlignment: false\nIndentCaseLabels: true\nIndentWidth: 2\nMaxEmptyLinesToKeep: 2\nNamespaceIndentation: None\nPointerAlignment: Left\nSpacesBeforeTrailingComments: 2\nTabWidth: 2\nUseTab: Never\n\nPenaltyExcessCharacter: 1000000\nPenaltyReturnTypeOnItsOwnLine: 10\nPenaltyBreakBeforeFirstCallParameter: 10\n"
  },
  {
    "path": ".gitignore",
    "content": "\n# Created by https://www.gitignore.io/api/c++,cmake\n\n### C++ ###\n# Prerequisites\n*.d\n\n# Compiled Object files\n*.slo\n*.lo\n*.o\n*.obj\n\n# Precompiled Headers\n*.gch\n*.pch\n\n# Compiled Dynamic libraries\n*.so\n*.dylib\n*.dll\n\n# Fortran module files\n*.mod\n*.smod\n\n# Compiled Static libraries\n*.lai\n*.la\n*.a\n*.lib\n\n# Executables\n*.exe\n*.out\n*.app\n\n\n### CMake ###\nCMakeCache.txt\nCMakeFiles\nCMakeScripts\nMakefile\ncmake_install.cmake\ninstall_manifest.txt\nCTestTestfile.cmake\n\n### Other ###\nbuild/\n*.dSYM/\ndocs/html/\ndocs/latex/\n"
  },
  {
    "path": ".gitmodules",
    "content": "[submodule \"tests/googletest\"]\n\tpath = tests/googletest\n\turl = https://github.com/google/googletest\n"
  },
  {
    "path": ".travis.yml",
    "content": "# http://genbattle.bitbucket.org/blog/2016/01/17/c++-travis-ci/\n# https://github.com/whoshuu/cpr/blob/master/.travis.yml\n\nlanguage: cpp\nsudo: required\ndist: trusty\n\nmatrix:\n  include:\n    - compiler: gcc\n      addons:\n        apt:\n          sources:\n            - ubuntu-toolchain-r-test\n          packages:\n            - g++-5\n            - gdb\n      env: COMPILER=g++-5\n    - compiler: clang\n      addons:\n        apt:\n          sources:\n            - ubuntu-toolchain-r-test\n            - llvm-toolchain-precise-3.7\n          packages:\n            - clang-3.7\n            - gdb\n      env: COMPILER=clang++-3.7\n\nbefore_install:\n # What is the current file size max for core files?\n # It is usually 0, which means no core file will be dumped if there is a crash\n - ulimit -c\n - ulimit -a -S\n - ulimit -a -H\n - cat /proc/sys/kernel/core_pattern\n\ninstall:\n  - CMAKE_VERSION_MM=3.2\n  - CMAKE_VERSION_FULL=$CMAKE_VERSION_MM.2\n  - if [ \"$TRAVIS_OS_NAME\" == \"linux\" ]; then\n      sudo apt-get update -qq\n      && sudo apt-get install -qq qt5-qmake qtbase5-dev qtdeclarative5-dev\n      && wget --no-check-certificate http://www.cmake.org/files/v${CMAKE_VERSION_MM}/cmake-${CMAKE_VERSION_FULL}-Linux-x86_64.sh\n      && sudo sh cmake-${CMAKE_VERSION_FULL}-Linux-x86_64.sh --prefix=/usr/local --exclude-subdir;\n    fi\n  - if [ \"$TRAVIS_OS_NAME\" = \"osx\" ]; then\n    brew update\n      && ((brew list -1 | grep -q \"^$cmake\\$\") || brew install cmake)\n      && (brew outdated cmake || brew upgrade cmake)\n      && cmake --version;\n    fi\n\nbefore_script:\n  - export CXX=$COMPILER\n  - cmake --version\n  - mkdir build\n  - cd build\n  - cmake -DCMAKE_CXX_COMPILER=$COMPILER ..\n  - cp ../tests/logbt.sh .\n  - sudo chmod a+x logbt.sh\n  - sudo bash -c \"echo '/tmp/logbt-coredumps/core.%p.%E' > /proc/sys/kernel/core_pattern\"\n\nscript:\n  - make VERBOSE=1 -j4\n  - ./logbt.sh bin/lru-cache-test\n\nnotifications:\n  email: false\n"
  },
  {
    "path": "CMakeLists.txt",
    "content": "###########################################################\n## CMAKE SETUP\n###########################################################\n\ncmake_minimum_required(VERSION 3.2)\nproject(lru-cache)\n\nadd_compile_options(-g)\n\n########################################\n# C++ VERSIONING\n########################################\n\ninclude(CheckCXXCompilerFlag)\n\ncheck_cxx_compiler_flag(\"-std=c++14\" COMPILER_SUPPORTS_CXX_14)\ncheck_cxx_compiler_flag(\"-std=c++1z\" COMPILER_SUPPORTS_CXX_1z)\ncheck_cxx_compiler_flag(\"-std=c++17\" COMPILER_SUPPORTS_CXX_17)\n\nif (COMPILER_SUPPORTS_CXX_1z)\n  message(STATUS \"Compiling with C++1z\")\n    set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++1z\")\nelseif (COMPILER_SUPPORTS_CXX_14)\n  message(STATUS \"Compiling with C++14\")\n    set(CMAKE_CXX_STANDARD 14)\nelse()\n    message(FATAL_ERROR \"Please install a modern C++ compiler, they are not expensive.\")\nendif()\n\n###########################################################\n## DEPENDENCIES\n###########################################################\n\nset(CMAKE_MODULE_PATH\n  ${CMAKE_MODULE_PATH}\n  \"${CMAKE_SOURCE_DIR}/cmake/Modules/\"\n)\n\n###########################################################\n## INCLUDES\n###########################################################\n\n# Need this top-level include for \"tests/\"\ninclude_directories(${CMAKE_CURRENT_SOURCE_DIR})\ninclude_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)\n\n###########################################################\n## EXAMPLES\n###########################################################\n\nadd_subdirectory(examples)\n\n########################################\n# TESTS\n########################################\n\noption(BUILD_LRU_CACHE_TESTS \"Enable tests\" ON)\n\nif(BUILD_LRU_CACHE_TESTS)\n  message(STATUS \"Enabling tests ...\")\n  enable_testing()\n  add_subdirectory(tests)\nelse()\n  message(STATUS \"Disabling tests ...\")\nendif()\n"
  },
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\nCopyright (c) 2016 Peter Goldsborough\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# lru-cache\n\n[![GitHub license](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square)](http://goldsborough.mit-license.org) [![Build Status](https://travis-ci.org/goldsborough/lru-cache.svg?branch=master)](https://travis-ci.org/goldsborough/lru-cache)\n\nA feature complete LRU cache implementation in C++.\n\n## Description\n\nA *least recently used* (LRU) cache is a fixed size cache that behaves just like a regular lookup table, but remembers the order in which elements are accessed. Once its (user-defined) capacity is reached, it uses this information to replace the least recently used element with a newly inserted one. This is ideal for caching function return values, where fast lookup of complex computations is favorable, but a memory blowup from caching all `(input, output)` pairs is to be avoided.\n\nWe provide two implementations of an LRU cache: one has only the basic functionality described above, and another can be additionally supplied with a *time to live*. This is useful, for example, when caching resources on a server, where cache entries should be invalidated automatically after a certain amount of time, because they are no longer \"fresh\".\n\nAdditionally, all our caches can be connected to *statistics* objects, that keep track of cache hits and misses for all keys and, upon request, individual keys (similar to `functools.lru_cache` in Python). You can also register arbitrary callbacks for hits, misses or accesses in general.\n\n## Basic Usage\n\nThe two main classes we provide are `LRU::Cache` and `LRU::TimedCache`. A basic usage example of these may look like so:\n\n__`LRU::Cache`__\n```C++\n#include <iostream>\n#include \"lru/lru.hpp\"\n\nusing Cache = LRU::Cache<int, int>;\n\nint fibonacci(int n, Cache& cache) {\n  if (n < 2) return 1;\n\n  // We internally keep track of the last accessed key, meaning a\n  // `contains(key)` + `lookup(key)` sequence will involve only a single hash\n  // table lookup.\n  if (cache.contains(n)) return cache.lookup(n);\n\n  auto value = fibonacci(n - 1, cache) + fibonacci(n - 2, cache);\n\n  // Caches are 100% move-aware and we have implemented\n  // `unordered_map` style emplacement and insertion.\n  cache.emplace(n, value);\n\n  return value;\n}\n\nint fibonacci(int n) {\n  // Use a capacity of 100 (after 100 insertions, the next insertion will evict\n  // the least-recently accessed element). The default capacity is 128.\n  Cache cache(100);\n  return fibonacci(n, cache);\n}\n```\n\n__`LRU::TimedCache`__\n```C++\n#include <chrono>\n#include <iostream>\n\n#include \"lru/lru.hpp\"\n\nusing namespace std::chrono_literals;\n\nusing Cache = LRU::TimedCache<int, int>;\n\nint fibonacci(int n, Cache& cache) {\n  if (n < 2) return 1;\n  if (cache.contains(n)) return cache[n];\n\n  auto value = fibonacci(n - 1, cache) + fibonacci(n - 2, cache);\n  cache.emplace(n, value);\n\n  return value;\n}\n\nint fibonacci(int n) {\n  // Use a time to live of 100ms. This means that 100ms after insertion, a key\n  // will be said to have \"expired\" and `contains(key)` will return false.\n  Cache cache(100ms);\n  return fibonacci(n, cache);\n}\n\nauto main() -> int {\n  std::cout << fibonacci(32) << std::endl;\n}\n```\n\n## Extended Usage\n\nOur caches bring along many exciting features including statistics monitoring, function wrapping, arbitrary callbacks as well as ordered and unordered iteration.\n\n### Ordered and Unordered Iteration\n\nBoth the `LRU::Cache` and `LRU::TimedCache` can be iterated over in two ways: ordered or unordered fashion (where the \"order\" refers to the order of insertion). The default iterators returned by `begin()`, `cbegin()`, `end()` etc. are *unordered* and mostly similar to `unordered_map` iterators (with some nice non-standard sugar):\n\n```C++\nLRU::Cache<int, int> cache = {{1, 2}, {2, 3}, {3, 4}};\n\nint sum = 0;\nfor (const auto& pair : cache) {\n  sum += pair.first; // Standards compliant (good for templates)\n  sum += pair.value(); // But sugar on top (also key())\n}\n\nauto iterator = cache.begin();           // These two lines\nauto iterator = cache.unordered_begin(); // are the same\nauto iterator = cache.ordered_end();     // This is something different\n```\n\nUnordered iterators are implemented directly over internal map iterators and thus have access to the key and value of a pointed-to entry.\n\nOrdered iterators respect the order of insertion. They differ in a few ways from unordered iterators:\n\n1. They are bidirectional, while unordered iterators are forward iterators.\n2. They provide fast access only to the `key()`. Accessing the value requires a hash table lookup the first time an iterator is dereferenced.\n3. They can be constructed from unordered iterators! This means writing something like `typename LRU::Cache<int, int>::OrderedIterator i(unordered_iterator)` will work and is fast.\n\nDreferencing an iterator will not change the order of elements in the cache.\n\n### Statistics\n\nOur caches can be associated with statistics objects, that monitor hits and misses. There are a few ways to create and use them. First of all, let's say you only wanted to record hits and misses for all keys and didn't care about any particular key. The simplest way to do this is to simply call:\n\n```cpp\ncache.monitor();\n```\n\nThis allows you to call `cache.stats()`, which returns an `LRU::Statistics` object. It's interface is quite clear, allowing you to write stuff like:\n\n```cpp\ncache.stats().total_hits(); // Hits for any key\ncache.stats().total_misses(); // Misses for any key\ncache.stats().hit_rate(); // Hit rate in [0, 1]\n```\n\nNote that a hit or miss only refers to lookup (i.e. methods `contains()`, `find()`, `lookup()` and `operator[]`) but not insertion via `emplace()` or `insert()`.\n\n#### Sharing Statistics\n\nAlready here, one idea might be that we have two functions, each with their own cache, but we'd like them to share statistics. This is easy to do. Simply create the `Statistics` object as a `std::shared_ptr` and plug it into `cache.monitor()` for as many caches as you like:\n\n```cpp\nauto stats = std::make_shared<LRU::Statistics<std::string>>();\n\ncache1.monitor(stats);\ncache2.monitor(stats);\n\n// Both affect the same statistics object\ncache1.lookup(\"key\");\ncache2.lookup(\"foo\");\n\nassert(&cache1.stats() == &cache2.stats()); // Ok\n\nstd::shared_ptr<Statistics<std::string>> stats2 = cache1.shared_stats();\n```\n\n#### Monitoring specific keys\n\nOne of the more interesting features of our statistics API is the ability to monitor hits and misses for a specific set of keys. Say we were writing a web server accepting HTTP requests and wanted to cache resources (I assume that's something people would do). Because our website changes in some way every hour, we'll use a timed cache with a time-to-live of one hour. We're also particularly interested in how many cache hits we get for `index.html`. For this, it's good to know that the empty `monitor()` call we made further up is actually a method accepting variadic arguments to forward to the constructor of an internal statistics object (the empty `monitor()` calls the default constructor). One constructor of `Statistics` takes a number of keys to monitor in particular. So calling `monitor(key1, key2, ...)` will set up monitoring for those keys. We could then something like this:\n\n```cpp\n#include <string>\n#include <chrono>\n\n#include \"lru/lru.hpp\"\n\nusing namespace std::chrono_literals;\n\nstruct MyWebServer {\n\n  // We pass 1h to let the cache know that resources are to be invalidated after one hour.\n  MyWebServer() : cache(1h) {\n    cache.monitor(\"index.html\");\n  }\n\n  std::string get(const std::string& resource_name) {\n    std::string resource;\n    if (cache.contains(resource_name)) {\n      resource = cache.lookup(resource_name);\n    } else {\n      resource = fetch_expensively(resource_name);\n      cache.insert(resource_name, resource);\n    }\n\n    return resource;\n  }\n\n  LRU::TimedCache<std::string, std::string> cache;\n};\n```\n\nLater on, we can use methods like `hits_for(\"index.html\")`, `misses_for(\"index.html\")` or `stats_for(\"index.html\")` on `cache.stats()` to find out how many hits or misses we got for our monitored resource. Note that `stats_for(key)` returns a lightweight `struct` holding hit and miss information about a particular key.\n\n### Callbacks\n\nNext to registering statistics, we also allow hook in arbitrary callbacks. The three kinds of callbacks that may be registered are:\n\n1. Hit callbacks, taking a key and value after a cache hit (registered with `hit_callback()`).\n2. Miss callbacks, taking only a key, that was not found in a cache (registered with `miss_callback()`).\n3. Access callbacks, taking a key and a boolean indicating a hit or a miss (registered with `access_callback()`).\n\nUsage could look something like this:\n\n```cpp\nLRU::Cache<int, int> cache;\n\ncache.hit_callback([](const auto& key, const auto& value) {\n  std::clog << \"Hit for entry (\"\n            << key << \", \" << value << \")\"\n            << std::endl;\n});\n\ncache.miss_callback([](const auto& key) {\n  std::clog << \"Miss for \" << key<< std::endl;\n});\n\n// Roll your own statistics\nstd::size_t miss_count = 0;\ncache.miss_callback([&miss_count](auto&) {\n  miss_count += 1;\n});\n\ncache.access_callback([](const auto& key, bool was_hit) {\n  std::clog << \"Access for \" << key\n            << \" was a \" << (was_hit ? \"hit\" : \"miss\")\n            << std::endl;\n});\n```\n\nNote that just like with statistics, these callbacks will only get invoked for lookup and not insertion.\n\n### Wrapping\n\nWe provide utility functions `LRU::wrap` and `LRU::timed_wrap` that take a function and return a new function, with a (timed) cache attached to it. Feels like Python. Just faster.\n\n```cpp\n#include \"lru/lru.hpp\"\n\nint my_expensive_function(int, char, double) {\n  // ...\n}\n\nauto my_cached_expensive_function = LRU::wrap(my_expensive_function);\n\nmy_cached_expensive_function(1, 'a', 3.14);\n```\n\nNext to the function to wrap, `LRU::wrap` and `LRU::timed_wrap` take any number of arguments to forward to the constructor of the internal cache:\n\n```cpp\n// Use a capacity of 100\nauto new_function = LRU::wrap(old_function, 1000);\n\n// Use a time-to-live of 100 milliseconds\nauto new_function = LRU::timed_wrap(old_function, 100ms);\n```\n\nNote that this will *not* cache recursive calls, since we cannot override the actual function symobl. As such we refer to this as \"shallow memoization\".\n\n### Lowercase Names\n\nNot everyone has the same taste. We get that. For this reason, for every public `CamelCase` type name, we've defined a `lower_case` (C++ standard style) alias. You can make these visible by including `lru/lowercase.hpp` instead of `lru/lru.hpp`:\n\n```cpp\n#include <chrono>\n#include <iostream>\n\n#include \"lru/lowercase.hpp\"\n\nvoid print(lru::tag::basic_cache) {\n  std::cout << \"basic cache\" << '\\n';\n}\n\nvoid print(lru::tag::timed_cache) {\n  std::cout << \"timed cache\" << '\\n';\n}\n\nauto main() -> int {\n  using namespace std::chrono_literals;\n\n  lru::cache<int, int> cache;\n  lru::timed_cache<int, int> timed_cache(100ms);\n\n  print(cache.tag());\n  print(timed_cache.tag());\n\n  lru::cache<int, int>::ordered_const_iterator iterator(cache.begin());\n\n  lru::statistics<int> stats;\n}\n\n```\n\n## Documentation\n\nWe have 100% public and private documentation coverage with a decent effort behind it. As such we ask you to RTFM to see the full interface we provide (it is a superset of `std::unordered_map`, minus the new node interface). Documentation can be generated with [Doxygen](http://www.stack.nl/~dimitri/doxygen/) by running the `doxygen` command inside the `docs/` folder.\n\nAlso do check out all the examples in the `examples/` folder!\n\n## LICENSE\n\nThis project is released under the [MIT License](http://goldsborough.mit-license.org). For more information, see the LICENSE file.\n\n## Authors\n\n[Peter Goldsborough](http://goldsborough.me) + [cat](https://goo.gl/IpUmJn) :heart:\n\nThanks to [@engelmarkus](https://github.com/engelmarkus) for technical and emotional support.\n"
  },
  {
    "path": "cpplint.cfg",
    "content": "# cpplint configuration\n\nfilter=-build/c++11,-whitespace/parens,-runtime/references,-whitespace/operators\n"
  },
  {
    "path": "docs/Doxyfile",
    "content": "# Doxyfile 1.8.6\n\n# This file describes the settings to be used by the documentation system\n# doxygen (www.doxygen.org) for a project.\n#\n# All text after a double hash (##) is considered a comment and is placed in\n# front of the TAG it is preceding.\n#\n# All text after a single hash (#) is considered a comment and will be ignored.\n# The format is:\n# TAG = value [value, ...]\n# For lists, items can also be appended using:\n# TAG += value [value, ...]\n# Values that contain spaces should be placed between quotes (\\\" \\\").\n\n#---------------------------------------------------------------------------\n# Project related configuration options\n#---------------------------------------------------------------------------\n\n# This tag specifies the encoding used for all characters in the config file\n# that follow. The default is UTF-8 which is also the encoding used for all text\n# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv\n# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv\n# for the list of possible encodings.\n# The default value is: UTF-8.\n\nDOXYFILE_ENCODING      = UTF-8\n\n# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by\n# double-quotes, unless you are using Doxywizard) that should identify the\n# project for which the documentation is generated. This name is used in the\n# title of most generated pages and in a few other places.\n# The default value is: My Project.\n\nPROJECT_NAME           = \"LRU Cache\"\n\n# The PROJECT_NUMBER tag can be used to enter a project or revision number. This\n# could be handy for archiving the generated documentation or if some version\n# control system is used.\n\nPROJECT_NUMBER         = 0.1\n\n# Using the PROJECT_BRIEF tag one can provide an optional one line description\n# for a project that appears at the top of each page and should give viewer a\n# quick idea about the purpose of the project. Keep the description short.\n\nPROJECT_BRIEF          = A feature-complete LRU cache implementation.\n\n# With the PROJECT_LOGO tag one can specify an logo or icon that is included in\n# the documentation. The maximum height of the logo should not exceed 55 pixels\n# and the maximum width should not exceed 200 pixels. Doxygen will copy the logo\n# to the output directory.\n\nPROJECT_LOGO           =\n\n# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path\n# into which the generated documentation will be written. If a relative path is\n# entered, it will be relative to the location where doxygen was started. If\n# left blank the current directory will be used.\n\nOUTPUT_DIRECTORY       =\n\n# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 4096 sub-\n# directories (in 2 levels) under the output directory of each output format and\n# will distribute the generated files over these directories. Enabling this\n# option can be useful when feeding doxygen a huge amount of source files, where\n# putting all generated files in the same directory would otherwise causes\n# performance problems for the file system.\n# The default value is: NO.\n\nCREATE_SUBDIRS         = NO\n\n# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII\n# characters to appear in the names of generated files. If set to NO, non-ASCII\n# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode\n# U+3044.\n# The default value is: NO.\n\nALLOW_UNICODE_NAMES    = NO\n\n# The OUTPUT_LANGUAGE tag is used to specify the language in which all\n# documentation generated by doxygen is written. Doxygen will use this\n# information to generate all constant output in the proper language.\n# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese,\n# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States),\n# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian,\n# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages),\n# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian,\n# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian,\n# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish,\n# Ukrainian and Vietnamese.\n# The default value is: English.\n\nOUTPUT_LANGUAGE        = English\n\n# If the BRIEF_MEMBER_DESC tag is set to YES doxygen will include brief member\n# descriptions after the members that are listed in the file and class\n# documentation (similar to Javadoc). Set to NO to disable this.\n# The default value is: YES.\n\nBRIEF_MEMBER_DESC      = YES\n\n# If the REPEAT_BRIEF tag is set to YES doxygen will prepend the brief\n# description of a member or function before the detailed description\n#\n# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the\n# brief descriptions will be completely suppressed.\n# The default value is: YES.\n\nREPEAT_BRIEF           = YES\n\n# This tag implements a quasi-intelligent brief description abbreviator that is\n# used to form the text in various listings. Each string in this list, if found\n# as the leading text of the brief description, will be stripped from the text\n# and the result, after processing the whole list, is used as the annotated\n# text. Otherwise, the brief description is used as-is. If left blank, the\n# following values are used ($name is automatically replaced with the name of\n# the entity):The $name class, The $name widget, The $name file, is, provides,\n# specifies, contains, represents, a, an and the.\n\nABBREVIATE_BRIEF       =\n\n# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then\n# doxygen will generate a detailed section even if there is only a brief\n# description.\n# The default value is: NO.\n\nALWAYS_DETAILED_SEC    = NO\n\n# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all\n# inherited members of a class in the documentation of that class as if those\n# members were ordinary class members. Constructors, destructors and assignment\n# operators of the base classes will not be shown.\n# The default value is: NO.\n\nINLINE_INHERITED_MEMB  = YES\n\n# If the FULL_PATH_NAMES tag is set to YES doxygen will prepend the full path\n# before files name in the file list and in the header files. If set to NO the\n# shortest path that makes the file name unique will be used\n# The default value is: YES.\n\nFULL_PATH_NAMES        = YES\n\n# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path.\n# Stripping is only done if one of the specified strings matches the left-hand\n# part of the path. The tag can be used to show relative paths in the file list.\n# If left blank the directory from which doxygen is run is used as the path to\n# strip.\n#\n# Note that you can specify absolute paths here, but also relative paths, which\n# will be relative from the directory where doxygen is started.\n# This tag requires that the tag FULL_PATH_NAMES is set to YES.\n\nSTRIP_FROM_PATH        =\n\n# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the\n# path mentioned in the documentation of a class, which tells the reader which\n# header file to include in order to use a class. If left blank only the name of\n# the header file containing the class definition is used. Otherwise one should\n# specify the list of include paths that are normally passed to the compiler\n# using the -I flag.\n\nSTRIP_FROM_INC_PATH    =\n\n# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but\n# less readable) file names. This can be useful is your file systems doesn't\n# support long names like on DOS, Mac, or CD-ROM.\n# The default value is: NO.\n\nSHORT_NAMES            = NO\n\n# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the\n# first line (until the first dot) of a Javadoc-style comment as the brief\n# description. If set to NO, the Javadoc-style will behave just like regular Qt-\n# style comments (thus requiring an explicit @brief command for a brief\n# description.)\n# The default value is: NO.\n\nJAVADOC_AUTOBRIEF      = YES\n\n# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first\n# line (until the first dot) of a Qt-style comment as the brief description. If\n# set to NO, the Qt-style will behave just like regular Qt-style comments (thus\n# requiring an explicit \\brief command for a brief description.)\n# The default value is: NO.\n\nQT_AUTOBRIEF           = NO\n\n# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a\n# multi-line C++ special comment block (i.e. a block of //! or /// comments) as\n# a brief description. This used to be the default behavior. The new default is\n# to treat a multi-line C++ comment block as a detailed description. Set this\n# tag to YES if you prefer the old behavior instead.\n#\n# Note that setting this tag to YES also means that rational rose comments are\n# not recognized any more.\n# The default value is: NO.\n\nMULTILINE_CPP_IS_BRIEF = NO\n\n# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the\n# documentation from any documented member that it re-implements.\n# The default value is: YES.\n\nINHERIT_DOCS           = YES\n\n# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce a\n# new page for each member. If set to NO, the documentation of a member will be\n# part of the file/class/namespace that contains it.\n# The default value is: NO.\n\nSEPARATE_MEMBER_PAGES  = NO\n\n# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen\n# uses this value to replace tabs by spaces in code fragments.\n# Minimum value: 1, maximum value: 16, default value: 4.\n\nTAB_SIZE               = 2\n\n# This tag can be used to specify a number of aliases that act as commands in\n# the documentation. An alias has the form:\n# name=value\n# For example adding\n# \"sideeffect=@par Side Effects:\\n\"\n# will allow you to put the command \\sideeffect (or @sideeffect) in the\n# documentation, which will result in a user-defined paragraph with heading\n# \"Side Effects:\". You can put \\n's in the value part of an alias to insert\n# newlines.\n\nALIASES                = \"complexity=\\par Complexity\\n\"\n\n# This tag can be used to specify a number of word-keyword mappings (TCL only).\n# A mapping has the form \"name=value\". For example adding \"class=itcl::class\"\n# will allow you to use the command class in the itcl::class meaning.\n\nTCL_SUBST              =\n\n# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources\n# only. Doxygen will then generate output that is more tailored for C. For\n# instance, some of the names that are used will be different. The list of all\n# members will be omitted, etc.\n# The default value is: NO.\n\nOPTIMIZE_OUTPUT_FOR_C  = NO\n\n# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or\n# Python sources only. Doxygen will then generate output that is more tailored\n# for that language. For instance, namespaces will be presented as packages,\n# qualified scopes will look different, etc.\n# The default value is: NO.\n\nOPTIMIZE_OUTPUT_JAVA   = NO\n\n# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran\n# sources. Doxygen will then generate output that is tailored for Fortran.\n# The default value is: NO.\n\nOPTIMIZE_FOR_FORTRAN   = NO\n\n# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL\n# sources. Doxygen will then generate output that is tailored for VHDL.\n# The default value is: NO.\n\nOPTIMIZE_OUTPUT_VHDL   = NO\n\n# Doxygen selects the parser to use depending on the extension of the files it\n# parses. With this tag you can assign which parser to use for a given\n# extension. Doxygen has a built-in mapping, but you can override or extend it\n# using this tag. The format is ext=language, where ext is a file extension, and\n# language is one of the parsers supported by doxygen: IDL, Java, Javascript,\n# C#, C, C++, D, PHP, Objective-C, Python, Fortran (fixed format Fortran:\n# FortranFixed, free formatted Fortran: FortranFree, unknown formatted Fortran:\n# Fortran. In the later case the parser tries to guess whether the code is fixed\n# or free formatted code, this is the default for Fortran type files), VHDL. For\n# instance to make doxygen treat .inc files as Fortran files (default is PHP),\n# and .f files as C (default is Fortran), use: inc=Fortran f=C.\n#\n# Note For files without extension you can use no_extension as a placeholder.\n#\n# Note that for custom extensions you also need to set FILE_PATTERNS otherwise\n# the files are not read by doxygen.\n\nEXTENSION_MAPPING      =\n\n# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments\n# according to the Markdown format, which allows for more readable\n# documentation. See http://daringfireball.net/projects/markdown/ for details.\n# The output of markdown processing is further processed by doxygen, so you can\n# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in\n# case of backward compatibilities issues.\n# The default value is: YES.\n\nMARKDOWN_SUPPORT       = YES\n\n# When enabled doxygen tries to link words that correspond to documented\n# classes, or namespaces to their corresponding documentation. Such a link can\n# be prevented in individual cases by by putting a % sign in front of the word\n# or globally by setting AUTOLINK_SUPPORT to NO.\n# The default value is: YES.\n\nAUTOLINK_SUPPORT       = YES\n\n# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want\n# to include (a tag file for) the STL sources as input, then you should set this\n# tag to YES in order to let doxygen match functions declarations and\n# definitions whose arguments contain STL classes (e.g. func(std::string);\n# versus func(std::string) {}). This also make the inheritance and collaboration\n# diagrams that involve STL classes more complete and accurate.\n# The default value is: NO.\n\nBUILTIN_STL_SUPPORT    = YES\n\n# If you use Microsoft's C++/CLI language, you should set this option to YES to\n# enable parsing support.\n# The default value is: NO.\n\nCPP_CLI_SUPPORT        = NO\n\n# Set the SIP_SUPPORT tag to YES if your project consists of sip (see:\n# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen\n# will parse them like normal C++ but will assume all classes use public instead\n# of private inheritance when no explicit protection keyword is present.\n# The default value is: NO.\n\nSIP_SUPPORT            = NO\n\n# For Microsoft's IDL there are propget and propput attributes to indicate\n# getter and setter methods for a property. Setting this option to YES will make\n# doxygen to replace the get and set methods by a property in the documentation.\n# This will only work if the methods are indeed getting or setting a simple\n# type. If this is not the case, or you want to show the methods anyway, you\n# should set this option to NO.\n# The default value is: YES.\n\nIDL_PROPERTY_SUPPORT   = YES\n\n# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC\n# tag is set to YES, then doxygen will reuse the documentation of the first\n# member in the group (if any) for the other members of the group. By default\n# all members of a group must be documented explicitly.\n# The default value is: NO.\n\nDISTRIBUTE_GROUP_DOC   = YES\n\n# Set the SUBGROUPING tag to YES to allow class member groups of the same type\n# (for instance a group of public functions) to be put as a subgroup of that\n# type (e.g. under the Public Functions section). Set it to NO to prevent\n# subgrouping. Alternatively, this can be done per class using the\n# \\nosubgrouping command.\n# The default value is: YES.\n\nSUBGROUPING            = YES\n\n# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions\n# are shown inside the group in which they are included (e.g. using \\ingroup)\n# instead of on a separate page (for HTML and Man pages) or section (for LaTeX\n# and RTF).\n#\n# Note that this feature does not work in combination with\n# SEPARATE_MEMBER_PAGES.\n# The default value is: NO.\n\nINLINE_GROUPED_CLASSES = NO\n\n# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions\n# with only public data fields or simple typedef fields will be shown inline in\n# the documentation of the scope in which they are defined (i.e. file,\n# namespace, or group documentation), provided this scope is documented. If set\n# to NO, structs, classes, and unions are shown on a separate page (for HTML and\n# Man pages) or section (for LaTeX and RTF).\n# The default value is: NO.\n\nINLINE_SIMPLE_STRUCTS  = NO\n\n# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or\n# enum is documented as struct, union, or enum with the name of the typedef. So\n# typedef struct TypeS {} TypeT, will appear in the documentation as a struct\n# with name TypeT. When disabled the typedef will appear as a member of a file,\n# namespace, or class. And the struct will be named TypeS. This can typically be\n# useful for C code in case the coding convention dictates that all compound\n# types are typedef'ed and only the typedef is referenced, never the tag name.\n# The default value is: NO.\n\nTYPEDEF_HIDES_STRUCT   = NO\n\n# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This\n# cache is used to resolve symbols given their name and scope. Since this can be\n# an expensive process and often the same symbol appears multiple times in the\n# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small\n# doxygen will become slower. If the cache is too large, memory is wasted. The\n# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range\n# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536\n# symbols. At the end of a run doxygen will report the cache usage and suggest\n# the optimal cache size from a speed point of view.\n# Minimum value: 0, maximum value: 9, default value: 0.\n\nLOOKUP_CACHE_SIZE      = 0\n\n#---------------------------------------------------------------------------\n# Build related configuration options\n#---------------------------------------------------------------------------\n\n# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in\n# documentation are documented, even if no documentation was available. Private\n# class members and static file members will be hidden unless the\n# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES.\n# Note: This will also disable the warnings about undocumented members that are\n# normally produced when WARNINGS is set to YES.\n# The default value is: NO.\n\nEXTRACT_ALL            = NO\n\n# If the EXTRACT_PRIVATE tag is set to YES all private members of a class will\n# be included in the documentation.\n# The default value is: NO.\n\nEXTRACT_PRIVATE        = YES\n\n# If the EXTRACT_PACKAGE tag is set to YES all members with package or internal\n# scope will be included in the documentation.\n# The default value is: NO.\n\nEXTRACT_PACKAGE        = YES\n\n# If the EXTRACT_STATIC tag is set to YES all static members of a file will be\n# included in the documentation.\n# The default value is: NO.\n\nEXTRACT_STATIC         = YES\n\n# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) defined\n# locally in source files will be included in the documentation. If set to NO\n# only classes defined in header files are included. Does not have any effect\n# for Java sources.\n# The default value is: YES.\n\nEXTRACT_LOCAL_CLASSES  = YES\n\n# This flag is only useful for Objective-C code. When set to YES local methods,\n# which are defined in the implementation section but not in the interface are\n# included in the documentation. If set to NO only methods in the interface are\n# included.\n# The default value is: NO.\n\nEXTRACT_LOCAL_METHODS  = NO\n\n# If this flag is set to YES, the members of anonymous namespaces will be\n# extracted and appear in the documentation as a namespace called\n# 'anonymous_namespace{file}', where file will be replaced with the base name of\n# the file that contains the anonymous namespace. By default anonymous namespace\n# are hidden.\n# The default value is: NO.\n\nEXTRACT_ANON_NSPACES   = YES\n\n# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all\n# undocumented members inside documented classes or files. If set to NO these\n# members will be included in the various overviews, but no documentation\n# section is generated. This option has no effect if EXTRACT_ALL is enabled.\n# The default value is: NO.\n\nHIDE_UNDOC_MEMBERS     = NO\n\n# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all\n# undocumented classes that are normally visible in the class hierarchy. If set\n# to NO these classes will be included in the various overviews. This option has\n# no effect if EXTRACT_ALL is enabled.\n# The default value is: NO.\n\nHIDE_UNDOC_CLASSES     = NO\n\n# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend\n# (class|struct|union) declarations. If set to NO these declarations will be\n# included in the documentation.\n# The default value is: NO.\n\nHIDE_FRIEND_COMPOUNDS  = NO\n\n# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any\n# documentation blocks found inside the body of a function. If set to NO these\n# blocks will be appended to the function's detailed documentation block.\n# The default value is: NO.\n\nHIDE_IN_BODY_DOCS      = NO\n\n# The INTERNAL_DOCS tag determines if documentation that is typed after a\n# \\internal command is included. If the tag is set to NO then the documentation\n# will be excluded. Set it to YES to include the internal documentation.\n# The default value is: NO.\n\nINTERNAL_DOCS          = NO\n\n# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file\n# names in lower-case letters. If set to YES upper-case letters are also\n# allowed. This is useful if you have classes or files whose names only differ\n# in case and if your file system supports case sensitive file names. Windows\n# and Mac users are advised to set this option to NO.\n# The default value is: system dependent.\n\nCASE_SENSE_NAMES       = NO\n\n# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with\n# their full class and namespace scopes in the documentation. If set to YES the\n# scope will be hidden.\n# The default value is: NO.\n\nHIDE_SCOPE_NAMES       = NO\n\n# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of\n# the files that are included by a file in the documentation of that file.\n# The default value is: YES.\n\nSHOW_INCLUDE_FILES     = YES\n\n# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each\n# grouped member an include statement to the documentation, telling the reader\n# which file to include in order to use the member.\n# The default value is: NO.\n\nSHOW_GROUPED_MEMB_INC  = NO\n\n# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include\n# files with double quotes in the documentation rather than with sharp brackets.\n# The default value is: NO.\n\nFORCE_LOCAL_INCLUDES   = YES\n\n# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the\n# documentation for inline members.\n# The default value is: YES.\n\nINLINE_INFO            = YES\n\n# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the\n# (detailed) documentation of file and class members alphabetically by member\n# name. If set to NO the members will appear in declaration order.\n# The default value is: YES.\n\nSORT_MEMBER_DOCS       = YES\n\n# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief\n# descriptions of file, namespace and class members alphabetically by member\n# name. If set to NO the members will appear in declaration order. Note that\n# this will also influence the order of the classes in the class list.\n# The default value is: NO.\n\nSORT_BRIEF_DOCS        = NO\n\n# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the\n# (brief and detailed) documentation of class members so that constructors and\n# destructors are listed first. If set to NO the constructors will appear in the\n# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS.\n# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief\n# member documentation.\n# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting\n# detailed member documentation.\n# The default value is: NO.\n\nSORT_MEMBERS_CTORS_1ST = NO\n\n# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy\n# of group names into alphabetical order. If set to NO the group names will\n# appear in their defined order.\n# The default value is: NO.\n\nSORT_GROUP_NAMES       = NO\n\n# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by\n# fully-qualified names, including namespaces. If set to NO, the class list will\n# be sorted only by class name, not including the namespace part.\n# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.\n# Note: This option applies only to the class list, not to the alphabetical\n# list.\n# The default value is: NO.\n\nSORT_BY_SCOPE_NAME     = NO\n\n# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper\n# type resolution of all parameters of a function it will reject a match between\n# the prototype and the implementation of a member function even if there is\n# only one candidate or it is obvious which candidate to choose by doing a\n# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still\n# accept a match between prototype and implementation in such cases.\n# The default value is: NO.\n\nSTRICT_PROTO_MATCHING  = NO\n\n# The GENERATE_TODOLIST tag can be used to enable ( YES) or disable ( NO) the\n# todo list. This list is created by putting \\todo commands in the\n# documentation.\n# The default value is: YES.\n\nGENERATE_TODOLIST      = YES\n\n# The GENERATE_TESTLIST tag can be used to enable ( YES) or disable ( NO) the\n# test list. This list is created by putting \\test commands in the\n# documentation.\n# The default value is: YES.\n\nGENERATE_TESTLIST      = YES\n\n# The GENERATE_BUGLIST tag can be used to enable ( YES) or disable ( NO) the bug\n# list. This list is created by putting \\bug commands in the documentation.\n# The default value is: YES.\n\nGENERATE_BUGLIST       = YES\n\n# The GENERATE_DEPRECATEDLIST tag can be used to enable ( YES) or disable ( NO)\n# the deprecated list. This list is created by putting \\deprecated commands in\n# the documentation.\n# The default value is: YES.\n\nGENERATE_DEPRECATEDLIST= YES\n\n# The ENABLED_SECTIONS tag can be used to enable conditional documentation\n# sections, marked by \\if <section_label> ... \\endif and \\cond <section_label>\n# ... \\endcond blocks.\n\nENABLED_SECTIONS       =\n\n# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the\n# initial value of a variable or macro / define can have for it to appear in the\n# documentation. If the initializer consists of more lines than specified here\n# it will be hidden. Use a value of 0 to hide initializers completely. The\n# appearance of the value of individual variables and macros / defines can be\n# controlled using \\showinitializer or \\hideinitializer command in the\n# documentation regardless of this setting.\n# Minimum value: 0, maximum value: 10000, default value: 30.\n\nMAX_INITIALIZER_LINES  = 30\n\n# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at\n# the bottom of the documentation of classes and structs. If set to YES the list\n# will mention the files that were used to generate the documentation.\n# The default value is: YES.\n\nSHOW_USED_FILES        = YES\n\n# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This\n# will remove the Files entry from the Quick Index and from the Folder Tree View\n# (if specified).\n# The default value is: YES.\n\nSHOW_FILES             = YES\n\n# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces\n# page. This will remove the Namespaces entry from the Quick Index and from the\n# Folder Tree View (if specified).\n# The default value is: YES.\n\nSHOW_NAMESPACES        = YES\n\n# The FILE_VERSION_FILTER tag can be used to specify a program or script that\n# doxygen should invoke to get the current version for each file (typically from\n# the version control system). Doxygen will invoke the program by executing (via\n# popen()) the command command input-file, where command is the value of the\n# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided\n# by doxygen. Whatever the program writes to standard output is used as the file\n# version. For an example see the documentation.\n\nFILE_VERSION_FILTER    =\n\n# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed\n# by doxygen. The layout file controls the global structure of the generated\n# output files in an output format independent way. To create the layout file\n# that represents doxygen's defaults, run doxygen with the -l option. You can\n# optionally specify a file name after the option, if omitted DoxygenLayout.xml\n# will be used as the name of the layout file.\n#\n# Note that if you run doxygen from a directory containing a file called\n# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE\n# tag is left empty.\n\nLAYOUT_FILE            =\n\n# The CITE_BIB_FILES tag can be used to specify one or more bib files containing\n# the reference definitions. This must be a list of .bib files. The .bib\n# extension is automatically appended if omitted. This requires the bibtex tool\n# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info.\n# For LaTeX the style of the bibliography can be controlled using\n# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the\n# search path. Do not use file names with spaces, bibtex cannot handle them. See\n# also \\cite for info how to create references.\n\nCITE_BIB_FILES         =\n\n#---------------------------------------------------------------------------\n# Configuration options related to warning and progress messages\n#---------------------------------------------------------------------------\n\n# The QUIET tag can be used to turn on/off the messages that are generated to\n# standard output by doxygen. If QUIET is set to YES this implies that the\n# messages are off.\n# The default value is: NO.\n\nQUIET                  = NO\n\n# The WARNINGS tag can be used to turn on/off the warning messages that are\n# generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES\n# this implies that the warnings are on.\n#\n# Tip: Turn warnings on while writing the documentation.\n# The default value is: YES.\n\nWARNINGS               = YES\n\n# If the WARN_IF_UNDOCUMENTED tag is set to YES, then doxygen will generate\n# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag\n# will automatically be disabled.\n# The default value is: YES.\n\nWARN_IF_UNDOCUMENTED   = YES\n\n# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for\n# potential errors in the documentation, such as not documenting some parameters\n# in a documented function, or documenting parameters that don't exist or using\n# markup commands wrongly.\n# The default value is: YES.\n\nWARN_IF_DOC_ERROR      = YES\n\n# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that\n# are documented, but have no documentation for their parameters or return\n# value. If set to NO doxygen will only warn about wrong or incomplete parameter\n# documentation, but not about the absence of documentation.\n# The default value is: NO.\n\nWARN_NO_PARAMDOC       = NO\n\n# The WARN_FORMAT tag determines the format of the warning messages that doxygen\n# can produce. The string should contain the $file, $line, and $text tags, which\n# will be replaced by the file and line number from which the warning originated\n# and the warning text. Optionally the format may contain $version, which will\n# be replaced by the version of the file (if it could be obtained via\n# FILE_VERSION_FILTER)\n# The default value is: $file:$line: $text.\n\nWARN_FORMAT            = \"$file:$line: $text\"\n\n# The WARN_LOGFILE tag can be used to specify a file to which warning and error\n# messages should be written. If left blank the output is written to standard\n# error (stderr).\n\nWARN_LOGFILE           =\n\n#---------------------------------------------------------------------------\n# Configuration options related to the input files\n#---------------------------------------------------------------------------\n\n# The INPUT tag is used to specify the files and/or directories that contain\n# documented source files. You may enter file names like myfile.cpp or\n# directories like /usr/src/myproject. Separate the files or directories with\n# spaces.\n# Note: If this tag is empty the current directory is searched.\n\nINPUT                  = ../include ../README.md\n\n# This tag can be used to specify the character encoding of the source files\n# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses\n# libiconv (or the iconv built into libc) for the transcoding. See the libiconv\n# documentation (see: http://www.gnu.org/software/libiconv) for the list of\n# possible encodings.\n# The default value is: UTF-8.\n\nINPUT_ENCODING         = UTF-8\n\n# If the value of the INPUT tag contains directories, you can use the\n# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and\n# *.h) to filter out the source-files in the directories. If left blank the\n# following patterns are tested:*.c, *.cc, *.cxx, *.cpp, *.c++, *.java, *.ii,\n# *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp,\n# *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown,\n# *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf,\n# *.qsf, *.as and *.js.\n\nFILE_PATTERNS          =\n\n# The RECURSIVE tag can be used to specify whether or not subdirectories should\n# be searched for input files as well.\n# The default value is: NO.\n\nRECURSIVE              = YES\n\n# The EXCLUDE tag can be used to specify files and/or directories that should be\n# excluded from the INPUT source files. This way you can easily exclude a\n# subdirectory from a directory tree whose root is specified with the INPUT tag.\n#\n# Note that relative paths are relative to the directory from which doxygen is\n# run.\n\nEXCLUDE                =\n\n# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or\n# directories that are symbolic links (a Unix file system feature) are excluded\n# from the input.\n# The default value is: NO.\n\nEXCLUDE_SYMLINKS       = NO\n\n# If the value of the INPUT tag contains directories, you can use the\n# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude\n# certain files from those directories.\n#\n# Note that the wildcards are matched against the file with absolute path, so to\n# exclude all test directories for example use the pattern */test/*\n\nEXCLUDE_PATTERNS       =\n\n# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names\n# (namespaces, classes, functions, etc.) that should be excluded from the\n# output. The symbol name can be a fully qualified name, a word, or if the\n# wildcard * is used, a substring. Examples: ANamespace, AClass,\n# AClass::ANamespace, ANamespace::*Test\n#\n# Note that the wildcards are matched against the file with absolute path, so to\n# exclude all test directories use the pattern */test/*\n\nEXCLUDE_SYMBOLS        =\n\n# The EXAMPLE_PATH tag can be used to specify one or more files or directories\n# that contain example code fragments that are included (see the \\include\n# command).\n\nEXAMPLE_PATH           =\n\n# If the value of the EXAMPLE_PATH tag contains directories, you can use the\n# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and\n# *.h) to filter out the source-files in the directories. If left blank all\n# files are included.\n\nEXAMPLE_PATTERNS       =\n\n# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be\n# searched for input files to be used with the \\include or \\dontinclude commands\n# irrespective of the value of the RECURSIVE tag.\n# The default value is: NO.\n\nEXAMPLE_RECURSIVE      = NO\n\n# The IMAGE_PATH tag can be used to specify one or more files or directories\n# that contain images that are to be included in the documentation (see the\n# \\image command).\n\nIMAGE_PATH             =\n\n# The INPUT_FILTER tag can be used to specify a program that doxygen should\n# invoke to filter for each input file. Doxygen will invoke the filter program\n# by executing (via popen()) the command:\n#\n# <filter> <input-file>\n#\n# where <filter> is the value of the INPUT_FILTER tag, and <input-file> is the\n# name of an input file. Doxygen will then use the output that the filter\n# program writes to standard output. If FILTER_PATTERNS is specified, this tag\n# will be ignored.\n#\n# Note that the filter must not add or remove lines; it is applied before the\n# code is scanned, but not when the output code is generated. If lines are added\n# or removed, the anchors will not be placed correctly.\n\nINPUT_FILTER           =\n\n# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern\n# basis. Doxygen will compare the file name with each pattern and apply the\n# filter if there is a match. The filters are a list of the form: pattern=filter\n# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how\n# filters are used. If the FILTER_PATTERNS tag is empty or if none of the\n# patterns match the file name, INPUT_FILTER is applied.\n\nFILTER_PATTERNS        =\n\n# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using\n# INPUT_FILTER ) will also be used to filter the input files that are used for\n# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES).\n# The default value is: NO.\n\nFILTER_SOURCE_FILES    = NO\n\n# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file\n# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and\n# it is also possible to disable source filtering for a specific pattern using\n# *.ext= (so without naming a filter).\n# This tag requires that the tag FILTER_SOURCE_FILES is set to YES.\n\nFILTER_SOURCE_PATTERNS =\n\n# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that\n# is part of the input, its contents will be placed on the main page\n# (index.html). This can be useful if you have a project on for instance GitHub\n# and want to reuse the introduction page also for the doxygen output.\n\nUSE_MDFILE_AS_MAINPAGE = README.md\n\n#---------------------------------------------------------------------------\n# Configuration options related to source browsing\n#---------------------------------------------------------------------------\n\n# If the SOURCE_BROWSER tag is set to YES then a list of source files will be\n# generated. Documented entities will be cross-referenced with these sources.\n#\n# Note: To get rid of all source code in the generated output, make sure that\n# also VERBATIM_HEADERS is set to NO.\n# The default value is: NO.\n\nSOURCE_BROWSER         = NO\n\n# Setting the INLINE_SOURCES tag to YES will include the body of functions,\n# classes and enums directly into the documentation.\n# The default value is: NO.\n\nINLINE_SOURCES         = NO\n\n# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any\n# special comment blocks from generated source code fragments. Normal C, C++ and\n# Fortran comments will always remain visible.\n# The default value is: YES.\n\nSTRIP_CODE_COMMENTS    = YES\n\n# If the REFERENCED_BY_RELATION tag is set to YES then for each documented\n# function all documented functions referencing it will be listed.\n# The default value is: NO.\n\nREFERENCED_BY_RELATION = NO\n\n# If the REFERENCES_RELATION tag is set to YES then for each documented function\n# all documented entities called/used by that function will be listed.\n# The default value is: NO.\n\nREFERENCES_RELATION    = NO\n\n# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set\n# to YES, then the hyperlinks from functions in REFERENCES_RELATION and\n# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will\n# link to the documentation.\n# The default value is: YES.\n\nREFERENCES_LINK_SOURCE = YES\n\n# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the\n# source code will show a tooltip with additional information such as prototype,\n# brief description and links to the definition and documentation. Since this\n# will make the HTML file larger and loading of large files a bit slower, you\n# can opt to disable this feature.\n# The default value is: YES.\n# This tag requires that the tag SOURCE_BROWSER is set to YES.\n\nSOURCE_TOOLTIPS        = YES\n\n# If the USE_HTAGS tag is set to YES then the references to source code will\n# point to the HTML generated by the htags(1) tool instead of doxygen built-in\n# source browser. The htags tool is part of GNU's global source tagging system\n# (see http://www.gnu.org/software/global/global.html). You will need version\n# 4.8.6 or higher.\n#\n# To use it do the following:\n# - Install the latest version of global\n# - Enable SOURCE_BROWSER and USE_HTAGS in the config file\n# - Make sure the INPUT points to the root of the source tree\n# - Run doxygen as normal\n#\n# Doxygen will invoke htags (and that will in turn invoke gtags), so these\n# tools must be available from the command line (i.e. in the search path).\n#\n# The result: instead of the source browser generated by doxygen, the links to\n# source code will now point to the output of htags.\n# The default value is: NO.\n# This tag requires that the tag SOURCE_BROWSER is set to YES.\n\nUSE_HTAGS              = NO\n\n# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a\n# verbatim copy of the header file for each class for which an include is\n# specified. Set to NO to disable this.\n# See also: Section \\class.\n# The default value is: YES.\n\nVERBATIM_HEADERS       = YES\n\n#---------------------------------------------------------------------------\n# Configuration options related to the alphabetical class index\n#---------------------------------------------------------------------------\n\n# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all\n# compounds will be generated. Enable this if the project contains a lot of\n# classes, structs, unions or interfaces.\n# The default value is: YES.\n\nALPHABETICAL_INDEX     = YES\n\n# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in\n# which the alphabetical index list will be split.\n# Minimum value: 1, maximum value: 20, default value: 5.\n# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.\n\nCOLS_IN_ALPHA_INDEX    = 5\n\n# In case all classes in a project start with a common prefix, all classes will\n# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag\n# can be used to specify a prefix (or a list of prefixes) that should be ignored\n# while generating the index headers.\n# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.\n\nIGNORE_PREFIX          =\n\n#---------------------------------------------------------------------------\n# Configuration options related to the HTML output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_HTML tag is set to YES doxygen will generate HTML output\n# The default value is: YES.\n\nGENERATE_HTML          = YES\n\n# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it.\n# The default directory is: html.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_OUTPUT            = html\n\n# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each\n# generated HTML page (for example: .htm, .php, .asp).\n# The default value is: .html.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_FILE_EXTENSION    = .html\n\n# The HTML_HEADER tag can be used to specify a user-defined HTML header file for\n# each generated HTML page. If the tag is left blank doxygen will generate a\n# standard header.\n#\n# To get valid HTML the header file that includes any scripts and style sheets\n# that doxygen needs, which is dependent on the configuration options used (e.g.\n# the setting GENERATE_TREEVIEW). It is highly recommended to start with a\n# default header using\n# doxygen -w html new_header.html new_footer.html new_stylesheet.css\n# YourConfigFile\n# and then modify the file new_header.html. See also section \"Doxygen usage\"\n# for information on how to generate the default header that doxygen normally\n# uses.\n# Note: The header is subject to change so you typically have to regenerate the\n# default header when upgrading to a newer version of doxygen. For a description\n# of the possible markers and block names see the documentation.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_HEADER            =\n\n# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each\n# generated HTML page. If the tag is left blank doxygen will generate a standard\n# footer. See HTML_HEADER for more information on how to generate a default\n# footer and what special commands can be used inside the footer. See also\n# section \"Doxygen usage\" for information on how to generate the default footer\n# that doxygen normally uses.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_FOOTER            =\n\n# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style\n# sheet that is used by each HTML page. It can be used to fine-tune the look of\n# the HTML output. If left blank doxygen will generate a default style sheet.\n# See also section \"Doxygen usage\" for information on how to generate the style\n# sheet that doxygen normally uses.\n# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as\n# it is more robust and this tag (HTML_STYLESHEET) will in the future become\n# obsolete.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_STYLESHEET        =\n\n# The HTML_EXTRA_STYLESHEET tag can be used to specify an additional user-\n# defined cascading style sheet that is included after the standard style sheets\n# created by doxygen. Using this option one can overrule certain style aspects.\n# This is preferred over using HTML_STYLESHEET since it does not replace the\n# standard style sheet and is therefor more robust against future updates.\n# Doxygen will copy the style sheet file to the output directory. For an example\n# see the documentation.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_EXTRA_STYLESHEET  =\n\n# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or\n# other source files which should be copied to the HTML output directory. Note\n# that these files will be copied to the base HTML output directory. Use the\n# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these\n# files. In the HTML_STYLESHEET file, use the file name only. Also note that the\n# files will be copied as-is; there are no commands or markers available.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_EXTRA_FILES       =\n\n# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen\n# will adjust the colors in the stylesheet and background images according to\n# this color. Hue is specified as an angle on a colorwheel, see\n# http://en.wikipedia.org/wiki/Hue for more information. For instance the value\n# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300\n# purple, and 360 is red again.\n# Minimum value: 0, maximum value: 359, default value: 220.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_COLORSTYLE_HUE    = 220\n\n# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors\n# in the HTML output. For a value of 0 the output will use grayscales only. A\n# value of 255 will produce the most vivid colors.\n# Minimum value: 0, maximum value: 255, default value: 100.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_COLORSTYLE_SAT    = 100\n\n# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the\n# luminance component of the colors in the HTML output. Values below 100\n# gradually make the output lighter, whereas values above 100 make the output\n# darker. The value divided by 100 is the actual gamma applied, so 80 represents\n# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not\n# change the gamma.\n# Minimum value: 40, maximum value: 240, default value: 80.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_COLORSTYLE_GAMMA  = 80\n\n# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML\n# page will contain the date and time when the page was generated. Setting this\n# to NO can help when comparing the output of multiple runs.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_TIMESTAMP         = YES\n\n# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML\n# documentation will contain sections that can be hidden and shown after the\n# page has loaded.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_DYNAMIC_SECTIONS  = NO\n\n# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries\n# shown in the various tree structured indices initially; the user can expand\n# and collapse entries dynamically later on. Doxygen will expand the tree to\n# such a level that at most the specified number of entries are visible (unless\n# a fully collapsed tree already exceeds this amount). So setting the number of\n# entries 1 will produce a full collapsed tree by default. 0 is a special value\n# representing an infinite number of entries and will result in a full expanded\n# tree by default.\n# Minimum value: 0, maximum value: 9999, default value: 100.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nHTML_INDEX_NUM_ENTRIES = 100\n\n# If the GENERATE_DOCSET tag is set to YES, additional index files will be\n# generated that can be used as input for Apple's Xcode 3 integrated development\n# environment (see: http://developer.apple.com/tools/xcode/), introduced with\n# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a\n# Makefile in the HTML output directory. Running make will produce the docset in\n# that directory and running make install will install the docset in\n# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at\n# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html\n# for more information.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_DOCSET        = NO\n\n# This tag determines the name of the docset feed. A documentation feed provides\n# an umbrella under which multiple documentation sets from a single provider\n# (such as a company or product suite) can be grouped.\n# The default value is: Doxygen generated docs.\n# This tag requires that the tag GENERATE_DOCSET is set to YES.\n\nDOCSET_FEEDNAME        = \"Doxygen generated docs\"\n\n# This tag specifies a string that should uniquely identify the documentation\n# set bundle. This should be a reverse domain-name style string, e.g.\n# com.mycompany.MyDocSet. Doxygen will append .docset to the name.\n# The default value is: org.doxygen.Project.\n# This tag requires that the tag GENERATE_DOCSET is set to YES.\n\nDOCSET_BUNDLE_ID       = org.doxygen.Project\n\n# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify\n# the documentation publisher. This should be a reverse domain-name style\n# string, e.g. com.mycompany.MyDocSet.documentation.\n# The default value is: org.doxygen.Publisher.\n# This tag requires that the tag GENERATE_DOCSET is set to YES.\n\nDOCSET_PUBLISHER_ID    = org.doxygen.Publisher\n\n# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher.\n# The default value is: Publisher.\n# This tag requires that the tag GENERATE_DOCSET is set to YES.\n\nDOCSET_PUBLISHER_NAME  = Publisher\n\n# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three\n# additional HTML index files: index.hhp, index.hhc, and index.hhk. The\n# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop\n# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on\n# Windows.\n#\n# The HTML Help Workshop contains a compiler that can convert all HTML output\n# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML\n# files are now used as the Windows 98 help format, and will replace the old\n# Windows help format (.hlp) on all Windows platforms in the future. Compressed\n# HTML files also contain an index, a table of contents, and you can search for\n# words in the documentation. The HTML workshop also contains a viewer for\n# compressed HTML files.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_HTMLHELP      = NO\n\n# The CHM_FILE tag can be used to specify the file name of the resulting .chm\n# file. You can add a path in front of the file if the result should not be\n# written to the html output directory.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nCHM_FILE               =\n\n# The HHC_LOCATION tag can be used to specify the location (absolute path\n# including file name) of the HTML help compiler ( hhc.exe). If non-empty\n# doxygen will try to run the HTML help compiler on the generated index.hhp.\n# The file has to be specified with full path.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nHHC_LOCATION           =\n\n# The GENERATE_CHI flag controls if a separate .chi index file is generated (\n# YES) or that it should be included in the master .chm file ( NO).\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nGENERATE_CHI           = NO\n\n# The CHM_INDEX_ENCODING is used to encode HtmlHelp index ( hhk), content ( hhc)\n# and project file content.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nCHM_INDEX_ENCODING     =\n\n# The BINARY_TOC flag controls whether a binary table of contents is generated (\n# YES) or a normal table of contents ( NO) in the .chm file. Furthermore it\n# enables the Previous and Next buttons.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nBINARY_TOC             = NO\n\n# The TOC_EXPAND flag can be set to YES to add extra items for group members to\n# the table of contents of the HTML help documentation and to the tree view.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTMLHELP is set to YES.\n\nTOC_EXPAND             = NO\n\n# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and\n# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that\n# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help\n# (.qch) of the generated HTML documentation.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_QHP           = NO\n\n# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify\n# the file name of the resulting .qch file. The path specified is relative to\n# the HTML output folder.\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQCH_FILE               =\n\n# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help\n# Project output. For more information please see Qt Help Project / Namespace\n# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace).\n# The default value is: org.doxygen.Project.\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_NAMESPACE          = org.doxygen.Project\n\n# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt\n# Help Project output. For more information please see Qt Help Project / Virtual\n# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual-\n# folders).\n# The default value is: doc.\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_VIRTUAL_FOLDER     = doc\n\n# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom\n# filter to add. For more information please see Qt Help Project / Custom\n# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-\n# filters).\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_CUST_FILTER_NAME   =\n\n# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the\n# custom filter to add. For more information please see Qt Help Project / Custom\n# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-\n# filters).\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_CUST_FILTER_ATTRS  =\n\n# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this\n# project's filter section matches. Qt Help Project / Filter Attributes (see:\n# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes).\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHP_SECT_FILTER_ATTRS  =\n\n# The QHG_LOCATION tag can be used to specify the location of Qt's\n# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the\n# generated .qhp file.\n# This tag requires that the tag GENERATE_QHP is set to YES.\n\nQHG_LOCATION           =\n\n# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be\n# generated, together with the HTML files, they form an Eclipse help plugin. To\n# install this plugin and make it available under the help contents menu in\n# Eclipse, the contents of the directory containing the HTML and XML files needs\n# to be copied into the plugins directory of eclipse. The name of the directory\n# within the plugins directory should be the same as the ECLIPSE_DOC_ID value.\n# After copying Eclipse needs to be restarted before the help appears.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_ECLIPSEHELP   = NO\n\n# A unique identifier for the Eclipse help plugin. When installing the plugin\n# the directory name containing the HTML and XML files should also have this\n# name. Each documentation set should have its own identifier.\n# The default value is: org.doxygen.Project.\n# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES.\n\nECLIPSE_DOC_ID         = org.doxygen.Project\n\n# If you want full control over the layout of the generated HTML pages it might\n# be necessary to disable the index and replace it with your own. The\n# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top\n# of each HTML page. A value of NO enables the index and the value YES disables\n# it. Since the tabs in the index contain the same information as the navigation\n# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nDISABLE_INDEX          = NO\n\n# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index\n# structure should be generated to display hierarchical information. If the tag\n# value is set to YES, a side panel will be generated containing a tree-like\n# index structure (just like the one that is generated for HTML Help). For this\n# to work a browser that supports JavaScript, DHTML, CSS and frames is required\n# (i.e. any modern browser). Windows users are probably better off using the\n# HTML help feature. Via custom stylesheets (see HTML_EXTRA_STYLESHEET) one can\n# further fine-tune the look of the index. As an example, the default style\n# sheet generated by doxygen has an example that shows how to put an image at\n# the root of the tree instead of the PROJECT_NAME. Since the tree basically has\n# the same information as the tab index, you could consider setting\n# DISABLE_INDEX to YES when enabling this option.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nGENERATE_TREEVIEW      = NO\n\n# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that\n# doxygen will group on one line in the generated HTML documentation.\n#\n# Note that a value of 0 will completely suppress the enum values from appearing\n# in the overview section.\n# Minimum value: 0, maximum value: 20, default value: 4.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nENUM_VALUES_PER_LINE   = 4\n\n# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used\n# to set the initial width (in pixels) of the frame in which the tree is shown.\n# Minimum value: 0, maximum value: 1500, default value: 250.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nTREEVIEW_WIDTH         = 250\n\n# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open links to\n# external symbols imported via tag files in a separate window.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nEXT_LINKS_IN_WINDOW    = NO\n\n# Use this tag to change the font size of LaTeX formulas included as images in\n# the HTML documentation. When you change the font size after a successful\n# doxygen run you need to manually remove any form_*.png images from the HTML\n# output directory to force them to be regenerated.\n# Minimum value: 8, maximum value: 50, default value: 10.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nFORMULA_FONTSIZE       = 10\n\n# Use the FORMULA_TRANPARENT tag to determine whether or not the images\n# generated for formulas are transparent PNGs. Transparent PNGs are not\n# supported properly for IE 6.0, but are supported on all modern browsers.\n#\n# Note that when changing this option you need to delete any form_*.png files in\n# the HTML output directory before the changes have effect.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nFORMULA_TRANSPARENT    = YES\n\n# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see\n# http://www.mathjax.org) which uses client side Javascript for the rendering\n# instead of using prerendered bitmaps. Use this if you do not have LaTeX\n# installed or if you want to formulas look prettier in the HTML output. When\n# enabled you may also need to install MathJax separately and configure the path\n# to it using the MATHJAX_RELPATH option.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nUSE_MATHJAX            = YES\n\n# When MathJax is enabled you can set the default output format to be used for\n# the MathJax output. See the MathJax site (see:\n# http://docs.mathjax.org/en/latest/output.html) for more details.\n# Possible values are: HTML-CSS (which is slower, but has the best\n# compatibility), NativeMML (i.e. MathML) and SVG.\n# The default value is: HTML-CSS.\n# This tag requires that the tag USE_MATHJAX is set to YES.\n\nMATHJAX_FORMAT         = HTML-CSS\n\n# When MathJax is enabled you need to specify the location relative to the HTML\n# output directory using the MATHJAX_RELPATH option. The destination directory\n# should contain the MathJax.js script. For instance, if the mathjax directory\n# is located at the same level as the HTML output directory, then\n# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax\n# Content Delivery Network so you can quickly see the result without installing\n# MathJax. However, it is strongly recommended to install a local copy of\n# MathJax from http://www.mathjax.org before deployment.\n# The default value is: http://cdn.mathjax.org/mathjax/latest.\n# This tag requires that the tag USE_MATHJAX is set to YES.\n\nMATHJAX_RELPATH        = http://cdn.mathjax.org/mathjax/latest\n\n# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax\n# extension names that should be enabled during MathJax rendering. For example\n# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols\n# This tag requires that the tag USE_MATHJAX is set to YES.\n\nMATHJAX_EXTENSIONS     =\n\n# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces\n# of code that will be used on startup of the MathJax code. See the MathJax site\n# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an\n# example see the documentation.\n# This tag requires that the tag USE_MATHJAX is set to YES.\n\nMATHJAX_CODEFILE       =\n\n# When the SEARCHENGINE tag is enabled doxygen will generate a search box for\n# the HTML output. The underlying search engine uses javascript and DHTML and\n# should work on any modern browser. Note that when using HTML help\n# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET)\n# there is already a search function so this one should typically be disabled.\n# For large projects the javascript based search engine can be slow, then\n# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to\n# search using the keyboard; to jump to the search box use <access key> + S\n# (what the <access key> is depends on the OS and browser, but it is typically\n# <CTRL>, <ALT>/<option>, or both). Inside the search box use the <cursor down\n# key> to jump into the search results window, the results can be navigated\n# using the <cursor keys>. Press <Enter> to select an item or <escape> to cancel\n# the search. The filter options can be selected when the cursor is inside the\n# search box by pressing <Shift>+<cursor down>. Also here use the <cursor keys>\n# to select a filter and <Enter> or <escape> to activate or cancel the filter\n# option.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_HTML is set to YES.\n\nSEARCHENGINE           = YES\n\n# When the SERVER_BASED_SEARCH tag is enabled the search engine will be\n# implemented using a web server instead of a web client using Javascript. There\n# are two flavors of web server based searching depending on the EXTERNAL_SEARCH\n# setting. When disabled, doxygen will generate a PHP script for searching and\n# an index file used by the script. When EXTERNAL_SEARCH is enabled the indexing\n# and searching needs to be provided by external tools. See the section\n# \"External Indexing and Searching\" for details.\n# The default value is: NO.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nSERVER_BASED_SEARCH    = NO\n\n# When EXTERNAL_SEARCH tag is enabled doxygen will no longer generate the PHP\n# script for searching. Instead the search results are written to an XML file\n# which needs to be processed by an external indexer. Doxygen will invoke an\n# external search engine pointed to by the SEARCHENGINE_URL option to obtain the\n# search results.\n#\n# Doxygen ships with an example indexer ( doxyindexer) and search engine\n# (doxysearch.cgi) which are based on the open source search engine library\n# Xapian (see: http://xapian.org/).\n#\n# See the section \"External Indexing and Searching\" for details.\n# The default value is: NO.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nEXTERNAL_SEARCH        = NO\n\n# The SEARCHENGINE_URL should point to a search engine hosted by a web server\n# which will return the search results when EXTERNAL_SEARCH is enabled.\n#\n# Doxygen ships with an example indexer ( doxyindexer) and search engine\n# (doxysearch.cgi) which are based on the open source search engine library\n# Xapian (see: http://xapian.org/). See the section \"External Indexing and\n# Searching\" for details.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nSEARCHENGINE_URL       =\n\n# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed\n# search data is written to a file for indexing by an external tool. With the\n# SEARCHDATA_FILE tag the name of this file can be specified.\n# The default file is: searchdata.xml.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nSEARCHDATA_FILE        = searchdata.xml\n\n# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the\n# EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is\n# useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple\n# projects and redirect the results back to the right project.\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nEXTERNAL_SEARCH_ID     =\n\n# The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen\n# projects other than the one defined by this configuration file, but that are\n# all added to the same external search index. Each project needs to have a\n# unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id of\n# to a relative location where the documentation can be found. The format is:\n# EXTRA_SEARCH_MAPPINGS = tagname1=loc1 tagname2=loc2 ...\n# This tag requires that the tag SEARCHENGINE is set to YES.\n\nEXTRA_SEARCH_MAPPINGS  =\n\n#---------------------------------------------------------------------------\n# Configuration options related to the LaTeX output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_LATEX tag is set to YES doxygen will generate LaTeX output.\n# The default value is: YES.d\n\nGENERATE_LATEX         = NO\n\n# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it.\n# The default directory is: latex.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_OUTPUT           = latex\n\n# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be\n# invoked.\n#\n# Note that when enabling USE_PDFLATEX this option is only used for generating\n# bitmaps for formulas in the HTML output, but not in the Makefile that is\n# written to the output directory.\n# The default file is: latex.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_CMD_NAME         = pdflatex\n\n# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to generate\n# index for LaTeX.\n# The default file is: makeindex.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nMAKEINDEX_CMD_NAME     = tableofcontents\n\n# If the COMPACT_LATEX tag is set to YES doxygen generates more compact LaTeX\n# documents. This may be useful for small projects and may help to save some\n# trees in general.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nCOMPACT_LATEX          = YES\n\n# The PAPER_TYPE tag can be used to set the paper type that is used by the\n# printer.\n# Possible values are: a4 (210 x 297 mm), letter (8.5 x 11 inches), legal (8.5 x\n# 14 inches) and executive (7.25 x 10.5 inches).\n# The default value is: a4.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nPAPER_TYPE             = a4\n\n# The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names\n# that should be included in the LaTeX output. To get the times font for\n# instance you can specify\n# EXTRA_PACKAGES=times\n# If left blank no extra packages will be included.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nEXTRA_PACKAGES         =\n\n# The LATEX_HEADER tag can be used to specify a personal LaTeX header for the\n# generated LaTeX document. The header should contain everything until the first\n# chapter. If it is left blank doxygen will generate a standard header. See\n# section \"Doxygen usage\" for information on how to let doxygen write the\n# default header to a separate file.\n#\n# Note: Only use a user-defined header if you know what you are doing! The\n# following commands have a special meaning inside the header: $title,\n# $datetime, $date, $doxygenversion, $projectname, $projectnumber. Doxygen will\n# replace them by respectively the title of the page, the current date and time,\n# only the current date, the version number of doxygen, the project name (see\n# PROJECT_NAME), or the project number (see PROJECT_NUMBER).\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_HEADER           =\n\n# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for the\n# generated LaTeX document. The footer should contain everything after the last\n# chapter. If it is left blank doxygen will generate a standard footer.\n#\n# Note: Only use a user-defined footer if you know what you are doing!\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_FOOTER           =\n\n# The LATEX_EXTRA_FILES tag can be used to specify one or more extra images or\n# other source files which should be copied to the LATEX_OUTPUT output\n# directory. Note that the files will be copied as-is; there are no commands or\n# markers available.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_EXTRA_FILES      =\n\n# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated is\n# prepared for conversion to PDF (using ps2pdf or pdflatex). The PDF file will\n# contain links (just like the HTML output) instead of page references. This\n# makes the output suitable for online browsing using a PDF viewer.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nPDF_HYPERLINKS         = YES\n\n# If the LATEX_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate\n# the PDF file directly from the LaTeX files. Set this option to YES to get a\n# higher quality PDF documentation.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nUSE_PDFLATEX           = YES\n\n# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode\n# command to the generated LaTeX files. This will instruct LaTeX to keep running\n# if errors occur, instead of asking the user for help. This option is also used\n# when generating formulas in HTML.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_BATCHMODE        = NO\n\n# If the LATEX_HIDE_INDICES tag is set to YES then doxygen will not include the\n# index chapters (such as File Index, Compound Index, etc.) in the output.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_HIDE_INDICES     = NO\n\n# If the LATEX_SOURCE_CODE tag is set to YES then doxygen will include source\n# code with syntax highlighting in the LaTeX output.\n#\n# Note that which sources are shown also depends on other settings such as\n# SOURCE_BROWSER.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_SOURCE_CODE      = NO\n\n# The LATEX_BIB_STYLE tag can be used to specify the style to use for the\n# bibliography, e.g. plainnat, or ieeetr. See\n# http://en.wikipedia.org/wiki/BibTeX and \\cite for more info.\n# The default value is: plain.\n# This tag requires that the tag GENERATE_LATEX is set to YES.\n\nLATEX_BIB_STYLE        = plain\n\n#---------------------------------------------------------------------------\n# Configuration options related to the RTF output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_RTF tag is set to YES doxygen will generate RTF output. The\n# RTF output is optimized for Word 97 and may not look too pretty with other RTF\n# readers/editors.\n# The default value is: NO.\n\nGENERATE_RTF           = NO\n\n# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it.\n# The default directory is: rtf.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_OUTPUT             = rtf\n\n# If the COMPACT_RTF tag is set to YES doxygen generates more compact RTF\n# documents. This may be useful for small projects and may help to save some\n# trees in general.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nCOMPACT_RTF            = NO\n\n# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated will\n# contain hyperlink fields. The RTF file will contain links (just like the HTML\n# output) instead of page references. This makes the output suitable for online\n# browsing using Word or some other Word compatible readers that support those\n# fields.\n#\n# Note: WordPad (write) and others do not support links.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_HYPERLINKS         = NO\n\n# Load stylesheet definitions from file. Syntax is similar to doxygen's config\n# file, i.e. a series of assignments. You only have to provide replacements,\n# missing definitions are set to their default value.\n#\n# See also section \"Doxygen usage\" for information on how to generate the\n# default style sheet that doxygen normally uses.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_STYLESHEET_FILE    =\n\n# Set optional variables used in the generation of an RTF document. Syntax is\n# similar to doxygen's config file. A template extensions file can be generated\n# using doxygen -e rtf extensionFile.\n# This tag requires that the tag GENERATE_RTF is set to YES.\n\nRTF_EXTENSIONS_FILE    =\n\n#---------------------------------------------------------------------------\n# Configuration options related to the man page output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_MAN tag is set to YES doxygen will generate man pages for\n# classes and files.\n# The default value is: NO.\n\nGENERATE_MAN           = NO\n\n# The MAN_OUTPUT tag is used to specify where the man pages will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it. A directory man3 will be created inside the directory specified by\n# MAN_OUTPUT.\n# The default directory is: man.\n# This tag requires that the tag GENERATE_MAN is set to YES.\n\nMAN_OUTPUT             = man\n\n# The MAN_EXTENSION tag determines the extension that is added to the generated\n# man pages. In case the manual section does not start with a number, the number\n# 3 is prepended. The dot (.) at the beginning of the MAN_EXTENSION tag is\n# optional.\n# The default value is: .3.\n# This tag requires that the tag GENERATE_MAN is set to YES.\n\nMAN_EXTENSION          = .3\n\n# The MAN_SUBDIR tag determines the name of the directory created within\n# MAN_OUTPUT in which the man pages are placed. If defaults to man followed by\n# MAN_EXTENSION with the initial . removed.\n# This tag requires that the tag GENERATE_MAN is set to YES.\n\nMAN_SUBDIR             =\n\n# If the MAN_LINKS tag is set to YES and doxygen generates man output, then it\n# will generate one additional man file for each entity documented in the real\n# man page(s). These additional files only source the real man page, but without\n# them the man command would be unable to find the correct page.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_MAN is set to YES.\n\nMAN_LINKS              = NO\n\n#---------------------------------------------------------------------------\n# Configuration options related to the XML output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_XML tag is set to YES doxygen will generate an XML file that\n# captures the structure of the code including all documentation.\n# The default value is: NO.\n\nGENERATE_XML           = NO\n\n# The XML_OUTPUT tag is used to specify where the XML pages will be put. If a\n# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of\n# it.\n# The default directory is: xml.\n# This tag requires that the tag GENERATE_XML is set to YES.\n\nXML_OUTPUT             = xml\n\n# If the XML_PROGRAMLISTING tag is set to YES doxygen will dump the program\n# listings (including syntax highlighting and cross-referencing information) to\n# the XML output. Note that enabling this will significantly increase the size\n# of the XML output.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_XML is set to YES.\n\nXML_PROGRAMLISTING     = YES\n\n#---------------------------------------------------------------------------\n# Configuration options related to the DOCBOOK output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_DOCBOOK tag is set to YES doxygen will generate Docbook files\n# that can be used to generate PDF.\n# The default value is: NO.\n\nGENERATE_DOCBOOK       = NO\n\n# The DOCBOOK_OUTPUT tag is used to specify where the Docbook pages will be put.\n# If a relative path is entered the value of OUTPUT_DIRECTORY will be put in\n# front of it.\n# The default directory is: docbook.\n# This tag requires that the tag GENERATE_DOCBOOK is set to YES.\n\nDOCBOOK_OUTPUT         = docbook\n\n#---------------------------------------------------------------------------\n# Configuration options for the AutoGen Definitions output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_AUTOGEN_DEF tag is set to YES doxygen will generate an AutoGen\n# Definitions (see http://autogen.sf.net) file that captures the structure of\n# the code including all documentation. Note that this feature is still\n# experimental and incomplete at the moment.\n# The default value is: NO.\n\nGENERATE_AUTOGEN_DEF   = NO\n\n#---------------------------------------------------------------------------\n# Configuration options related to the Perl module output\n#---------------------------------------------------------------------------\n\n# If the GENERATE_PERLMOD tag is set to YES doxygen will generate a Perl module\n# file that captures the structure of the code including all documentation.\n#\n# Note that this feature is still experimental and incomplete at the moment.\n# The default value is: NO.\n\nGENERATE_PERLMOD       = NO\n\n# If the PERLMOD_LATEX tag is set to YES doxygen will generate the necessary\n# Makefile rules, Perl scripts and LaTeX code to be able to generate PDF and DVI\n# output from the Perl module output.\n# The default value is: NO.\n# This tag requires that the tag GENERATE_PERLMOD is set to YES.\n\nPERLMOD_LATEX          = NO\n\n# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be nicely\n# formatted so it can be parsed by a human reader. This is useful if you want to\n# understand what is going on. On the other hand, if this tag is set to NO the\n# size of the Perl module output will be much smaller and Perl will parse it\n# just the same.\n# The default value is: YES.\n# This tag requires that the tag GENERATE_PERLMOD is set to YES.\n\nPERLMOD_PRETTY         = YES\n\n# The names of the make variables in the generated doxyrules.make file are\n# prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. This is useful\n# so different doxyrules.make files included by the same Makefile don't\n# overwrite each other's variables.\n# This tag requires that the tag GENERATE_PERLMOD is set to YES.\n\nPERLMOD_MAKEVAR_PREFIX =\n\n#---------------------------------------------------------------------------\n# Configuration options related to the preprocessor\n#---------------------------------------------------------------------------\n\n# If the ENABLE_PREPROCESSING tag is set to YES doxygen will evaluate all\n# C-preprocessor directives found in the sources and include files.\n# The default value is: YES.\n\nENABLE_PREPROCESSING   = YES\n\n# If the MACRO_EXPANSION tag is set to YES doxygen will expand all macro names\n# in the source code. If set to NO only conditional compilation will be\n# performed. Macro expansion can be done in a controlled way by setting\n# EXPAND_ONLY_PREDEF to YES.\n# The default value is: NO.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nMACRO_EXPANSION        = NO\n\n# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then\n# the macro expansion is limited to the macros specified with the PREDEFINED and\n# EXPAND_AS_DEFINED tags.\n# The default value is: NO.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nEXPAND_ONLY_PREDEF     = NO\n\n# If the SEARCH_INCLUDES tag is set to YES the includes files in the\n# INCLUDE_PATH will be searched if a #include is found.\n# The default value is: YES.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nSEARCH_INCLUDES        = YES\n\n# The INCLUDE_PATH tag can be used to specify one or more directories that\n# contain include files that are not input files but should be processed by the\n# preprocessor.\n# This tag requires that the tag SEARCH_INCLUDES is set to YES.\n\nINCLUDE_PATH           =\n\n# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard\n# patterns (like *.h and *.hpp) to filter out the header-files in the\n# directories. If left blank, the patterns specified with FILE_PATTERNS will be\n# used.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nINCLUDE_FILE_PATTERNS  =\n\n# The PREDEFINED tag can be used to specify one or more macro names that are\n# defined before the preprocessor is started (similar to the -D option of e.g.\n# gcc). The argument of the tag is a list of macros of the form: name or\n# name=definition (no spaces). If the definition and the \"=\" are omitted, \"=1\"\n# is assumed. To prevent a macro definition from being undefined via #undef or\n# recursively expanded use the := operator instead of the = operator.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nPREDEFINED             =\n\n# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this\n# tag can be used to specify a list of macro names that should be expanded. The\n# macro definition that is found in the sources will be used. Use the PREDEFINED\n# tag if you want to use a different macro definition that overrules the\n# definition found in the source code.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nEXPAND_AS_DEFINED      =\n\n# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will\n# remove all references to function-like macros that are alone on a line, have\n# an all uppercase name, and do not end with a semicolon. Such function macros\n# are typically used for boiler-plate code, and will confuse the parser if not\n# removed.\n# The default value is: YES.\n# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.\n\nSKIP_FUNCTION_MACROS   = YES\n\n#---------------------------------------------------------------------------\n# Configuration options related to external references\n#---------------------------------------------------------------------------\n\n# The TAGFILES tag can be used to specify one or more tag files. For each tag\n# file the location of the external documentation should be added. The format of\n# a tag file without this location is as follows:\n# TAGFILES = file1 file2 ...\n# Adding location for the tag files is done as follows:\n# TAGFILES = file1=loc1 \"file2 = loc2\" ...\n# where loc1 and loc2 can be relative or absolute paths or URLs. See the\n# section \"Linking to external documentation\" for more information about the use\n# of tag files.\n# Note: Each tag file must have a unique name (where the name does NOT include\n# the path). If a tag file is not located in the directory in which doxygen is\n# run, you must also specify the path to the tagfile here.\n\nTAGFILES               =\n\n# When a file name is specified after GENERATE_TAGFILE, doxygen will create a\n# tag file that is based on the input files it reads. See section \"Linking to\n# external documentation\" for more information about the usage of tag files.\n\nGENERATE_TAGFILE       =\n\n# If the ALLEXTERNALS tag is set to YES all external class will be listed in the\n# class index. If set to NO only the inherited external classes will be listed.\n# The default value is: NO.\n\nALLEXTERNALS           = NO\n\n# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed in\n# the modules index. If set to NO, only the current project's groups will be\n# listed.\n# The default value is: YES.\n\nEXTERNAL_GROUPS        = YES\n\n# If the EXTERNAL_PAGES tag is set to YES all external pages will be listed in\n# the related pages index. If set to NO, only the current project's pages will\n# be listed.\n# The default value is: YES.\n\nEXTERNAL_PAGES         = YES\n\n# The PERL_PATH should be the absolute path and name of the perl script\n# interpreter (i.e. the result of 'which perl').\n# The default file (with absolute path) is: /usr/bin/perl.\n\nPERL_PATH              = /usr/bin/perl\n\n#---------------------------------------------------------------------------\n# Configuration options related to the dot tool\n#---------------------------------------------------------------------------\n\n# If the CLASS_DIAGRAMS tag is set to YES doxygen will generate a class diagram\n# (in HTML and LaTeX) for classes with base or super classes. Setting the tag to\n# NO turns the diagrams off. Note that this option also works with HAVE_DOT\n# disabled, but it is recommended to install and use dot, since it yields more\n# powerful graphs.\n# The default value is: YES.\n\nCLASS_DIAGRAMS         = YES\n\n# You can define message sequence charts within doxygen comments using the \\msc\n# command. Doxygen will then run the mscgen tool (see:\n# http://www.mcternan.me.uk/mscgen/)) to produce the chart and insert it in the\n# documentation. The MSCGEN_PATH tag allows you to specify the directory where\n# the mscgen tool resides. If left empty the tool is assumed to be found in the\n# default search path.\n\nMSCGEN_PATH            =\n\n# You can include diagrams made with dia in doxygen documentation. Doxygen will\n# then run dia to produce the diagram and insert it in the documentation. The\n# DIA_PATH tag allows you to specify the directory where the dia binary resides.\n# If left empty dia is assumed to be found in the default search path.\n\nDIA_PATH               =\n\n# If set to YES, the inheritance and collaboration graphs will hide inheritance\n# and usage relations if the target is undocumented or is not a class.\n# The default value is: YES.\n\nHIDE_UNDOC_RELATIONS   = YES\n\n# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is\n# available from the path. This tool is part of Graphviz (see:\n# http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent\n# Bell Labs. The other options in this section have no effect if this option is\n# set to NO\n# The default value is: NO.\n\nHAVE_DOT               = NO\n\n# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed\n# to run in parallel. When set to 0 doxygen will base this on the number of\n# processors available in the system. You can set it explicitly to a value\n# larger than 0 to get control over the balance between CPU load and processing\n# speed.\n# Minimum value: 0, maximum value: 32, default value: 0.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_NUM_THREADS        = 0\n\n# When you want a differently looking font n the dot files that doxygen\n# generates you can specify the font name using DOT_FONTNAME. You need to make\n# sure dot is able to find the font, which can be done by putting it in a\n# standard location or by setting the DOTFONTPATH environment variable or by\n# setting DOT_FONTPATH to the directory containing the font.\n# The default value is: Helvetica.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_FONTNAME           = Helvetica\n\n# The DOT_FONTSIZE tag can be used to set the size (in points) of the font of\n# dot graphs.\n# Minimum value: 4, maximum value: 24, default value: 10.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_FONTSIZE           = 10\n\n# By default doxygen will tell dot to use the default font as specified with\n# DOT_FONTNAME. If you specify a different font using DOT_FONTNAME you can set\n# the path where dot can find it using this tag.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_FONTPATH           =\n\n# If the CLASS_GRAPH tag is set to YES then doxygen will generate a graph for\n# each documented class showing the direct and indirect inheritance relations.\n# Setting this tag to YES will force the CLASS_DIAGRAMS tag to NO.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nCLASS_GRAPH            = YES\n\n# If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a\n# graph for each documented class showing the direct and indirect implementation\n# dependencies (inheritance, containment, and class references variables) of the\n# class with other documented classes.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nCOLLABORATION_GRAPH    = YES\n\n# If the GROUP_GRAPHS tag is set to YES then doxygen will generate a graph for\n# groups, showing the direct groups dependencies.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nGROUP_GRAPHS           = YES\n\n# If the UML_LOOK tag is set to YES doxygen will generate inheritance and\n# collaboration diagrams in a style similar to the OMG's Unified Modeling\n# Language.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nUML_LOOK               = NO\n\n# If the UML_LOOK tag is enabled, the fields and methods are shown inside the\n# class node. If there are many fields or methods and many nodes the graph may\n# become too big to be useful. The UML_LIMIT_NUM_FIELDS threshold limits the\n# number of items for each type to make the size more manageable. Set this to 0\n# for no limit. Note that the threshold may be exceeded by 50% before the limit\n# is enforced. So when you set the threshold to 10, up to 15 fields may appear,\n# but if the number exceeds 15, the total amount of fields shown is limited to\n# 10.\n# Minimum value: 0, maximum value: 100, default value: 10.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nUML_LIMIT_NUM_FIELDS   = 10\n\n# If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and\n# collaboration graphs will show the relations between templates and their\n# instances.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nTEMPLATE_RELATIONS     = NO\n\n# If the INCLUDE_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are set to\n# YES then doxygen will generate a graph for each documented file showing the\n# direct and indirect include dependencies of the file with other documented\n# files.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nINCLUDE_GRAPH          = YES\n\n# If the INCLUDED_BY_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are\n# set to YES then doxygen will generate a graph for each documented file showing\n# the direct and indirect include dependencies of the file with other documented\n# files.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nINCLUDED_BY_GRAPH      = YES\n\n# If the CALL_GRAPH tag is set to YES then doxygen will generate a call\n# dependency graph for every global function or class method.\n#\n# Note that enabling this option will significantly increase the time of a run.\n# So in most cases it will be better to enable call graphs for selected\n# functions only using the \\callgraph command.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nCALL_GRAPH             = NO\n\n# If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller\n# dependency graph for every global function or class method.\n#\n# Note that enabling this option will significantly increase the time of a run.\n# So in most cases it will be better to enable caller graphs for selected\n# functions only using the \\callergraph command.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nCALLER_GRAPH           = NO\n\n# If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical\n# hierarchy of all classes instead of a textual one.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nGRAPHICAL_HIERARCHY    = YES\n\n# If the DIRECTORY_GRAPH tag is set to YES then doxygen will show the\n# dependencies a directory has on other directories in a graphical way. The\n# dependency relations are determined by the #include relations between the\n# files in the directories.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDIRECTORY_GRAPH        = YES\n\n# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images\n# generated by dot.\n# Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order\n# to make the SVG files visible in IE 9+ (other browsers do not have this\n# requirement).\n# Possible values are: png, jpg, gif and svg.\n# The default value is: png.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_IMAGE_FORMAT       = png\n\n# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to\n# enable generation of interactive SVG images that allow zooming and panning.\n#\n# Note that this requires a modern browser other than Internet Explorer. Tested\n# and working are Firefox, Chrome, Safari, and Opera.\n# Note: For IE 9+ you need to set HTML_FILE_EXTENSION to xhtml in order to make\n# the SVG files visible. Older versions of IE do not have SVG support.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nINTERACTIVE_SVG        = NO\n\n# The DOT_PATH tag can be used to specify the path where the dot tool can be\n# found. If left blank, it is assumed the dot tool can be found in the path.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_PATH               =\n\n# The DOTFILE_DIRS tag can be used to specify one or more directories that\n# contain dot files that are included in the documentation (see the \\dotfile\n# command).\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOTFILE_DIRS           =\n\n# The MSCFILE_DIRS tag can be used to specify one or more directories that\n# contain msc files that are included in the documentation (see the \\mscfile\n# command).\n\nMSCFILE_DIRS           =\n\n# The DIAFILE_DIRS tag can be used to specify one or more directories that\n# contain dia files that are included in the documentation (see the \\diafile\n# command).\n\nDIAFILE_DIRS           =\n\n# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes\n# that will be shown in the graph. If the number of nodes in a graph becomes\n# larger than this value, doxygen will truncate the graph, which is visualized\n# by representing a node as a red box. Note that doxygen if the number of direct\n# children of the root node in a graph is already larger than\n# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note that\n# the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.\n# Minimum value: 0, maximum value: 10000, default value: 50.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_GRAPH_MAX_NODES    = 50\n\n# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the graphs\n# generated by dot. A depth value of 3 means that only nodes reachable from the\n# root by following a path via at most 3 edges will be shown. Nodes that lay\n# further from the root node will be omitted. Note that setting this option to 1\n# or 2 may greatly reduce the computation time needed for large code bases. Also\n# note that the size of a graph can be further restricted by\n# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.\n# Minimum value: 0, maximum value: 1000, default value: 0.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nMAX_DOT_GRAPH_DEPTH    = 0\n\n# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent\n# background. This is disabled by default, because dot on Windows does not seem\n# to support this out of the box.\n#\n# Warning: Depending on the platform used, enabling this option may lead to\n# badly anti-aliased labels on the edges of a graph (i.e. they become hard to\n# read).\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_TRANSPARENT        = NO\n\n# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output\n# files in one run (i.e. multiple -o and -T options on the command line). This\n# makes dot run faster, but since only newer versions of dot (>1.8.10) support\n# this, this feature is disabled by default.\n# The default value is: NO.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_MULTI_TARGETS      = NO\n\n# If the GENERATE_LEGEND tag is set to YES doxygen will generate a legend page\n# explaining the meaning of the various boxes and arrows in the dot generated\n# graphs.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nGENERATE_LEGEND        = YES\n\n# If the DOT_CLEANUP tag is set to YES doxygen will remove the intermediate dot\n# files that are used to generate the various graphs.\n# The default value is: YES.\n# This tag requires that the tag HAVE_DOT is set to YES.\n\nDOT_CLEANUP            = YES\n"
  },
  {
    "path": "examples/CMakeLists.txt",
    "content": "###########################################################\n## BINARIES\n###########################################################\n\nset(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/examples)\n\n########################################\n# TARGETS\n########################################\n\nadd_executable(fibonacci-basic fibonacci-basic.cpp)\nadd_executable(fibonacci-timed fibonacci-timed.cpp)\nadd_executable(statistics statistics.cpp)\nadd_executable(callbacks callbacks.cpp)\nadd_executable(lowercase lowercase.cpp)\nadd_executable(wrap wrap.cpp)\n"
  },
  {
    "path": "examples/callbacks.cpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#include <iostream>\n\n#include \"lru/lru.hpp\"\n\nusing Cache = LRU::Cache<std::uint64_t, std::uint64_t>;\n\nstd::uint64_t fibonacci(std::uint64_t n, Cache& cache) {\n  if (n < 2) return 1;\n\n  // We std::uint64_ternally keep track of the last accessed key, meaning a\n  // `contains(key)` + `lookup(key)` sequence will involve only a single hash\n  // table lookup.\n  if (cache.contains(n)) return cache[n];\n\n  auto value = fibonacci(n - 1, cache) + fibonacci(n - 2, cache);\n\n  // Caches are 100% move-aware and we have implemented\n  // `unordered_map` style emplacement and insertion.\n  cache.emplace(n, value);\n\n  return value;\n}\n\nstd::uint64_t fibonacci(std::uint64_t n) {\n  // Use a capacity of 100 (after 100 insertions, the next insertion will evict\n  // the least-recently inserted element). The default capacity is 128. Note\n  // that for fibonacci, a capacity of 2 is sufficient (and ideal).\n  Cache cache(100);\n\n  // clang-format off\n  cache.hit_callback([](auto& key, auto& value) {\n    std::clog << \"Hit for entry (\"\n              << key << \", \" << value << \")\"\n              << std::endl;\n  });\n\n  cache.miss_callback([](auto& key) {\n    std::clog << \"Miss for \" << key<< std::endl;\n  });\n\n  cache.access_callback([](auto& key, bool was_hit) {\n    std::clog << \"Access for \" << key\n              << \" was a \" << (was_hit ? \"hit\" : \"miss\")\n              << std::endl;\n  });\n  // clang-format on\n\n  auto value = fibonacci(n, cache);\n\n  return value;\n}\n\nauto main() -> int {\n  std::cout << fibonacci(10) << std::endl;\n}\n"
  },
  {
    "path": "examples/fibonacci-basic.cpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#include <iostream>\n\n#include \"lru/lru.hpp\"\n\nusing Cache = LRU::Cache<int, int>;\n\nint fibonacci(int n, Cache& cache) {\n  if (n < 2) return 1;\n\n  // We internally keep track of the last accessed key, meaning a\n  // `contains(key)` + `lookup(key)` sequence will involve only a single hash\n  // table lookup.\n  if (cache.contains(n)) return cache[n];\n\n  auto value = fibonacci(n - 1, cache) + fibonacci(n - 2, cache);\n\n  // Caches are 100% move-aware and we have implemented\n  // `unordered_map` style emplacement and insertion.\n  cache.emplace(n, value);\n\n  return value;\n}\n\nint fibonacci(int n) {\n  // Use a capacity of 100 (after 100 insertions, the next insertion will evict\n  // the least-recently accessed element). The default capacity is 128. Note\n  // that for fibonacci, a capacity of 2 is sufficient (and ideal).\n  Cache cache(100);\n  return fibonacci(n, cache);\n}\n\nauto main() -> int {\n  std::cout << fibonacci(32) << std::endl;\n}\n"
  },
  {
    "path": "examples/fibonacci-timed.cpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#include <chrono>\n#include <iostream>\n\n#include \"lru/lru.hpp\"\n\nusing namespace std::chrono_literals;\n\nusing Cache = LRU::TimedCache<int, int>;\n\nint fibonacci(int n, Cache& cache) {\n  if (n < 2) return 1;\n\n  // We internally keep track of the last accessed key, meaning a\n  // `contains(key)` + `lookup(key)` sequence will involve only a single hash\n  // table lookup.\n  if (cache.contains(n)) return cache[n];\n\n  auto value = fibonacci(n - 1, cache) + fibonacci(n - 2, cache);\n\n  // Caches are 100% move-aware and we have implemented\n  // `unordered_map` style emplacement and insertion.\n  cache.emplace(n, value);\n\n  return value;\n}\n\nint fibonacci(int n) {\n  // Use a time to live of 100ms. This means that 100ms after insertion, a key\n  // will be said to have \"expired\" and `contains(key)` will return false.\n  Cache cache(100ms);\n  return fibonacci(n, cache);\n}\n\nauto main() -> int {\n  std::cout << fibonacci(32) << std::endl;\n}\n"
  },
  {
    "path": "examples/lowercase.cpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#include <chrono>\n#include <iostream>\n\n#include \"lru/lowercase.hpp\"\n\nvoid print(lru::tag::basic_cache) {\n  std::cout << \"basic cache\" << '\\n';\n}\n\nvoid print(lru::tag::timed_cache) {\n  std::cout << \"timed cache\" << '\\n';\n}\n\nauto main() -> int {\n  using namespace std::chrono_literals;\n\n  lru::cache<int, int> cache;\n  lru::timed_cache<int, int> timed_cache(100ms);\n\n  print(cache.tag());\n  print(timed_cache.tag());\n\n  lru::cache<int, int>::ordered_const_iterator iterator(cache.begin());\n\n  lru::statistics<int> stats;\n}\n"
  },
  {
    "path": "examples/statistics.cpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#include <iostream>\n\n#include \"lru/lru.hpp\"\n\nusing Cache = LRU::Cache<std::uint64_t, std::uint64_t>;\n\nstd::uint64_t fibonacci(std::uint64_t n, Cache& cache) {\n  if (n < 2) return 1;\n\n  // We std::uint64_ternally keep track of the last accessed key, meaning a\n  // `contains(key)` + `lookup(key)` sequence will involve only a single hash\n  // table lookup.\n  if (cache.contains(n)) return cache[n];\n\n  auto value = fibonacci(n - 1, cache) + fibonacci(n - 2, cache);\n\n  // Caches are 100% move-aware and we have implemented\n  // `unordered_map` style emplacement and insertion.\n  cache.emplace(n, value);\n\n  return value;\n}\n\nstd::uint64_t fibonacci(std::uint64_t n) {\n  // Use a capacity of 100 (after 100 insertions, the next insertion will evict\n  // the least-recently inserted element). The default capacity is 128. Note\n  // that for fibonacci, a capacity of 2 is sufficient (and ideal).\n  Cache cache(100);\n  cache.monitor(2, 3, 4, 5);\n  auto value = fibonacci(n, cache);\n\n  for (auto i : {2, 3, 4, 5}) {\n    auto stats = cache.stats().stats_for(i);\n    // clang-format off\n    std::cout << \"Statistics for \" << i << \": \"\n              << stats.hits << \" hit(s), \"\n              << stats.misses << \" miss(es).\"\n              << std::endl;\n  }\n\n  // You'll notice we'll always have n - 1 misses, for each time we access\n  // one of the numbers in [0, n] for the first time.\n  std::cout << \"Overall: \"\n            << cache.stats().total_hits() << \" hit(s), \"\n            << cache.stats().total_misses() << \" miss(es).\"\n            << std::endl;\n  // clang-format on\n\n  return value;\n}\n\nauto main() -> int {\n  // The last number that fits into a 64 bit unsigned number\n  std::cout << fibonacci(92) << std::endl;\n}\n"
  },
  {
    "path": "examples/wrap.cpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#include <chrono>\n#include <iostream>\n#include <thread>\n\n#include \"lru/lru.hpp\"\n\nusing namespace std::chrono_literals;\n\nint f(int x) {\n  std::this_thread::sleep_for(1s);\n  return x;\n}\n\nauto main() -> int {\n  // Use a time-to-live of 2 minutes and a\n  // capacity of 128 for an LRU::TimedCache\n  auto wrapped = LRU::timed_wrap(f, 2min, 128);\n\n  std::cout << \"Slow the first time ...\" << '\\n';\n  wrapped(42);\n\n  std::cout << \"Fast the second time!\" << '\\n';\n  wrapped(42);\n}\n"
  },
  {
    "path": "include/lru/cache-tags.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef LRU_CACHE_TAGS_HPP\n#define LRU_CACHE_TAGS_HPP\n\nnamespace LRU {\nnamespace Tag {\nstruct BasicCache {};\nstruct TimedCache {};\n}  // namespace Tag\n\nnamespace Lowercase {\nnamespace tag {\nusing basic_cache = ::LRU::Tag::BasicCache;\nusing timed_cache = ::LRU::Tag::TimedCache;\n}  // namespace tag\n}  // namespace Lowercase\n\n}  // namespace LRU\n\n#endif  // LRU_CACHE_TAGS_HPP\n"
  },
  {
    "path": "include/lru/cache.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef LRU_CACHE_HPP\n#define LRU_CACHE_HPP\n\n#include <cassert>\n#include <chrono>\n#include <cstddef>\n#include <functional>\n#include <iterator>\n#include <list>\n#include <stdexcept>\n#include <unordered_map>\n\n#include <lru/cache-tags.hpp>\n#include <lru/error.hpp>\n#include <lru/internal/base-cache.hpp>\n#include <lru/internal/information.hpp>\n#include <lru/internal/last-accessed.hpp>\n\nnamespace LRU {\nnamespace Internal {\ntemplate <typename Key,\n          typename Value,\n          typename HashFunction,\n          typename KeyEqual>\nusing UntimedCacheBase = Internal::BaseCache<Key,\n                                             Value,\n                                             Internal::Information,\n                                             HashFunction,\n                                             KeyEqual,\n                                             Tag::BasicCache>;\n}  // namespace Internal\n\n/// A basic LRU cache implementation.\n///\n/// An LRU cache is a fixed-size cache that remembers the order in which\n/// elements were inserted into it. When the size of the cache exceeds its\n/// capacity, the \"least-recently-used\" (LRU) element is erased. In our\n/// implementation, usage is defined as insertion, but not lookup. That is,\n/// looking up an element does not move it to the \"front\" of the cache (making\n/// the operation faster). Only insertions (and erasures) can change the order\n/// of elements. The capacity of the cache can be modified at any time.\n///\n/// \\see LRU::TimedCache\ntemplate <typename Key,\n          typename Value,\n          typename HashFunction = std::hash<Key>,\n          typename KeyEqual = std::equal_to<Key>>\nclass Cache\n    : public Internal::UntimedCacheBase<Key, Value, HashFunction, KeyEqual> {\n private:\n  using super = Internal::UntimedCacheBase<Key, Value, HashFunction, KeyEqual>;\n  using PRIVATE_BASE_CACHE_MEMBERS;\n\n public:\n  using PUBLIC_BASE_CACHE_MEMBERS;\n  using typename super::size_t;\n\n  /// \\copydoc BaseCache::BaseCache(size_t,const HashFunction&,const KeyEqual&)\n  /// \\detailss The capacity defaults to an internal constant, currently 128.\n  explicit Cache(size_t capacity = Internal::DEFAULT_CAPACITY,\n                 const HashFunction& hash = HashFunction(),\n                 const KeyEqual& equal = KeyEqual())\n  : super(capacity, hash, equal) {\n  }\n\n  /// \\copydoc BaseCache(size_t,Iterator,Iterator,const HashFunction&,const\n  /// KeyEqual&)\n  template <typename Iterator>\n  Cache(size_t capacity,\n        Iterator begin,\n        Iterator end,\n        const HashFunction& hash = HashFunction(),\n        const KeyEqual& equal = KeyEqual())\n  : super(capacity, begin, end, hash, equal) {\n  }\n\n  /// \\copydoc BaseCache(Iterator,Iterator,const HashFunction&,const\n  /// KeyEqual&)\n  template <typename Iterator>\n  Cache(Iterator begin,\n        Iterator end,\n        const HashFunction& hash = HashFunction(),\n        const KeyEqual& equal = KeyEqual())\n  : super(begin, end, hash, equal) {\n  }\n\n  /// Constructor.\n  ///\n  /// \\param capacity The capacity of the cache.\n  /// \\param range A range to construct the cache with.\n  /// \\param hash The hash function to use for the internal map.\n  /// \\param key_equal The key equality function to use for the internal map.\n  template <typename Range, typename = Internal::enable_if_range<Range>>\n  Cache(size_t capacity,\n        Range&& range,\n        const HashFunction& hash = HashFunction(),\n        const KeyEqual& equal = KeyEqual())\n  : super(capacity, std::forward<Range>(range), hash, equal) {\n  }\n\n  /// Constructor.\n  ///\n  /// \\param range A range to construct the cache with.\n  /// \\param hash The hash function to use for the internal map.\n  /// \\param key_equal The key equality function to use for the internal map.\n  template <typename Range, typename = Internal::enable_if_range<Range>>\n  explicit Cache(Range&& range,\n                 const HashFunction& hash = HashFunction(),\n                 const KeyEqual& equal = KeyEqual())\n  : super(std::forward<Range>(range), hash, equal) {\n  }\n\n  /// \\copydoc BaseCache(InitializerList,const HashFunction&,const\n  /// KeyEqual&)\n  Cache(InitializerList list,\n        const HashFunction& hash = HashFunction(),\n        const KeyEqual& equal = KeyEqual())  // NOLINT(runtime/explicit)\n      : super(list, hash, equal) {\n  }\n\n  /// \\copydoc BaseCache(size_t,InitializerList,const HashFunction&,const\n  /// KeyEqual&)\n  Cache(size_t capacity,\n        InitializerList list,\n        const HashFunction& hash = HashFunction(),\n        const KeyEqual& equal = KeyEqual())  // NOLINT(runtime/explicit)\n      : super(capacity, list, hash, equal) {\n  }\n\n  /// \\copydoc BaseCache::find(const Key&)\n  UnorderedIterator find(const Key& key) override {\n    auto iterator = _map.find(key);\n    if (iterator != _map.end()) {\n      _register_hit(key, iterator->second.value);\n      _move_to_front(iterator->second.order);\n      _last_accessed = iterator;\n    } else {\n      _register_miss(key);\n    }\n\n    return {*this, iterator};\n  }\n\n  /// \\copydoc BaseCache::find(const Key&) const\n  UnorderedConstIterator find(const Key& key) const override {\n    auto iterator = _map.find(key);\n    if (iterator != _map.end()) {\n      _register_hit(key, iterator->second.value);\n      _move_to_front(iterator->second.order);\n      _last_accessed = iterator;\n    } else {\n      _register_miss(key);\n    }\n\n    return {*this, iterator};\n  }\n\n  /// \\returns The most-recently inserted element.\n  const Key& front() const noexcept {\n    if (is_empty()) {\n      throw LRU::Error::EmptyCache(\"front\");\n    } else {\n      // The queue is reversed for natural order of iteration.\n      return _order.back();\n    }\n  }\n\n  /// \\returns The least-recently inserted element.\n  const Key& back() const noexcept {\n    if (is_empty()) {\n      throw LRU::Error::EmptyCache(\"back\");\n    } else {\n      // The queue is reversed for natural order of iteration.\n      return _order.front();\n    }\n  }\n};\n\nnamespace Lowercase {\ntemplate <typename... Ts>\nusing cache = Cache<Ts...>;\n}  // namespace Lowercase\n\n}  // namespace LRU\n\n#endif  // LRU_CACHE_HPP\n"
  },
  {
    "path": "include/lru/entry.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef LRU_PAIR_HPP\n#define LRU_PAIR_HPP\n\n#include <algorithm>\n#include <type_traits>\n#include <utility>\n\nnamespace LRU {\n\n/// A entry of references to the key and value of an entry in a cache.\n///\n/// Instances of this class are usually the result of dereferencing an iterator.\n///\n/// \\tparam Key The key type of the pair.\n/// \\tparam Value The value type of the pair.\ntemplate <typename Key, typename Value>\nstruct Entry final {\n  using KeyType = Key;\n  using ValueType = Value;\n  using first_type = Key;\n  using second_type = Value;\n\n  /// Constructor.\n  ///\n  /// \\param key The key of the entry.\n  /// \\param value The value of the entry.\n  Entry(const Key& key, Value& value) : first(key), second(value) {\n  }\n\n  /// Generalized copy constructor.\n  ///\n  /// Mainly for conversion from non-const values to const values.\n  ///\n  /// \\param other The entry to construct from.\n  template <typename AnyKey,\n            typename AnyValue,\n            typename =\n                std::enable_if_t<(std::is_convertible<AnyKey, Key>::value &&\n                                  std::is_convertible<AnyValue, Value>::value)>>\n  Entry(const Entry<AnyKey, AnyValue>& other)\n  : first(other.first), second(other.second) {\n  }\n\n  /// Compares two entrys for equality.\n  ///\n  /// \\param first The first entry to compare.\n  /// \\param second The second entry to compare.\n  /// \\returns True if the firest entry equals the second, else false.\n  template <typename Pair, typename = typename Pair::first_type>\n  friend bool operator==(const Entry& first, const Pair& second) noexcept {\n    return first.first == second.first && first.second == second.second;\n  }\n\n  /// Compares two entrys for equality.\n  ///\n  /// \\param first The first entry to compare.\n  /// \\param second The second entry to compare.\n  /// \\returns True if the first entry equals the second, else false.\n  template <typename Pair, typename = typename Pair::first_type>\n  friend bool operator==(const Pair& first, const Entry& second) noexcept {\n    return second == first;\n  }\n\n  /// Compares two entrys for inequality.\n  ///\n  /// \\param first The first entry to compare.\n  /// \\param second The second entry to compare.\n  /// \\returns True if the first entry does not equal the second, else false.\n  template <typename Pair, typename = typename Pair::first_type>\n  friend bool operator!=(const Entry& first, const Pair& second) noexcept {\n    return !(first == second);\n  }\n\n  /// Compares two entrys for inequality.\n  ///\n  /// \\param first The first entry to compare.\n  /// \\param second The second entry to compare.fdas\n  /// \\returns True if the first entry does not equal the second, else false.\n  template <typename Pair, typename = typename Pair::first_type>\n  friend bool operator!=(const Pair& first, const Entry& second) noexcept {\n    return second != first;\n  }\n\n  /// \\returns A `std::pair` instance with the key and value of this entry.\n  operator std::pair<const Key&, Value&>() noexcept {\n    return {first, second};\n  }\n\n  /// \\returns The key of the entry (`first`).\n  const Key& key() const noexcept {\n    return first;\n  }\n\n  /// \\returns The value of the entry (`second`).\n  Value& value() noexcept {\n    return second;\n  }\n\n  /// \\returns The value of the entry (`second`).\n  const Value& value() const noexcept {\n    return second;\n  }\n\n  /// The key of the entry.\n  const Key& first;\n\n  /// The value of the entry.\n  Value& second;\n};\n}  // namespace LRU\n\n\n#endif  // LRU_PAIR_HPP\n"
  },
  {
    "path": "include/lru/error.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef LRU_INTERNAL_ERRORS_HPP\n#define LRU_INTERNAL_ERRORS_HPP\n\n#include <stdexcept>\n#include <string>\n\nnamespace LRU {\nnamespace Error {\n\n/// Exception thrown when the value of an invalid key was requested.\nstruct KeyNotFound : public std::runtime_error {\n  using super = std::runtime_error;\n\n  KeyNotFound() : super(\"Failed to find key\") {\n  }\n\n  explicit KeyNotFound(const std::string& key)\n  : super(\"Failed to find key: \" + key) {\n  }\n};\n\n/// Exception thrown when the value of an expired key was requested.\nstruct KeyExpired : public std::runtime_error {\n  using super = std::runtime_error;\n\n  explicit KeyExpired(const std::string& key)\n  : super(\"Key found, but expired: \" + key) {\n  }\n\n  KeyExpired() : super(\"Key found, but expired\") {\n  }\n};\n\n/// Exception thrown when requesting the front or end key of an empty cache.\nstruct EmptyCache : public std::runtime_error {\n  using super = std::runtime_error;\n  explicit EmptyCache(const std::string& what_was_expected)\n  : super(\"Requested \" + what_was_expected + \" of empty cache\") {\n  }\n};\n\n/// Exception thrown when attempting to convert an invalid unordered iterator to\n/// an ordered iterator.\nstruct InvalidIteratorConversion : public std::runtime_error {\n  using super = std::runtime_error;\n  InvalidIteratorConversion()\n  : super(\"Cannot convert past-the-end unordered to ordered iterator\") {\n  }\n};\n\n/// Exception thrown when attempting to erase the past-the-end iterator.\nstruct InvalidIterator : public std::runtime_error {\n  using super = std::runtime_error;\n  InvalidIterator() : super(\"Past-the-end iterator is invalid here\") {\n  }\n};\n\n/// Exception thrown when requesting statistics about an unmonitored key.\nstruct UnmonitoredKey : public std::runtime_error {\n  using super = std::runtime_error;\n  UnmonitoredKey() : super(\"Requested statistics for unmonitored key\") {\n  }\n};\n\n/// Exception thrown when requesting the statistics object of a cache when none\n/// was registered.\nstruct NotMonitoring : public std::runtime_error {\n  using super = std::runtime_error;\n  NotMonitoring() : super(\"Statistics monitoring not enabled for this cache\") {\n  }\n};\n\nnamespace Lowercase {\nusing key_not_found = KeyNotFound;\nusing key_expired = KeyExpired;\nusing empty_cache = EmptyCache;\nusing invalid_iterator_conversion = InvalidIteratorConversion;\nusing invalid_iterator = InvalidIterator;\nusing unmonitored_key = UnmonitoredKey;\nusing not_monitoring = NotMonitoring;\n}  // namespace Lowercase\n\n}  // namespace Error\n}  // namespace LRU\n\n#endif  // LRU_INTERNAL_ERRORS_HPP\n"
  },
  {
    "path": "include/lru/insertion-result.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef LRU_INSERTION_RESULT_HPP\n#define LRU_INSERTION_RESULT_HPP\n\n#include <algorithm>\n#include <type_traits>\n#include <utility>\n\nnamespace LRU {\n\n/// The result of an insertion into a cache.\n///\n/// This is a semantically nicer alternative to a generic `std::pair`, as is\n/// returned by `std::unordered_map` or so. It still has the same static\n/// interface as the `std::pair` (with `first` and `second` members), but adds\n/// nicer `was_inserted()` and `iterator()` accessors.\n///\n/// \\tparam Iterator The class of the iterator contained in the result.\ntemplate <typename Iterator>\nstruct InsertionResult final {\n  using IteratorType = Iterator;\n\n  /// Constructor.\n  ///\n  /// \\param result Whether the result was successful.\n  /// \\param iterator The iterator pointing to the inserted or updated key.\n  InsertionResult(bool result, Iterator iterator)\n  : first(result), second(iterator) {\n  }\n\n  /// \\returns True if the key was newly inserted, false if it was only updated.\n  bool was_inserted() const noexcept {\n    return first;\n  }\n\n  /// \\returns The iterator pointing to the inserted or updated key.\n  Iterator iterator() const noexcept {\n    return second;\n  }\n\n  /// \\copydoc was_inserted\n  explicit operator bool() const noexcept {\n    return was_inserted();\n  }\n\n  /// Whether the result was successful.\n  bool first;\n\n  /// The iterator pointing to the inserted or updated key.\n  Iterator second;\n};\n\n}  // namespace LRU\n\n\n#endif  // LRU_INSERTION_RESULT_HPP\n"
  },
  {
    "path": "include/lru/internal/base-cache.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef LRU_INTERNAL_BASE_CACHE_HPP\n#define LRU_INTERNAL_BASE_CACHE_HPP\n\n#include <algorithm>\n#include <cmath>\n#include <cstddef>\n#include <initializer_list>\n#include <iterator>\n#include <list>\n#include <memory>\n#include <tuple>\n#include <unordered_map>\n#include <utility>\n\n#include <lru/insertion-result.hpp>\n#include <lru/internal/base-ordered-iterator.hpp>\n#include <lru/internal/base-unordered-iterator.hpp>\n#include <lru/internal/callback-manager.hpp>\n#include <lru/internal/definitions.hpp>\n#include <lru/internal/last-accessed.hpp>\n#include <lru/internal/optional.hpp>\n#include <lru/internal/statistics-mutator.hpp>\n#include <lru/internal/utility.hpp>\n#include <lru/statistics.hpp>\n\nnamespace LRU {\nnamespace Internal {\n\n// Macros are bad, but also more readable sometimes:\n// Without this macro, it becomes a pain to have a `using` directive for every\n// new member we add to the `BaseCache` and rename or remove every such\n// directive when we make a change to the `BaseCache`.\n// With this macro, you can simply do:\n// using super = BaseCache<Key, Value, Information>;\n// using BASE_CACHE_MEMBERS;\n#define PUBLIC_BASE_CACHE_MEMBERS               \\\n  super::is_full;                               \\\n  using super::is_empty;                        \\\n  using super::clear;                           \\\n  using super::end;                             \\\n  using super::cend;                            \\\n  using super::operator=;                       \\\n  using typename super::Information;            \\\n  using typename super::UnorderedIterator;      \\\n  using typename super::UnorderedConstIterator; \\\n  using typename super::OrderedIterator;        \\\n  using typename super::OrderedConstIterator;   \\\n  using typename super::InitializerList;\n\n#define PRIVATE_BASE_CACHE_MEMBERS        \\\n  super::_map;                            \\\n  using typename super::Map;              \\\n  using typename super::MapIterator;      \\\n  using typename super::MapConstIterator; \\\n  using typename super::Queue;            \\\n  using typename super::QueueIterator;    \\\n  using super::_order;                    \\\n  using super::_last_accessed;            \\\n  using super::_capacity;                 \\\n  using super::_erase;                    \\\n  using super::_erase_lru;                \\\n  using super::_move_to_front;            \\\n  using super::_value_from_result;        \\\n  using super::_last_accessed_is_ok;      \\\n  using super::_register_miss;            \\\n  using super::_register_hit;\n\n/// The base class for the LRU::Cache and LRU::TimedCache.\n///\n/// This base class (base as opposed to abstract, because it is not intended to\n/// be used polymorphically) provides the great bulk of the implementation of\n/// both the LRU::Cache and the timed version. For example, it builds the\n/// `contains()`, `lookup()` and `operator[]()` functions on top of the pure\n/// virtual `find()` methods, making the final implementation of the LRU::Cache\n/// much less strenuous.\n///\n/// This class also defines all concrete iterator classes and provides the main\n/// iterator interface of all caches via ordered and unordered iterators and\n/// appropriate `begin()`, `end()` and similar methods.\n///\n/// Lastly, the `BaseCache` provides a statistics interface to register and\n/// access shared or owned statistics.\n///\n/// \\tparam Key The key type of the cache.\n/// \\tparam Value The value type of the cache.\n/// \\tparam InformationType The internal information class to be used.\n/// \\tparam HashFunction The hash function type for the internal map.\n/// \\tparam KeyEqual The type of the key equality function for the internal map.\n/// \\tparam TagType The cache tag type of the concrete derived class.\ntemplate <typename Key,\n          typename Value,\n          template <typename, typename> class InformationType,\n          typename HashFunction,\n          typename KeyEqual,\n          typename TagType>\nclass BaseCache {\n protected:\n  using Information = InformationType<Key, Value>;\n  using Queue = Internal::Queue<const Key>;\n  using QueueIterator = typename Queue::const_iterator;\n\n  using Map = Internal::Map<Key, Information, HashFunction, KeyEqual>;\n  using MapIterator = typename Map::iterator;\n  using MapConstIterator = typename Map::const_iterator;\n\n  using CallbackManagerType = CallbackManager<Key, Value>;\n  using HitCallback = typename CallbackManagerType::HitCallback;\n  using MissCallback = typename CallbackManagerType::MissCallback;\n  using AccessCallback = typename CallbackManagerType::AccessCallback;\n  using HitCallbackContainer =\n      typename CallbackManagerType::HitCallbackContainer;\n  using MissCallbackContainer =\n      typename CallbackManagerType::MissCallbackContainer;\n  using AccessCallbackContainer =\n      typename CallbackManagerType::AccessCallbackContainer;\n\n public:\n  using Tag = TagType;\n  using InitializerList = std::initializer_list<std::pair<Key, Value>>;\n  using StatisticsPointer = std::shared_ptr<Statistics<Key>>;\n  using size_t = std::size_t;\n\n  static constexpr Tag tag() noexcept {\n    return {};\n  }\n\n  /////////////////////////////////////////////////////////////////////////////\n  // ITERATORS CLASSES\n  /////////////////////////////////////////////////////////////////////////////\n\n  /// A non-const unordered iterator.\n  ///\n  /// Unordered iterators provide faster lookup than ordered iterators because\n  /// they have direct access to the underlying map. Also, they can convert to\n  /// ordered iterators cheaply.\n  struct UnorderedIterator\n      : public BaseUnorderedIterator<BaseCache, MapIterator> {\n    using super = BaseUnorderedIterator<BaseCache, MapIterator>;\n    friend BaseCache;\n\n    /// Default constructor.\n    UnorderedIterator() = default;\n\n    /// Constructs a new UnorderedIterator from an unordered base iterator.\n    ///\n    /// \\param iterator The iterator to initialize this one from.\n    UnorderedIterator(BaseUnorderedIterator<BaseCache, MapIterator>\n                          iterator)  // NOLINT(runtime/explicit)\n        : super(std::move(iterator)) {\n      // Note that this only works because these derived iterator\n      // classes dont' have any members of their own.\n      // It is necessary because the increment operators return base iterators.\n    }\n\n    /// Constructs a new UnorderedIterator.\n    ///\n    /// \\param cache The cache this iterator references.\n    /// \\param iterator The underlying map iterator.\n    UnorderedIterator(BaseCache& cache,\n                      MapIterator iterator)  // NOLINT(runtime/explicit)\n        : super(cache, iterator) {\n    }\n  };\n\n  /// A const unordered iterator.\n  ///\n  /// Unordered iterators provide faster lookup than ordered iterators because\n  /// they have direct access to the underlying map. Also, they can convert to\n  /// ordered iterators cheaply.\n  struct UnorderedConstIterator\n      : public BaseUnorderedIterator<const BaseCache, MapConstIterator> {\n    using super = BaseUnorderedIterator<const BaseCache, MapConstIterator>;\n    friend BaseCache;\n\n    /// Default constructor.\n    UnorderedConstIterator() = default;\n\n    /// Constructs a new UnorderedConstIterator from any unordered base\n    /// iterator.\n    ///\n    /// \\param iterator The iterator to initialize this one from.\n    template <typename AnyCache, typename AnyUnderlyingIterator>\n    UnorderedConstIterator(\n        BaseUnorderedIterator<AnyCache, AnyUnderlyingIterator> iterator)\n    : super(std::move(iterator)) {\n      // Note that this only works because these derived iterator\n      // classes dont' have any members of their own.\n    }\n\n    /// Constructs a new UnorderedConstIterator from a non-const iterator.\n    ///\n    /// \\param iterator The non-const iterator to initialize this one from.\n    UnorderedConstIterator(\n        UnorderedIterator iterator)  // NOLINT(runtime/explicit)\n        : super(std::move(iterator)) {\n    }\n\n    /// Constructs a new UnorderedConstIterator.\n    ///\n    /// \\param cache The cache this iterator references.\n    /// \\param iterator The underlying map iterator.\n    UnorderedConstIterator(\n        const BaseCache& cache,\n        MapConstIterator iterator)  // NOLINT(runtime/explicit)\n        : super(cache, iterator) {\n    }\n  };\n\n  /// An ordered iterator.\n  ///\n  /// Ordered iterators have a performance disadvantage compared to unordered\n  /// iterators the first time they are dereferenced. However, they may be\n  /// constructed or assigned from unordered iterators (of compatible\n  /// qualifiers).\n  struct OrderedIterator\n      : public BaseOrderedIterator<const Key, Value, BaseCache> {\n    using super = BaseOrderedIterator<const Key, Value, BaseCache>;\n    using UnderlyingIterator = typename super::UnderlyingIterator;\n    friend BaseCache;\n\n    /// Default constructor.\n    OrderedIterator() = default;\n\n    /// Constructs an ordered iterator from an unordered iterator.\n    ///\n    /// \\param unordered_iterator The unordered iterator to construct from.\n    explicit OrderedIterator(UnorderedIterator unordered_iterator)\n    : super(std::move(unordered_iterator)) {\n    }\n\n    /// Constructs a new OrderedIterator from an unordered base iterator.\n    ///\n    /// \\param iterator The iterator to initialize this one from.\n    OrderedIterator(BaseOrderedIterator<Key, Value, BaseCache>\n                        iterator)  // NOLINT(runtime/explicit)\n        : super(std::move(iterator)) {\n      // Note that this only works because these derived iterator\n      // classes dont' have any members of their own.\n      // It is necessary because the increment operators return base iterators.\n    }\n\n    /// Constructs a new ordered iterator.\n    ///\n    /// \\param cache The cache this iterator references.\n    /// \\param iterator The underlying iterator.\n    OrderedIterator(BaseCache& cache, UnderlyingIterator iterator)\n    : super(cache, iterator) {\n    }\n  };\n\n  /// A const ordered iterator.\n  ///\n  /// Ordered iterators have a performance disadvantage compared to unordered\n  /// iterators the first time they are dereferenced. However, they may be\n  /// constructed or assigned from unordered iterators (of compatible\n  /// qualifiers).\n  struct OrderedConstIterator\n      : public BaseOrderedIterator<const Key, const Value, const BaseCache> {\n    using super = BaseOrderedIterator<const Key, const Value, const BaseCache>;\n    using UnderlyingIterator = typename super::UnderlyingIterator;\n\n    friend BaseCache;\n\n    /// Default constructor.\n    OrderedConstIterator() = default;\n\n    /// Constructs a new OrderedConstIterator from a compatible ordered\n    /// iterator.\n    ///\n    /// \\param iterator The iterator to initialize this one from.\n    template <typename AnyKey, typename AnyValue, typename AnyCache>\n    OrderedConstIterator(BaseOrderedIterator<AnyKey, AnyValue, AnyCache>\n                             iterator)  // NOLINT(runtime/explicit)\n        : super(iterator) {\n      // Note that this only works because these derived iterator\n      // classes dont' have any members of their own.\n    }\n\n    /// Constructs a new const ordered iterator from a non-const one.\n    ///\n    /// \\param iterator The non-const ordered iterator to construct from.\n    OrderedConstIterator(OrderedIterator iterator)  // NOLINT(runtime/explicit)\n        : super(std::move(iterator)) {\n    }\n\n    /// Constructs a new const ordered iterator from an unordered iterator.\n    ///\n    /// \\param unordered_iterator The unordered iterator to construct from.\n    explicit OrderedConstIterator(UnorderedIterator unordered_iterator)\n    : super(std::move(unordered_iterator)) {\n    }\n\n    /// Constructs a new const ordered iterator from a const unordered iterator.\n    ///\n    /// \\param unordered_iterator The unordered iterator to construct from.\n    explicit OrderedConstIterator(\n        UnorderedConstIterator unordered_iterator)  // NOLINT(runtime/explicit)\n        : super(std::move(unordered_iterator)) {\n    }\n\n    /// Constructs a new const ordered iterator.\n    ///\n    /// \\param cache The cache this iterator references.\n    /// \\param iterator The underlying iterator.\n    OrderedConstIterator(const BaseCache& cache, UnderlyingIterator iterator)\n    : super(cache, iterator) {\n    }\n  };\n\n  using InsertionResultType = InsertionResult<UnorderedIterator>;\n\n  // Can't put these in LRU::Lowercase because they are nested, unfortunately\n  using ordered_iterator = OrderedIterator;\n  using ordered_const_iterator = OrderedConstIterator;\n  using unordered_iterator = UnorderedIterator;\n  using unordered_const_iterator = UnorderedConstIterator;\n\n  /////////////////////////////////////////////////////////////////////////////\n  // SPECIAL MEMBER FUNCTIONS\n  /////////////////////////////////////////////////////////////////////////////\n\n  /// Constructor.\n  ///\n  /// \\param capacity The capacity of the cache.\n  /// \\param hash The hash function to use for the internal map.\n  /// \\param key_equal The key equality function to use for the internal map.\n  BaseCache(size_t capacity,\n            const HashFunction& hash,\n            const KeyEqual& key_equal)\n  : _map(0, hash, key_equal), _capacity(capacity), _last_accessed(key_equal) {\n  }\n\n  /// Constructor.\n  ///\n  /// \\param capacity The capacity of the cache.\n  /// \\param begin The start of a range to construct the cache with.\n  /// \\param end The end of a range to construct the cache with.\n  /// \\param hash The hash function to use for the internal map.\n  /// \\param key_equal The key equality function to use for the internal map.\n  template <typename Iterator>\n  BaseCache(size_t capacity,\n            Iterator begin,\n            Iterator end,\n            const HashFunction& hash,\n            const KeyEqual& key_equal)\n  : BaseCache(capacity, hash, key_equal) {\n    insert(begin, end);\n  }\n\n  /// Constructor.\n  ///\n  /// The capacity is inferred from the distance between the two iterators and\n  /// lower-bounded by an internal constant $c_0$, usually 128 (i.e. the actual\n  /// capacity will be $\\max(\\text{distance}, c_0)$).\n  /// This may be expensive for iterators that are not random-access.\n  ///\n  /// \\param begin The start of a range to construct the cache with.\n  /// \\param end The end of a range to construct the cache with.\n  /// \\param hash The hash function to use for the internal map.\n  /// \\param key_equal The key equality function to use for the internal map.\n  template <typename Iterator>\n  BaseCache(Iterator begin,\n            Iterator end,\n            const HashFunction& hash,\n            const KeyEqual& key_equal)\n      // This may be expensive\n      : BaseCache(std::max<size_t>(std::distance(begin, end),\n                                   Internal::DEFAULT_CAPACITY),\n                  begin,\n                  end,\n                  hash,\n                  key_equal) {\n  }\n\n  /// Constructor.\n  ///\n  /// \\param capacity The capacity of the cache.\n  /// \\param range A range to construct the cache with.\n  /// \\param hash The hash function to use for the internal map.\n  /// \\param key_equal The key equality function to use for the internal map.\n  template <typename Range, typename = Internal::enable_if_range<Range>>\n  BaseCache(size_t capacity,\n            Range& range,\n            const HashFunction& hash,\n            const KeyEqual& key_equal)\n  : BaseCache(capacity, hash, key_equal) {\n    insert(range);\n  }\n\n  /// Constructor.\n  ///\n  /// The capacity is inferred from the distance between the beginning and end\n  /// of the range. This may be expensive for iterators that are not\n  /// random-access.\n  ///\n  /// \\param range A range to construct the cache with.\n  /// \\param hash The hash function to use for the internal map.\n  /// \\param key_equal The key equality function to use for the internal map.\n  template <typename Range, typename = Internal::enable_if_range<Range>>\n  explicit BaseCache(Range& range,\n                     const HashFunction& hash,\n                     const KeyEqual& key_equal)\n  : BaseCache(std::begin(range), std::end(range), hash, key_equal) {\n  }\n\n  /// Constructor.\n  ///\n  /// Elements of the range will be moved into the cache.\n  ///\n  /// \\param capacity The capacity of the cache.\n  /// \\param range A range to construct the cache with.\n  /// \\param hash The hash function to use for the internal map.\n  /// \\param key_equal The key equality function to use for the internal map.\n  template <typename Range, typename = Internal::enable_if_range<Range>>\n  BaseCache(size_t capacity,\n            Range&& range,\n            const HashFunction& hash,\n            const KeyEqual& key_equal)\n  : BaseCache(capacity, hash, key_equal) {\n    insert(std::move(range));\n  }\n\n  /// Constructor.\n  ///\n  /// The capacity is inferred from the distance between the beginning and end\n  /// of the range. This may be expensive for iterators that are not\n  /// random-access.\n  ///\n  /// Elements of the range will be moved into the cache.\n  ///\n  /// \\param range A range to construct the cache with.\n  /// \\param hash The hash function to use for the internal map.\n  /// \\param key_equal The key equality function to use for the internal map.\n  template <typename Range, typename = Internal::enable_if_range<Range>>\n  explicit BaseCache(Range&& range,\n                     const HashFunction& hash,\n                     const KeyEqual& key_equal)\n  : BaseCache(std::distance(std::begin(range), std::end(range)),\n              std::move(range),\n              hash,\n              key_equal) {\n  }\n\n  /// Constructor.\n  ///\n  /// \\param capacity The capacity of the cache.\n  /// \\param list The initializer list to construct the cache with.\n  /// \\param hash The hash function to use for the internal map.\n  /// \\param key_equal The key equality function to use for the internal map.\n  BaseCache(size_t capacity,\n            InitializerList list,\n            const HashFunction& hash,\n            const KeyEqual& key_equal)\n  : BaseCache(capacity, list.begin(), list.end(), hash, key_equal) {\n  }\n\n  /// Constructor.\n  ///\n  /// \\param list The initializer list to construct the cache with.\n  /// \\param hash The hash function to use for the internal map.\n  /// \\param key_equal The key equality function to use for the internal map.\n  BaseCache(InitializerList list,\n            const HashFunction& hash,\n            const KeyEqual& key_equal)  // NOLINT(runtime/explicit)\n      : BaseCache(list.size(), list.begin(), list.end(), hash, key_equal) {\n  }\n\n  /// Copy constructor.\n  BaseCache(const BaseCache& other)\n  : _map(other._map)\n  , _order(other._order)\n  , _stats(other._stats)\n  , _last_accessed(other._last_accessed)\n  , _callback_manager(other._callback_manager)\n  , _capacity(other._capacity) {\n    _reassign_references();\n  }\n\n  /// Move constructor.\n  BaseCache(BaseCache&& other) {\n    // Following the copy-swap idiom.\n    swap(other);\n  }\n\n  /// Copy assignment operator.\n  BaseCache& operator=(const BaseCache& other) noexcept {\n    if (this != &other) {\n      _map = other._map;\n      _order = other._order;\n      _stats = other._stats;\n      _last_accessed = other._last_accessed;\n      _callback_manager = other._callback_manager;\n      _capacity = other._capacity;\n      _reassign_references();\n    }\n\n    return *this;\n  }\n\n  /// Move assignment operator.\n  BaseCache& operator=(BaseCache&& other) noexcept {\n    // Following the copy-swap idiom.\n    swap(other);\n    return *this;\n  }\n\n  /// Destructor.\n  virtual ~BaseCache() = default;\n\n  /// Sets the contents of the cache to a range.\n  ///\n  /// If the size of the range is greater than the current capacity,\n  /// the capacity is increased to match the range's size. If the size of\n  /// the range is less than the current capacity, the cache's capacity is *not*\n  /// changed.\n  ///\n  /// \\param range A range of pairs to assign to the cache.\n  /// \\returns The cache instance.\n  template <typename Range, typename = Internal::enable_if_range<Range>>\n  BaseCache& operator=(const Range& range) {\n    _clear_and_increase_capacity(range);\n    insert(range);\n    return *this;\n  }\n\n  /// Sets the contents of the cache to an rvalue range.\n  ///\n  /// Pairs of the range are moved into the cache.\n  ///\n  /// \\param range A range of pairs to assign to the cache.\n  /// \\returns The cache instance.\n  template <typename Range, typename = Internal::enable_if_range<Range>>\n  BaseCache& operator=(Range&& range) {\n    _clear_and_increase_capacity(range);\n    insert(std::move(range));\n    return *this;\n  }\n\n  /// Sets the contents of the cache to pairs from a list.\n  ///\n  /// \\param list The list to assign to the cache.\n  /// \\returns The cache instance.\n  BaseCache& operator=(InitializerList list) {\n    return operator=<InitializerList>(list);\n  }\n\n  /// Swaps the contents of the cache with another cache.\n  ///\n  /// \\param other The other cache to swap with.\n  virtual void swap(BaseCache& other) noexcept {\n    using std::swap;\n\n    swap(_order, other._order);\n    swap(_map, other._map);\n    swap(_last_accessed, other._last_accessed);\n    swap(_capacity, other._capacity);\n  }\n\n  /// Swaps the contents of one cache with another cache.\n  ///\n  /// \\param first The first cache to swap.\n  /// \\param second The second cache to swap.\n  friend void swap(BaseCache& first, BaseCache& second) noexcept {\n    first.swap(second);\n  }\n\n  /// Compares the cache for equality with another cache.\n  ///\n  /// \\complexity O(N)\n  /// \\param other The other cache to compare with.\n  /// \\returns True if the keys __and values__ of the cache are identical to the\n  ///         other, else false.\n  bool operator==(const BaseCache& other) const noexcept {\n    if (this == &other) return true;\n    if (this->_map != other._map) return false;\n    // clang-format off\n    return std::equal(\n      this->_order.begin(),\n      this->_order.end(),\n      other._order.begin(),\n      other._order.end(),\n      [](const auto& first, const auto& second) {\n        return first.get() == second.get();\n    });\n    // clang-format on\n  }\n\n  /// Compares the cache for inequality with another cache.\n  ///\n  /// \\complexity O(N)\n  /// \\param other The other cache to compare with.\n  /// \\returns True if there is any mismatch in keys __or their values__\n  /// betweent\n  /// the two caches, else false.\n  bool operator!=(const BaseCache& other) const noexcept {\n    return !(*this == other);\n  }\n\n  /////////////////////////////////////////////////////////////////////////////\n  // ITERATOR INTERFACE\n  /////////////////////////////////////////////////////////////////////////////\n\n  /// \\returns An unordered iterator to the beginning of the cache (this need\n  /// not be the first key inserted).\n  UnorderedIterator unordered_begin() noexcept {\n    return {*this, _map.begin()};\n  }\n\n  /// \\returns A const unordered iterator to the beginning of the cache (this\n  /// need not be the key least recently inserted).\n  UnorderedConstIterator unordered_begin() const noexcept {\n    return unordered_cbegin();\n  }\n\n  /// \\returns A const unordered iterator to the beginning of the cache (this\n  /// need not be the key least recently inserted).\n  UnorderedConstIterator unordered_cbegin() const noexcept {\n    return {*this, _map.cbegin()};\n  }\n\n  /// \\returns An unordered iterator to the end of the cache (this\n  /// need not be one past the key most recently inserted).\n  UnorderedIterator unordered_end() noexcept {\n    return {*this, _map.end()};\n  }\n\n  /// \\returns A const unordered iterator to the end of the cache (this\n  /// need not be one past the key most recently inserted).\n  UnorderedConstIterator unordered_end() const noexcept {\n    return unordered_cend();\n  }\n\n  /// \\returns A const unordered iterator to the end of the cache (this\n  /// need not be one past the key most recently inserted).\n  UnorderedConstIterator unordered_cend() const noexcept {\n    return {*this, _map.cend()};\n  }\n\n  /// \\returns An ordered iterator to the beginning of the cache (the key least\n  /// recently inserted).\n  OrderedIterator ordered_begin() noexcept {\n    return {*this, _order.begin()};\n  }\n\n  /// \\returns A const ordered iterator to the beginning of the cache (the key\n  /// least recently inserted).\n  OrderedConstIterator ordered_begin() const noexcept {\n    return ordered_cbegin();\n  }\n\n  /// \\returns A const ordered iterator to the beginning of the cache (the key\n  /// least recently inserted).\n  OrderedConstIterator ordered_cbegin() const noexcept {\n    return {*this, _order.cbegin()};\n  }\n\n  /// \\returns An ordered iterator to the end of the cache (one past the key\n  /// most recently inserted).\n  OrderedIterator ordered_end() noexcept {\n    return {*this, _order.end()};\n  }\n\n  /// \\returns A const ordered iterator to the end of the cache (one past the\n  /// key least recently inserted).\n  OrderedConstIterator ordered_end() const noexcept {\n    return ordered_cend();\n  }\n\n  /// \\returns A const ordered iterator to the end of the cache (one past the\n  /// key least recently inserted).\n  OrderedConstIterator ordered_cend() const noexcept {\n    return {*this, _order.cend()};\n  }\n\n  /// \\copydoc unordered_begin()\n  UnorderedIterator begin() noexcept {\n    return unordered_begin();\n  }\n\n  /// \\copydoc unordered_cbegin()\n  UnorderedConstIterator begin() const noexcept {\n    return cbegin();\n  }\n\n  /// \\copydoc unordered_cbegin()\n  UnorderedConstIterator cbegin() const noexcept {\n    return unordered_begin();\n  }\n\n  /// \\copydoc unordered_end() const\n  UnorderedIterator end() noexcept {\n    return unordered_end();\n  }\n\n  /// \\copydoc unordered_cend() const\n  UnorderedConstIterator end() const noexcept {\n    return cend();\n  }\n\n  /// \\copydoc unordered_cend() const\n  UnorderedConstIterator cend() const noexcept {\n    return unordered_cend();\n  }\n\n  /// \\returns True if the given iterator may be safely dereferenced, else\n  /// false.\n  /// \\details Behavior is undefined if the iterator does not point into this\n  /// cache.\n  /// \\param unordered_iterator The iterator to check.\n  virtual bool is_valid(UnorderedConstIterator unordered_iterator) const\n      noexcept {\n    return unordered_iterator != unordered_end();\n  }\n\n  /// \\returns True if the given iterator may be safely dereferenced, else\n  /// false.\n  /// \\details Behavior is undefined if the iterator does not point into this\n  /// cache.\n  /// \\param ordered_iterator The iterator to check.\n  virtual bool is_valid(OrderedConstIterator ordered_iterator) const noexcept {\n    return ordered_iterator != ordered_end();\n  }\n\n  /// Checks if the given iterator may be dereferencend and throws an exception\n  /// if not.\n  ///\n  /// The exception thrown, if any, depends on the state of the iterator.\n  ///\n  /// \\param unordered_iterator The iterator to check.\n  /// \\throws LRU::Error::InvalidIterator if the iterator is the end iterator.\n  virtual void\n  throw_if_invalid(UnorderedConstIterator unordered_iterator) const {\n    if (unordered_iterator == unordered_end()) {\n      throw LRU::Error::InvalidIterator();\n    }\n  }\n\n  /// Checks if the given iterator may be dereferencend and throws an exception\n  /// if not.\n  ///\n  /// The exception thrown, if any, depends on the state of the iterator.\n  ///\n  /// \\param ordered_iterator The iterator to check.\n  /// \\throws LRU::Error::InvalidIterator if the iterator is the end iterator.\n  virtual void throw_if_invalid(OrderedConstIterator ordered_iterator) const {\n    if (ordered_iterator == ordered_end()) {\n      throw LRU::Error::InvalidIterator();\n    }\n  }\n\n  /////////////////////////////////////////////////////////////////////////////\n  // CACHE INTERFACE\n  /////////////////////////////////////////////////////////////////////////////\n\n  /// Tests if the given key is contained in the cache.\n  ///\n  /// This function may return false even if the key is actually currently\n  /// stored in the cache, but the concrete cache class places some additional\n  /// constraint as to when a key may be accessed (such as a time limit).\n  ///\n  /// \\complexity O(1) expected and amortized.\n  /// \\param key The key to check for.\n  /// \\returns True if the key's value may be accessed via `lookup()` without an\n  /// error, else false.\n  virtual bool contains(const Key& key) const {\n    if (key == _last_accessed) {\n      if (_last_accessed_is_ok(key)) {\n        _register_hit(key, _last_accessed.value());\n        // If this is the last accessed key, it's at the front anyway\n        return true;\n      } else {\n        return false;\n      }\n    }\n\n    return find(key) != end();\n  }\n\n  /// Looks up the value for the given key.\n  ///\n  /// If the key is found in the cache, it is moved to the front. Any iterators\n  /// pointing to that key are still valid, but the subsequent order of\n  /// iteration may be different from what it was before.\n  ///\n  /// \\complexity O(1) expected and amortized.\n  /// \\param key The key whose value to look for.\n  /// \\throws LRU::Error::KeyNotFound if the key's value may not be accessed.\n  /// \\returns The value stored in the cache for the given key.\n  /// \\see contains()\n  virtual const Value& lookup(const Key& key) const {\n    if (key == _last_accessed) {\n      auto& value = _value_for_last_accessed();\n      _register_hit(key, value);\n      // If this is the last accessed key, it's at the front anyway\n      return value;\n    }\n\n    auto iterator = find(key);\n    if (iterator == end()) {\n      throw LRU::Error::KeyNotFound();\n    } else {\n      return iterator.value();\n    }\n  }\n\n  /// Looks up the value for the given key.\n  ///\n  /// If the key is found in the cache, it is moved to the front. Any iterators\n  /// pointing to that key are still valid, but the subsequent order of\n  /// iteration may be different from what it was before.\n  ///\n  /// \\complexity O(1) expected and amortized.\n  /// \\param key The key whose value to look for.\n  /// \\throws LRU::Error::KeyNotFound if the key's value may not be accessed.\n  /// \\returns The value stored in the cache for the given key.\n  /// \\see contains()\n  virtual Value& lookup(const Key& key) {\n    if (key == _last_accessed) {\n      auto& value = _value_for_last_accessed();\n      _register_hit(key, value);\n      // If this is the last accessed key, it's at the front anyway\n      return value;\n    }\n\n    auto iterator = find(key);\n    if (iterator == end()) {\n      throw LRU::Error::KeyNotFound();\n    } else {\n      return iterator.value();\n    }\n  }\n\n  /// Attempts to return an iterator to the given key in the cache.\n  ///\n  /// If the key is found in the cache, it is moved to the front. Any iterators\n  /// pointing to that key are still valid, but the subsequent order of\n  /// iteration may be different from what it was before.\n  ///\n  /// \\complexity O(1) expected and amortized.\n  /// \\param key The key whose value to look for.\n  /// \\returns An iterator pointing to the entry with the given key, if one\n  /// exists, else the end iterator.\n  virtual UnorderedIterator find(const Key& key) = 0;\n\n  /// Attempts to return a const iterator to the given key in the cache.\n  ///\n  /// If the key is found in the cache, it is moved to the front. Any iterators\n  /// pointing to that key are still valid, but the subsequent order of\n  /// iteration may be different from what it was before.\n  ///\n  /// \\complexity O(1) expected and amortized.\n  /// \\param key The key whose value to look for.\n  /// \\returns A const iterator pointing to the entry with the given key, if one\n  /// exists, else the end iterator.\n  virtual UnorderedConstIterator find(const Key& key) const = 0;\n\n  /// \\copydoc lookup(const Key&)\n  virtual Value& operator[](const Key& key) {\n    return lookup(key);\n  }\n\n  /// \\copydoc lookup(const Key&) const\n  virtual const Value& operator[](const Key& key) const {\n    return lookup(key);\n  }\n\n  /// Inserts the given `(key, value)` pair into the cache.\n  ///\n  /// If the cache's capacity is reached, the most recently used element will be\n  /// evicted. Any iterators pointing to that element will be invalidated.\n  /// Iterators pointing to other elements are not affected.\n  ///\n  /// \\complexity O(1) expected and amortized.\n  /// \\param key The key to insert.\n  /// \\param value The value to insert with the key.\n  /// \\returns An `InsertionResult`, holding a boolean indicating whether the\n  /// key was newly inserted (true) or only updated (false) as well as an\n  /// iterator pointing to the entry for the key.\n  virtual InsertionResultType insert(const Key& key, const Value& value) {\n    if (_capacity == 0) return {false, end()};\n\n    auto iterator = _map.find(key);\n\n    // To insert, we first check if the key is already present in the cache\n    // and if so, update its value and move its order iterator to the front\n    // of the queue. Else, we insert the key at the end of the queue and\n    // possibly pop the front if the cache has reached its capacity.\n\n    if (iterator == _map.end()) {\n      auto result = _map.emplace(key, Information(value));\n      assert(result.second);\n      auto order = _insert_new_key(result.first->first);\n      result.first->second.order = order;\n\n      _last_accessed = result.first;\n      return {true, {*this, result.first}};\n    } else {\n      _move_to_front(iterator, value);\n      _last_accessed = iterator;\n      return {false, {*this, iterator}};\n    }\n  }\n\n  /// Inserts a range of `(key, value)` pairs.\n  ///\n  /// If, at any point, the cache's capacity is reached, the most recently used\n  /// element will be evicted. Any iterators pointing to that element will\n  /// be invalidated. Iterators pointing to other elements are not affected.\n  ///\n  /// Note: This operation has no performance benefits over\n  /// element-wise insertion via `insert()`.\n  ///\n  /// \\param begin An iterator for the start of the range to insert.\n  /// \\param end An iterator for the end of the range to insert.\n  /// \\returns The number of elements newly inserted (as opposed to only\n  /// updated).\n  template <typename Iterator,\n            typename = Internal::enable_if_iterator_over_pair<Iterator>>\n  size_t insert(Iterator begin, Iterator end) {\n    size_t newly_inserted = 0;\n    for (; begin != end; ++begin) {\n      const auto result = insert(begin->first, begin->second);\n      newly_inserted += result.was_inserted();\n    }\n\n    return newly_inserted;\n  }\n\n  /// Inserts a range of `(key, value)` pairs.\n  ///\n  /// If, at any point, the cache's capacity is reached, the most recently used\n  /// element will be evicted. Any iterators pointing to that element will\n  /// be invalidated. Iterators pointing to other elements are not affected.\n  ///\n  /// This operation has no performance benefits over\n  /// element-wise insertion via `insert()`.\n  ///\n  /// \\param range The range of `(key, value)` pairs to insert.\n  /// \\returns The number of elements newly inserted (as opposed to only\n  /// updated).\n  template <typename Range, typename = Internal::enable_if_range<Range>>\n  size_t insert(Range& range) {\n    using std::begin;\n    using std::end;\n\n    return insert(begin(range), end(range));\n  }\n\n  /// Moves the elements of the range into the cache.\n  ///\n  /// If, at any point, the cache's capacity is reached, the most recently used\n  /// element will be evicted. Any iterators pointing to that element will\n  /// be invalidated. Iterators pointing to other elements are not affected.\n  ///\n  /// \\param range The range of `(key, value)` pairs to move into the cache.\n  /// \\returns The number of elements newly inserted (as opposed to only\n  /// updated).\n  template <typename Range, typename = Internal::enable_if_range<Range>>\n  size_t insert(Range&& range) {\n    size_t newly_inserted = 0;\n    for (auto& pair : range) {\n      const auto result =\n          emplace(std::move(pair.first), std::move(pair.second));\n      newly_inserted += result.was_inserted();\n    }\n\n    return newly_inserted;\n  }\n\n  /// Inserts a list `(key, value)` pairs.\n  ///\n  /// If the cache's capacity is reached, the most recently used element will be\n  /// evicted (one or more times). Any iterators pointing to that element will\n  /// be invalidated. Iterators pointing to other elements are not affected.\n  ///\n  /// This operation has no performance benefits over\n  /// element-wise insertion via `insert()`.\n  ///\n  /// \\param list The list of `(key, value)` pairs to insert.\n  /// \\returns The number of elements newly inserted (as opposed to only\n  /// updated).\n  virtual size_t insert(InitializerList list) {\n    return insert(list.begin(), list.end());\n  }\n\n  /// Emplaces a new `(key, value)` pair into the cache.\n  ///\n  /// This emplacement function allows perfectly forwarding an arbitrary number\n  /// of arguments to the constructor of both the key and value type, via\n  /// appropriate tuples. The intended usage is with `std::forward_as_tuple`,\n  /// for example:\n  /// \\code{.cpp}\n  /// struct A { A(int, const std::string&) { } };\n  /// struct B { B(double) {} };\n  ///\n  /// LRU::Cache<A> cache;\n  ///\n  /// cache.emplace(\n  ///   std::piecewise_construct,\n  ///   std::forward_as_tuple(1, \"hello\"),\n  ///   std::forward_as_tuple(5.0),\n  ///  );\n  /// \\endcode\n  ///\n  /// There is a convenience overload that requires much less overhead, if both\n  /// constructors expect only a single argument.\n  ///\n  /// If the cache's capacity is reached, the most recently used element will be\n  /// evicted. Any iterators pointing to that element will be invalidated.\n  /// Iterators pointing to other elements are not affected.\n  ///\n  /// \\complexity O(1) expected and amortized.\n  /// \\param _ A dummy parameter to work around overload resolution.\n  /// \\param key_arguments A tuple of arguments to construct a key object with.\n  /// \\param value_arguments A tuple of arguments to construct a value object\n  ///                        with.\n  /// \\returns An `InsertionResult`, holding a boolean indicating whether the\n  /// key was newly inserted (true) or only updated (false) as well as an\n  /// iterator pointing to the entry for the key.\n  template <typename... Ks, typename... Vs>\n  InsertionResultType emplace(std::piecewise_construct_t _,\n                              const std::tuple<Ks...>& key_arguments,\n                              const std::tuple<Vs...>& value_arguments) {\n    if (_capacity == 0) return {false, end()};\n\n    auto key = Internal::construct_from_tuple<Key>(key_arguments);\n    auto iterator = _map.find(key);\n\n    if (iterator == _map.end()) {\n      auto result = _map.emplace(std::move(key), Information(value_arguments));\n      auto order = _insert_new_key(result.first->first);\n      result.first->second.order = order;\n      assert(result.second);\n\n      _last_accessed = result.first;\n      return {true, {*this, result.first}};\n    } else {\n      auto value = Internal::construct_from_tuple<Value>(value_arguments);\n      _move_to_front(iterator, value);\n      _last_accessed = iterator;\n      return {false, {*this, iterator}};\n    }\n  }\n\n  /// Emplaces a `(key, value)` pair.\n  ///\n  /// This is a convenience overload removing the necessity for\n  /// `std::piecewise_construct` and `std::forward_as_tuple` that may be used in\n  /// the case that both the key and value have constructors expecting only a\n  /// single argument.\n  ///\n  /// If the cache's capacity is reached, the most recently used element will be\n  /// evicted. Any iterators pointing to that element will be invalidated.\n  /// Iterators pointing to other elements are not affected.\n  ///\n  /// \\param key_argument The argument to construct a key object with.\n  /// \\param value_argument The argument to construct a value object with.\n  /// \\returns An `InsertionResult`, holding a boolean indicating whether the\n  /// key was newly inserted (true) or only updated (false) as well as an\n  /// iterator pointing to the entry for the key.\n  template <typename K, typename V>\n  InsertionResultType emplace(K&& key_argument, V&& value_argument) {\n    auto key_tuple = std::forward_as_tuple(std::forward<K>(key_argument));\n    auto value_tuple = std::forward_as_tuple(std::forward<V>(value_argument));\n    return emplace(std::piecewise_construct, key_tuple, value_tuple);\n  }\n\n  /// Erases the given key from the cache, if it is present.\n  ///\n  /// If the key is not present in the cache, this is a no-op.\n  /// All iterators pointing to the given key are invalidated.\n  /// Other iterators are not affected.\n  ///\n  /// \\param key The key to erase.\n  /// \\returns True if the key was erased, else false.\n  virtual bool erase(const Key& key) {\n    // No need to use _last_accessed_is_ok here, because even\n    // if it has expired, it's no problem to erase it anyway\n    if (_last_accessed == key) {\n      _erase(_last_accessed.key(), _last_accessed.information());\n      return true;\n    }\n\n    auto iterator = _map.find(key);\n    if (iterator != _map.end()) {\n      _erase(iterator);\n      return true;\n    }\n\n    return false;\n  }\n\n  /// Erases the key pointed to by the given iterator.\n  ///\n  /// \\param iterator The iterator whose key to erase.\n  /// \\throws LRU::Error::InvalidIterator if the iterator is the end iterator.\n  virtual void erase(UnorderedConstIterator iterator) {\n    /// We have this overload to avoid the extra conversion-construction from\n    /// unordered to ordered iterator (and renewed hash lookup)\n    if (iterator == unordered_cend()) {\n      throw LRU::Error::InvalidIterator();\n    } else {\n      _erase(iterator._iterator);\n    }\n  }\n\n\n  /// Erases the key pointed to by the given iterator.\n  ///\n  /// \\param iterator The iterator whose key to erase.\n  /// \\throws LRU::Error::InvalidIterator if the iterator is the end iterator.\n  virtual void erase(OrderedConstIterator iterator) {\n    if (iterator == ordered_cend()) {\n      throw LRU::Error::InvalidIterator();\n    } else {\n      _erase(_map.find(iterator.key()));\n    }\n  }\n\n  /// Clears the cache entirely.\n  virtual void clear() {\n    _map.clear();\n    _order.clear();\n    _last_accessed.invalidate();\n  }\n\n  /// Requests shrinkage of the cache to the given size.\n  ///\n  /// If the passed size is 0, this operation is equivalent to `clear()`. If the\n  /// size is greater than the current size, it is a no-op. Otherwise, the size\n  /// of the cache is reduzed to the given size by repeatedly removing the least\n  /// recent element.\n  ///\n  /// \\param new_size The size to (maybe) shrink to.\n  virtual void shrink(size_t new_size) {\n    if (new_size >= size()) return;\n    if (new_size == 0) {\n      clear();\n      return;\n    }\n\n    while (size() > new_size) {\n      _erase_lru();\n    }\n  }\n\n  /////////////////////////////////////////////////////////////////////////////\n  // SIZE AND CAPACITY INTERFACE\n  /////////////////////////////////////////////////////////////////////////////\n\n  /// \\returns The number of keys present in the cache.\n  virtual size_t size() const noexcept {\n    return _map.size();\n  }\n\n  /// Sets the capacity of the cache to the given value.\n  ///\n  /// If the given capacity is less than the current capacity of the cache,\n  /// the least-recently inserted element is removed repeatedly until the\n  /// capacity is equal to the given value.\n  ///\n  /// \\param new_capacity The capacity to shrink or grow to.\n  virtual void capacity(size_t new_capacity) {\n    // Pop the front of the cache if we have to resize\n    while (size() > new_capacity) {\n      _erase_lru();\n    }\n    _capacity = new_capacity;\n  }\n\n  /// Returns the current capacity of the cache.\n  virtual size_t capacity() const noexcept {\n    return _capacity;\n  }\n\n  /// \\returns the number of slots left in the cache.\n  ///\n  /// \\details After this number of elements have been inserted, the next one\n  /// insertion is preceded by an erasure of the least-recently inserted\n  /// element.\n  virtual size_t space_left() const noexcept {\n    return _capacity - size();\n  }\n\n  /// \\returns True if the cache contains no elements, else false.\n  virtual bool is_empty() const noexcept {\n    return size() == 0;\n  }\n\n  /// \\returns True if the cache's size equals its capacity, else false.\n  ///\n  /// \\details If `is_full()` returns `true`, the next insertion is preceded by\n  /// an erasure of the least-recently inserted element.\n  virtual bool is_full() const noexcept {\n    return size() == _capacity;\n  }\n\n  /// \\returns The function used to hash keys.\n  virtual HashFunction hash_function() const {\n    return _map.hash_function();\n  }\n\n  /// \\returns The function used to compare keys.\n  virtual KeyEqual key_equal() const {\n    return _map.key_eq();\n  }\n\n  /////////////////////////////////////////////////////////////////////////////\n  // STATISTICS INTERFACE\n  /////////////////////////////////////////////////////////////////////////////\n\n  /// Registers the given statistics object for monitoring.\n  ///\n  /// This method is useful if the statistics object is to\n  /// be shared between caches.\n  ///\n  /// Ownership of the statistics object remains with the user and __not__ with\n  /// the cache object. Also, behavior is undefined if the lifetime of the cache\n  /// exceeds that of the registered statistics object.\n  ///\n  /// \\param statistics The statistics object to register.\n  virtual void monitor(const StatisticsPointer& statistics) {\n    _stats = statistics;\n  }\n\n  /// Registers the given statistics object for monitoring.\n  ///\n  /// Ownership of the statistics object is transferred to the cache.\n  ///\n  /// \\param statistics The statistics object to register.\n  virtual void monitor(StatisticsPointer&& statistics) {\n    _stats = std::move(statistics);\n  }\n\n  /// Constructs a new statistics in-place in the cache.\n  ///\n  /// This method is useful if the cache is to have exclusive ownership of the\n  /// statistics and out-of-place construction and move is inconvenient.\n  ///\n  /// \\param args Arguments to be forwarded to the constructor of the statistics\n  ///             object.\n  template <typename... Args,\n            typename = std::enable_if_t<\n                Internal::none_of_type<StatisticsPointer, Args...>>>\n  void monitor(Args&&... args) {\n    _stats = std::make_shared<Statistics<Key>>(std::forward<Args>(args)...);\n  }\n\n  /// Stops any monitoring being performed with a statistics object.\n  ///\n  /// If the cache is not currently monitoring at all, this is a no-op.\n  virtual void stop_monitoring() {\n    _stats.reset();\n  }\n\n  /// \\returns True if the cache is currently monitoring statistics, else\n  /// false.\n  bool is_monitoring() const noexcept {\n    return _stats.has_stats();\n  }\n\n  /// \\returns The statistics object currently in use by the cache.\n  /// \\throws LRU::Error::NotMonitoring if the cache is currently not\n  /// monitoring.\n  virtual Statistics<Key>& stats() {\n    if (!is_monitoring()) {\n      throw LRU::Error::NotMonitoring();\n    }\n    return _stats.get();\n  }\n\n  /// \\returns The statistics object currently in use by the cache.\n  /// \\throws LRU::Error::NotMonitoring if the cache is currently not\n  /// monitoring.\n  virtual const Statistics<Key>& stats() const {\n    if (!is_monitoring()) {\n      throw LRU::Error::NotMonitoring();\n    }\n    return _stats.get();\n  }\n\n  /// \\returns A `shared_ptr` to the statistics currently in use by the cache.\n  virtual StatisticsPointer& shared_stats() {\n    return _stats.shared();\n  }\n\n  /// \\returns A `shared_ptr` to the statistics currently in use by the cache.\n  virtual const StatisticsPointer& shared_stats() const {\n    return _stats.shared();\n  }\n\n  /////////////////////////////////////////////////////////////////////////////\n  // CALLBACK INTERFACE\n  /////////////////////////////////////////////////////////////////////////////\n\n  /// Registers a new hit callback.\n  ///\n  /// \\param hit_callback The hit callback function to register with the cache.\n  template <typename Callback,\n            typename = Internal::enable_if_same<HitCallback, Callback>>\n  void hit_callback(Callback&& hit_callback) {\n    _callback_manager.hit_callback(std::forward<Callback>(hit_callback));\n  }\n\n  /// Registers a new miss callback.\n  ///\n  /// \\param miss_callback The miss callback function to register with the\n  ///                       cache.\n  template <typename Callback,\n            typename = Internal::enable_if_same<MissCallback, Callback>>\n  void miss_callback(Callback&& miss_callback) {\n    _callback_manager.miss_callback(std::forward<Callback>(miss_callback));\n  }\n\n  /// Registers a new access callback.\n  ///\n  /// \\param access_callback The access callback function to register with the\n  ///                        cache.\n  template <typename Callback,\n            typename = Internal::enable_if_same<AccessCallback, Callback>>\n  void access_callback(Callback&& access_callback) {\n    _callback_manager.access_callback(std::forward<Callback>(access_callback));\n  }\n\n  /// Clears all hit callbacks.\n  void clear_hit_callbacks() {\n    _callback_manager.clear_hit_callbacks();\n  }\n\n  /// Clears all miss callbacks.\n  void clear_miss_callbacks() {\n    _callback_manager.clear_miss_callbacks();\n  }\n\n  /// Clears all access callbacks.\n  void clear_access_callbacks() {\n    _callback_manager.clear_access_callbacks();\n  }\n\n  /// Clears all callbacks.\n  void clear_all_callbacks() {\n    _callback_manager.clear();\n  }\n\n  /// \\returns All hit callbacks.\n  const HitCallbackContainer& hit_callbacks() const noexcept {\n    return _callback_manager.hit_callbacks();\n  }\n\n  /// \\returns All miss callbacks.\n  const MissCallbackContainer& miss_callbacks() const noexcept {\n    return _callback_manager.miss_callbacks();\n  }\n\n  /// \\returns All access callbacks.\n  const AccessCallbackContainer& access_callbacks() const noexcept {\n    return _callback_manager.access_callbacks();\n  }\n\n protected:\n  // The ordered iterators need to perform lookups without changing\n  // the order of elements or affecting statistics.\n  template <typename, typename, typename>\n  friend class BaseOrderedIterator;\n\n  using MapInsertionResult = decltype(Map().emplace());\n  using LastAccessed =\n      typename Internal::LastAccessed<Key, Information, KeyEqual>;\n\n  /// Moves the key pointed to by the iterator to the front of the order.\n  ///\n  /// \\param iterator The iterator pointing to the key to move.\n  virtual void _move_to_front(QueueIterator iterator) const {\n    if (size() == 1) return;\n    // Extract the current linked-list node and insert (splice it) at the end\n    // The original iterator is not invalidated and now points to the new\n    // position (which is still the same node).\n    _order.splice(_order.end(), _order, iterator);\n  }\n\n  /// Moves the key pointed to by the iterator to the front of the order and\n  /// assigns a new value.\n  ///\n  /// \\param iterator The iterator pointing to the key to move.\n  /// \\param new_value The updated value to move the key with.\n  virtual void _move_to_front(MapIterator iterator, const Value& new_value) {\n    // Extract the current linked-list node and insert (splice it) at the end\n    // The original iterator is not invalidated and now points to the new\n    // position (which is still the same node).\n    _move_to_front(iterator->second.order);\n    iterator->second.value = new_value;\n  }\n\n  /// Erases the element most recently inserted into the cache.\n  virtual void _erase_lru() {\n    _erase(_map.find(_order.front()));\n  }\n\n  /// Erases the element pointed to by the iterator.\n  ///\n  /// \\param iterator The iterator pointing to the key to erase.\n  virtual void _erase(MapConstIterator iterator) {\n    if (_last_accessed == iterator) {\n      _last_accessed.invalidate();\n    }\n\n    _order.erase(iterator->second.order);\n    _map.erase(iterator);\n  }\n\n  /// Erases the given key.\n  ///\n  /// This method is useful if the key and information are already present, to\n  /// avoid an additional hash lookup to get an iterator to the corresponding\n  /// map entry.\n  ///\n  /// \\param key The key to erase.\n  /// \\param information The information associated with the key to erase.\n  virtual void _erase(const Key& key, const Information& information) {\n    if (key == _last_accessed) {\n      _last_accessed.invalidate();\n    }\n\n    // To be sure, we should do this first, since the order stores a reference\n    // to the key in the map.\n    _order.erase(information.order);\n\n    // Requires an additional hash-lookup, whereas erase(iterator) doesn't\n    _map.erase(key);\n  }\n\n  /// Convenience methhod to get the value for an insertion result into a map.\n  /// \\returns The value for the given result.\n  virtual Value& _value_from_result(MapInsertionResult& result) noexcept {\n    // `result.first` is the map iterator (to a pair), whose `second` member\n    // is\n    // the information object, whose `value` member is the value stored.\n    return result.first->second.value;\n  }\n\n  /// The main use of this method is that it may be override by a base class\n  /// if\n  /// there are any stronger constraints (such as time expiration) as to when\n  /// the last-accessed object may be used to access a key.\n  ///\n  /// \\param key The key to compare the last accessed object against.\n  /// \\returns True if the last-accessed object is valid.\n  virtual bool _last_accessed_is_ok(const Key& key) const noexcept {\n    return true;\n  }\n\n  /// \\copydoc _value_for_last_accessed() const\n  virtual Value& _value_for_last_accessed() {\n    return _last_accessed.value();\n  }\n\n  /// Attempts to access the last accessed key's value.\n  /// \\returns The value of the last accessed object.\n  /// \\details This method exists so that derived classes may perform\n  /// additional\n  /// checks (and possibly throw exceptions) or perform other operations to\n  /// retrieve the value.\n  virtual const Value& _value_for_last_accessed() const {\n    return _last_accessed.value();\n  }\n\n  /// Registers a hit for the key and performs appropriate actions.\n  /// \\param key The key to register a hit for.\n  /// \\param value The value that was found for the key.\n  virtual void _register_hit(const Key& key, const Value& value) const {\n    if (is_monitoring()) {\n      _stats.register_hit(key);\n    }\n\n    _callback_manager.hit(key, value);\n  }\n\n  /// Registers a miss for the key and performs appropriate actions.\n  /// \\param key The key to register a miss for.\n  virtual void _register_miss(const Key& key) const {\n    if (is_monitoring()) {\n      _stats.register_miss(key);\n    }\n\n    _callback_manager.miss(key);\n  }\n\n  /// The common part of both range assignment operators.\n  ///\n  /// \\param range The range to assign to.\n  template <typename Range>\n  void _clear_and_increase_capacity(const Range& range) {\n    using std::begin;\n    using std::end;\n\n    clear();\n\n    auto distance = std::distance(begin(range), end(range));\n    if (distance > _capacity) {\n      _capacity = distance;\n    }\n  }\n\n  /// Looks up each key in the queue and re-assigns it to the proper key in the\n  /// map.\n  ///\n  /// After a copy, the reference (wrappers) in the order queue point\n  /// to the keys of the other cache's map. Thus we need to re-assign them.\n  void _reassign_references() noexcept {\n    for (auto& key_reference : _order) {\n      key_reference = std::ref(_map.find(key_reference)->first);\n    }\n  }\n\n  /// Inserts a new key into the queue.\n  ///\n  /// If the cache is full, the LRU node is re-used.\n  /// Else a node is inserted at the order.\n  ///\n  /// \\returns The resulting iterator.\n  QueueIterator _insert_new_key(const Key& key) {\n    if (_is_too_full()) {\n      _evict_lru_for(key);\n    } else {\n      _order.emplace_back(key);\n    }\n\n    return std::prev(_order.end());\n  }\n\n  /// Evicts the LRU element for the given new key.\n  ///\n  /// \\param key The new key to insert into the queue.\n  void _evict_lru_for(const Key& key) {\n    _map.erase(_order.front());\n    _order.front() = std::ref(key);\n    _move_to_front(_order.begin());\n  }\n\n  /// \\returns True if the cache is too full and an element must be evicted,\n  /// else false.\n  bool _is_too_full() const noexcept {\n    return size() > _capacity;\n  }\n\n  /// The map from keys to information objects.\n  Map _map;\n\n  /// The queue keeping track of the insertion order of elements.\n  mutable Queue _order;\n\n  /// The object to mutate statistics if any are registered.\n  mutable StatisticsMutator<Key> _stats;\n\n  /// The last-accessed cache object.\n  mutable LastAccessed _last_accessed;\n\n  /// The callback manager to store any callbacks.\n  mutable CallbackManagerType _callback_manager;\n\n  /// The current capacity of the cache.\n  size_t _capacity;\n};\n}  // namespace Internal\n}  // namespace LRU\n\n#endif  // LRU_INTERNAL_BASE_CACHE_HPP\n"
  },
  {
    "path": "include/lru/internal/base-iterator.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef LRU_INTERNAL_BASE_ITERATOR_HPP\n#define LRU_INTERNAL_BASE_ITERATOR_HPP\n\n#include <algorithm>\n#include <iterator>\n\n#include <lru/entry.hpp>\n#include <lru/internal/optional.hpp>\n\n#define PUBLIC_BASE_ITERATOR_MEMBERS \\\n  typename super::Entry;             \\\n  using typename super::KeyType;     \\\n  using typename super::ValueType;\n\n#define PRIVATE_BASE_ITERATOR_MEMBERS \\\n  super::_iterator;                   \\\n  using super::_entry;                \\\n  using super::_cache;\n\n\nnamespace LRU {\nnamespace Internal {\n\n/// The base class for all (ordered and unordered) iterators.\n///\n/// All iterators over our LRU caches store a reference to the cache they point\n/// into, an underlying iterator they adapt (e.g. a map iterator or list\n/// iterator) as well as a entry, a reference to which is returned when\n/// dereferencing the iterator.\n///\n/// \\tparam IteratorTag A standard iterator category tag.\n/// \\tparam Key The key type over which instances of the iterator iterate.\n/// \\tparam Value The value type over which instances of the iterator iterate.\n/// \\tparam Cache The type of the cache instances of the iterator point into.\n/// \\tparam UnderlyingIterator The underlying iterator class used to implement\n///                            the iterator.\ntemplate <typename IteratorTag,\n          typename Key,\n          typename Value,\n          typename Cache,\n          typename UnderlyingIterator>\nclass BaseIterator : public std::iterator<IteratorTag, LRU::Entry<Key, Value>> {\n public:\n  using KeyType = Key;\n  using ValueType =\n      std::conditional_t<std::is_const<Cache>::value, const Value, Value>;\n  using Entry = LRU::Entry<KeyType, ValueType>;\n\n  /// Default constructor.\n  BaseIterator() noexcept : _cache(nullptr) {\n  }\n\n  /// Constructor.\n  ///\n  /// \\param cache The cache this iterator points into.\n  /// \\param iterator The underlying iterator to adapt.\n  BaseIterator(Cache& cache, const UnderlyingIterator& iterator) noexcept\n  : _iterator(iterator), _cache(&cache) {\n  }\n\n  /// Copy constructor.\n  ///\n  /// Differs from the default copy constructor in that it does not copy the\n  /// entry.\n  ///\n  /// \\param other The base iterator to copy.\n  BaseIterator(const BaseIterator& other) noexcept\n  : _iterator(other._iterator), _cache(other._cache) {\n    // Note: we do not copy the entry, as it would require a new allocation.\n    // Since iterators are often taken by value, this may incur a high cost.\n    // As such we delay the retrieval of the entry to the first call to entry().\n  }\n\n  /// Copy assignment operator.\n  ///\n  /// Differs from the default copy assignment\n  /// operator in that it does not copy the entry.\n  ///\n  /// \\param other The base iterator to copy.\n  /// \\return The base iterator instance.\n  BaseIterator& operator=(const BaseIterator& other) noexcept {\n    if (this != &other) {\n      _iterator = other._iterator;\n      _cache = other._cache;\n      _entry.reset();\n    }\n    return *this;\n  }\n\n  /// Move constructor.\n  BaseIterator(BaseIterator&& other) noexcept = default;\n\n  /// Move assignment operator.\n  BaseIterator& operator=(BaseIterator&& other) noexcept = default;\n\n  /// Generalized copy constructor.\n  ///\n  /// Mainly necessary for non-const to const conversion.\n  ///\n  /// \\param other The base iterator to copy from.\n  template <typename AnyIteratorTag,\n            typename AnyKeyType,\n            typename AnyValueType,\n            typename AnyCacheType,\n            typename AnyUnderlyingIteratorType>\n  BaseIterator(const BaseIterator<AnyIteratorTag,\n                                  AnyKeyType,\n                                  AnyValueType,\n                                  AnyCacheType,\n                                  AnyUnderlyingIteratorType>& other)\n  : _iterator(other._iterator), _entry(other._entry), _cache(other._cache) {\n  }\n\n  /// Generalized move constructor.\n  ///\n  /// Mainly necessary for non-const to const conversion.\n  ///\n  /// \\param other The base iterator to move into this one.\n  template <typename AnyIteratorTag,\n            typename AnyKeyType,\n            typename AnyValueType,\n            typename AnyCacheType,\n            typename AnyUnderlyingIteratorType>\n  BaseIterator(BaseIterator<AnyIteratorTag,\n                            AnyKeyType,\n                            AnyValueType,\n                            AnyCacheType,\n                            AnyUnderlyingIteratorType>&& other) noexcept\n  : _iterator(std::move(other._iterator))\n  , _entry(std::move(other._entry))\n  , _cache(std::move(other._cache)) {\n  }\n\n  /// Destructor.\n  virtual ~BaseIterator() = default;\n\n  /// Swaps this base iterator with another one.\n  ///\n  /// \\param other The other iterator to swap with.\n  void swap(BaseIterator& other) noexcept {\n    // Enable ADL\n    using std::swap;\n\n    swap(_iterator, other._iterator);\n    swap(_entry, other._entry);\n    swap(_cache, other._cache);\n  }\n\n  /// Swaps two base iterator.\n  ///\n  /// \\param first The first iterator to swap.\n  /// \\param second The second iterator to swap.\n  friend void swap(BaseIterator& first, BaseIterator& second) noexcept {\n    first.swap(second);\n  }\n\n  /// \\returns A reference to the current entry pointed to by the iterator.\n  virtual Entry& operator*() noexcept = 0;\n\n  /// \\returns A pointer to the current entry pointed to by the iterator.\n  Entry* operator->() noexcept {\n    return &(**this);\n  }\n\n  /// \\copydoc operator*()\n  virtual Entry& entry() = 0;\n\n  /// \\returns A reference to the value of the entry currently pointed to by the\n  /// iterator.\n  virtual ValueType& value() = 0;\n\n  /// \\returns A reference to the key of the entry currently pointed to by the\n  /// iterator.\n  virtual const Key& key() = 0;\n\n protected:\n  template <typename, typename, typename, typename, typename>\n  friend class BaseIterator;\n\n  /// The underlying iterator this iterator class adapts.\n  UnderlyingIterator _iterator;\n\n  /// The entry optionally being stored.\n  Optional<Entry> _entry;\n\n  /// A pointer to the cache this iterator points into.\n  /// Pointer and not reference because it's cheap to copy.\n  /// Pointer and not `std::reference_wrapper` because the class needs to be\n  /// default-constructible.\n  Cache* _cache;\n};\n}  // namespace Internal\n}  // namespace LRU\n\n#endif  // LRU_INTERNAL_BASE_ITERATOR_HPP\n"
  },
  {
    "path": "include/lru/internal/base-ordered-iterator.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef BASE_ORDERED_ITERATOR_HPP\n#define BASE_ORDERED_ITERATOR_HPP\n\n#include <algorithm>\n#include <functional>\n#include <iterator>\n#include <type_traits>\n\n#include <lru/entry.hpp>\n#include <lru/error.hpp>\n#include <lru/internal/base-iterator.hpp>\n#include <lru/internal/base-unordered-iterator.hpp>\n#include <lru/internal/definitions.hpp>\n#include <lru/internal/optional.hpp>\n#include <lru/iterator-tags.hpp>\n\nnamespace LRU {\nnamespace Internal {\n\ntemplate <typename Key, typename Value, typename Cache>\nusing BaseForBaseOrderedIterator =\n    BaseIterator<std::bidirectional_iterator_tag,\n                 Key,\n                 Value,\n                 Cache,\n                 typename Queue<Key>::const_iterator>;\n\n/// The base class for all const and non-const ordered iterators.\n///\n/// Ordered iterators are bidirectional iterators that iterate over the keys of\n/// a cache in the order in which they were inserted into the cache. As they\n/// only iterate over the keys, they must perform hash lookups to retrieve the\n/// value the first time they are dereferenced. This makes them slightly less\n/// efficient than unordered iterators. However, they also have the additional\n/// property that they may be constructed from unordered iterators, and that\n/// they can be decremented.\n///\n/// \\tparam Key The key type over which instances of the iterator iterate.\n/// \\tparam Value The value type over which instances of the iterator iterate.\n/// \\tparam Cache The type of the cache instances of the iterator point into.\ntemplate <typename Key, typename Value, typename Cache>\nclass BaseOrderedIterator\n    : public BaseForBaseOrderedIterator<Key, Value, Cache> {\n protected:\n  using super = BaseForBaseOrderedIterator<Key, Value, Cache>;\n  using PRIVATE_BASE_ITERATOR_MEMBERS;\n  using UnderlyingIterator = typename Queue<Key>::const_iterator;\n\n public:\n  using Tag = LRU::Tag::OrderedIterator;\n  using PUBLIC_BASE_ITERATOR_MEMBERS;\n\n  /// Constructor.\n  BaseOrderedIterator() noexcept = default;\n\n  /// \\copydoc BaseIterator::BaseIterator(Cache,UnderlyingIterator)\n  BaseOrderedIterator(Cache& cache, UnderlyingIterator iterator)\n  : super(cache, iterator) {\n  }\n\n  /// Generalized copy constructor.\n  ///\n  /// \\param other The ordered iterator to contruct from.\n  template <typename AnyKey, typename AnyValue, typename AnyCache>\n  BaseOrderedIterator(\n      const BaseOrderedIterator<AnyKey, AnyValue, AnyCache>& other)\n  : super(other) {\n  }\n\n  /// Generalized move constructor.\n  ///\n  /// \\param other The ordered iterator to move into this one.\n  template <typename AnyKey, typename AnyValue, typename AnyCache>\n  BaseOrderedIterator(BaseOrderedIterator<AnyKey, AnyValue, AnyCache>&& other)\n  : super(std::move(other)) {\n  }\n\n  /// Generalized conversion copy constructor.\n  ///\n  /// \\param unordered_iterator The unordered iterator to construct from.\n  template <\n      typename AnyCache,\n      typename UnderlyingIterator,\n      typename = std::enable_if_t<\n          std::is_same<std::decay_t<AnyCache>, std::decay_t<Cache>>::value>>\n  BaseOrderedIterator(const BaseUnorderedIterator<AnyCache, UnderlyingIterator>&\n                          unordered_iterator) {\n    // Atomicity\n    _throw_if_at_invalid(unordered_iterator);\n    _cache = unordered_iterator._cache;\n    _iterator = unordered_iterator._iterator->second.order;\n  }\n\n  /// Generalized conversion move constructor.\n  ///\n  /// \\param unordered_iterator The unordered iterator to move-construct from.\n  template <\n      typename AnyCache,\n      typename UnderlyingIterator,\n      typename = std::enable_if_t<\n          std::is_same<std::decay_t<AnyCache>, std::decay_t<Cache>>::value>>\n  BaseOrderedIterator(BaseUnorderedIterator<AnyCache, UnderlyingIterator>&&\n                          unordered_iterator) {\n    // Atomicity\n    _throw_if_at_invalid(unordered_iterator);\n    _cache = std::move(unordered_iterator._cache);\n    _entry = std::move(unordered_iterator._entry);\n    _iterator = std::move(unordered_iterator._iterator->second.order);\n  }\n\n  /// Copy constructor.\n  BaseOrderedIterator(const BaseOrderedIterator& other) = default;\n\n  /// Move constructor.\n  BaseOrderedIterator(BaseOrderedIterator&& other) = default;\n\n  /// Copy assignment operator.\n  BaseOrderedIterator& operator=(const BaseOrderedIterator& other) = default;\n\n  /// Move assignment operator.\n  BaseOrderedIterator& operator=(BaseOrderedIterator&& other) = default;\n\n  /// Destructor.\n  virtual ~BaseOrderedIterator() = default;\n\n  /// Checks for equality between this iterator and another ordered iterator.\n  ///\n  /// \\param other The other ordered iterator.\n  /// \\returns True if both iterators point to the same entry, else false.\n  bool operator==(const BaseOrderedIterator& other) const noexcept {\n    return this->_iterator == other._iterator;\n  }\n\n  /// Checks for inequality between this iterator another ordered iterator.\n  ///\n  /// \\param other The other ordered iterator.\n  /// \\returns True if the iterators point to different entries, else false.\n  bool operator!=(const BaseOrderedIterator& other) const noexcept {\n    return !(*this == other);\n  }\n\n  /// Checks for inequality between this iterator and another unordered\n  /// iterator.\n  ///\n  /// \\param other The other unordered iterator.\n  /// \\returns True if both iterators point to the end of the same cache, else\n  /// the result of comparing with the unordered iterator, converted to an\n  /// ordered iterator.\n  template <typename AnyCache, typename AnyUnderlyingIterator>\n  bool operator==(\n      const BaseUnorderedIterator<AnyCache, AnyUnderlyingIterator>& other) const\n      noexcept {\n    if (this->_cache != other._cache) return false;\n\n    // The past-the-end iterators of the same cache should compare equal.\n    // This is an exceptional guarantee we make. This is also the reason\n    // why we can't rely on the conversion from unordered to ordered iterators\n    // because construction of an ordered iterator from the past-the-end\n    // unordered iterator will fail (with an InvalidIteratorConversion error)\n    if (other == other._cache->unordered_end()) {\n      return *this == this->_cache->ordered_end();\n    }\n\n    // Will call the other overload\n    return *this == static_cast<BaseOrderedIterator>(other);\n  }\n\n  /// Checks for equality between an unordered iterator and an ordered iterator.\n  ///\n  /// \\param first The unordered iterator.\n  /// \\param second The ordered iterator.\n  /// \\returns True if both iterators point to the end of the same cache, else\n  /// the result of comparing with the unordered iterator, converted to an\n  /// ordered iterator.\n  template <typename AnyCache, typename AnyUnderlyingIterator>\n  friend bool operator==(\n      const BaseUnorderedIterator<AnyCache, AnyUnderlyingIterator>& first,\n      const BaseOrderedIterator& second) noexcept {\n    return second == first;\n  }\n\n  /// Checks for inequality between an unordered\n  /// iterator and an ordered iterator.\n  ///\n  /// \\param first The ordered iterator.\n  /// \\param second The unordered iterator.\n  /// \\returns True if the iterators point to different entries, else false.\n  template <typename AnyCache, typename AnyUnderlyingIterator>\n  friend bool\n  operator!=(const BaseOrderedIterator& first,\n             const BaseUnorderedIterator<AnyCache, AnyUnderlyingIterator>&\n                 second) noexcept {\n    return !(first == second);\n  }\n\n  /// Checks for inequality between an unordered\n  /// iterator and an ordered iterator.\n  ///\n  /// \\param first The unordered iterator.\n  /// \\param second The ordered iterator.\n  /// \\returns True if the iterators point to different entries, else false.\n  template <typename AnyCache, typename AnyUnderlyingIterator>\n  friend bool operator!=(\n      const BaseUnorderedIterator<AnyCache, AnyUnderlyingIterator>& first,\n      const BaseOrderedIterator& second) noexcept {\n    return second != first;\n  }\n\n  /// Increments the iterator to the next entry.\n  ///\n  /// If the iterator already pointed to the end any number of increments\n  /// before, behavior is undefined.\n  ///\n  /// \\returns The resulting iterator.\n  BaseOrderedIterator& operator++() {\n    ++_iterator;\n    _entry.reset();\n    return *this;\n  }\n\n  /// Increments the iterator and returns a copy of the previous one.\n  ///\n  /// If the iterator already pointed to the end any number of increments\n  /// before, behavior is undefined.\n  ///\n  /// \\returns A copy of the previous iterator.\n  BaseOrderedIterator operator++(int) {\n    auto previous = *this;\n    ++*this;\n    return previous;\n  }\n\n  /// Decrements the iterator to the previous entry.\n  ///\n  /// \\returns The resulting iterator.\n  BaseOrderedIterator& operator--() {\n    --_iterator;\n    _entry.reset();\n    return *this;\n  }\n\n  /// Decrements the iterator and returns a copy of the  previous entry.\n  ///\n  /// \\returns The previous iterator.\n  BaseOrderedIterator operator--(int) {\n    auto previous = *this;\n    --*this;\n    return previous;\n  }\n\n  Entry& operator*() noexcept override {\n    return _maybe_lookup();\n  }\n\n  /// \\returns A reference to the entry the iterator points to.\n  /// \\details If the iterator is invalid, behavior is undefined.\n  Entry& entry() override {\n    _cache->throw_if_invalid(*this);\n    return _maybe_lookup();\n  }\n\n  /// \\returns A reference to the value the iterator points to.\n  /// \\details If the iterator is invalid, behavior is undefined.\n  Value& value() override {\n    return entry().value();\n  }\n\n  /// \\returns A reference to the key the iterator points to.\n  /// \\details If the iterator is invalid, behavior is undefined.\n  const Key& key() override {\n    // No lookup required\n    _cache->throw_if_invalid(*this);\n    return *_iterator;\n  }\n\n protected:\n  template <typename, typename, typename>\n  friend class BaseOrderedIterator;\n\n  /// Looks up the entry for a key if this was not done already.\n  ///\n  /// \\returns The entry, which was possibly newly looked up.\n  Entry& _maybe_lookup() {\n    if (!_entry.has_value()) {\n      _lookup();\n    }\n\n    return *_entry;\n  }\n\n  /// Looks up the entry for a key and sets the internal entry member.\n  void _lookup() {\n    auto iterator = _cache->_map.find(*_iterator);\n    _entry.emplace(iterator->first, iterator->second.value);\n  }\n\n private:\n  /// Throws an exception if the given unordered iterator is invalid.\n  ///\n  /// \\param unordered_iterator The iterator to check.\n  /// \\throws LRU::Error::InvalidIteratorConversion if the iterator is invalid.\n  template <typename UnorderedIterator>\n  void _throw_if_at_invalid(const UnorderedIterator& unordered_iterator) {\n    // For atomicity of the copy assignment, we assign the cache pointer only\n    // after this check in the copy/move constructor and use the iterator's\n    // cache. If an exception is thrown, the state of the ordered iterator is\n    // unchanged compared to before the assignment.\n    if (unordered_iterator == unordered_iterator._cache->unordered_end()) {\n      throw LRU::Error::InvalidIteratorConversion();\n    }\n  }\n};\n\n}  // namespace Internal\n}  // namespace LRU\n\n#endif  // BASE_ORDERED_ITERATOR_HPP\n"
  },
  {
    "path": "include/lru/internal/base-unordered-iterator.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef BASE_UNORDERED_ITERATOR_HPP\n#define BASE_UNORDERED_ITERATOR_HPP\n\n#include <algorithm>\n#include <iterator>\n#include <type_traits>\n\n#include <lru/entry.hpp>\n#include <lru/internal/base-iterator.hpp>\n#include <lru/internal/definitions.hpp>\n#include <lru/internal/optional.hpp>\n#include <lru/iterator-tags.hpp>\n\n\nnamespace LRU {\n\n// Forward declaration.\ntemplate <typename, typename, typename, typename, typename>\nclass TimedCache;\n\nnamespace Internal {\ntemplate <typename Cache, typename UnderlyingIterator>\nusing BaseForBaseUnorderedIterator =\n    BaseIterator<std::forward_iterator_tag,\n                 decltype(UnderlyingIterator()->first),\n                 decltype(UnderlyingIterator()->second.value),\n                 Cache,\n                 UnderlyingIterator>;\n\n/// The base class for all const and non-const unordered iterators.\n///\n/// An unordered iterator is a wrapper around an `unordered_map` iterator with\n/// ForwardIterator category. As such, it is (nearly) as fast to access the pair\n/// as through the unordered iterator as through the map iterator directly.\n/// However, the order of keys is unspecified. For this reason, unordered\n/// iterators have the special property that they may be used to construct\n/// ordered iterators, after which the order of insertion is respected.\n///\n/// \\tparam Cache The type of the cache instances of the iterator point into.\n/// \\tparam UnderlyingIterator The underlying iterator class used to implement\n///                            the iterator.\ntemplate <typename Cache, typename UnderlyingIterator>\nclass BaseUnorderedIterator\n    : public BaseForBaseUnorderedIterator<Cache, UnderlyingIterator> {\n protected:\n  using super = BaseForBaseUnorderedIterator<Cache, UnderlyingIterator>;\n  using PRIVATE_BASE_ITERATOR_MEMBERS;\n  // These are the key and value types the BaseIterator extracts\n  using Key = typename super::KeyType;\n  using Value = typename super::ValueType;\n\n public:\n  using Tag = LRU::Tag::UnorderedIterator;\n  using PUBLIC_BASE_ITERATOR_MEMBERS;\n\n  /// Constructor.\n  BaseUnorderedIterator() noexcept = default;\n\n  /// \\copydoc BaseIterator::BaseIterator(Cache,UnderlyingIterator)\n  explicit BaseUnorderedIterator(Cache& cache,\n                                 const UnderlyingIterator& iterator) noexcept\n  : super(cache, iterator) {\n  }\n\n  /// Generalized copy constructor.\n  ///\n  /// Useful mainly for non-const to const conversion.\n  ///\n  /// \\param other The iterator to copy from.\n  template <typename AnyCache, typename AnyUnderlyingIterator>\n  BaseUnorderedIterator(\n      const BaseUnorderedIterator<AnyCache, AnyUnderlyingIterator>&\n          other) noexcept\n  : super(other) {\n  }\n\n  /// Copy constructor.\n  BaseUnorderedIterator(const BaseUnorderedIterator& other) noexcept = default;\n\n  /// Move constructor.\n  BaseUnorderedIterator(BaseUnorderedIterator&& other) noexcept = default;\n\n  /// Copy assignment operator.\n  BaseUnorderedIterator&\n  operator=(const BaseUnorderedIterator& other) noexcept = default;\n\n  /// Move assignment operator.\n  template <typename AnyCache, typename AnyUnderlyingIterator>\n  BaseUnorderedIterator&\n  operator=(BaseUnorderedIterator<AnyCache, AnyUnderlyingIterator>\n                unordered_iterator) noexcept {\n    swap(unordered_iterator);\n    return *this;\n  }\n\n  /// Destructor.\n  virtual ~BaseUnorderedIterator() = default;\n\n  /// Compares this iterator for equality with another unordered iterator.\n  ///\n  /// \\param other Another unordered iterator.\n  /// \\returns True if both iterators point to the same entry, else false.\n  template <typename AnyCache, typename AnyIterator>\n  bool\n  operator==(const BaseUnorderedIterator<AnyCache, AnyIterator>& other) const\n      noexcept {\n    return this->_iterator == other._iterator;\n  }\n\n  /// Compares this iterator for inequality with another unordered iterator.\n  ///\n  /// \\param other Another unordered iterator.\n  /// \\returns True if the iterators point to different entries, else false.\n  template <typename AnyCache, typename AnyIterator>\n  bool\n  operator!=(const BaseUnorderedIterator<AnyCache, AnyIterator>& other) const\n      noexcept {\n    return !(*this == other);\n  }\n\n  /// Increments the iterator to the next entry.\n  ///\n  /// If the iterator already pointed to the end any number of increments\n  /// before, behavior is undefined.\n  ///\n  /// \\returns The resulting iterator.\n  BaseUnorderedIterator& operator++() {\n    ++_iterator;\n    _entry.reset();\n    return *this;\n  }\n\n  /// Increments the iterator and returns a copy of the previous one.\n  ///\n  /// If the iterator already pointed to the end any number of increments\n  /// before, behavior is undefined.\n  ///\n  /// \\returns A copy of the previous iterator.\n  BaseUnorderedIterator operator++(int) {\n    auto previous = *this;\n    ++*this;\n    return previous;\n  }\n\n  /// \\copydoc BaseIterator::operator*\n  /// \\details If the iterator is invalid, behavior is undefined. No exception\n  /// handling is performed.\n  Entry& operator*() noexcept override {\n    if (!_entry.has_value()) {\n      _entry.emplace(_iterator->first, _iterator->second.value);\n    }\n\n    return *_entry;\n  }\n\n  /// \\returns A reference to the entry the iterator points to.\n  /// \\throws LRU::Error::InvalidIterator if the iterator is the end iterator.\n  /// \\throws LRU::Error::KeyExpired if the key pointed to by the iterator has\n  /// expired.\n  Entry& entry() override {\n    if (!_entry.has_value()) {\n      _entry.emplace(_iterator->first, _iterator->second.value);\n    }\n\n    _cache->throw_if_invalid(*this);\n    return *_entry;\n  }\n\n  /// \\returns A reference to the key the iterator points to.\n  /// \\throws LRU::Error::InvalidIterator if the iterator is the end iterator.\n  /// \\throws LRU::Error::KeyExpired if the key pointed to by the iterator has\n  /// expired.\n  const Key& key() override {\n    return entry().key();\n  }\n\n  /// \\returns A reference to the value the iterator points to.\n  /// \\throws LRU::Error::InvalidIterator if the iterator is the end iterator.\n  /// \\throws LRU::Error::KeyExpired if the key pointed to by the iterator has\n  /// expired.\n  Value& value() override {\n    return entry().value();\n  }\n\n protected:\n  template <typename, typename, typename>\n  friend class BaseOrderedIterator;\n\n  template <typename, typename, typename, typename, typename>\n  friend class LRU::TimedCache;\n};\n}  // namespace Internal\n}  // namespace LRU\n\n#endif  // BASE_UNORDERED_ITERATOR_HPP\n"
  },
  {
    "path": "include/lru/internal/callback-manager.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef LRU_INTERNAL_CALLBACK_MANAGER_HPP\n#define LRU_INTERNAL_CALLBACK_MANAGER_HPP\n\n#include <functional>\n#include <vector>\n\n#include <lru/entry.hpp>\n#include <lru/internal/optional.hpp>\n\nnamespace LRU {\nnamespace Internal {\n\n/// Manages hit, miss and access callbacks for a cache.\n///\n/// The callback manager implements the \"publisher\" of the observer pattern we\n/// implement. It stores and calls three kinds of callbacks:\n/// 1. Hit callbacks, taking a key and value after a cache hit.\n/// 2. Miss callbacks, taking only a key, that was not found in a cache.\n/// 3. Access callbacks, taking a key and a boolean indicating a hit or a miss.\n///\n/// Callbacks can be added, accessed and cleared.\ntemplate <typename Key, typename Value>\nclass CallbackManager {\n public:\n  using HitCallback = std::function<void(const Key&, const Value&)>;\n  using MissCallback = std::function<void(const Key&)>;\n  using AccessCallback = std::function<void(const Key&, bool)>;\n\n  using HitCallbackContainer = std::vector<HitCallback>;\n  using MissCallbackContainer = std::vector<MissCallback>;\n  using AccessCallbackContainer = std::vector<AccessCallback>;\n\n  /// Calls all callbacks registered for a hit, with the given key and value.\n  ///\n  /// \\param key The key for which a cache hit ocurred.\n  /// \\param value The value that was found for the key.\n  void hit(const Key& key, const Value& value) {\n    _call_each(_hit_callbacks, key, value);\n    _call_each(_access_callbacks, key, true);\n  }\n\n  /// Calls all callbacks registered for a miss, with the given key.\n  ///\n  /// \\param key The key for which a cache miss ocurred.\n  void miss(const Key& key) {\n    _call_each(_miss_callbacks, key);\n    _call_each(_access_callbacks, key, false);\n  }\n\n  /// Registers a new hit callback.\n  ///\n  /// \\param hit_callback The hit callback function to register with the\n  ///                     manager.\n  template <typename Callback>\n  void hit_callback(Callback&& hit_callback) {\n    _hit_callbacks.emplace_back(std::forward<Callback>(hit_callback));\n  }\n\n  /// Registers a new miss callback.\n  ///\n  /// \\param miss_callback The miss callback function to register with the\n  ///                      manager.\n  template <typename Callback>\n  void miss_callback(Callback&& miss_callback) {\n    _miss_callbacks.emplace_back(std::forward<Callback>(miss_callback));\n  }\n\n  /// Registers a new access callback.\n  ///\n  /// \\param access_callback The access callback function to register with the\n  ///                        manager.\n  template <typename Callback>\n  void access_callback(Callback&& access_callback) {\n    _access_callbacks.emplace_back(std::forward<Callback>(access_callback));\n  }\n\n  /// Clears all hit callbacks.\n  void clear_hit_callbacks() {\n    _hit_callbacks.clear();\n  }\n\n  /// Clears all miss callbacks.\n  void clear_miss_callbacks() {\n    _miss_callbacks.clear();\n  }\n\n  /// Clears all access callbacks.\n  void clear_access_callbacks() {\n    _access_callbacks.clear();\n  }\n\n  /// Clears all callbacks.\n  void clear() {\n    clear_hit_callbacks();\n    clear_miss_callbacks();\n    clear_access_callbacks();\n  }\n\n  /// \\returns All hit callbacks.\n  const HitCallbackContainer& hit_callbacks() const noexcept {\n    return _hit_callbacks;\n  }\n\n  /// \\returns All miss callbacks.\n  const MissCallbackContainer& miss_callbacks() const noexcept {\n    return _miss_callbacks;\n  }\n\n  /// \\returns All access callbacks.\n  const AccessCallbackContainer& access_callbacks() const noexcept {\n    return _access_callbacks;\n  }\n\n private:\n  /// Calls each function in the given container with the given arguments.\n  ///\n  /// \\param callbacks The container of callbacks to call.\n  /// \\param args The arguments to call the callbacks with.\n  template <typename CallbackContainer, typename... Args>\n  void _call_each(const CallbackContainer& callbacks, Args&&... args) {\n    for (const auto& callback : callbacks) {\n      callback(std::forward<Args>(args)...);\n    }\n  }\n\n  /// The container of hit callbacks registered.\n  HitCallbackContainer _hit_callbacks;\n\n  /// The container of miss callbacks registered.\n  MissCallbackContainer _miss_callbacks;\n\n  /// The container of access callbacks registered.\n  AccessCallbackContainer _access_callbacks;\n};\n}  // namespace Internal\n}  // namespace LRU\n\n#endif  // LRU_INTERNAL_CALLBACK_MANAGER_HPP\n"
  },
  {
    "path": "include/lru/internal/definitions.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef LRU_INTERNAL_DEFINITIONS_HPP\n#define LRU_INTERNAL_DEFINITIONS_HPP\n\n#include <chrono>\n#include <cstddef>\n#include <functional>\n#include <list>\n#include <tuple>\n#include <unordered_map>\n\nnamespace LRU {\nnamespace Internal {\n\n/// The default capacity for all caches.\nconst std::size_t DEFAULT_CAPACITY = 128;\n\n/// The reference type use to store keys in the order queue.\ntemplate <typename T>\nusing Reference = std::reference_wrapper<T>;\n\n/// Compares two References for equality.\n///\n/// This is necessary because `std::reference_wrapper` does not define any\n/// operator overloads. We do need them, however (e.g. for container\n/// comparison).\n///\n/// \\param first The first reference to compare.\n/// \\param second The second reference to compare.\ntemplate <typename T, typename U>\nbool operator==(const Reference<T>& first, const Reference<U>& second) {\n  return first.get() == second.get();\n}\n\n/// Compares two References for inequality.\n///\n/// This is necessary because `std::reference_wrapper` does not define any\n/// operator overloads. We do need them, however (e.g. for container\n/// comparison).\n///\n/// \\param first The first reference to compare.\n/// \\param second The second reference to compare.\ntemplate <typename T, typename U>\nbool operator!=(const Reference<T>& first, const Reference<U>& second) {\n  return !(first == second);\n}\n\n/// The default queue type used internally.\ntemplate <typename T>\nusing Queue = std::list<Reference<T>>;\n\n/// The default map type used internally.\ntemplate <typename Key,\n          typename Information,\n          typename HashFunction,\n          typename KeyEqual>\nusing Map = std::unordered_map<Key, Information, HashFunction, KeyEqual>;\n\n/// The default clock used internally.\nusing Clock = std::chrono::steady_clock;\n\n/// The default timestamp (time point) used internally.\nusing Timestamp = Clock::time_point;\n}  // namespace Internal\n}  // namespace LRU\n\n\n#endif  // LRU_INTERNAL_DEFINITIONS_HPP\n"
  },
  {
    "path": "include/lru/internal/hash.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef LRU_INTERNAL_HASH_HPP\n#define LRU_INTERNAL_HASH_HPP\n\n#include <cstddef>\n#include <functional>\n#include <tuple>\n\n/// `std::hash` specialization to allow storing tuples as keys\n/// in `std::unordered_map`.\n///\n/// Essentially hashes all tuple elements and jumbles the\n/// individual hashes together.\nnamespace std {\ntemplate <typename... Ts>\nstruct hash<std::tuple<Ts...>> {\n  using argument_type = std::tuple<Ts...>;\n  using result_type = std::size_t;\n\n  result_type operator()(const argument_type& argument) const {\n    return hash_tuple(argument, std::make_index_sequence<sizeof...(Ts)>());\n  }\n\n private:\n  template <std::size_t I, std::size_t... Is>\n  result_type\n  hash_tuple(const argument_type& tuple, std::index_sequence<I, Is...>) const {\n    auto value = std::get<I>(tuple);\n    auto current = std::hash<decltype(value)>{}(value);\n    auto seed = hash_tuple(tuple, std::index_sequence<Is...>());\n\n    // http://www.boost.org/doc/libs/1_35_0/doc/html/boost/hash_combine_id241013.html\n    return current + 0x9e3779b9 + (seed << 6) + (seed >> 2);\n  }\n\n  result_type hash_tuple(const argument_type&, std::index_sequence<>) const {\n    return 0;\n  }\n};\n}  // namespace std\n\n#endif  // LRU_INTERNAL_HASH_HPP\n"
  },
  {
    "path": "include/lru/internal/information.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef LRU_INTERNAL_INFORMATION_HPP\n#define LRU_INTERNAL_INFORMATION_HPP\n\n#include <cstddef>\n#include <tuple>\n#include <utility>\n\n#include <lru/internal/definitions.hpp>\n#include <lru/internal/utility.hpp>\n\nnamespace LRU {\nnamespace Internal {\n\n/// The value type of internal maps, used to store a value and iterator.\n///\n/// This information object is the basis of an LRU cache, which must associated\n/// a value and such an order iterator with a key, such that the iterator may be\n/// moved to the front of the order when the key is updated with a new value.\n///\n/// \\tparam Key The key type of the information.\n/// \\tparam Value The value type of the information.\ntemplate <typename Key, typename Value>\nstruct Information {\n  using KeyType = Key;\n  using ValueType = Value;\n  using QueueIterator = typename Internal::Queue<const Key>::const_iterator;\n\n  /// Constructor.\n  ///\n  /// \\param value_ The value for the information.\n  /// \\param order_ The order iterator for the information.\n  explicit Information(const Value& value_,\n                       QueueIterator order_ = QueueIterator())\n  : value(value_), order(order_) {\n  }\n\n  /// Constructor.\n  ///\n  /// \\param order_ The order iterator for the information.\n  /// \\param value_arguments Any number of arguments to perfectly forward to the\n  ///                        value type's constructor.\n  // template <typename... ValueArguments>\n  // Information(QueueIterator order_, ValueArguments&&... value_arguments)\n  // : value(std::forward<ValueArguments>(value_arguments)...), order(order_) {\n  // }\n\n  /// Constructor.\n  ///\n  /// \\param order_ The order iterator for the information.\n  /// \\param value_arguments A tuple of arguments to perfectly forward to the\n  ///                        value type's constructor.\n  ///\n  template <typename... ValueArguments>\n  explicit Information(const std::tuple<ValueArguments...>& value_arguments,\n                       QueueIterator order_ = QueueIterator())\n  : Information(\n        order_, value_arguments, Internal::tuple_indices(value_arguments)) {\n  }\n\n  /// Copy constructor.\n  Information(const Information& other) = default;\n\n  /// Move constructor.\n  Information(Information&& other) = default;\n\n  /// Copy assignment operator.\n  Information& operator=(const Information& other) = default;\n\n  /// Move assignment operator.\n  Information& operator=(Information&& other) = default;\n\n  /// Destructor.\n  virtual ~Information() = default;\n\n  /// Compares the information for equality with another information object.\n  ///\n  /// \\param other The other information object to compare to.\n  /// \\returns True if key and value (not the iterator itself) of the two\n  /// information objects are equal, else false.\n  virtual bool operator==(const Information& other) const noexcept {\n    if (this == &other) return true;\n    if (this->value != other.value) return false;\n    // We do not compare the iterator (because otherwise two containers\n    // holding information would never be equal). We also do not compare\n    // the key stored in the iterator, because keys will always have been\n    // compared before this operator is called.\n    return true;\n  }\n\n  /// Compares the information for inequality with another information object.\n  ///\n  /// \\param other The other information object to compare for.\n  /// \\returns True if key and value (not the iterator itself) of the two\n  /// information objects are unequal, else false.\n  virtual bool operator!=(const Information& other) const noexcept {\n    return !(*this == other);\n  }\n\n  /// The value of the information.\n  Value value;\n\n  /// The order iterator of the information.\n  QueueIterator order;\n\n private:\n  /// Implementation for the constructor taking a tuple of arguments for the\n  /// value.\n  ///\n  /// \\param order_ The order iterator for the information.\n  /// \\param value_argument The tuple of arguments to perfectly forward to the\n  ///                       value type's constructor.\n  /// \\param _ An index sequence to access the elements of the tuple\n  template <typename... ValueArguments, std::size_t... Indices>\n  Information(const QueueIterator& order_,\n              const std::tuple<ValueArguments...>& value_argument,\n              std::index_sequence<Indices...> _)\n  : value(std::forward<ValueArguments>(std::get<Indices>(value_argument))...)\n  , order(order_) {\n  }\n};\n}  // namespace Internal\n}  // namespace LRU\n\n#endif  // LRU_INTERNAL_INFORMATION_HPP\n"
  },
  {
    "path": "include/lru/internal/last-accessed.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef LRU_INTERNAL_LAST_ACCESSED_HPP\n#define LRU_INTERNAL_LAST_ACCESSED_HPP\n\n#include <algorithm>\n#include <functional>\n#include <iterator>\n\n#include <lru/internal/utility.hpp>\n\nnamespace LRU {\nnamespace Internal {\n\n/// Provides a simple iterator-compatible pointer object for a key and\n/// information.\n///\n/// The easisest idea for this class, theoretically, would be to just store an s\n/// iterator to the internal cache map (i.e. template the class on the iterator\n/// type). However, the major trouble with that approach is that this class\n/// should be 100% *mutable*, as in \"always non-const\", so that  keys and\n/// informations\n/// we store for fast access can be (quickly) retrieved as either const or\n/// non-const (iterators for example). This is not possible, since the\n/// const-ness of `const_iterators` are not the usual idea of const in C++,\n/// meaning especially it cannot be cast away with a `const_cast` as is required\n/// for the mutability. As such, we *must* store the plain keys and\n/// informations.\n/// This, however, means that iterators cannot be stored efficiently, since a\n/// new hash table lookup would be required to go from a key to its iterator.\n/// However, since the main use case of this class is to avoid a second lookup\n/// in the usual `if (cache.contains(key)) return cache.lookup(key)`, which is\n/// not an issue for iterators since they can be compared to the `end` iterator\n/// in constant time (equivalent to the call to `contains()`).\n///\n/// WARNING: This class stores *pointers* to keys and informations. As such\n/// lifetime\n/// of the pointed-to objects must be cared for by the user of this class.\n///\n/// \\tparam Key The type of key being accessed.\n/// \\tparam InformationType The type of information being accessed.\n/// \\tparam KeyEqual The type of the key comparison function.\ntemplate <typename Key,\n          typename InformationType,\n          typename KeyEqual = std::equal_to<Key>>\nclass LastAccessed {\n public:\n  /// Constructor.\n  ///\n  /// \\param key_equal The function to compare keys with.\n  explicit LastAccessed(const KeyEqual& key_equal = KeyEqual())\n  : _key(nullptr)\n  , _information(nullptr)\n  , _is_valid(false)\n  , _key_equal(key_equal) {\n  }\n\n  /// Constructor.\n  ///\n  /// \\param key The key to store a reference to.\n  /// \\param information The information to store a reference to.\n  /// \\param key_equal The function to compare keys with.\n  LastAccessed(const Key& key,\n               const InformationType& information,\n               const KeyEqual& key_equal = KeyEqual())\n  : _key(const_cast<Key*>(&key))\n  , _information(const_cast<InformationType*>(&information))\n  , _is_valid(true)\n  , _key_equal(key_equal) {\n  }\n\n  /// Constructor.\n  ///\n  /// \\param iterator An iterator pointing to a key and information to use for\n  ///                constructing the instance.\n  /// \\param key_equal The function to compare keys with.\n  template <typename Iterator>\n  explicit LastAccessed(Iterator iterator,\n                        const KeyEqual& key_equal = KeyEqual())\n  : LastAccessed(iterator->first, iterator->second, key_equal) {\n  }\n\n  /// Copy assignment operator for iterators.\n  ///\n  /// \\param iterator An iterator pointing to a key and value to use for the\n  ///                 `LastAccessed` instance.\n  /// \\return The resulting `LastAccessed` instance.\n  template <typename Iterator>\n  LastAccessed& operator=(Iterator iterator) {\n    _key = const_cast<Key*>(&(iterator->first));\n    _information = const_cast<InformationType*>(&(iterator->second));\n    _is_valid = true;\n\n    return *this;\n  }\n\n  /// Compares a `LastAccessed` object for equality with a key.\n  ///\n  /// \\param last_accessed The `LastAccessed` instance to compare.\n  /// \\param key The key instance to compare.\n  /// \\returns True if the key of the `LastAccessed` object's key equals the\n  /// given key, else false.\n  friend bool\n  operator==(const LastAccessed& last_accessed, const Key& key) noexcept {\n    if (!last_accessed._is_valid) return false;\n    return last_accessed._key_equal(key, last_accessed.key());\n  }\n\n  /// \\copydoc operator==(const LastAccessed&,const Key&)\n  friend bool\n  operator==(const Key& key, const LastAccessed& last_accessed) noexcept {\n    return last_accessed == key;\n  }\n\n  /// Compares a `LastAccessed` object  for equality with an iterator.\n  ///\n  /// \\param last_accessed The `LastAccessed` instance to compare.\n  /// \\param iterator The iterator to compare with.\n  /// \\returns True if the `LastAccessed` object's key equals that of the\n  /// iterator, else false.\n  template <typename Iterator, typename = enable_if_iterator<Iterator>>\n  friend bool\n  operator==(const LastAccessed& last_accessed, Iterator iterator) noexcept {\n    /// Fast comparisons to an iterator (not relying on implicit conversion)\n    return last_accessed == iterator->first;\n  }\n\n  /// \\copydoc operator==(const LastAccessed&,Iterator)\n  template <typename Iterator, typename = enable_if_iterator<Iterator>>\n  friend bool\n  operator==(Iterator iterator, const LastAccessed& last_accessed) noexcept {\n    return last_accessed == iterator;\n  }\n\n  /// Compares a `LastAccessed` object for inequality with something.\n  ///\n  /// \\param last_accessed The `LastAccessed` instance to compare.\n  /// \\param other Something else to compare to.\n  /// \\returns True if the key of the `LastAccessed` object's key does not equal\n  /// the given other object's key, else false.\n  template <typename T>\n  friend bool\n  operator!=(const LastAccessed& last_accessed, const T& other) noexcept {\n    return !(last_accessed == other);\n  }\n\n  /// \\copydoc operator!=(const LastAccessed&,const T&)\n  template <typename T>\n  friend bool\n  operator!=(const T& other, const LastAccessed& last_accessed) noexcept {\n    return !(other == last_accessed);\n  }\n\n  /// \\returns The last accessed key.\n  Key& key() noexcept {\n    assert(is_valid());\n    return *_key;\n  }\n\n  /// \\returns The last accessed key.\n  const Key& key() const noexcept {\n    assert(is_valid());\n    return *_key;\n  }\n\n  /// \\returns The last accessed information.\n  InformationType& information() noexcept {\n    assert(is_valid());\n    return *_information;\n  }\n\n  /// \\returns The last accessed information.\n  const InformationType& information() const noexcept {\n    assert(is_valid());\n    return *_information;\n  }\n\n  /// \\returns The last accessed information.\n  auto& iterator() noexcept {\n    assert(is_valid());\n    return _information->order;\n  }\n\n  /// \\returns The last accessed value.\n  auto& value() noexcept {\n    assert(is_valid());\n    return _information->value;\n  }\n\n  /// \\returns The last accessed value.\n  const auto& value() const noexcept {\n    assert(is_valid());\n    return _information->value;\n  }\n\n  /// \\returns True if the key and information of the instance may be accessed,\n  /// else false.\n  bool is_valid() const noexcept {\n    return _is_valid;\n  }\n\n  /// \\copydoc is_valid()\n  explicit operator bool() const noexcept {\n    return is_valid();\n  }\n\n  /// Invalidates the instance.\n  void invalidate() noexcept {\n    _is_valid = false;\n    _key = nullptr;\n    _information = nullptr;\n  }\n\n  /// \\returns The key comparison function used.\n  const KeyEqual& key_equal() const noexcept {\n    return _key_equal;\n  }\n\n private:\n  /// A pointer to the key that was last accessed (if any).\n  Key* _key;\n\n  /// A pointer to the information that was last accessed (if any).\n  InformationType* _information;\n\n  /// True if the key and information pointers are valid, else false.\n  bool _is_valid;\n\n  /// The function used to compare keys.\n  KeyEqual _key_equal;\n};\n}  // namespace Internal\n}  // namespace LRU\n\n#endif  // LRU_INTERNAL_LAST_ACCESSED_HPP\n"
  },
  {
    "path": "include/lru/internal/optional.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef LRU_INTERNAL_OPTIONAL_HPP\n#define LRU_INTERNAL_OPTIONAL_HPP\n\n#ifndef __has_include\n#define USE_LRU_OPTIONAL\n#elif __has_include(<optional>)\n\n#include <optional>\n\nnamespace LRU {\nnamespace Internal {\ntemplate <typename T>\nusing Optional = std::optional<T>;\n}  // namespace Internal\n}  // namespace LRU\n\n#else\n#define USE_LRU_OPTIONAL\n#endif\n\n#ifdef USE_LRU_OPTIONAL\n#include <memory>\n#include <stdexcept>\n\nnamespace LRU {\nnamespace Internal {\n\n// A roll-your-own replacement of `std::optional`.\n//\n// This class is only to be used if `std::optional` is unavailable. It\n// implements an optional type simply on top of a `unique_ptr`. It is\n// API-compatible with `std::optional`, as required for our purposes.\ntemplate <typename T>\nclass Optional {\n public:\n  /// Constructor.\n  Optional() = default;\n\n  /// Copy constructor.\n  ///\n  /// \\param other The other optional object to copy from.\n  Optional(const Optional& other) {\n    if (other) emplace(*other);\n  }\n\n  /// Generalized copy constructor.\n  ///\n  /// \\param other The other optional object to copy from.\n  template <typename U,\n            typename = std::enable_if_t<std::is_convertible<T, U>::value>>\n  Optional(const Optional<U>& other) {\n    if (other) emplace(*other);\n  }\n\n  /// Move constructor.\n  ///\n  /// \\param other The other optional object to move into this one.\n  Optional(Optional&& other) noexcept {\n    swap(other);\n  }\n\n  /// Generalized move constructor.\n  ///\n  /// \\param other The other optional object to move into this one.\n  template <typename U,\n            typename = std::enable_if_t<std::is_convertible<T, U>::value>>\n  Optional(Optional<U>&& other) noexcept {\n    if (other) {\n      _value = std::make_unique<T>(std::move(*other));\n    }\n  }\n\n  /// Assignment operator.\n  ///\n  /// \\param other The other object to assign from.\n  /// \\returns The resulting optional instance.\n  Optional& operator=(Optional other) noexcept {\n    swap(other);\n    return *this;\n  }\n\n  /// Swaps the contents of this optional with another one.\n  ///\n  /// \\param other The other optional to swap with.\n  void swap(Optional& other) {\n    _value.swap(other._value);\n  }\n\n  /// Swaps the contents of two optionals.\n  ///\n  /// \\param first The first optional to swap.\n  /// \\param second The second optional to swap.\n  friend void swap(Optional& first, Optional& second) /* NOLINT */ {\n    first.swap(second);\n  }\n\n  /// \\returns True if the `Optional` has a value, else false.\n  bool has_value() const noexcept {\n    return static_cast<bool>(_value);\n  }\n\n  /// \\copydoc has_value()\n  explicit operator bool() const noexcept {\n    return has_value();\n  }\n\n  /// \\returns A pointer to the current value. Behavior is undefined if the\n  /// optional has no value.\n  T* operator->() {\n    return _value.get();\n  }\n\n  /// \\returns A const pointer to the current value. Behavior is undefined if\n  /// the `Optional` has no value.\n  const T* operator->() const {\n    return _value.get();\n  }\n\n  /// \\returns A const reference to the current value. Behavior is undefined if\n  /// the `Optional` has no value.\n  const T& operator*() const {\n    return *_value;\n  }\n\n  /// \\returns A reference to the current value. Behavior is undefined if\n  /// the `Optional` has no value.\n  T& operator*() {\n    return *_value;\n  }\n\n  /// \\returns A reference to the current value.\n  /// \\throws std::runtime_error If the `Optional` currently has no value.\n  T& value() {\n    if (!has_value()) {\n      // Actually std::bad_optional_access\n      throw std::runtime_error(\"optional has no value\");\n    }\n\n    return *_value;\n  }\n\n  /// \\returns A const reference to the current value.\n  /// \\throws std::runtime_error If the `Optional` currently has no value.\n  const T& value() const {\n    if (!has_value()) {\n      // Actually std::bad_optional_access\n      throw std::runtime_error(\"optional has no value\");\n    }\n\n    return *_value;\n  }\n\n  /// \\returns The current value, or the given argument if there is no value.\n  /// \\param default_value The value to return if this `Optional` currently has\n  ///                      no value.\n  template <class U>\n  T value_or(U&& default_value) const {\n    return *this ? **this : static_cast<T>(std::forward<U>(default_value));\n  }\n\n  /// Resets the `Optional` to have no value.\n  void reset() noexcept {\n    _value.reset();\n  }\n\n  /// Constructs the `Optional`'s value with the given arguments.\n  ///\n  /// \\param args Arguments to perfeclty forward to the value's constructor.\n  template <typename... Args>\n  void emplace(Args&&... args) {\n    _value = std::make_unique<T>(std::forward<Args>(args)...);\n  }\n\n private:\n  template <typename>\n  friend class Optional;\n\n  /// The value, as we implement it.\n  std::unique_ptr<T> _value;\n};\n}  // namespace Internal\n}  // namespace LRU\n\n#endif\n\n#endif  // LRU_INTERNAL_OPTIONAL_HPP\n"
  },
  {
    "path": "include/lru/internal/statistics-mutator.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef LRU_STATISTICS_MUTATOR_HPP\n#define LRU_STATISTICS_MUTATOR_HPP\n\n#include <cassert>\n#include <cstddef>\n#include <memory>\n#include <utility>\n\n#include <lru/internal/optional.hpp>\n#include <lru/statistics.hpp>\n\nnamespace LRU {\nnamespace Internal {\n\n/// A mutable proxy interface to a statistics object.\n///\n/// The `StatisticsMutator` allows modification of the members of a statistics\n/// object via a narrow interface, available only to internal classes. The point\n/// of this is that while we don't want the user to be able to modify the hit or\n/// miss count on a statistics object (it is \"getter-only\" in that sense), it's\n/// also not ideal, from an encapsulation standpoint, to make the cache classes\n/// (which do need to access and modify the hit and miss counts) friends of the\n/// statistics. This is especially true since the caches should only need to\n/// register hits or misses and not have to increment the count of total\n/// accesses. As such, we really require a \"package-level\" interface that is not\n/// visible to the end user, while at the same time providing an interface to\n/// internal classes. The `StatisticsMutator` is a proxy/adapter class that\n/// serves exactly this purpose. It is friends with the `Statistics` and can\n/// thus access its members. At the same time the interface it defines is narrow\n/// and provides only the necessary interface for the cache classes to register\n/// hits and misses.\ntemplate <typename Key>\nclass StatisticsMutator {\n public:\n  using StatisticsPointer = std::shared_ptr<Statistics<Key>>;\n\n  /// Constructor.\n  StatisticsMutator() noexcept = default;\n\n  /// Constructor.\n  ///\n  /// \\param stats A shared pointer lvalue reference.\n  StatisticsMutator(const StatisticsPointer& stats)  // NOLINT(runtime/explicit)\n      : _stats(stats) {\n  }\n\n  /// Constructor.\n  ///\n  /// \\param stats A shared pointer rvalue reference to move into the\n  ///                   mutator.\n  StatisticsMutator(StatisticsPointer&& stats)  // NOLINT(runtime/explicit)\n      : _stats(std::move(stats)) {\n  }\n\n  /// Registers a hit for the given key with the internal statistics.\n  ///\n  /// \\param key The key to register a hit for.\n  void register_hit(const Key& key) {\n    assert(has_stats());\n\n    _stats->_total_accesses += 1;\n    _stats->_total_hits += 1;\n\n    auto iterator = _stats->_key_map.find(key);\n    if (iterator != _stats->_key_map.end()) {\n      iterator->second.hits += 1;\n    }\n  }\n\n  /// Registers a miss for the given key with the internal statistics.\n  ///\n  /// \\param key The key to register a miss for.\n  void register_miss(const Key& key) {\n    assert(has_stats());\n\n    _stats->_total_accesses += 1;\n\n    auto iterator = _stats->_key_map.find(key);\n    if (iterator != _stats->_key_map.end()) {\n      iterator->second.misses += 1;\n    }\n  }\n\n  /// \\returns A reference to the statistics object.\n  Statistics<Key>& get() noexcept {\n    assert(has_stats());\n    return *_stats;\n  }\n\n  /// \\returns A const reference to the statistics object.\n  const Statistics<Key>& get() const noexcept {\n    assert(has_stats());\n    return *_stats;\n  }\n\n  /// \\returns A `shared_ptr` to the statistics object.\n  StatisticsPointer& shared() noexcept {\n    return _stats;\n  }\n\n  /// \\returns A const `shared_ptr` to the statistics object.\n  const StatisticsPointer& shared() const noexcept {\n    return _stats;\n  }\n\n  /// \\returns True if the mutator has a statistics object, else false.\n  bool has_stats() const noexcept {\n    return _stats != nullptr;\n  }\n\n  /// \\copydoc has_stats()\n  explicit operator bool() const noexcept {\n    return has_stats();\n  }\n\n  /// Resets the internal statistics pointer.\n  void reset() {\n    _stats.reset();\n  }\n\n private:\n  /// A shared pointer to a statistics object.\n  std::shared_ptr<Statistics<Key>> _stats;\n};\n\n}  // namespace Internal\n}  // namespace LRU\n\n#endif  // LRU_STATISTICS_MUTATOR_HPP\n"
  },
  {
    "path": "include/lru/internal/timed-information.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef LRU_INTERNAL_TIMED_INFORMATION_HPP\n#define LRU_INTERNAL_TIMED_INFORMATION_HPP\n\n#include <cstddef>\n#include <tuple>\n#include <utility>\n\n#include <lru/internal/definitions.hpp>\n#include <lru/internal/information.hpp>\n#include <lru/internal/utility.hpp>\n\nnamespace LRU {\nnamespace Internal {\n\n/// The information object for timed caches.\n///\n/// TimedInformation differs from plain information only in that it stores the\n/// creation time, to know when a key has expired.\n///\n/// \\tparam Key The key type of the information.\n/// \\tparam Value The value type of the information.\ntemplate <typename Key, typename Value>\nstruct TimedInformation : public Information<Key, Value> {\n  using super = Information<Key, Value>;\n  using typename super::QueueIterator;\n  using Timestamp = Internal::Timestamp;\n\n  /// Constructor.\n  ///\n  /// \\param value_ The value for the information.\n  /// \\param insertion_time_ The insertion timestamp of the key.\n  /// \\param order_ The order iterator for the information.\n  TimedInformation(const Value& value_,\n                   const Timestamp& insertion_time_,\n                   QueueIterator order_ = QueueIterator())\n  : super(value_, order_), insertion_time(insertion_time_) {\n  }\n\n  /// Constructor.\n  ///\n  /// Uses the current time as the insertion timestamp.\n  ///\n  /// \\param value_ The value for the information.\n  /// \\param order_ The order iterator for the information.\n  explicit TimedInformation(const Value& value_,\n                            QueueIterator order_ = QueueIterator())\n  : TimedInformation(value_, Internal::Clock::now(), order_) {\n  }\n\n  /// \\copydoc Information::Information(QueueIterator,ValueArguments&&)\n  template <typename... ValueArguments>\n  TimedInformation(QueueIterator order_, ValueArguments&&... value_argument)\n  : super(std::forward<ValueArguments>(value_argument)..., order_)\n  , insertion_time(Internal::Clock::now()) {\n  }\n\n  /// \\copydoc Information::Information(QueueIterator,const\n  /// std::tuple<ValueArguments...>&)\n  template <typename... ValueArguments>\n  explicit TimedInformation(\n      const std::tuple<ValueArguments...>& value_arguments,\n      QueueIterator order_ = QueueIterator())\n  : super(value_arguments, order_), insertion_time(Internal::Clock::now()) {\n  }\n\n  /// Compares this timed information for equality with another one.\n  ///\n  /// Additionally to key and value equality, the timed information requires\n  /// that the insertion timestamps be equal.\n  ///\n  /// \\param other The other timed information.\n  /// \\returns True if this information equals the other one, else false.\n  bool operator==(const TimedInformation& other) const noexcept {\n    if (super::operator!=(other)) return false;\n    return this->insertion_time == other.insertion_time;\n  }\n\n  /// Compares this timed information for inequality with another one.\n  ///\n  /// \\param other The other timed information.\n  /// \\returns True if this information does not equal the other one, else\n  /// false.\n  /// \\see operator==()\n  bool operator!=(const TimedInformation& other) const noexcept {\n    return !(*this == other);\n  }\n\n  /// The time at which the key of the information was insterted into a cache.\n  const Timestamp insertion_time;\n};\n\n}  // namespace Internal\n}  // namespace LRU\n\n#endif  // LRU_INTERNAL_TIMED_INFORMATION_HPP\n"
  },
  {
    "path": "include/lru/internal/utility.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef LRU_UTILITY_HPP\n#define LRU_UTILITY_HPP\n\n#include <cstddef>\n#include <iterator>\n#include <tuple>\n#include <utility>\n\nnamespace LRU {\nnamespace Internal {\n\n/// Generates an index sequence for a tuple.\n///\n/// \\tparam Ts The types of the tuple (to deduce the size).\ntemplate <typename... Ts>\nconstexpr auto tuple_indices(const std::tuple<Ts...>&) {\n  return std::make_index_sequence<sizeof...(Ts)>();\n}\n\n/// Applies (in the functional sense) a tuple to the constructor of a class.\n///\n/// \\tparam T The type to construct.\n/// \\tparam Indices The indices into the tuple (generated from an index\n///                 sequence).\n/// \\param args The tuple of arguments to construct the object with.\ntemplate <typename T, typename... Args, std::size_t... Indices>\nconstexpr T construct_from_tuple(const std::tuple<Args...>& arguments,\n                                 std::index_sequence<Indices...>) {\n  return T(std::forward<Args>(std::get<Indices>(arguments))...);\n}\n\n/// Applies (in the functional sense) a tuple to the constructor of a class.\n///\n/// \\tparam T The type to construct.\n/// \\param args The tuple of arguments to construct the object with.\ntemplate <typename T, typename... Args>\nconstexpr T construct_from_tuple(const std::tuple<Args...>& args) {\n  return construct_from_tuple<T>(args, tuple_indices(args));\n}\n\n/// Applies (in the functional sense) a tuple to the constructor of a class.\n///\n/// \\tparam T The type to construct.\n/// \\param args The tuple of arguments to construct the object with.\ntemplate <typename T, typename... Args>\nconstexpr T construct_from_tuple(std::tuple<Args...>&& args) {\n  return construct_from_tuple<T>(std::move(args), tuple_indices(args));\n}\n\n/// A type trait that disables a template overload if a type is not an iterator.\n///\n/// \\tparam T the type to check.\ntemplate <typename T>\nusing enable_if_iterator = typename std::iterator_traits<T>::value_type;\n\n/// A type trait that disables a template overload if a type is not a range.\n///\n/// \\tparam T the type to check.\ntemplate <typename T>\nusing enable_if_range = std::pair<decltype(std::declval<T>().begin()),\n                                  decltype(std::declval<T>().end())>;\n\n/// A type trait that disables a template overload if a type is not an iterator\n/// over a pair.\n///\n/// \\tparam T the type to check.\ntemplate <typename T>\nusing enable_if_iterator_over_pair =\n    std::pair<typename std::iterator_traits<T>::value_type::first_type,\n              typename std::iterator_traits<T>::value_type::first_type>;\n\n\n/// A type trait that disables a template overload if a type is not convertible\n/// to a target type.\n///\n/// \\tparam Target The type one wants to check against.\n/// \\tparam T The type to check.\ntemplate <typename Target, typename T>\nusing enable_if_same = std::enable_if_t<std::is_convertible<T, Target>::value>;\n\n/// Base case for `static_all_of` (the neutral element of AND is true).\nconstexpr bool static_all_of() noexcept {\n  return true;\n}\n\n/// Checks if all the given parameters evaluate to true.\n///\n/// \\param head The first expression to check.\n/// \\param tail The remaining expression to check.\ntemplate <typename Head, typename... Tail>\nconstexpr bool static_all_of(Head&& head, Tail&&... tail) {\n  // Replace with (ts && ...) when the time is right\n  return std::forward<Head>(head) && static_all_of(std::forward<Tail>(tail)...);\n}\n\n/// Base case for `static_any_of` (the neutral element of OR is false).\nconstexpr bool static_any_of() noexcept {\n  return false;\n}\n\n/// Checks if any the given parameters evaluate to true.\n///\n/// \\param head The first expression to check.\n/// \\param tail The remaining expression to check.\n/// \\returns True if any of the given parameters evaluate to true.\ntemplate <typename Head, typename... Tail>\nconstexpr bool static_any_of(Head&& head, Tail&&... tail) {\n  // Replace with (ts || ...) when the time is right\n  return std::forward<Head>(head) || static_any_of(std::forward<Tail>(tail)...);\n}\n\n/// Checks if none the given parameters evaluate to true.\n///\n/// \\param ts The expressions to check.\n/// \\returns True if any of the given parameters evaluate to true.\ntemplate <typename... Ts>\nconstexpr bool static_none_of(Ts&&... ts) {\n  // Replace with (!ts && ...) when the time is right\n  return !static_any_of(std::forward<Ts>(ts)...);\n}\n\n/// Checks if all the given types are convertible to the first type.\n///\n/// \\tparam T the first type.\n/// \\tparam Ts The types to check against the first.\ntemplate <typename T, typename... Ts>\nconstexpr bool\n    all_of_type = static_all_of(std::is_convertible<Ts, T>::value...);\n\n/// Checks if none of the given types are convertible to the first type.\n///\n/// \\tparam T the first type.\n/// \\tparam Ts The types to check against the first.\ntemplate <typename T, typename... Ts>\nconstexpr bool\n    none_of_type = static_none_of(std::is_convertible<Ts, T>::value...);\n\n/// Base case for `for_each`.\ntemplate <typename Function>\nvoid for_each(Function) noexcept {\n}\n\n/// Calls a function for each of the given variadic arguments.\n///\n/// \\param function The function to call for each argument.\n/// \\param head The first value to call the function with.\n/// \\param tail The remaining values to call the function with.\ntemplate <typename Function, typename Head, typename... Tail>\nvoid for_each(Function function, Head&& head, Tail&&... tail) {\n  function(std::forward<Head>(head));\n  for_each(function, std::forward<Tail>(tail)...);\n}\n\n}  // namespace Internal\n}  // namespace LRU\n\n#endif  // LRU_UTILITY_HPP\n"
  },
  {
    "path": "include/lru/iterator-tags.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef LRU_ITERATOR_TAGS_HPP\n#define LRU_ITERATOR_TAGS_HPP\n\nnamespace LRU {\nnamespace Tag {\nstruct OrderedIterator {};\nstruct UnorderedIterator {};\n}  // namespace Tag\n\nnamespace Lowercase {\nnamespace tag {\nusing ordered_iterator = ::LRU::Tag::OrderedIterator;\nusing unordered_iterator = ::LRU::Tag::UnorderedIterator;\n}  // namespace tag\n}  // namespace Lowercase\n\n}  // namespace LRU\n\n#endif  // LRU_ITERATOR_TAGS_HPP\n"
  },
  {
    "path": "include/lru/key-statistics.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n\n#ifndef LRU_KEY_STATISTICS_HPP\n#define LRU_KEY_STATISTICS_HPP\n\n#include <cstddef>\n\nnamespace LRU {\n\n/// Stores statistics for a single key.\n///\n/// The statistics stored are the total number of hits and the total number of\n/// misses. The total number of acccesses (the sum of hits and misses) may be\n/// accessed as well.\nstruct KeyStatistics {\n  using size_t = std::size_t;\n\n  /// Constructor.\n  ///\n  /// \\param hits_ The initial number of hits for the key.\n  /// \\param misses_ The initial number of misses for the key.\n  explicit KeyStatistics(size_t hits_ = 0, size_t misses_ = 0)\n  : hits(hits_), misses(misses_) {\n  }\n\n  /// \\returns The total number of accesses made for the key.\n  /// \\details This is the sum of the hits and misses.\n  size_t accesses() const noexcept {\n    return hits + misses;\n  }\n\n  /// Resets the statistics for a key (sets them to zero).\n  void reset() {\n    hits = 0;\n    misses = 0;\n  }\n\n  /// The number of hits for the key.\n  size_t hits;\n\n  /// The number of misses for the key.\n  size_t misses;\n};\n\n}  // namespace LRU\n\n#endif  // LRU_KEY_STATISTICS_HPP\n"
  },
  {
    "path": "include/lru/lowercase.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef LRU_LOWERCASE_HPP\n#define LRU_LOWERCASE_HPP\n\n#include <lru/lru.hpp>\n\nnamespace LRU {\nusing namespace Lowercase;  // NOLINT(build/namespaces)\n}  // namespace LRU\n\nnamespace lru = LRU;\n\n\n#endif  // LRU_LOWERCASE_HPP\n"
  },
  {
    "path": "include/lru/lru.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef LRU_HPP\n#define LRU_HPP\n\n#include <lru/cache-tags.hpp>\n#include <lru/cache.hpp>\n#include <lru/error.hpp>\n#include <lru/iterator-tags.hpp>\n#include <lru/statistics.hpp>\n#include <lru/timed-cache.hpp>\n#include <lru/wrap.hpp>\n\n#endif  // LRU_HPP\n"
  },
  {
    "path": "include/lru/statistics.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n\n#ifndef LRU_STATISTICS_HPP\n#define LRU_STATISTICS_HPP\n\n#include <cstddef>\n#include <initializer_list>\n#include <iterator>\n#include <type_traits>\n#include <unordered_map>\n#include <utility>\n\n#include <lru/error.hpp>\n#include <lru/internal/utility.hpp>\n#include <lru/key-statistics.hpp>\n\nnamespace LRU {\nnamespace Internal {\ntemplate <typename>\nclass StatisticsMutator;\n}\n\n/// Stores statistics about LRU cache utilization and efficiency.\n///\n/// The statistics object stores the number of misses and hits were recorded for\n/// a cache in total. Furthemore, it is possibly to register a number of keys\n/// for *monitoring*. For each of these keys, an additional hit and miss count\n/// is maintained, that can keep insight into the utiliization of a particular\n/// cache. Note that accesses only mean lookups -- insertions or erasures will\n/// never signify an \"access\".\n///\n/// \\tparam Key The type of the keys being monitored.\ntemplate <typename Key>\nclass Statistics {\n public:\n  using size_t = std::size_t;\n  using InitializerList = std::initializer_list<Key>;\n\n  /// Constructor.\n  Statistics() noexcept : _total_accesses(0), _total_hits(0) {\n  }\n\n  /// Constructor.\n  ///\n  /// \\param keys Any number of keys to monitor.\n  template <typename... Keys,\n            typename = std::enable_if_t<Internal::all_of_type<Key, Keys...>>>\n  explicit Statistics(Keys&&... keys) : Statistics() {\n    // clang-format off\n    Internal::for_each([this](auto&& key) {\n      this->monitor(std::forward<decltype(key)>(key));\n    }, std::forward<Keys>(keys)...);\n    // clang-format on\n  }\n\n  /// Constructor.\n  ///\n  /// \\param range A range of keys to monitor.\n  template <typename Range, typename = Internal::enable_if_range<Range>>\n  explicit Statistics(const Range& range)\n  : Statistics(std::begin(range), std::end(range)) {\n  }\n\n  /// Constructor.\n  ///\n  /// \\param begin The start iterator of a range of keys to monitor.\n  /// \\param end The end iterator of a range of keys to monitor.\n  template <typename Iterator,\n            typename = Internal::enable_if_iterator<Iterator>>\n  Statistics(Iterator begin, Iterator end) : Statistics() {\n    for (; begin != end; ++begin) {\n      monitor(*begin);\n    }\n  }\n\n  /// Constructor.\n  ///\n  /// \\param list A list of keys to monitor.\n  Statistics(InitializerList list)  // NOLINT(runtime/explicit)\n      : Statistics(list.begin(), list.end()) {\n  }\n\n  /// \\returns The total number of accesses (hits + misses) made to the cache.\n  size_t total_accesses() const noexcept {\n    return _total_accesses;\n  }\n\n  /// \\returns The total number of hits made to the cache.\n  size_t total_hits() const noexcept {\n    return _total_hits;\n  }\n\n  /// \\returns The total number of misses made to the cache.\n  size_t total_misses() const noexcept {\n    return total_accesses() - total_hits();\n  }\n\n  /// \\returns The ratio of hits ($\\in [0, 1]$) relative to all accesses.\n  double hit_rate() const noexcept {\n    return static_cast<double>(total_hits()) / total_accesses();\n  }\n\n  /// \\returns The ratio of misses ($\\in [0, 1]$) relative to all accesses.\n  double miss_rate() const noexcept {\n    return 1 - hit_rate();\n  }\n\n  /// \\returns The number of hits for the given key.\n  /// \\param key The key to retrieve the hits for.\n  /// \\throws LRU::UnmonitoredKey if the key was not registered for monitoring.\n  size_t hits_for(const Key& key) const {\n    return stats_for(key).hits;\n  }\n\n  /// \\returns The number of misses for the given key.\n  /// \\param key The key to retrieve the misses for.\n  /// \\throws LRU::UnmonitoredKey if the key was not registered for monitoring.\n  size_t misses_for(const Key& key) const {\n    return stats_for(key).misses;\n  }\n\n  /// \\returns The number of accesses (hits + misses) for the given key.\n  /// \\param key The key to retrieve the accesses for.\n  /// \\throws LRU::UnmonitoredKey if the key was not registered for monitoring.\n  size_t accesses_for(const Key& key) const {\n    return stats_for(key).accesses();\n  }\n\n  /// \\returns A `KeyStatistics` object for the given key.\n  /// \\param key The key to retrieve the stats for.\n  /// \\throws LRU::UnmonitoredKey if the key was not registered for monitoring.\n  const KeyStatistics& stats_for(const Key& key) const {\n    auto iterator = _key_map.find(key);\n    if (iterator == _key_map.end()) {\n      throw LRU::Error::UnmonitoredKey();\n    }\n\n    return iterator->second;\n  }\n\n  /// \\copydoc stats_for()\n  const KeyStatistics& operator[](const Key& key) const {\n    return stats_for(key);\n  }\n\n  /// Registers the key for monitoring.\n  ///\n  /// If the key was already registered, this is a no-op (most importantly, the\n  /// old statistics are __not__ wiped).\n  ///\n  /// \\param key The key to register.\n  void monitor(const Key& key) {\n    // emplace does nothing if the key is already present\n    _key_map.emplace(key, KeyStatistics());\n  }\n\n  /// Unregisters the given key from monitoring.\n  ///\n  /// \\param key The key to unregister.\n  /// \\throws LRU::Error::UnmonitoredKey if the key was never registered for\n  /// monitoring.\n  void unmonitor(const Key& key) {\n    auto iterator = _key_map.find(key);\n    if (iterator == _key_map.end()) {\n      throw LRU::Error::UnmonitoredKey();\n    } else {\n      _key_map.erase(iterator);\n    }\n  }\n\n  /// Unregisters all keys from monitoring.\n  void unmonitor_all() {\n    _key_map.clear();\n  }\n\n  /// Clears all statistics for the given key, but keeps on monitoring it.\n  ///\n  /// \\param key The key to reset.\n  void reset_key(const Key& key) {\n    auto iterator = _key_map.find(key);\n    if (iterator == _key_map.end()) {\n      throw LRU::Error::UnmonitoredKey();\n    } else {\n      iterator->second.reset();\n    }\n  }\n\n  /// Clears the statistics of all keys, but keeps on monitoring it them.\n  void reset_all() {\n    for (auto& pair : _key_map) {\n      _key_map.second.reset();\n    }\n  }\n\n  /// \\returns True if the given key is currently registered for monitoring,\n  /// else false.\n  /// \\param key The key to check for.\n  bool is_monitoring(const Key& key) const noexcept {\n    return _key_map.count(key);\n  }\n\n  /// \\returns The number of keys currnetly being monitored.\n  size_t number_of_monitored_keys() const noexcept {\n    return _key_map.size();\n  }\n\n  /// \\returns True if currently any keys at all are being monitored, else\n  /// false.\n  bool is_monitoring_keys() const noexcept {\n    return !_key_map.empty();\n  }\n\n private:\n  template <typename>\n  friend class Internal::StatisticsMutator;\n\n  using HitMap = std::unordered_map<Key, KeyStatistics>;\n\n  /// The total number of accesses made for any key.\n  size_t _total_accesses;\n\n  /// The total number of htis made for any key.\n  size_t _total_hits;\n\n  /// The map to keep track of statistics for monitored keys.\n  HitMap _key_map;\n};\n\nnamespace Lowercase {\ntemplate <typename... Ts>\nusing statistics = Statistics<Ts...>;\n}  // namespace Lowercase\n\n}  // namespace LRU\n\n#endif  // LRU_STATISTICS_HPP\n"
  },
  {
    "path": "include/lru/timed-cache.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef LRU_TIMED_CACHE_HPP\n#define LRU_TIMED_CACHE_HPP\n\n#include <algorithm>\n#include <cassert>\n#include <chrono>\n#include <cstddef>\n#include <functional>\n#include <iterator>\n#include <list>\n#include <stdexcept>\n#include <unordered_map>\n#include <utility>\n\n#include <lru/error.hpp>\n#include <lru/internal/base-cache.hpp>\n#include <lru/internal/last-accessed.hpp>\n#include <lru/internal/timed-information.hpp>\n\nnamespace LRU {\nnamespace Internal {\ntemplate <typename Key,\n          typename Value,\n          typename HashFunction,\n          typename KeyEqual>\nusing TimedCacheBase = BaseCache<Key,\n                                 Value,\n                                 Internal::TimedInformation,\n                                 HashFunction,\n                                 KeyEqual,\n                                 Tag::TimedCache>;\n}  // namespace Internal\n\n\n/// A timed LRU cache.\n///\n/// A timed LRU cache behaves like a regular LRU cache, but adds the concept of\n/// \"expiration\". The cache now not only remembers the order of insertion, but\n/// also the point in time at which each element was inserted into the cache.\n/// The cache then has an additional \"time to live\" property, which designates\n/// the time after which a key in the cache is said to be \"expired\". Once a key\n/// has expired, the cache will behave as if the key were not present in the\n/// cache at all and, for example, return false on calls to `contains()` or\n/// throw on calls to `lookup()`.\n///\n/// \\see LRU::Cache\ntemplate <typename Key,\n          typename Value,\n          typename Duration = std::chrono::duration<double, std::milli>,\n          typename HashFunction = std::hash<Key>,\n          typename KeyEqual = std::equal_to<Key>>\nclass TimedCache\n    : public Internal::TimedCacheBase<Key, Value, HashFunction, KeyEqual> {\n private:\n  using super = Internal::TimedCacheBase<Key, Value, HashFunction, KeyEqual>;\n  using PRIVATE_BASE_CACHE_MEMBERS;\n\n public:\n  using Tag = LRU::Tag::TimedCache;\n  using PUBLIC_BASE_CACHE_MEMBERS;\n  using super::ordered_end;\n  using super::unordered_end;\n  using typename super::size_t;\n\n  /// \\param time_to_live The time to live for keys in the cache.\n  /// \\copydoc BaseCache::BaseCache(size_t,const HashFunction&,const KeyEqual&)\n  template <typename AnyDurationType = Duration>\n  explicit TimedCache(const AnyDurationType& time_to_live,\n                      size_t capacity = Internal::DEFAULT_CAPACITY,\n                      const HashFunction& hash = HashFunction(),\n                      const KeyEqual& equal = KeyEqual())\n  : super(capacity, hash, equal)\n  , _time_to_live(std::chrono::duration_cast<Duration>(time_to_live)) {\n  }\n\n  /// \\param time_to_live The time to live for keys in the cache.\n  /// \\copydoc BaseCache::BaseCache(size_t,Iterator,Iterator,const\n  /// HashFunction&,const\n  /// KeyEqual&)\n  template <typename Iterator, typename AnyDurationType = Duration>\n  TimedCache(const AnyDurationType& time_to_live,\n             size_t capacity,\n             Iterator begin,\n             Iterator end,\n             const HashFunction& hash = HashFunction(),\n             const KeyEqual& equal = KeyEqual())\n  : super(capacity, begin, end, hash, equal)\n  , _time_to_live(std::chrono::duration_cast<Duration>(time_to_live)) {\n  }\n\n  /// \\param time_to_live The time to live for keys in the cache.\n  /// \\copydoc BaseCache::BaseCache(Iterator,Iterator,const HashFunction&,const\n  /// KeyEqual&)\n  template <typename Iterator, typename AnyDurationType = Duration>\n  TimedCache(const AnyDurationType& time_to_live,\n             Iterator begin,\n             Iterator end,\n             const HashFunction& hash = HashFunction(),\n             const KeyEqual& equal = KeyEqual())\n  : super(begin, end, hash, equal)\n  , _time_to_live(std::chrono::duration_cast<Duration>(time_to_live)) {\n  }\n\n  /// \\param time_to_live The time to live for keys in the cache.\n  /// \\copydoc BaseCache::BaseCache(Range,size_t,const HashFunction&,const\n  /// KeyEqual&)\n  template <typename Range,\n            typename AnyDurationType = Duration,\n            typename = Internal::enable_if_range<Range>>\n  TimedCache(const AnyDurationType& time_to_live,\n             size_t capacity,\n             Range&& range,\n             const HashFunction& hash = HashFunction(),\n             const KeyEqual& equal = KeyEqual())\n  : super(capacity, std::forward<Range>(range), hash, equal)\n  , _time_to_live(std::chrono::duration_cast<Duration>(time_to_live)) {\n  }\n\n  /// \\param time_to_live The time to live for keys in the cache.\n  /// \\copydoc BaseCache::BaseCache(Range,const HashFunction&,const\n  /// KeyEqual&)\n  template <typename Range,\n            typename AnyDurationType = Duration,\n            typename = Internal::enable_if_range<Range>>\n  explicit TimedCache(const AnyDurationType& time_to_live,\n                      Range&& range,\n                      const HashFunction& hash = HashFunction(),\n                      const KeyEqual& equal = KeyEqual())\n  : super(std::forward<Range>(range), hash, equal)\n  , _time_to_live(std::chrono::duration_cast<Duration>(time_to_live)) {\n  }\n\n  /// \\param time_to_live The time to live for keys in the cache.\n  /// \\copydoc BaseCache::BaseCache(InitializerList,const HashFunction&,const\n  /// KeyEqual&)\n  template <typename AnyDurationType = Duration>\n  TimedCache(const AnyDurationType& time_to_live,\n             InitializerList list,\n             const HashFunction& hash = HashFunction(),\n             const KeyEqual& equal = KeyEqual())  // NOLINT(runtime/explicit)\n      : super(list, hash, equal),\n        _time_to_live(std::chrono::duration_cast<Duration>(time_to_live)) {\n  }\n\n  /// \\param time_to_live The time to live for keys in the cache.\n  /// \\copydoc BaseCache::BaseCache(InitializerList,size_t,const\n  /// HashFunction&,const\n  /// KeyEqual&)\n  template <typename AnyDurationType = Duration>\n  TimedCache(const AnyDurationType& time_to_live,\n             size_t capacity,\n             InitializerList list,\n             const HashFunction& hash = HashFunction(),\n             const KeyEqual& equal = KeyEqual())  // NOLINT(runtime/explicit)\n      : super(capacity, list, hash, equal),\n        _time_to_live(std::chrono::duration_cast<Duration>(time_to_live)) {\n  }\n\n  /// \\copydoc BaseCache::swap\n  void swap(TimedCache& other) noexcept {\n    using std::swap;\n\n    super::swap(other);\n    swap(_time_to_live, other._time_to_live);\n  }\n\n  /// Swaps the contents of one cache with another cache.\n  ///\n  /// \\param first The first cache to swap.\n  /// \\param second The second cache to swap.\n  friend void swap(TimedCache& first, TimedCache& second) noexcept {\n    first.swap(second);\n  }\n\n  /// \\copydoc BaseCache::find(const Key&)\n  UnorderedIterator find(const Key& key) override {\n    auto iterator = _map.find(key);\n    if (iterator != _map.end()) {\n      if (!_has_expired(iterator->second)) {\n        _register_hit(key, iterator->second.value);\n        _move_to_front(iterator->second.order);\n        _last_accessed = iterator;\n        return {*this, iterator};\n      }\n    }\n\n    _register_miss(key);\n\n    return end();\n  }\n\n  /// \\copydoc BaseCache::find(const Key&) const\n  UnorderedConstIterator find(const Key& key) const override {\n    auto iterator = _map.find(key);\n    if (iterator != _map.end()) {\n      if (!_has_expired(iterator->second)) {\n        _register_hit(key, iterator->second.value);\n        _move_to_front(iterator->second.order);\n        _last_accessed = iterator;\n        return {*this, iterator};\n      }\n    }\n\n    _register_miss(key);\n\n    return cend();\n  }\n\n  // no front() because we may have to erase the\n  // entire cache if everything happens to be expired\n\n  /// \\returns True if all keys in the cache have expired, else false.\n  bool all_expired() const {\n    // By the laws of predicate logic, any statement about any empty set is true\n    if (is_empty()) return true;\n\n    /// If the most-recently inserted key has expired, all others must have too.\n    auto latest = _map.find(_order.back());\n    return _has_expired(latest->second);\n  }\n\n  /// Erases all expired elements from the cache.\n  ///\n  /// \\complexity O(N)\n  /// \\returns The number of elements erased.\n  size_t clear_expired() {\n    // We have to do a linear search here because linked lists do not\n    // support O(log N) binary searches given their node-based nature.\n    // Either way, in the worst case the entire cache has expired and\n    // we would have to do O(N) erasures.\n\n    if (is_empty()) return 0;\n\n    auto iterator = _order.begin();\n    size_t number_of_erasures = 0;\n\n    while (iterator != _order.end()) {\n      auto map_iterator = _map.find(*iterator);\n\n      // If the current element hasn't expired, also all elements inserted\n      // after will not have, so we can stop.\n      if (!_has_expired(map_iterator->second)) break;\n\n      _erase(map_iterator);\n\n      iterator = _order.begin();\n      number_of_erasures += 1;\n    }\n\n    return number_of_erasures;\n  }\n\n  /// \\returns True if the given key is contained in the cache and has expired.\n  /// \\param key The key to test expiration for.\n  bool has_expired(const Key& key) const noexcept {\n    auto iterator = _map.find(key);\n    return iterator != _map.end() && _has_expired(iterator->second);\n  }\n\n  /// \\returns True if the key pointed to by the iterator has expired.\n  /// \\param ordered_iterator The ordered iterator to check.\n  /// \\details If this is the end iterator, this method returns false.\n  bool has_expired(OrderedConstIterator ordered_iterator) const noexcept {\n    if (ordered_iterator == ordered_end()) return false;\n    auto iterator = _map.find(ordered_iterator->key());\n    assert(iterator != _map.end());\n\n    return _has_expired(iterator->second);\n  }\n\n  /// \\returns True if the key pointed to by the iterator has expired.\n  /// \\param unordered_iterator The unordered iterator to check.\n  /// \\details If this is the end iterator, this method returns false.\n  bool has_expired(UnorderedConstIterator unordered_iterator) const noexcept {\n    if (unordered_iterator == unordered_end()) return false;\n    assert(unordered_iterator._iterator != _map.end());\n\n    return _has_expired(unordered_iterator._iterator->second);\n  }\n\n  /// \\copydoc BaseCache::is_valid(UnorderedConstIterator)\n  bool is_valid(UnorderedConstIterator unordered_iterator) const\n      noexcept override {\n    if (!super::is_valid(unordered_iterator)) return false;\n    if (has_expired(unordered_iterator)) return false;\n    return true;\n  }\n\n  /// \\copydoc BaseCache::is_valid(OrderedConstIterator)\n  bool is_valid(OrderedConstIterator ordered_iterator) const noexcept override {\n    if (!super::is_valid(ordered_iterator)) return false;\n    if (has_expired(ordered_iterator)) return false;\n    return true;\n  }\n\n  /// \\copydoc BaseCache::is_valid(UnorderedConstIterator)\n  /// \\throws LRU::Error::KeyExpired if the key pointed to by the iterator has\n  /// expired.\n  void\n  throw_if_invalid(UnorderedConstIterator unordered_iterator) const override {\n    super::throw_if_invalid(unordered_iterator);\n    if (has_expired(unordered_iterator)) {\n      throw LRU::Error::KeyExpired();\n    }\n  }\n\n  /// \\copydoc BaseCache::is_valid(OrderedConstIterator)\n  /// \\throws LRU::Error::KeyExpired if the key pointed to by the iterator has\n  /// expired.\n  void throw_if_invalid(OrderedConstIterator ordered_iterator) const override {\n    super::throw_if_invalid(ordered_iterator);\n    if (has_expired(ordered_iterator)) {\n      throw LRU::Error::KeyExpired();\n    }\n  }\n\n private:\n  using Clock = Internal::Clock;\n\n  /// \\returns True if the last accessed object is valid.\n  /// \\details Next to performing the base cache's action, this method also\n  /// checks for expiration of the last accessed key.\n  bool _last_accessed_is_ok(const Key& key) const noexcept override {\n    if (!super::_last_accessed_is_ok(key)) return false;\n    return !_has_expired(_last_accessed.information());\n  }\n\n  /// \\copydoc _value_for_last_accessed() const\n  Value& _value_for_last_accessed() override {\n    auto& information = _last_accessed.information();\n    if (_has_expired(information)) {\n      throw LRU::Error::KeyExpired();\n    } else {\n      return information.value;\n    }\n  }\n\n  /// Attempts to access the last accessed key's value.\n  /// \\throws LRU::Error::KeyExpired if the key has expired.\n  /// \\returns The value of the last accessed key.\n  const Value& _value_for_last_accessed() const override {\n    const auto& information = _last_accessed.information();\n    if (_has_expired(information)) {\n      throw LRU::Error::KeyExpired();\n    } else {\n      return information.value;\n    }\n  }\n\n  /// Checks if a key has expired, given its information.\n  ///\n  /// \\param information The information to check expiration with.\n  /// \\returns True if the key has expired, else false.\n  bool _has_expired(const Information& information) const noexcept {\n    auto elapsed = Clock::now() - information.insertion_time;\n    return std::chrono::duration_cast<Duration>(elapsed) > _time_to_live;\n  }\n\n  /// The duration after which a key is said to be expired.\n  Duration _time_to_live;\n};\n\nnamespace Lowercase {\ntemplate <typename... Ts>\nusing timed_cache = TimedCache<Ts...>;\n}  // namespace Lowercase\n\n}  // namespace LRU\n\n#endif  // LRU_TIMED_CACHE_HPP\n"
  },
  {
    "path": "include/lru/wrap.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#ifndef LRU_WRAP_HPP\n#define LRU_WRAP_HPP\n\n#include <cstddef>\n#include <tuple>\n#include <type_traits>\n#include <utility>\n\n#include <lru/cache.hpp>\n#include <lru/internal/hash.hpp>\n#include <lru/internal/utility.hpp>\n\nnamespace LRU {\n\n/// Wraps a function with a \"shallow\" LRU cache.\n///\n/// Given a function, this function will return a new function, where\n/// \"top-level\" calls are cached. With \"top-level\" or \"shallow\", we mean\n/// that recursive calls to the same function are not cached, since those\n/// will call the original function symbol, not the wrapped one.\n///\n/// \\tparam CacheType The cache template class to use.\n/// \\param original_function The function to wrap.\n/// \\param args Any arguments to forward to the cache.\n/// \\returns A new function with a shallow LRU cache.\ntemplate <typename Function,\n          template <typename...> class CacheType = Cache,\n          typename... Args>\nauto wrap(Function original_function, Args&&... args) {\n  return [\n    original_function,\n    cache_args = std::forward_as_tuple(std::forward<Args>(args)...)\n  ](auto&&... arguments) mutable {\n    using Arguments = std::tuple<std::decay_t<decltype(arguments)>...>;\n    using ReturnType = decltype(\n        original_function(std::forward<decltype(arguments)>(arguments)...));\n\n    static_assert(!std::is_void<ReturnType>::value,\n                  \"Return type of wrapped function must not be void\");\n\n    static auto cache =\n        Internal::construct_from_tuple<CacheType<Arguments, ReturnType>>(\n            cache_args);\n\n    auto key = std::make_tuple(arguments...);\n    auto iterator = cache.find(key);\n\n    if (iterator != cache.end()) {\n      return iterator->second;\n    }\n\n    auto value =\n        original_function(std::forward<decltype(arguments)>(arguments)...);\n    cache.emplace(key, value);\n\n    return value;\n  };\n}\n\n/// Wraps a function with a \"shallow\" LRU timed cache.\n///\n/// Given a function, this function will return a new function, where\n/// \"top-level\" calls are cached. With \"top-level\" or \"shallow\", we mean\n/// that recursive calls to the same function are not cached, since those\n/// will call the original function symbol, not the wrapped one.\n///\n/// \\param original_function The function to wrap.\n/// \\param args Any arguments to forward to the cache.\n/// \\returns A new function with a shallow LRU cache.\ntemplate <typename Function, typename Duration, typename... Args>\nauto timed_wrap(Function original_function, Duration duration, Args&&... args) {\n  return wrap<Function, TimedCache>(\n      original_function, duration, std::forward<Args>(args)...);\n}\n\n}  //  namespace LRU\n\n#endif  // LRU_WRAP_HPP\n"
  },
  {
    "path": "tests/CMakeLists.txt",
    "content": "########################################\n# CONFIG\n########################################\n\nadd_compile_options(-g -Werror -DDEBUG)\n\n########################################\n# DEPENDENCIES\n########################################\n\nadd_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/googletest)\n\nset(GTEST_INCLUDE_DIRS\n  ${gtest_SOURCE_DIR}/include\n  ${gtest_SOURCE_DIR})\n\n########################################\n# INCLUDES\n########################################\n\ninclude_directories(${GTEST_INCLUDE_DIRS})\n\n########################################\n# SOURCES\n########################################\n\nset(TEST_LRU_CACHE_SOURCES\n  move-awareness-test.cpp\n  last-accessed-test.cpp\n  iterator-test.cpp\n  cache-test.cpp\n  timed-cache-test.cpp\n  statistics-test.cpp\n  wrap-test.cpp\n  callback-test.cpp\n)\n\n###########################################################\n## BINARIES\n###########################################################\n\nset(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)\n\n########################################\n# TARGET\n########################################\n\nadd_executable(lru-cache-test ${TEST_LRU_CACHE_SOURCES})\n\ntarget_link_libraries(lru-cache-test gtest gtest_main)\n\nadd_test(\n  NAME lru-cache-test\n  COMMAND lru-cache-test\n  WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}\n)\n"
  },
  {
    "path": "tests/cache-test.cpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#include <algorithm>\n#include <functional>\n#include <string>\n#include <utility>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"lru/lru.hpp\"\n\nusing namespace LRU;\n\nstruct CacheTest : public ::testing::Test {\n  using CacheType = Cache<std::string, int>;\n\n  template <typename Cache, typename Range>\n  bool is_equal_to_range(const Cache& cache, const Range& range) {\n    using std::begin;\n    return std::equal(cache.ordered_begin(), cache.ordered_end(), begin(range));\n  }\n\n  CacheType cache;\n};\n\nTEST(CacheConstructionTest, IsConstructibleFromInitializerList) {\n  Cache<std::string, int> cache = {\n      {\"one\", 1}, {\"two\", 2}, {\"three\", 3},\n  };\n\n  EXPECT_FALSE(cache.is_empty());\n  EXPECT_EQ(cache.size(), 3);\n  EXPECT_EQ(cache[\"one\"], 1);\n  EXPECT_EQ(cache[\"two\"], 2);\n  EXPECT_EQ(cache[\"three\"], 3);\n}\n\nTEST(CacheConstructionTest, IsConstructibleFromInitializerListWithCapacity) {\n  // clang-format off\n  Cache<std::string, int> cache(2, {\n    {\"one\", 1}, {\"two\", 2}, {\"three\", 3},\n  });\n  // clang-format on\n\n  EXPECT_FALSE(cache.is_empty());\n  EXPECT_EQ(cache.size(), 2);\n  EXPECT_FALSE(cache.contains(\"one\"));\n  EXPECT_EQ(cache[\"two\"], 2);\n  EXPECT_EQ(cache[\"three\"], 3);\n}\n\nTEST(CacheConstructionTest, IsConstructibleFromRange) {\n  const std::vector<std::pair<std::string, int>> range = {\n      {\"one\", 1}, {\"two\", 2}, {\"three\", 3}};\n\n  Cache<std::string, int> cache(range);\n\n  EXPECT_FALSE(cache.is_empty());\n  EXPECT_EQ(cache.size(), 3);\n  EXPECT_EQ(cache[\"one\"], 1);\n  EXPECT_EQ(cache[\"two\"], 2);\n  EXPECT_EQ(cache[\"three\"], 3);\n}\n\nTEST(CacheConstructionTest, IsConstructibleFromIterators) {\n  std::vector<std::pair<std::string, int>> range = {\n      {\"one\", 1}, {\"two\", 2}, {\"three\", 3}};\n\n  Cache<std::string, int> cache(range.begin(), range.end());\n\n  EXPECT_FALSE(cache.is_empty());\n  EXPECT_EQ(cache.size(), 3);\n  EXPECT_EQ(cache[\"one\"], 1);\n  EXPECT_EQ(cache[\"two\"], 2);\n  EXPECT_EQ(cache[\"three\"], 3);\n}\n\nTEST(CacheConstructionTest, CapacityIsMaxOfInternalDefaultAndIteratorDistance) {\n  std::vector<std::pair<std::string, int>> range = {\n      {\"one\", 1}, {\"two\", 2}, {\"three\", 3}};\n\n  Cache<std::string, int> cache(range.begin(), range.end());\n\n  EXPECT_EQ(cache.capacity(), Internal::DEFAULT_CAPACITY);\n\n  for (int i = 0; i < Internal::DEFAULT_CAPACITY; ++i) {\n    range.emplace_back(std::to_string(i), i);\n  }\n\n  cache = std::move(range);\n  EXPECT_EQ(cache.capacity(), range.size());\n\n  Cache<std::string, int> cache2(range.begin(), range.end());\n  EXPECT_EQ(cache2.capacity(), range.size());\n}\n\nTEST(CacheConstructionTest, UsesCustomHashFunction) {\n  using MockHash = std::function<int(int)>;\n\n  std::size_t mock_hash_call_count = 0;\n  MockHash mock_hash = [&mock_hash_call_count](int value) {\n    mock_hash_call_count += 1;\n    return value;\n  };\n\n  Cache<int, int, decltype(mock_hash)> cache(128, mock_hash);\n\n  EXPECT_EQ(mock_hash_call_count, 0);\n\n  cache.contains(5);\n  EXPECT_EQ(mock_hash_call_count, 1);\n}\n\nTEST(CacheConstructionTest, UsesCustomKeyEqual) {\n  using MockCompare = std::function<bool(int, int)>;\n\n  std::size_t mock_equal_call_count = 0;\n  MockCompare mock_equal = [&mock_equal_call_count](int a, int b) {\n    mock_equal_call_count += 1;\n    return a == b;\n  };\n\n  Cache<int, int, std::hash<int>, decltype(mock_equal)> cache(\n      128, std::hash<int>(), mock_equal);\n\n  EXPECT_EQ(mock_equal_call_count, 0);\n\n  cache.insert(5, 1);\n  ASSERT_TRUE(cache.contains(5));\n  EXPECT_EQ(mock_equal_call_count, 1);\n}\n\nTEST_F(CacheTest, ContainsAfterInsertion) {\n  ASSERT_TRUE(cache.is_empty());\n\n  for (std::size_t i = 1; i <= 100; ++i) {\n    const auto key = std::to_string(i);\n    cache.insert(key, i);\n    EXPECT_EQ(cache.size(), i);\n    EXPECT_TRUE(cache.contains(key));\n  }\n\n  EXPECT_FALSE(cache.is_empty());\n}\n\nTEST_F(CacheTest, ContainsAfteEmplacement) {\n  ASSERT_TRUE(cache.is_empty());\n\n  for (std::size_t i = 1; i <= 100; ++i) {\n    const auto key = std::to_string(i);\n    cache.emplace(key, i);\n    EXPECT_EQ(cache.size(), i);\n    EXPECT_TRUE(cache.contains(key));\n  }\n\n  EXPECT_FALSE(cache.is_empty());\n}\n\nTEST_F(CacheTest, RemovesLRUElementWhenFull) {\n  cache.capacity(2);\n  ASSERT_EQ(cache.capacity(), 2);\n\n  cache.emplace(\"one\", 1);\n  cache.emplace(\"two\", 2);\n  ASSERT_EQ(cache.size(), 2);\n  ASSERT_TRUE(cache.contains(\"one\"));\n  ASSERT_TRUE(cache.contains(\"two\"));\n\n\n  cache.emplace(\"three\", 3);\n  EXPECT_EQ(cache.size(), 2);\n  EXPECT_TRUE(cache.contains(\"two\"));\n  EXPECT_TRUE(cache.contains(\"three\"));\n  EXPECT_FALSE(cache.contains(\"one\"));\n}\n\nTEST_F(CacheTest, LookupReturnsTheRightValue) {\n  for (std::size_t i = 1; i <= 10; ++i) {\n    const auto key = std::to_string(i);\n    cache.emplace(key, i);\n    ASSERT_EQ(cache.size(), i);\n    EXPECT_EQ(cache.lookup(key), i);\n    EXPECT_EQ(cache[key], i);\n  }\n}\n\nTEST_F(CacheTest, LookupOnlyThrowsWhenKeyNotFound) {\n  cache.emplace(\"one\", 1);\n\n  ASSERT_EQ(cache.size(), 1);\n  EXPECT_EQ(cache.lookup(\"one\"), 1);\n\n  EXPECT_THROW(cache.lookup(\"two\"), LRU::Error::KeyNotFound);\n  EXPECT_THROW(cache.lookup(\"three\"), LRU::Error::KeyNotFound);\n\n  cache.emplace(\"two\", 2);\n  EXPECT_EQ(cache.lookup(\"two\"), 2);\n}\n\nTEST_F(CacheTest, SizeIsUpdatedProperly) {\n  ASSERT_EQ(cache.size(), 0);\n\n  for (std::size_t i = 1; i <= 10; ++i) {\n    cache.emplace(std::to_string(i), i);\n    // Use ASSERT and not EXPECT to terminate the loop early\n    ASSERT_EQ(cache.size(), i);\n  }\n\n  for (std::size_t i = 10; i >= 1; --i) {\n    ASSERT_EQ(cache.size(), i);\n    cache.erase(std::to_string(i));\n    // Use ASSERT and not EXPECT to terminate the loop early\n  }\n\n  EXPECT_EQ(cache.size(), 0);\n}\n\nTEST_F(CacheTest, SpaceLeftWorks) {\n  cache.capacity(10);\n  ASSERT_EQ(cache.size(), 0);\n\n  for (std::size_t i = 10; i >= 1; --i) {\n    EXPECT_EQ(cache.space_left(), i);\n    cache.emplace(std::to_string(i), i);\n  }\n\n  EXPECT_EQ(cache.space_left(), 0);\n}\n\nTEST_F(CacheTest, IsEmptyWorks) {\n  ASSERT_TRUE(cache.is_empty());\n  cache.emplace(\"one\", 1);\n  EXPECT_FALSE(cache.is_empty());\n  cache.clear();\n  EXPECT_TRUE(cache.is_empty());\n}\n\nTEST_F(CacheTest, IsFullWorks) {\n  ASSERT_FALSE(cache.is_full());\n  cache.capacity(0);\n  ASSERT_TRUE(cache.is_full());\n\n  cache.capacity(2);\n  cache.emplace(\"one\", 1);\n  EXPECT_FALSE(cache.is_full());\n  cache.emplace(\"two\", 1);\n  EXPECT_TRUE(cache.is_full());\n\n  cache.clear();\n  EXPECT_FALSE(cache.is_full());\n}\n\nTEST_F(CacheTest, CapacityCanBeAdjusted) {\n  cache.capacity(10);\n\n  ASSERT_EQ(cache.capacity(), 10);\n\n  for (std::size_t i = 0; i < 10; ++i) {\n    cache.emplace(std::to_string(i), i);\n  }\n\n  ASSERT_EQ(cache.size(), 10);\n\n  cache.emplace(\"foo\", 0xdeadbeef);\n  EXPECT_EQ(cache.size(), 10);\n\n  cache.capacity(11);\n  ASSERT_EQ(cache.capacity(), 11);\n\n  cache.emplace(\"bar\", 0xdeadbeef);\n  EXPECT_EQ(cache.size(), 11);\n\n  cache.capacity(5);\n  EXPECT_EQ(cache.capacity(), 5);\n  EXPECT_EQ(cache.size(), 5);\n\n  cache.capacity(0);\n  EXPECT_EQ(cache.capacity(), 0);\n  EXPECT_EQ(cache.size(), 0);\n\n  cache.capacity(128);\n  EXPECT_EQ(cache.capacity(), 128);\n  EXPECT_EQ(cache.size(), 0);\n}\n\nTEST_F(CacheTest, EraseErasesAndReturnsTrueWhenElementContained) {\n  cache.emplace(\"one\", 1);\n  ASSERT_TRUE(cache.contains(\"one\"));\n\n  EXPECT_TRUE(cache.erase(\"one\"));\n  EXPECT_FALSE(cache.contains(\"one\"));\n}\n\nTEST_F(CacheTest, EraseReturnsFalseWhenElementNotContained) {\n  ASSERT_FALSE(cache.contains(\"one\"));\n  EXPECT_FALSE(cache.erase(\"one\"));\n}\n\nTEST_F(CacheTest, ClearRemovesAllElements) {\n  ASSERT_TRUE(cache.is_empty());\n\n  cache.emplace(\"one\", 1);\n  EXPECT_FALSE(cache.is_empty());\n\n  cache.clear();\n  EXPECT_TRUE(cache.is_empty());\n}\n\nTEST_F(CacheTest, ShrinkAdjustsSizeWell) {\n  cache.emplace(\"one\", 1);\n  cache.emplace(\"two\", 2);\n\n  ASSERT_EQ(cache.size(), 2);\n\n  cache.shrink(1);\n\n  EXPECT_EQ(cache.size(), 1);\n\n  cache.emplace(\"three\", 2);\n  cache.emplace(\"four\", 3);\n\n  ASSERT_EQ(cache.size(), 3);\n\n  cache.shrink(1);\n\n  EXPECT_EQ(cache.size(), 1);\n\n  cache.shrink(0);\n\n  EXPECT_TRUE(cache.is_empty());\n}\n\nTEST_F(CacheTest, ShrinkDoesNothingWhenRequestedSizeIsGreaterThanCurrent) {\n  cache.emplace(\"one\", 1);\n  cache.emplace(\"two\", 2);\n\n  ASSERT_EQ(cache.size(), 2);\n\n  cache.shrink(50);\n\n  EXPECT_EQ(cache.size(), 2);\n}\n\nTEST_F(CacheTest, ShrinkRemovesLRUElements) {\n  cache.emplace(\"one\", 1);\n  cache.emplace(\"two\", 2);\n  cache.emplace(\"three\", 3);\n\n  ASSERT_EQ(cache.size(), 3);\n\n  cache.shrink(2);\n\n  EXPECT_EQ(cache.size(), 2);\n  EXPECT_FALSE(cache.contains(\"one\"));\n  EXPECT_TRUE(cache.contains(\"two\"));\n  EXPECT_TRUE(cache.contains(\"three\"));\n\n  cache.shrink(1);\n\n  EXPECT_EQ(cache.size(), 1);\n  EXPECT_FALSE(cache.contains(\"one\"));\n  EXPECT_FALSE(cache.contains(\"two\"));\n  EXPECT_TRUE(cache.contains(\"three\"));\n}\n\nTEST_F(CacheTest, CanInsertIterators) {\n  using Range = std::vector<std::pair<std::string, int>>;\n  Range range = {{\"one\", 1}, {\"two\", 2}, {\"three\", 3}};\n\n  EXPECT_EQ(cache.insert(range.begin(), range.end()), 3);\n  EXPECT_TRUE(is_equal_to_range(cache, range));\n\n  Range range2 = {{\"one\", 1}, {\"four\", 4}};\n\n  EXPECT_EQ(cache.insert(range2.begin(), range2.end()), 1);\n  // clang-format off\n  EXPECT_TRUE(is_equal_to_range(cache, Range({\n    {\"two\", 2}, {\"three\", 3}, {\"one\", 1}, {\"four\", 4}\n  })));\n  // clang-format on\n}\n\nTEST_F(CacheTest, CanInsertRange) {\n  std::vector<std::pair<std::string, int>> range = {\n      {\"one\", 1}, {\"two\", 2}, {\"three\", 3}};\n\n  cache.insert(range);\n  EXPECT_TRUE(is_equal_to_range(cache, range));\n}\n\nTEST_F(CacheTest, CanInsertList) {\n  std::initializer_list<std::pair<std::string, int>> list = {\n      {\"one\", 1}, {\"two\", 2}, {\"three\", 3}};\n\n  // Do it like this, just to verify that template deduction fails if only\n  // the range function exists and no explicit overload for the initializer list\n  cache.insert({{\"one\", 1}, {\"two\", 2}, {\"three\", 3}});\n  EXPECT_TRUE(is_equal_to_range(cache, list));\n}\n\nTEST_F(CacheTest, ResultIsCorrectForInsert) {\n  auto result = cache.insert(\"one\", 1);\n\n  EXPECT_TRUE(result.was_inserted());\n  EXPECT_TRUE(result);\n\n  EXPECT_EQ(result.iterator(), cache.begin());\n\n  result = cache.insert(\"one\", 1);\n\n  EXPECT_FALSE(result.was_inserted());\n  EXPECT_FALSE(result);\n\n  EXPECT_EQ(result.iterator(), cache.begin());\n}\n\nTEST_F(CacheTest, ResultIsCorrectForEmplace) {\n  auto result = cache.emplace(\"one\", 1);\n\n  EXPECT_TRUE(result.was_inserted());\n  EXPECT_TRUE(result);\n\n  EXPECT_EQ(result.iterator(), cache.begin());\n\n  result = cache.emplace(\"one\", 1);\n\n  EXPECT_FALSE(result.was_inserted());\n  EXPECT_FALSE(result);\n\n  EXPECT_EQ(result.iterator(), cache.begin());\n}\n\nTEST_F(CacheTest, CapacityIsSameAfterCopy) {\n  cache.capacity(100);\n  auto cache2 = cache;\n\n  EXPECT_EQ(cache.capacity(), cache2.capacity());\n}\n\nTEST_F(CacheTest, CapacityIsSameAfterMove) {\n  cache.capacity(100);\n  auto cache2 = std::move(cache);\n\n  EXPECT_EQ(cache2.capacity(), 100);\n}\n\nTEST_F(CacheTest, ComparisonOperatorWorks) {\n  ASSERT_EQ(cache, cache);\n\n  auto cache2 = cache;\n  EXPECT_EQ(cache, cache2);\n\n  cache.emplace(\"one\", 1);\n  cache2.emplace(\"one\", 1);\n  EXPECT_EQ(cache, cache2);\n\n  cache.emplace(\"two\", 2);\n  cache2.emplace(\"two\", 2);\n  EXPECT_EQ(cache, cache2);\n\n  cache.erase(\"two\");\n  EXPECT_NE(cache, cache2);\n}\n\nTEST_F(CacheTest, SwapWorks) {\n  auto cache2 = cache;\n\n  cache.emplace(\"one\", 1);\n  cache2.emplace(\"two\", 2);\n\n  ASSERT_TRUE(cache.contains(\"one\"));\n  ASSERT_TRUE(cache2.contains(\"two\"));\n\n  cache.swap(cache2);\n\n  EXPECT_FALSE(cache.contains(\"one\"));\n  EXPECT_TRUE(cache.contains(\"two\"));\n  EXPECT_FALSE(cache2.contains(\"two\"));\n  EXPECT_TRUE(cache2.contains(\"one\"));\n}\n\nTEST_F(CacheTest, SizeStaysZeroWhenCapacityZero) {\n  cache.capacity(0);\n\n  ASSERT_EQ(cache.capacity(), 0);\n  ASSERT_EQ(cache.size(), 0);\n\n  auto result = cache.insert(\"one\", 1);\n\n  EXPECT_EQ(cache.capacity(), 0);\n  EXPECT_EQ(cache.size(), 0);\n  EXPECT_FALSE(result.was_inserted());\n  EXPECT_EQ(result.iterator(), cache.end());\n\n  result = cache.emplace(\"two\", 2);\n\n  EXPECT_EQ(cache.capacity(), 0);\n  EXPECT_EQ(cache.size(), 0);\n  EXPECT_FALSE(result.was_inserted());\n  EXPECT_EQ(result.iterator(), cache.end());\n}\n\nTEST_F(CacheTest, LookupsMoveElementsToFront) {\n  cache.capacity(2);\n  cache.insert({{\"one\", 1}, {\"two\", 2}});\n\n  // The LRU principle mandates that lookups place\n  // accessed elements to the front.\n\n  typename CacheType::OrderedIterator iterator(cache.find(\"one\"));\n  cache.emplace(\"three\", 3);\n\n  EXPECT_TRUE(cache.contains(\"one\"));\n  EXPECT_FALSE(cache.contains(\"two\"));\n  EXPECT_TRUE(cache.contains(\"three\"));\n  EXPECT_EQ(std::prev(cache.ordered_end()).key(), \"three\");\n  EXPECT_EQ(cache.front(), \"three\");\n  EXPECT_EQ(cache.back(), \"one\");\n\n  ASSERT_EQ(cache.lookup(\"one\"), 1);\n  EXPECT_EQ(std::prev(cache.ordered_end()).key(), \"one\");\n  EXPECT_EQ(cache.ordered_begin().key(), \"three\");\n  EXPECT_EQ(cache.front(), \"one\");\n  EXPECT_EQ(cache.back(), \"three\");\n}\n"
  },
  {
    "path": "tests/callback-test.cpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#include <array>\n\n#include \"gtest/gtest.h\"\n\n#include \"lru/lru.hpp\"\n\nusing namespace LRU;\n\nstruct CallbackTest : public ::testing::Test {\n  Cache<int, int> cache;\n};\n\nTEST_F(CallbackTest, HitCallbacksGetCalled) {\n  std::array<int, 3> counts = {0, 0, 0};\n\n  cache.hit_callback([&counts](auto& key, auto& value) { counts[key] += 1; });\n\n  cache.emplace(0, 0);\n  cache.emplace(1, 1);\n  cache.emplace(2, 2);\n\n  ASSERT_TRUE(cache.contains(0));\n  EXPECT_EQ(counts[0], 1);\n  EXPECT_EQ(counts[1], 0);\n  EXPECT_EQ(counts[2], 0);\n\n  cache.find(2);\n  EXPECT_EQ(counts[0], 1);\n  EXPECT_EQ(counts[1], 0);\n  EXPECT_EQ(counts[2], 1);\n\n  cache.lookup(1);\n  EXPECT_EQ(counts[0], 1);\n  EXPECT_EQ(counts[1], 1);\n  EXPECT_EQ(counts[2], 1);\n\n  cache.lookup(0);\n  EXPECT_EQ(counts[0], 2);\n  EXPECT_EQ(counts[1], 1);\n  EXPECT_EQ(counts[2], 1);\n\n  cache.contains(5);\n  EXPECT_EQ(counts[0], 2);\n  EXPECT_EQ(counts[1], 1);\n  EXPECT_EQ(counts[2], 1);\n}\n\nTEST_F(CallbackTest, MissCallbacksGetCalled) {\n  std::array<int, 3> counts = {0, 0, 0};\n\n  cache.miss_callback([&counts](auto& key) { counts[key] += 1; });\n\n  cache.emplace(0, 0);\n\n  ASSERT_TRUE(cache.contains(0));\n  EXPECT_EQ(counts[0], 0);\n  EXPECT_EQ(counts[1], 0);\n  EXPECT_EQ(counts[2], 0);\n\n  cache.find(2);\n  EXPECT_EQ(counts[0], 0);\n  EXPECT_EQ(counts[1], 0);\n  EXPECT_EQ(counts[2], 1);\n\n  cache.find(1);\n  EXPECT_EQ(counts[0], 0);\n  EXPECT_EQ(counts[1], 1);\n  EXPECT_EQ(counts[2], 1);\n\n  cache.contains(1);\n  EXPECT_EQ(counts[0], 0);\n  EXPECT_EQ(counts[1], 2);\n  EXPECT_EQ(counts[2], 1);\n}\n\nTEST_F(CallbackTest, AccessCallbacksGetCalled) {\n  std::array<int, 3> counts = {0, 0, 0};\n\n  cache.access_callback(\n      [&counts](auto& key, bool found) { counts[key] += found ? 1 : -1; });\n\n  cache.emplace(0, 0);\n\n  ASSERT_TRUE(cache.contains(0));\n  EXPECT_EQ(counts[0], 1);\n  EXPECT_EQ(counts[1], 0);\n  EXPECT_EQ(counts[2], 0);\n\n  cache.find(2);\n  EXPECT_EQ(counts[0], 1);\n  EXPECT_EQ(counts[1], 0);\n  EXPECT_EQ(counts[2], -1);\n\n  cache.find(1);\n  EXPECT_EQ(counts[0], 1);\n  EXPECT_EQ(counts[1], -1);\n  EXPECT_EQ(counts[2], -1);\n\n  cache.contains(1);\n  EXPECT_EQ(counts[0], 1);\n  EXPECT_EQ(counts[1], -2);\n  EXPECT_EQ(counts[2], -1);\n\n  cache.find(0);\n  EXPECT_EQ(counts[0], 2);\n  EXPECT_EQ(counts[1], -2);\n  EXPECT_EQ(counts[2], -1);\n}\n\nTEST_F(CallbackTest, CallbacksAreNotCalledAfterBeingCleared) {\n  int hit = 0, miss = 0, access = 0;\n  cache.hit_callback([&hit](auto&, auto&) { hit += 1; });\n  cache.miss_callback([&miss](auto&) { miss += 1; });\n  cache.access_callback([&access](auto&, bool) { access += 1; });\n\n  cache.emplace(0, 0);\n\n  cache.contains(0);\n  cache.find(1);\n\n  ASSERT_EQ(hit, 1);\n  ASSERT_EQ(miss, 1);\n  ASSERT_EQ(access, 2);\n\n  cache.clear_all_callbacks();\n\n  cache.contains(0);\n  cache.find(1);\n  cache.find(2);\n\n  ASSERT_EQ(hit, 1);\n  ASSERT_EQ(miss, 1);\n  ASSERT_EQ(access, 2);\n}\n"
  },
  {
    "path": "tests/iterator-test.cpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#include <chrono>\n#include <string>\n#include <thread>\n\n#include \"gtest/gtest.h\"\n#include \"lru/lru.hpp\"\n\nusing namespace LRU;\nusing namespace std::chrono_literals;\n\nstruct IteratorTest : public ::testing::Test {\n  using CacheType = Cache<std::string, int>;\n  using UnorderedIterator = typename CacheType::UnorderedIterator;\n  using UnorderedConstIterator = typename CacheType::UnorderedConstIterator;\n  using OrderedIterator = typename CacheType::OrderedIterator;\n  using OrderedConstIterator = typename CacheType::OrderedConstIterator;\n\n  CacheType cache;\n};\n\nTEST_F(IteratorTest, UnorderedIteratorsAreCompatibleAsExpected) {\n  cache.emplace(\"one\", 1);\n\n  // Move construction\n  UnorderedIterator first(cache.unordered_begin());\n\n  // Copy construction\n  UnorderedIterator second(first);\n\n  // Copy assignment\n  UnorderedIterator third;\n  third = second;\n\n  // Move construction from non-const to const\n  UnorderedConstIterator first_const(std::move(first));\n\n  // Copy construction from non-const to const\n  UnorderedConstIterator second_const(second);\n\n  // Copy assignment\n  UnorderedConstIterator third_const;\n  third_const = third;\n}\n\nTEST_F(IteratorTest, OrderedIteratorsAreCompatibleAsExpected) {\n  cache.emplace(\"one\", 1);\n\n  // Move construction\n  OrderedIterator first(cache.ordered_begin());\n\n  // Copy construction\n  OrderedIterator second(first);\n\n  // Copy assignment\n  OrderedIterator third;\n  third = second;\n\n  // Move construction from non-const to const\n  OrderedConstIterator first_const(std::move(first));\n\n  // Copy construction from non-const to const\n  OrderedConstIterator second_const(second);\n\n  // Copy assignment\n  OrderedConstIterator third_const;\n  third_const = third;\n}\n\nTEST_F(IteratorTest, OrderedAndUnorderedAreComparable) {\n  cache.emplace(\"one\", 1);\n\n  // Basic assumptions\n  ASSERT_EQ(cache.unordered_begin(), cache.unordered_begin());\n  ASSERT_EQ(cache.ordered_begin(), cache.ordered_begin());\n  ASSERT_EQ(cache.unordered_end(), cache.unordered_end());\n  ASSERT_EQ(cache.ordered_end(), cache.ordered_end());\n\n  EXPECT_EQ(cache.unordered_begin(), cache.ordered_begin());\n\n  // We need to ensure symmetry!\n  EXPECT_EQ(cache.ordered_begin(), cache.unordered_begin());\n\n  // This is an exceptional property we expect\n  EXPECT_EQ(cache.unordered_end(), cache.ordered_end());\n  EXPECT_EQ(cache.ordered_end(), cache.unordered_end());\n\n  // These assumptions should hold because there is only one element\n  // so the unordered iterator will convert to an ordered iterator, then\n  // compare equal because both point to the same single element.\n  EXPECT_EQ(cache.ordered_begin(), cache.unordered_begin());\n  EXPECT_EQ(cache.unordered_begin(), cache.ordered_begin());\n\n  cache.emplace(\"two\", 1);\n\n  // But then the usual assumptions should hold\n  EXPECT_NE(cache.ordered_begin(), cache.find(\"two\"));\n  EXPECT_NE(cache.find(\"two\"), cache.ordered_begin());\n}\n\nTEST_F(IteratorTest, TestConversionFromUnorderedToOrdered) {\n  cache.emplace(\"one\", 1);\n  cache.emplace(\"two\", 2);\n  cache.emplace(\"three\", 3);\n\n  // Note: find() will always return end() - 1\n  UnorderedIterator unordered = cache.find(\"one\");\n\n  ASSERT_EQ(unordered.key(), \"one\");\n  ASSERT_EQ(unordered.value(), 1);\n\n  OrderedIterator ordered(unordered);\n  ordered = OrderedIterator(unordered);\n\n  EXPECT_EQ(ordered.key(), \"one\");\n  EXPECT_EQ(ordered.value(), 1);\n\n  // Once it's ordered, the ordering shold be maintained\n  --ordered;\n  EXPECT_EQ(ordered.key(), \"three\");\n  EXPECT_EQ(ordered.value(), 3);\n\n  UnorderedConstIterator const_unordered = unordered;\n  const_unordered = unordered;\n\n  OrderedConstIterator const_ordered(std::move(const_unordered));\n  const_ordered = OrderedConstIterator(std::move(const_unordered));\n\n  // Just making sure this compiles\n  const_ordered = --ordered;\n  const_ordered = OrderedConstIterator(unordered);\n\n  EXPECT_EQ(ordered.key(), \"two\");\n  EXPECT_EQ(ordered.value(), 2);\n}\n\nTEST_F(IteratorTest, OrdereredIteratorsAreOrdered) {\n  for (std::size_t i = 0; i < 100; ++i) {\n    cache.emplace(std::to_string(i), i);\n  }\n\n  auto iterator = cache.ordered_begin();\n  for (std::size_t i = 0; i < 100; ++i, ++iterator) {\n    ASSERT_EQ(iterator.value(), i);\n  }\n}\n\nTEST_F(IteratorTest, OrderedIteratorsDoNotChangeTheOrderOfElements) {\n  cache.capacity(2);\n  cache.insert({{\"one\", 1}});\n\n  auto begin = cache.ordered_begin();\n\n  cache.emplace(\"two\", 2);\n\n  // This here will cause a lookup, but it should not\n  // change the order of elements\n  ASSERT_EQ(begin->key(), \"one\");\n  ASSERT_EQ((++begin)->key(), \"two\");\n  ASSERT_EQ((--begin)->key(), \"one\");\n  cache.emplace(\"three\", 3);\n\n  EXPECT_FALSE(cache.contains(\"one\"));\n  EXPECT_TRUE(cache.contains(\"two\"));\n  EXPECT_TRUE(cache.contains(\"three\"));\n}\n\nTEST_F(IteratorTest, UnorderedIteratorsDoNotChangeTheOrderOfElements) {\n  cache.capacity(2);\n  cache.insert({{\"one\", 1}});\n\n  auto begin = cache.unordered_begin();\n\n  cache.emplace(\"two\", 2);\n\n  ASSERT_EQ(begin->key(), \"one\");\n  cache.emplace(\"three\", 3);\n\n  EXPECT_FALSE(cache.contains(\"one\"));\n  EXPECT_TRUE(cache.contains(\"two\"));\n  EXPECT_TRUE(cache.contains(\"three\"));\n\n  ASSERT_EQ(cache.back(), \"two\");\n  ASSERT_EQ(cache.front(), \"three\");\n}\n\n\nTEST_F(IteratorTest, OrderedIteratorsThrowWhenAccessingExpiredElements) {\n  TimedCache<int, int> timed_cache(0ms);\n\n  timed_cache.emplace(1, 1);\n\n  auto iterator = timed_cache.ordered_begin();\n\n  EXPECT_THROW(iterator.entry(), LRU::Error::KeyExpired);\n}\n\nTEST_F(IteratorTest, UnorderedIteratorsThrowWhenAccessingExpiredElements) {\n  TimedCache<int, int> timed_cache(0ms);\n\n  timed_cache.emplace(1, 1);\n\n  auto iterator = timed_cache.unordered_begin();\n\n  EXPECT_THROW(iterator.entry(), LRU::Error::KeyExpired);\n}\n\nTEST_F(IteratorTest, IsValidReturnsTrueForValidIterators) {\n  cache.emplace(\"one\", 1);\n  cache.emplace(\"two\", 1);\n\n  auto ordered_iterator = cache.ordered_begin();\n  EXPECT_TRUE(cache.is_valid(ordered_iterator));\n  EXPECT_TRUE(cache.is_valid(++ordered_iterator));\n\n  auto unordered_iterator = cache.unordered_begin();\n  EXPECT_TRUE(cache.is_valid(unordered_iterator));\n  EXPECT_TRUE(cache.is_valid(++unordered_iterator));\n}\n\nTEST_F(IteratorTest, IsValidReturnsFalseForInvalidIterators) {\n  TimedCache<int, int> timed_cache(0ms);\n\n  EXPECT_FALSE(cache.is_valid(cache.ordered_begin()));\n  EXPECT_FALSE(cache.is_valid(cache.ordered_end()));\n  EXPECT_FALSE(cache.is_valid(cache.unordered_begin()));\n  EXPECT_FALSE(cache.is_valid(cache.unordered_end()));\n\n  timed_cache.emplace(1, 1);\n\n  EXPECT_FALSE(cache.is_valid(cache.ordered_begin()));\n  EXPECT_FALSE(cache.is_valid(cache.unordered_begin()));\n}\n\nTEST_F(IteratorTest, ThrowIfInvalidThrowsAsExpected) {\n  EXPECT_THROW(cache.throw_if_invalid(cache.ordered_begin()),\n               LRU::Error::InvalidIterator);\n  EXPECT_THROW(cache.throw_if_invalid(cache.ordered_end()),\n               LRU::Error::InvalidIterator);\n  EXPECT_THROW(cache.throw_if_invalid(cache.unordered_begin()),\n               LRU::Error::InvalidIterator);\n  EXPECT_THROW(cache.throw_if_invalid(cache.unordered_end()),\n               LRU::Error::InvalidIterator);\n\n  TimedCache<int, int> timed_cache(0s, {{1, 1}});\n\n  ASSERT_EQ(timed_cache.size(), 1);\n\n  EXPECT_THROW(timed_cache.throw_if_invalid(timed_cache.ordered_begin()),\n               LRU::Error::KeyExpired);\n  EXPECT_THROW(timed_cache.throw_if_invalid(timed_cache.unordered_begin()),\n               LRU::Error::KeyExpired);\n}\n\nTEST_F(IteratorTest, DereferencingNeverThrows) {\n  TimedCache<int, int> timed_cache(1ms, {{1, 1}});\n\n  // Test valid iterators.\n  EXPECT_EQ(timed_cache.ordered_begin()->key(), 1);\n  EXPECT_EQ(timed_cache.unordered_begin()->key(), 1);\n\n  std::this_thread::sleep_for(1ms);\n\n  // Test invalid iterators.\n  *timed_cache.ordered_begin();\n  *timed_cache.unordered_begin();\n  timed_cache.ordered_begin()->key();\n  timed_cache.unordered_begin()->key();\n  timed_cache.ordered_begin()->value();\n  timed_cache.unordered_begin()->value();\n}\n\nTEST_F(IteratorTest, CallingAccessThrowsForInvalidIterators) {\n  TimedCache<int, int> timed_cache(1ms, {{1, 1}});\n\n  // Test valid iterators.\n  ASSERT_EQ(timed_cache.ordered_begin()->key(), 1);\n  ASSERT_EQ(timed_cache.unordered_begin()->key(), 1);\n\n  std::this_thread::sleep_for(1ms);\n\n  // Test invalid iterators.\n  EXPECT_THROW(timed_cache.ordered_begin().key(), LRU::Error::KeyExpired);\n  EXPECT_THROW(timed_cache.unordered_begin().key(), LRU::Error::KeyExpired);\n  EXPECT_THROW(timed_cache.ordered_begin().value(), LRU::Error::KeyExpired);\n  EXPECT_THROW(timed_cache.unordered_begin().value(), LRU::Error::KeyExpired);\n  EXPECT_THROW(timed_cache.ordered_end().key(), LRU::Error::InvalidIterator);\n  EXPECT_THROW(timed_cache.unordered_end().key(), LRU::Error::InvalidIterator);\n  EXPECT_THROW(timed_cache.ordered_end().value(), LRU::Error::InvalidIterator);\n  EXPECT_THROW(timed_cache.unordered_end().value(),\n               LRU::Error::InvalidIterator);\n}\n"
  },
  {
    "path": "tests/last-accessed-test.cpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n\n#include <iterator>\n#include <string>\n#include <unordered_map>\n\n#include \"gtest/gtest.h\"\n#include \"lru/internal/last-accessed.hpp\"\n\nusing namespace LRU::Internal;\n\nstruct LastAccessedTest : public ::testing::Test {\n  using Map = std::unordered_map<std::string, int>;\n  static Map map;\n};\n\n// clang-format off\nLastAccessedTest::Map LastAccessedTest::map = {\n  {\"one\", 1},\n  {\"two\", 2},\n  {\"three\", 3}\n};\n// clang-format on\n\nTEST_F(LastAccessedTest, IsAssignableFromConstAndNonConst) {\n  auto front = map.find(\"one\");\n\n  LastAccessed<std::string, int> last_accessed(front->first, front->second);\n\n  ASSERT_EQ(last_accessed.key(), \"one\");\n  ASSERT_EQ(last_accessed.information(), 1);\n\n  last_accessed = map.find(\"two\");\n\n  EXPECT_EQ(last_accessed.key(), \"two\");\n  EXPECT_EQ(last_accessed.information(), 2);\n\n  last_accessed = map.find(\"three\");\n\n  EXPECT_EQ(last_accessed.key(), \"three\");\n  EXPECT_EQ(last_accessed.information(), 3);\n}\n\nTEST_F(LastAccessedTest, IsComparableWithConstAndNonConstIterators) {\n  auto front = map.find(\"one\");\n  LastAccessed<std::string, int> last_accessed(front->first, front->second);\n\n  // non-const\n  EXPECT_EQ(last_accessed, front);\n  EXPECT_EQ(front, last_accessed);\n\n  EXPECT_NE(map.find(\"two\"), last_accessed);\n  EXPECT_NE(last_accessed, map.find(\"three\"));\n\n  // const\n  Map::const_iterator const_front = map.find(\"one\");\n  EXPECT_EQ(last_accessed, const_front);\n  EXPECT_EQ(const_front, last_accessed);\n\n  Map::const_iterator iterator = map.find(\"two\");\n  EXPECT_NE(iterator, last_accessed);\n\n  iterator = map.find(\"three\");\n  EXPECT_NE(last_accessed, iterator);\n}\n\nTEST_F(LastAccessedTest, IsComparableToConstAndNonConstKeys) {\n  using namespace std::string_literals;\n\n  std::string key = \"forty-two\";\n  int information = 42;\n\n  LastAccessed<std::string, int> last_accessed(key, information);\n\n  EXPECT_EQ(last_accessed, key);\n  EXPECT_EQ(key, last_accessed);\n\n  EXPECT_EQ(last_accessed, \"forty-two\"s);\n  EXPECT_EQ(\"forty-two\"s, last_accessed);\n\n  const std::string& key_const_reference = key;\n\n  EXPECT_EQ(key_const_reference, last_accessed);\n  EXPECT_EQ(last_accessed, key_const_reference);\n\n  EXPECT_NE(last_accessed, \"asdf\"s);\n  EXPECT_NE(last_accessed, \"foo\"s);\n  EXPECT_NE(last_accessed, \"forty-three\"s);\n}\n"
  },
  {
    "path": "tests/logbt.sh",
    "content": "#!/bin/bash\n\n# Taken from:\n# https://github.com/mapbox/logbt\n\nset -eu\nset -o pipefail\nshopt -s nullglob\n\nexport CORE_DIRECTORY=/tmp/logbt-coredumps\n\nfunction error() {\n  >&2 echo \"$@\"\n  exit 1\n}\n\nif [[ $(uname -s) == 'Linux' ]]; then\n  if ! which gdb > /dev/null; then\n    error \"Could not find required command 'gdb'\"\n  fi\n\n  # if we have sudo then set core pattern\n  if [[ $(id -u) == 0 ]]; then\n    echo \"Setting $(cat /proc/sys/kernel/core_pattern) -> ${CORE_DIRECTORY}/core.%p.%E\"\n    echo \"${CORE_DIRECTORY}/core.%p.%E\" > /proc/sys/kernel/core_pattern\n  else\n    # if we cannot modify the pattern we assert it has\n    # already been set as we expect and need\n    if [[ $(cat /proc/sys/kernel/core_pattern) != '/tmp/logbt-coredumps/core.%p.%E' ]]; then\n      error \"unexpected core_pattern: $(cat /proc/sys/kernel/core_pattern)\"\n      exit 1\n    fi\n    echo \"Using existing corefile location: $(cat /proc/sys/kernel/core_pattern)\"\n  fi\nelse\n  if ! which lldb > /dev/null; then\n    error \"Could not find required command 'lldb'\"\n    exit 1\n  fi\n\n  # if we have sudo then set core pattern\n  if [[ $(id -u) == 0 ]]; then\n    sudo sysctl kern.corefile=${CORE_DIRECTORY}/core.%P\n  else\n    if [[ $(sysctl -n kern.corefile) == '/cores/core.%P' ]]; then\n      # OS X default is /cores/core.%P which works for logbt out of the box\n      export CORE_DIRECTORY=/cores\n    elif [[ $(sysctl -n kern.corefile) == '${CORE_DIRECTORY}/core.%P' ]]; then\n      # all good, previously set\n      :\n    else\n      # restore default with:\n      # sudo sysctl kern.corefile=/cores/core.%P\n      error \"unexpected core_pattern: $(sysctl -n kern.corefile)\"\n      exit 1\n    fi\n    echo \"Using existing corefile location: $(sysctl -n kern.corefile)\"\n  fi\n\n  # Recommend running with the following setting to only show crashes\n  # in the notification center\n  # defaults write com.apple.CrashReporter UseUNC 1\nfi\n\nif [[ ! -d ${CORE_DIRECTORY} ]]; then\n  # TODO: enable this once tests are adapted to extra stdout\n  # echo \"Creating directory for core files at '${CORE_DIRECTORY}'\"\n  mkdir -p ${CORE_DIRECTORY}\nfi\n\n# ensure we can write to the directory, otherwise\n# core files might not be able to be written\nWRITE_RETURN=0\ntouch ${CORE_DIRECTORY}/test.txt || WRITE_RETURN=$?\nif [[ ${WRITE_RETURN} != 0 ]]; then\n  error \"Permissions problem: unable to write to ${CORE_DIRECTORY} (exited with ${WRITE_RETURN})\"\n  exit 1\nelse\n  # cleanup from test\n  rm ${CORE_DIRECTORY}/test.txt\nfi\n\nfunction process_core() {\n  if [[ $(uname -s) == 'Darwin' ]]; then\n    lldb --core ${2} --batch -o 'thread backtrace all' -o 'quit'\n  else\n    gdb ${1} --core ${2} -ex \"set pagination 0\" -ex \"thread apply all bt\" --batch\n  fi\n  # note: on OS X the -f avoids a hang on prompt 'remove write-protected regular file?'\n  rm -f ${2}\n}\n\nfunction backtrace {\n  local code=$?\n  echo \"$1 exited with code:${code}\"\n  if [[ $(uname -s) == 'Darwin' ]]; then\n    local COREFILE=\"${CORE_DIRECTORY}/core.${CHILD_PID}\"\n    if [ -e ${COREFILE} ]; then\n      echo \"Found core at ${COREFILE}\"\n      process_core $1 ${COREFILE}\n    else\n      if [[ ${code} != 0 ]]; then\n          echo \"No core found at ${COREFILE}\"\n      fi\n    fi\n  else\n    local SEARCH_PATTERN_BY_PID=\"core.${CHILD_PID}.*\"\n    local hit=false\n    for corefile in ${CORE_DIRECTORY}/${SEARCH_PATTERN_BY_PID}; do\n      echo \"Found core at ${corefile}\"\n      # extract program name from corefile\n      filename=$(basename \"${corefile}\")\n      binary_program=/$(echo ${filename##*.\\!} | tr '!' '/')\n      process_core ${binary_program} ${corefile}\n      hit=true\n    done\n    if [[ ${hit} == false ]] && [[ ${code} != 0 ]]; then\n        echo \"No core found at ${CORE_DIRECTORY}/${SEARCH_PATTERN_BY_PID}\"\n    fi\n  fi\n  local SEARCH_PATTERN_NON_TRACKED=\"core.*\"\n  local hit=false\n  for corefile in ${CORE_DIRECTORY}/${SEARCH_PATTERN_NON_TRACKED}; do\n    echo \"Found non-tracked core at ${corefile}\"\n    hit=true\n  done\n  if [[ ${code} != 0 ]]; then\n    if [[ ${hit} == true ]]; then\n      echo \"Processing cores...\"\n    fi\n    for corefile in ${CORE_DIRECTORY}/${SEARCH_PATTERN_NON_TRACKED}; do\n      filename=$(basename \"${corefile}\")\n      binary_program=/$(echo ${filename##*.\\!} | tr '!' '/')\n      process_core ${binary_program} ${corefile}\n    done\n  else\n    if [[ ${hit} == true ]]; then\n      echo \"Skipping processing cores...\"\n    fi\n  fi\n  exit $code\n}\n\nfunction warn_on_existing_cores() {\n  local SEARCH_PATTERN_NON_TRACKED=\"core.*\"\n  # at startup warn about existing corefiles, since these are unexpected\n  for corefile in ${CORE_DIRECTORY}/${SEARCH_PATTERN_NON_TRACKED}; do\n    echo \"WARNING: Found existing corefile at ${corefile}\"\n  done\n}\n\nwarn_on_existing_cores\n\n# Hook up function to run when logbt exits\ntrap \"backtrace $1\" EXIT\n\n# Enable corefile generation\nulimit -c unlimited\n\n# Run the child process in a background process\n# in order to get the PID\n$* & export CHILD_PID=$!\n\n# Keep logbt running as long as the child is running\n# to be able to hook into a potential crash\nwait ${CHILD_PID}\n"
  },
  {
    "path": "tests/move-aware-dummies.hpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#include <cstddef>\n#include <string>\n#include <utility>\n\ntemplate <typename SubClassTemplateParameterJustForNewStaticMembersHehehe>\nstruct MoveAwareBase {\n  static std::size_t move_count;\n  static std::size_t non_move_count;\n  static std::size_t forwarding_count;\n  static std::size_t copy_count;\n\n  static void reset() {\n    move_count = 0;\n    non_move_count = 0;\n    forwarding_count = 0;\n    copy_count = 0;\n  }\n\n  MoveAwareBase(const MoveAwareBase& other) : s(other.s) {\n    copy_count += 1;\n  }\n\n  MoveAwareBase(MoveAwareBase&& other) : s(std::move(other.s)) {\n    // Just need to implement so it's not deactivated\n    // (because we do need the copy constructor)\n  }\n\n  MoveAwareBase(std::string&& s_) : s(std::move(s_)) {\n    move_count += 1;\n  }\n\n  MoveAwareBase(std::string& s_) : s(s_) {\n    non_move_count += 1;\n  }\n\n  MoveAwareBase(const char* s_) : s(s_) {\n    forwarding_count += 1;\n  }\n\n  MoveAwareBase(const int& x, const double& y)\n  : s(std::to_string(x) + std::to_string(y)) {\n    non_move_count += 1;\n  }\n\n  MoveAwareBase(int&& x, double&& y)\n  : s(std::to_string(x) + std::to_string(y)) {\n    move_count += 1;\n  }\n\n  virtual ~MoveAwareBase() = default;\n\n  MoveAwareBase& operator=(const MoveAwareBase& other) {\n    copy_count += 1;\n    s = other.s;\n    return *this;\n  }\n\n  MoveAwareBase& operator=(MoveAwareBase&& other) {\n    s = std::move(other.s);\n    return *this;\n  }\n\n  bool operator==(const MoveAwareBase& other) const noexcept {\n    return this->s == other.s;\n  }\n\n  bool operator!=(const MoveAwareBase& other) const noexcept {\n    return !(*this == other);\n  }\n\n  std::string s;\n};\n\ntemplate <typename T>\nstd::size_t MoveAwareBase<T>::move_count = 0;\n\ntemplate <typename T>\nstd::size_t MoveAwareBase<T>::non_move_count = 0;\n\ntemplate <typename T>\nstd::size_t MoveAwareBase<T>::forwarding_count = 0;\n\ntemplate <typename T>\nstd::size_t MoveAwareBase<T>::copy_count = 0;\n\nstruct MoveAwareKey : public MoveAwareBase<MoveAwareKey> {\n  using super = MoveAwareBase<MoveAwareKey>;\n\n  // clang-format off\n  MoveAwareKey() = default;\n  MoveAwareKey(const MoveAwareKey& other) : super(other) {}\n  MoveAwareKey(MoveAwareKey&& other) : super(std::move(other)) {}\n  MoveAwareKey(std::string&& s_) : super(std::move(s_)) {}\n  MoveAwareKey(std::string& s_) : super(s_) {}\n  MoveAwareKey(const char* s_) : super(s_) {}\n  MoveAwareKey(const int& x, const double& y) : super(x, y) {}\n  MoveAwareKey(int&& x, double&& y) : super(std::move(x), std::move(y)) {}\n  // clang-format on\n\n  MoveAwareKey& operator=(const MoveAwareKey& other) {\n    super::operator=(other);\n    return *this;\n  }\n\n  MoveAwareKey& operator=(MoveAwareKey&& other) {\n    super::operator=(std::move(other));\n    return *this;\n  }\n};\n\nstruct MoveAwareValue : public MoveAwareBase<MoveAwareValue> {\n  using super = MoveAwareBase<MoveAwareValue>;\n\n  // clang-format off\n  MoveAwareValue() = default;\n  MoveAwareValue(const MoveAwareValue& other) : super(other) {}\n  MoveAwareValue(MoveAwareValue&& other) : super(std::move(other)) {}\n  MoveAwareValue(std::string&& s_) : super(std::move(s_)) {}\n  MoveAwareValue(std::string& s_) : super(s_) {}\n  MoveAwareValue(const char* s_) : super(s_) {}\n  MoveAwareValue(const int& x, const double& y) : super(x, y) {}\n  MoveAwareValue(int&& x, double&& y) : super(std::move(x), std::move(y)) {}\n  // clang-format on\n\n  MoveAwareValue& operator=(const MoveAwareValue& other) {\n    super::operator=(other);\n    return *this;\n  }\n\n  MoveAwareValue& operator=(MoveAwareValue&& other) {\n    super::operator=(std::move(other));\n    return *this;\n  }\n};\n\nnamespace std {\ntemplate <>\nstruct hash<MoveAwareKey> {\n  auto operator()(const MoveAwareKey& key) const {\n    return hash<std::string>()(key.s);\n  }\n};\n\ntemplate <>\nstruct hash<MoveAwareValue> {\n  auto operator()(const MoveAwareValue& value) const {\n    return hash<std::string>()(value.s);\n  }\n};\n}  // namespace std\n"
  },
  {
    "path": "tests/move-awareness-test.cpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#include <string>\n#include <utility>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n#include \"lru/lru.hpp\"\n#include \"tests/move-aware-dummies.hpp\"\n\nstruct MoveAwarenessTest : public ::testing::Test {\n  MoveAwarenessTest() {\n    MoveAwareKey::reset();\n    MoveAwareValue::reset();\n  }\n\n  LRU::Cache<MoveAwareKey, MoveAwareValue> cache;\n};\n\nTEST_F(MoveAwarenessTest, DoesNotMoveForInsert) {\n  cache.insert(\"x\", \"y\");\n\n  // One construction (right there)\n  ASSERT_EQ(MoveAwareKey::forwarding_count, 1);\n  ASSERT_EQ(MoveAwareValue::forwarding_count, 1);\n\n  ASSERT_EQ(MoveAwareKey::copy_count, 1);\n\n  // Values only go into the map\n  ASSERT_EQ(MoveAwareValue::copy_count, 1);\n\n  // Do this at the end to avoid incrementing the counts\n  ASSERT_EQ(cache[\"x\"], \"y\");\n}\n\nTEST_F(MoveAwarenessTest, ForwardsValuesWell) {\n  cache.emplace(\"x\", \"y\");\n\n  // One construction to make the key first\n  EXPECT_GE(MoveAwareKey::forwarding_count, 1);\n  EXPECT_GE(MoveAwareValue::forwarding_count, 1);\n\n  EXPECT_EQ(MoveAwareKey::copy_count, 0);\n  EXPECT_EQ(MoveAwareValue::copy_count, 0);\n\n  ASSERT_EQ(cache[\"x\"], \"y\");\n}\n\nTEST_F(MoveAwarenessTest, MovesSingleRValues) {\n  cache.emplace(std::string(\"x\"), std::string(\"y\"));\n\n  // Move constructions from the string\n  EXPECT_EQ(MoveAwareKey::move_count, 1);\n  EXPECT_EQ(MoveAwareValue::move_count, 1);\n\n  EXPECT_EQ(MoveAwareKey::non_move_count, 0);\n  EXPECT_EQ(MoveAwareValue::non_move_count, 0);\n\n  EXPECT_EQ(MoveAwareKey::copy_count, 0);\n  EXPECT_EQ(MoveAwareValue::copy_count, 0);\n\n  ASSERT_EQ(cache[\"x\"], \"y\");\n}\n\nTEST_F(MoveAwarenessTest, CopiesSingleLValues) {\n  std::string x(\"x\");\n  std::string y(\"y\");\n  cache.emplace(x, y);\n\n  // Move constructions from the string\n  EXPECT_EQ(MoveAwareKey::non_move_count, 1);\n  EXPECT_EQ(MoveAwareValue::non_move_count, 1);\n\n  EXPECT_EQ(MoveAwareKey::move_count, 0);\n  EXPECT_EQ(MoveAwareValue::move_count, 0);\n\n  EXPECT_EQ(MoveAwareKey::copy_count, 0);\n  EXPECT_EQ(MoveAwareValue::copy_count, 0);\n\n  ASSERT_EQ(cache[\"x\"], \"y\");\n}\n\nTEST_F(MoveAwarenessTest, MovesRValueTuples) {\n  cache.emplace(std::piecewise_construct,\n                std::forward_as_tuple(1, 3.14),\n                std::forward_as_tuple(2, 2.718));\n\n  // construct_from_tuple performs one move construction\n  // (i.e. construction from rvalues)\n  EXPECT_EQ(MoveAwareKey::move_count, 1);\n  EXPECT_EQ(MoveAwareValue::move_count, 1);\n\n  EXPECT_EQ(MoveAwareKey::non_move_count, 0);\n  EXPECT_EQ(MoveAwareValue::non_move_count, 0);\n\n  EXPECT_EQ(MoveAwareKey::copy_count, 0);\n  EXPECT_EQ(MoveAwareValue::copy_count, 0);\n}\n\nTEST_F(MoveAwarenessTest, MovesLValueTuples) {\n  int x = 1, z = 2;\n  double y = 3.14, w = 2.718;\n\n  cache.emplace(std::piecewise_construct,\n                std::forward_as_tuple(x, y),\n                std::forward_as_tuple(z, w));\n\n  // construct_from_tuple will perfom one copy construction\n  // (i.e. construction from lvalues)\n  EXPECT_EQ(MoveAwareKey::non_move_count, 1);\n  EXPECT_EQ(MoveAwareValue::non_move_count, 1);\n\n  EXPECT_EQ(MoveAwareKey::move_count, 0);\n  EXPECT_EQ(MoveAwareValue::move_count, 0);\n\n  EXPECT_EQ(MoveAwareKey::copy_count, 0);\n  EXPECT_EQ(MoveAwareValue::copy_count, 0);\n}\n\nTEST_F(MoveAwarenessTest, MovesElementsOutOfRValueRanges) {\n  std::vector<std::pair<std::string, std::string>> range = {{\"x\", \"y\"}};\n  cache.insert(std::move(range));\n\n  // Move constructions from the string\n  EXPECT_EQ(MoveAwareKey::move_count, 1);\n  EXPECT_EQ(MoveAwareValue::move_count, 1);\n\n  EXPECT_EQ(MoveAwareKey::non_move_count, 0);\n  EXPECT_EQ(MoveAwareValue::non_move_count, 0);\n\n  EXPECT_EQ(MoveAwareKey::copy_count, 0);\n  EXPECT_EQ(MoveAwareValue::copy_count, 0);\n\n  ASSERT_EQ(cache[\"x\"], \"y\");\n}\n"
  },
  {
    "path": "tests/statistics-test.cpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#include <memory>\n#include <vector>\n\n#include \"gtest/gtest.h\"\n\n#include \"lru/internal/statistics-mutator.hpp\"\n#include \"lru/lru.hpp\"\n\nusing namespace LRU;\nusing namespace LRU::Internal;\n\nTEST(StatisticsTest, ConstructsWellFromRange) {\n  std::vector<int> range = {1, 2, 3};\n  Statistics<int> stats(range);\n\n  for (const auto& i : range) {\n    ASSERT_TRUE(stats.is_monitoring(i));\n  }\n}\n\nTEST(StatisticsTest, ConstructsWellFromIterator) {\n  std::vector<int> range = {1, 2, 3};\n  Statistics<int> stats(range.begin(), range.end());\n\n  for (const auto& i : range) {\n    ASSERT_TRUE(stats.is_monitoring(i));\n  }\n}\n\nTEST(StatisticsTest, ConstructsWellFromInitializerList) {\n  Statistics<int> stats({1, 2, 3});\n\n  std::vector<int> range = {1, 2, 3};\n  for (const auto& i : range) {\n    ASSERT_TRUE(stats.is_monitoring(i));\n  }\n}\n\nTEST(StatisticsTest, ConstructsWellFromVariadicArguments) {\n  Statistics<int> stats(1, 2, 3);\n\n  std::vector<int> range = {1, 2, 3};\n  for (const auto& i : range) {\n    ASSERT_TRUE(stats.is_monitoring(i));\n  }\n}\n\nTEST(StatisticsTest, EmptyPreconditions) {\n  Statistics<int> stats;\n\n  EXPECT_FALSE(stats.is_monitoring_keys());\n  EXPECT_EQ(stats.number_of_monitored_keys(), 0);\n  EXPECT_FALSE(stats.is_monitoring(1));\n  EXPECT_FALSE(stats.is_monitoring(2));\n  EXPECT_EQ(stats.total_accesses(), 0);\n  EXPECT_EQ(stats.total_hits(), 0);\n  EXPECT_EQ(stats.total_misses(), 0);\n}\n\nTEST(StatisticsTest, StatisticsMutatorCanRegisterHits) {\n  auto stats = std::make_shared<Statistics<int>>(1, 2, 3);\n  StatisticsMutator<int> mutator(stats);\n\n  mutator.register_hit(1);\n  EXPECT_EQ(stats->hits_for(1), 1);\n  EXPECT_EQ(stats->total_accesses(), 1);\n  EXPECT_EQ(stats->total_hits(), 1);\n  EXPECT_EQ(stats->total_misses(), 0);\n  EXPECT_EQ(stats->hit_rate(), 1);\n  EXPECT_EQ(stats->miss_rate(), 0);\n\n  mutator.register_hit(1);\n  EXPECT_EQ(stats->hits_for(1), 2);\n  EXPECT_EQ(stats->total_accesses(), 2);\n  EXPECT_EQ(stats->total_hits(), 2);\n  EXPECT_EQ(stats->total_misses(), 0);\n  EXPECT_EQ(stats->hit_rate(), 1);\n  EXPECT_EQ(stats->miss_rate(), 0);\n\n  mutator.register_hit(2);\n  EXPECT_EQ(stats->hits_for(1), 2);\n  EXPECT_EQ(stats->hits_for(2), 1);\n  EXPECT_EQ(stats->total_accesses(), 3);\n  EXPECT_EQ(stats->total_hits(), 3);\n  EXPECT_EQ(stats->total_misses(), 0);\n  EXPECT_EQ(stats->hit_rate(), 1);\n  EXPECT_EQ(stats->miss_rate(), 0);\n}\n\nTEST(StatisticsTest, StatisticsMutatorCanRegisterMisses) {\n  auto stats = std::make_shared<Statistics<int>>(1, 2, 3);\n  StatisticsMutator<int> mutator(stats);\n\n  mutator.register_miss(1);\n  EXPECT_EQ(stats->misses_for(1), 1);\n  EXPECT_EQ(stats->total_accesses(), 1);\n  EXPECT_EQ(stats->total_hits(), 0);\n  EXPECT_EQ(stats->total_misses(), 1);\n  EXPECT_EQ(stats->hit_rate(), 0);\n  EXPECT_EQ(stats->miss_rate(), 1);\n\n  mutator.register_miss(1);\n  EXPECT_EQ(stats->misses_for(1), 2);\n  EXPECT_EQ(stats->total_accesses(), 2);\n  EXPECT_EQ(stats->total_hits(), 0);\n  EXPECT_EQ(stats->total_misses(), 2);\n  EXPECT_EQ(stats->hit_rate(), 0);\n  EXPECT_EQ(stats->miss_rate(), 1);\n\n  mutator.register_miss(2);\n  EXPECT_EQ(stats->misses_for(1), 2);\n  EXPECT_EQ(stats->misses_for(2), 1);\n  EXPECT_EQ(stats->total_accesses(), 3);\n  EXPECT_EQ(stats->total_hits(), 0);\n  EXPECT_EQ(stats->total_misses(), 3);\n  EXPECT_EQ(stats->hit_rate(), 0);\n  EXPECT_EQ(stats->miss_rate(), 1);\n}\n\nTEST(StatisticsTest, CanDynamicallyMonitorAndUnmonitorKeys) {\n  Statistics<int> stats;\n\n  ASSERT_EQ(stats.number_of_monitored_keys(), 0);\n\n  stats.monitor(1);\n\n  EXPECT_EQ(stats.number_of_monitored_keys(), 1);\n  EXPECT_TRUE(stats.is_monitoring(1));\n  EXPECT_FALSE(stats.is_monitoring(2));\n\n  stats.monitor(2);\n\n  EXPECT_EQ(stats.number_of_monitored_keys(), 2);\n  EXPECT_TRUE(stats.is_monitoring(1));\n  EXPECT_TRUE(stats.is_monitoring(2));\n\n  stats.unmonitor(1);\n\n  EXPECT_EQ(stats.number_of_monitored_keys(), 1);\n  EXPECT_FALSE(stats.is_monitoring(1));\n  EXPECT_TRUE(stats.is_monitoring(2));\n\n  stats.unmonitor_all();\n\n  EXPECT_FALSE(stats.is_monitoring_keys());\n  EXPECT_FALSE(stats.is_monitoring(1));\n  EXPECT_FALSE(stats.is_monitoring(2));\n}\n\nTEST(StatisticsTest, ThrowsForUnmonitoredKey) {\n  Statistics<int> stats;\n\n  EXPECT_THROW(stats.stats_for(1), LRU::Error::UnmonitoredKey);\n  EXPECT_THROW(stats.hits_for(2), LRU::Error::UnmonitoredKey);\n  EXPECT_THROW(stats.misses_for(3), LRU::Error::UnmonitoredKey);\n  EXPECT_THROW(stats[4], LRU::Error::UnmonitoredKey);\n}\n\nTEST(StatisticsTest, RatesAreCalculatedCorrectly) {\n  auto stats = std::make_shared<Statistics<int>>(1, 2, 3);\n  StatisticsMutator<int> mutator(stats);\n\n  for (std::size_t i = 0; i < 20; ++i) {\n    mutator.register_hit(1);\n  }\n\n  for (std::size_t i = 0; i < 80; ++i) {\n    mutator.register_miss(1);\n  }\n\n  EXPECT_EQ(stats->hit_rate(), 0.2);\n  EXPECT_EQ(stats->miss_rate(), 0.8);\n}\n\nTEST(StatisticsTest, CanShareStatistics) {\n  auto stats = std::make_shared<Statistics<int>>(1, 2, 3);\n  StatisticsMutator<int> mutator1(stats);\n  StatisticsMutator<int> mutator2(stats);\n  StatisticsMutator<int> mutator3(stats);\n\n  ASSERT_EQ(mutator1.shared(), mutator2.shared());\n  ASSERT_EQ(mutator2.shared(), mutator3.shared());\n  ASSERT_EQ(&mutator2.get(), &mutator3.get());\n\n  mutator1.register_hit(1);\n  EXPECT_EQ(stats->total_accesses(), 1);\n  EXPECT_EQ(stats->total_hits(), 1);\n  EXPECT_EQ(stats->total_misses(), 0);\n  EXPECT_EQ(stats->hits_for(1), 1);\n\n  mutator2.register_hit(1);\n  EXPECT_EQ(stats->total_accesses(), 2);\n  EXPECT_EQ(stats->total_hits(), 2);\n  EXPECT_EQ(stats->total_misses(), 0);\n  EXPECT_EQ(stats->hits_for(1), 2);\n\n  mutator3.register_miss(2);\n  EXPECT_EQ(stats->total_accesses(), 3);\n  EXPECT_EQ(stats->total_hits(), 2);\n  EXPECT_EQ(stats->total_misses(), 1);\n  EXPECT_EQ(stats->hits_for(1), 2);\n  EXPECT_EQ(stats->misses_for(1), 0);\n  EXPECT_EQ(stats->hits_for(2), 0);\n  EXPECT_EQ(stats->misses_for(2), 1);\n}\n\nstruct CacheWithStatisticsTest : public ::testing::Test {\n  void assert_total_stats(int accesses, int hits, int misses) {\n    ASSERT_EQ(cache.stats().total_accesses(), accesses);\n    ASSERT_EQ(cache.stats().total_hits(), hits);\n    ASSERT_EQ(cache.stats().total_misses(), misses);\n  }\n\n  void expect_total_stats(int accesses, int hits, int misses) {\n    EXPECT_EQ(cache.stats().total_accesses(), accesses);\n    EXPECT_EQ(cache.stats().total_hits(), hits);\n    EXPECT_EQ(cache.stats().total_misses(), misses);\n  }\n\n  Cache<int, int> cache;\n};\n\nTEST_F(CacheWithStatisticsTest,\n       RequestForCacheStatisticsThrowsWhenNoneRegistered) {\n  EXPECT_THROW(cache.stats(), LRU::Error::NotMonitoring);\n}\n\nTEST_F(CacheWithStatisticsTest, CanRegisterLValueStatistics) {\n  auto stats = std::make_shared<Statistics<int>>();\n  cache.monitor(stats);\n\n  EXPECT_TRUE(cache.is_monitoring());\n\n  // This is a strong constraint, but must hold for lvalue stats object\n  EXPECT_EQ(&cache.stats(), &*stats);\n\n  cache.contains(1);\n  EXPECT_EQ(cache.shared_stats()->total_accesses(), 1);\n  EXPECT_EQ(cache.stats().total_misses(), 1);\n\n  cache.emplace(1, 2);\n\n  cache.contains(1);\n  EXPECT_EQ(cache.stats().total_accesses(), 2);\n  EXPECT_EQ(cache.stats().total_misses(), 1);\n  EXPECT_EQ(cache.stats().total_hits(), 1);\n}\n\nTEST_F(CacheWithStatisticsTest, CanRegisterRValueStatistics) {\n  auto s = std::make_unique<Statistics<int>>(1);\n  cache.monitor(std::move(s));\n\n  EXPECT_TRUE(cache.is_monitoring());\n\n  cache.contains(1);\n  EXPECT_EQ(cache.stats().total_accesses(), 1);\n  EXPECT_EQ(cache.stats().total_misses(), 1);\n\n  cache.emplace(1, 2);\n\n  cache.contains(1);\n  EXPECT_EQ(cache.stats().total_accesses(), 2);\n  EXPECT_EQ(cache.stats().total_misses(), 1);\n  EXPECT_EQ(cache.stats().total_hits(), 1);\n}\n\nTEST_F(CacheWithStatisticsTest, CanConstructItsOwnStatistics) {\n  cache.monitor(1, 2, 3);\n\n  EXPECT_TRUE(cache.is_monitoring());\n  EXPECT_TRUE(cache.stats().is_monitoring(1));\n  EXPECT_TRUE(cache.stats().is_monitoring(2));\n  EXPECT_TRUE(cache.stats().is_monitoring(3));\n\n  cache.contains(1);\n  EXPECT_EQ(cache.stats().total_accesses(), 1);\n  EXPECT_EQ(cache.stats().total_misses(), 1);\n\n  cache.emplace(1, 2);\n\n  cache.contains(1);\n  EXPECT_EQ(cache.stats().total_accesses(), 2);\n  EXPECT_EQ(cache.stats().total_misses(), 1);\n  EXPECT_EQ(cache.stats().total_hits(), 1);\n}\n\nTEST_F(CacheWithStatisticsTest, KnowsWhenItIsMonitoring) {\n  EXPECT_FALSE(cache.is_monitoring());\n\n  cache.monitor();\n\n  EXPECT_TRUE(cache.is_monitoring());\n\n  cache.stop_monitoring();\n\n  EXPECT_FALSE(cache.is_monitoring());\n}\n\nTEST_F(CacheWithStatisticsTest, StatisticsWorkWithCache) {\n  cache.monitor(1);\n  ASSERT_TRUE(cache.is_monitoring());\n  assert_total_stats(0, 0, 0);\n\n  // contains\n  cache.contains(1);\n  expect_total_stats(1, 0, 1);\n\n  // An access should only occur for lookup(),\n  // find(), contains() and operator[]\n  cache.emplace(1, 1);\n  expect_total_stats(1, 0, 1);\n\n  cache.contains(1);\n  expect_total_stats(2, 1, 1);\n\n  // find\n  cache.find(2);\n  expect_total_stats(3, 1, 2);\n\n  cache.emplace(2, 2);\n\n  cache.find(2);\n  expect_total_stats(4, 2, 2);\n\n  EXPECT_THROW(cache.lookup(3), LRU::Error::KeyNotFound);\n  expect_total_stats(5, 2, 3);\n\n  cache.emplace(3, 3);\n\n  ASSERT_EQ(cache.lookup(3), 3);\n  expect_total_stats(6, 3, 3);\n\n  EXPECT_THROW(cache[4], LRU::Error::KeyNotFound);\n  expect_total_stats(7, 3, 4);\n\n  cache.emplace(4, 4);\n\n  ASSERT_EQ(cache[4], 4);\n  expect_total_stats(8, 4, 4);\n}\n\nTEST_F(CacheWithStatisticsTest, StopsMonitoringWhenAsked) {\n  auto stats = std::make_shared<Statistics<int>>(1);\n  cache.monitor(stats);\n  cache.emplace(1, 1);\n\n  ASSERT_TRUE(cache.contains(1));\n  ASSERT_EQ(cache.stats().hits_for(1), 1);\n\n  cache.stop_monitoring();\n\n  ASSERT_TRUE(cache.contains(1));\n  EXPECT_EQ(stats->hits_for(1), 1);\n}\n"
  },
  {
    "path": "tests/timed-cache-test.cpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#include <chrono>\n#include <initializer_list>\n#include <string>\n#include <thread>\n#include <utility>\n\n#include \"gtest/gtest.h\"\n#include \"lru/lru.hpp\"\n\nusing namespace LRU;\nusing namespace std::chrono_literals;\n\nTEST(TimedCacheTest, ContainsRespectsExpiration) {\n  TimedCache<int, int> cache(2ms);\n\n  cache.insert(1, 2);\n  ASSERT_EQ(cache.size(), 1);\n  ASSERT_TRUE(cache.contains(1));\n  ASSERT_EQ(cache[1], 2);\n\n  std::this_thread::sleep_for(1ms);\n\n  EXPECT_TRUE(cache.contains(1));\n\n  std::this_thread::sleep_for(1ms);\n\n  EXPECT_FALSE(cache.contains(1));\n}\n\nTEST(TimedCacheTest, KnowsWhenAllKeysHaveExpired) {\n  TimedCache<int, int> cache(2ms);\n\n  ASSERT_TRUE(cache.all_expired());\n\n  cache = {{1, 2}, {2, 3}};\n\n  ASSERT_EQ(cache.size(), 2);\n  ASSERT_FALSE(cache.all_expired());\n\n  std::this_thread::sleep_for(1ms);\n\n  cache.insert(3, 4);\n\n  std::this_thread::sleep_for(1ms);\n\n  EXPECT_FALSE(cache.all_expired());\n  EXPECT_FALSE(cache.contains(1));\n  EXPECT_FALSE(cache.contains(2));\n  EXPECT_TRUE(cache.contains(3));\n\n  std::this_thread::sleep_for(1ms);\n\n  EXPECT_TRUE(cache.all_expired());\n  EXPECT_FALSE(cache.contains(1));\n  EXPECT_FALSE(cache.contains(2));\n  EXPECT_FALSE(cache.contains(3));\n}\n\nTEST(TimedCacheTest, CleanExpiredRemovesExpiredElements) {\n  TimedCache<int, int> cache(2ms, 128, {{1, 2}, {2, 3}});\n\n  ASSERT_EQ(cache.size(), 2);\n  ASSERT_FALSE(cache.all_expired());\n\n  std::this_thread::sleep_for(1ms);\n\n  cache.insert(3, 4);\n  ASSERT_EQ(cache.size(), 3);\n\n  std::this_thread::sleep_for(1ms);\n\n  ASSERT_EQ(cache.size(), 3);\n\n  cache.clear_expired();\n\n  EXPECT_EQ(cache.size(), 1);\n  EXPECT_FALSE(cache.contains(1));\n  EXPECT_FALSE(cache.contains(2));\n  EXPECT_TRUE(cache.contains(3));\n\n  std::this_thread::sleep_for(1ms);\n\n  cache.clear_expired();\n\n  EXPECT_FALSE(cache.contains(3));\n  EXPECT_EQ(cache.size(), 0);\n  EXPECT_TRUE(cache.is_empty());\n}\n\nTEST(TimedCacheTest, LookupThrowsWhenKeyExpired) {\n  TimedCache<int, int> cache(2ms, 128, {{1, 2}});\n\n  ASSERT_EQ(cache.lookup(1), 2);\n\n  std::this_thread::sleep_for(2ms);\n\n  ASSERT_THROW(cache.lookup(1), LRU::Error::KeyExpired);\n}\n\nTEST(TimedCacheTest, HasExpiredReturnsFalseForNonContainedKeys) {\n  TimedCache<int, int> cache(2ms);\n\n  EXPECT_FALSE(cache.has_expired(1));\n  EXPECT_FALSE(cache.has_expired(2));\n}\n\nTEST(TimedCacheTest, HasExpiredReturnsFalseForContainedButNotExpiredKeys) {\n  TimedCache<int, int> cache(100ms);\n\n  cache.emplace(1, 1);\n  cache.emplace(2, 2);\n\n  EXPECT_FALSE(cache.has_expired(1));\n  EXPECT_FALSE(cache.has_expired(2));\n}\n\nTEST(TimedCacheTest, HasExpiredReturnsTrueForContainedAndExpiredKeys) {\n  TimedCache<int, int> cache(2ms);\n\n  cache.emplace(1, 1);\n\n  std::this_thread::sleep_for(1ms);\n\n  cache.emplace(2, 2);\n\n  EXPECT_FALSE(cache.has_expired(1));\n\n  std::this_thread::sleep_for(1ms);\n\n  EXPECT_TRUE(cache.has_expired(1));\n  EXPECT_FALSE(cache.has_expired(2));\n\n  std::this_thread::sleep_for(3ms);\n\n  EXPECT_TRUE(cache.has_expired(1));\n  EXPECT_TRUE(cache.has_expired(2));\n}\n\nTEST(TimedCacheTest, LookupsMoveElementsToFront) {\n  TimedCache<std::string, int> cache(1s);\n\n  cache.capacity(2);\n  cache.insert({{\"one\", 1}, {\"two\", 2}});\n\n  // The LRU principle mandates that lookups place\n  // accessed elements to the front. So when we look at\n  // one it should move to the front.\n\n  auto iterator = cache.find(\"one\");\n  cache.emplace(\"three\", 3);\n\n  EXPECT_TRUE(cache.contains(\"one\"));\n  EXPECT_FALSE(cache.contains(\"two\"));\n  EXPECT_TRUE(cache.contains(\"three\"));\n  EXPECT_EQ(++iterator, cache.end());\n}\n"
  },
  {
    "path": "tests/wrap-test.cpp",
    "content": "/// The MIT License (MIT)\n/// Copyright (c) 2016 Peter Goldsborough\n///\n/// Permission is hereby granted, free of charge, to any person obtaining a copy\n/// of this software and associated documentation files (the \"Software\"), to\n/// deal in the Software without restriction, including without limitation the\n/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n/// sell copies of the Software, and to permit persons to whom the Software is\n/// furnished to do so, subject to the following conditions:\n///\n/// The above copyright notice and this permission notice shall be included in\n/// all copies or substantial portions of the Software.\n///\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n/// IN THE SOFTWARE.\n\n#include <chrono>\n\n#include \"gtest/gtest.h\"\n\n#include \"lru/lru.hpp\"\n\nTEST(WrapTest, CanWrapMutableAndNonMutableLambdas) {\n  // This is purely to make sure both variants compile\n  LRU::wrap([](int x) { return x; })(5);\n  LRU::wrap([](int x) mutable { return x; })(5);\n}\n\nTEST(WrapTest, WrappingWorks) {\n  auto f = [x = 0](int _) mutable {\n    return ++x;\n  };\n  auto wrapped = LRU::wrap(f);\n\n  EXPECT_EQ(wrapped(69), 1);\n  EXPECT_EQ(wrapped(69), 1);\n  EXPECT_EQ(wrapped(42), 2);\n  EXPECT_EQ(wrapped(42), 2);\n  EXPECT_EQ(wrapped(50), 3);\n}\n\nTEST(WrapTest, CanPassCapacityArgumentToWrap) {\n  std::size_t call_count = 0;\n  auto f = [&call_count](int _) { return call_count += 1; };\n\n  auto wrapped1 = LRU::wrap(f, 1);\n\n  wrapped1(1);\n  EXPECT_EQ(call_count, 1);\n\n  wrapped1(1);\n  EXPECT_EQ(call_count, 1);\n\n  auto wrapped2 = LRU::wrap(f, 0);\n\n  wrapped1(1);\n  EXPECT_EQ(call_count, 1);\n\n  wrapped1(1);\n  EXPECT_EQ(call_count, 1);\n}\n\n\nTEST(WrapTest, CanPassTimeArgumentToTimedCacheWrap) {\n  using namespace std::chrono_literals;\n\n  std::size_t call_count = 0;\n  auto f = [&call_count](int _) { return call_count += 1; };\n\n  auto wrapped1 = LRU::wrap<decltype(f), LRU::TimedCache>(f, 100ms);\n\n  wrapped1(1);\n  EXPECT_EQ(call_count, 1);\n\n  wrapped1(1);\n  EXPECT_EQ(call_count, 1);\n\n  auto wrapped2 = LRU::timed_wrap(f, 0ms);\n\n  wrapped1(1);\n  EXPECT_EQ(call_count, 1);\n\n  wrapped1(1);\n  EXPECT_EQ(call_count, 1);\n}\n"
  }
]