File tree Expand file tree Collapse file tree 2 files changed +5
-14
lines changed Expand file tree Collapse file tree 2 files changed +5
-14
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.16)
3
3
set (This Example )
4
4
5
5
set (Sources
6
- Example .cpp
6
+ example .cpp
7
7
)
8
8
9
9
add_executable (${This} ${Sources} )
Original file line number Diff line number Diff line change
1
+ #include < chrono>
1
2
#include < iostream>
2
3
#include < string>
4
+ #include < thread>
3
5
#include < gh-lru/expiring_lru_cache.hpp>
4
6
5
- #ifdef _WIN32
6
- #include < Windows.h>
7
- #else
8
- #include < unistd.h>
9
- #endif
10
-
11
7
int main ()
12
8
{
13
9
using Cache = ExpiringLruCache<int , std::string>;
@@ -32,19 +28,14 @@ int main()
32
28
std::cout << std::get<0 >(cache.find (1 )->second ) << std::endl; // prints "a"
33
29
std::cout << std::get<0 >(cache.find (2 )->second ) << std::endl; // prints "b"
34
30
35
- sleep ( 2 );
31
+ std::this_thread::sleep_for ( std::chrono::milliseconds ( 2000 ) );
36
32
// Refresh the timestamp.
37
33
cache.at (1 );
38
34
39
- sleep ( 2 );
35
+ std::this_thread::sleep_for ( std::chrono::milliseconds ( 2000 ) );
40
36
std::cout << cache.at (1 ) << std::endl; // prints "a"
41
37
// prints 1 (true), as the element was evicted due to being outdated
42
38
std::cout << (cache.find (2 ) == cache.end ()) << std::endl;
43
39
44
- std::unordered_map<int , int > map;
45
- map.emplace (1 , 10 );
46
- map.emplace (1 , 11 );
47
- std::cout << map.at (1 ) << std::endl;
48
-
49
40
return 0 ;
50
41
}
You can’t perform that action at this time.
0 commit comments