Skip to content

Commit

Permalink
Add windows msvc support (#35)
Browse files Browse the repository at this point in the history
* Add windows msvc support

Closes #34
  • Loading branch information
jbaldwin authored Nov 25, 2023
1 parent 8725375 commit 451cda6
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 54 deletions.
2 changes: 2 additions & 0 deletions .githooks/readme-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,12 @@ This project has a GitHub Actions CI implementation to compile and run unit test
Currently tested distros:
* ubuntu:latest
* fedora:latest
* msvc:latest

Currently tested compilers:
* g++
* clang
* msvc

Contributing a new feature should include relevant tests. Examples
are welcome if understanding how the feature works is difficult or provides some additional value the tests otherwise cannot.
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,19 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: build-debug-g++/libcappuccino_tests.info
build-windows:
name: windows
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: build-release-cl
run: |
mkdir build-release-cl
cd build-release-cl
cmake ..
cmake --build . --config Release
- name: test-release-cl
run: |
cd build-release-cl
ctest --build-config Release -VV
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
cmake_minimum_required(VERSION 3.0)
project(cappuccino CXX)
cmake_minimum_required(VERSION 3.5)
project(cappuccino
VERSION 0.9
LANGUAGES CXX
DESCRIPTION "C++17 Cache and Associative Data Structure Library")

# Set the githooks directory to auto format and update the readme.
message("${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR} -> git config --local core.hooksPath .githooks")
Expand Down Expand Up @@ -60,6 +63,8 @@ elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
-Wpedantic
-pedantic-errors
)
elseif(MSVC)
target_compile_options(${PROJECT_NAME} PUBLIC /W4)
endif()

if(CAPPUCCINO_BUILD_EXAMPLES)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,12 @@ This project has a GitHub Actions CI implementation to compile and run unit test
Currently tested distros:
* ubuntu:latest
* fedora:latest
* msvc:latest

Currently tested compilers:
* g++
* clang
* msvc

Contributing a new feature should include relevant tests. Examples
are welcome if understanding how the feature works is difficult or provides some additional value the tests otherwise cannot.
Expand Down
5 changes: 4 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ target_link_libraries(${PROJECT_NAME} PRIVATE cappuccino)
### bench ###
project(cap_bench CXX)
add_executable(${PROJECT_NAME} bench.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE cappuccino pthread)
target_link_libraries(${PROJECT_NAME} PRIVATE cappuccino)
if(NOT MSVC)
target_link_libraries(${PROJECT_NAME} PRIVATE pthread)
endif()

### mru_simple ###
project(cap_mru_simple CXX)
Expand Down
3 changes: 3 additions & 0 deletions examples/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,9 @@ static auto lru_cache_bench_test() -> void

int main(int argc, char* argv[])
{
(void)argc;
(void)argv;

constexpr size_t iterations = 1'000'000;
constexpr size_t worker_count = 12;
constexpr size_t cache_size = 100'000;
Expand Down
11 changes: 5 additions & 6 deletions inc/cappuccino/fifo_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class fifo_cache
{
size_t deleted_elements{0};

std::lock_guard{m_lock};
std::lock_guard guard{m_lock};
while (begin != end)
{
auto keyed_position = m_keyed_elements.find(*begin);
Expand All @@ -157,8 +157,8 @@ class fifo_cache
* @param key_range The keys to delete from the cache.
* @return The number of items deleted from the cache.
*/
template<template<class...> typename range_type>
auto erase_range(const range_type<key_type>& key_range) -> size_t
template<typename range_type>
auto erase_range(const range_type& key_range) -> size_t
{
return erase(std::begin(key_range), std::end(key_range));
}
Expand Down Expand Up @@ -212,9 +212,8 @@ class fifo_cache
* @param key_range The keys to lookup their pairs.
* @return The full set of keys to std::nullopt if the key wasn't found, or the value if found.
*/
template<template<class...> typename range_type>
auto find_range(const range_type<key_type>& key_range)
-> std::vector<std::pair<key_type, std::optional<value_type>>>
template<typename range_type>
auto find_range(const range_type& key_range) -> std::vector<std::pair<key_type, std::optional<value_type>>>
{
return find(std::begin(key_range), std::end(key_range), std::size(key_range));
}
Expand Down
8 changes: 4 additions & 4 deletions inc/cappuccino/lfu_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ class lfu_cache
* @param key_range The keys to delete from the cache.
* @return The number of items deleted from the cache.
*/
template<template<class...> typename range_type>
auto erase_range(const range_type<key_type>& key_range) -> size_t
template<typename range_type>
auto erase_range(const range_type& key_range) -> size_t
{
size_t deleted_elements{0};

Expand Down Expand Up @@ -166,8 +166,8 @@ class lfu_cache
* @param peek Should the find act like all the items were not used?
* @return The full set of keys to std::nullopt if the key wasn't found, or the value if found.
*/
template<template<class...> typename range_type>
auto find_range(const range_type<key_type>& key_range, bool peek = false)
template<typename range_type>
auto find_range(const range_type& key_range, bool peek = false)
-> std::vector<std::pair<key_type, std::optional<value_type>>>
{
std::vector<std::pair<key_type, std::optional<value_type>>> output;
Expand Down
10 changes: 5 additions & 5 deletions inc/cappuccino/lfuda_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ class lfuda_cache
* @param key_range The keys to delete from the cache.
* @return The number of items deleted from the cache.
*/
template<template<class...> typename range_type>
auto erase_range(const range_type<key_type>& key_range) -> size_t
template<typename range_type>
auto erase_range(const range_type& key_range) -> size_t
{
size_t deleted_elements{0};

Expand Down Expand Up @@ -202,8 +202,8 @@ class lfuda_cache
* @param peek Should the find act like all the items were not used?
* @return The full set of keys to std::nullopt if the key wasn't found, or the value if found.
*/
template<template<class...> typename range_type>
auto find_range(const range_type<key_type>& key_range, bool peek = false)
template<typename range_type>
auto find_range(const range_type& key_range, bool peek = false)
-> std::vector<std::pair<key_type, std::optional<value_type>>>
{
auto now = std::chrono::steady_clock::now();
Expand Down Expand Up @@ -443,7 +443,7 @@ class lfuda_cache
// deleting from and re-inserting into the lfu data structure.
size_t use_count = e.m_lfu_position->first;
m_lfu_list.erase(e.m_lfu_position);
use_count *= m_dynamic_age_ratio;
use_count = (size_t)(use_count * m_dynamic_age_ratio);
e.m_lfu_position = m_lfu_list.emplace(use_count, da_start);

// The last item is now this item! This will maintain the insertion order.
Expand Down
8 changes: 4 additions & 4 deletions inc/cappuccino/lru_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ class lru_cache
* @param key_range The keys to delete from the cache.
* @return The number of items deleted from the cache.
*/
template<template<class...> typename range_type>
auto erase_range(const range_type<key_type>& key_range) -> size_t
template<typename range_type>
auto erase_range(const range_type& key_range) -> size_t
{
size_t deleted_elements{0};

Expand Down Expand Up @@ -154,8 +154,8 @@ class lru_cache
* @param peek Should the find act like all the items were not used?
* @return The full set of keys to std::nullopt if the key wasn't found, or the value if found.
*/
template<template<class...> typename range_type>
auto find_range(const range_type<key_type>& key_range, peek peek = peek::no)
template<typename range_type>
auto find_range(const range_type& key_range, peek peek = peek::no)
-> std::vector<std::pair<key_type, std::optional<value_type>>>
{
std::vector<std::pair<key_type, std::optional<value_type>>> output;
Expand Down
8 changes: 4 additions & 4 deletions inc/cappuccino/mru_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ class mru_cache
* @param key_range The keys to delete from the cache.
* @return The number of items deleted from the cache.
*/
template<template<class...> typename range_type>
auto erase_range(const range_type<key_type>& key_range) -> size_t
template<typename range_type>
auto erase_range(const range_type& key_range) -> size_t
{
size_t deleted_elements{0};

Expand Down Expand Up @@ -151,8 +151,8 @@ class mru_cache
* @param peek Should the find act like all the items were not used?
* @return The full set of keys to std::nullopt if the key wasn't found, or the value if found.
*/
template<template<class...> typename range_type>
auto find_range(const range_type<key_type>& key_range, peek peek = peek::no)
template<typename range_type>
auto find_range(const range_type& key_range, peek peek = peek::no)
-> std::vector<std::pair<key_type, std::optional<value_type>>>
{
std::vector<std::pair<key_type, std::optional<value_type>>> output;
Expand Down
9 changes: 4 additions & 5 deletions inc/cappuccino/rr_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ class rr_cache
* @param key_range The keys to delete from the cache.
* @return The number of items deleted from the cache.
*/
template<template<class...> typename range_type>
auto erase_range(const range_type<key_type>& key_range) -> size_t
template<typename range_type>
auto erase_range(const range_type& key_range) -> size_t
{
size_t deleted_elements{0};

Expand Down Expand Up @@ -151,9 +151,8 @@ class rr_cache
* @param key_range The keys to lookup their pairs.
* @return The full set of keys to std::nullopt if the key wasn't found, or the value if found.
*/
template<template<class...> typename range_type>
auto find_range(const range_type<key_type>& key_range)
-> std::vector<std::pair<key_type, std::optional<value_type>>>
template<typename range_type>
auto find_range(const range_type& key_range) -> std::vector<std::pair<key_type, std::optional<value_type>>>
{
std::vector<std::pair<key_type, std::optional<value_type>>> output;
output.reserve(std::size(key_range));
Expand Down
12 changes: 6 additions & 6 deletions inc/cappuccino/tlru_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ class tlru_cache
* @param key_range The keys to delete from the cache.
* @return The number of items deleted from the cache.
*/
template<template<class...> typename range_type>
auto erase_range(const range_type<key_type>& key_range) -> size_t
template<typename range_type>
auto erase_range(const range_type& key_range) -> size_t
{
size_t deleted_elements{0};

Expand Down Expand Up @@ -166,8 +166,8 @@ class tlru_cache
* @param peek Should the find act like all the items were not used?
* @return The full set of keys to std::nullopt if the key wasn't found, or the value if found.
*/
template<template<class...> typename range_type>
auto find_range(const range_type<key_type>& key_range, peek peek = peek::no)
template<typename range_type>
auto find_range(const range_type& key_range, peek peek = peek::no)
-> std::vector<std::pair<key_type, std::optional<value_type>>>
{
std::vector<std::pair<key_type, std::optional<value_type>>> output;
Expand Down Expand Up @@ -280,8 +280,8 @@ class tlru_cache
{
// If the item has expired and this is INSERT then allow the
// insert to proceed, this can just be an update in place.
const auto& [key, element_idx] = *keyed_position;
element& e = m_elements[element_idx];
const auto& [k, element_idx] = *keyed_position;
element& e = m_elements[element_idx];
if (now >= e.m_expire_time)
{
do_update(keyed_position, std::move(value), expire_time);
Expand Down
9 changes: 4 additions & 5 deletions inc/cappuccino/ut_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ class ut_map
* @param key_range The keys to delete from the map.
* @return The number of items deleted from the map.
*/
template<template<class...> typename range_type>
auto erase_range(const range_type<key_type>& key_range) -> size_t
template<typename range_type>
auto erase_range(const range_type& key_range) -> size_t
{
size_t deleted{0};
std::lock_guard guard{m_lock};
Expand Down Expand Up @@ -173,9 +173,8 @@ class ut_map
* @return All input keys to either a std::nullopt if it doesn't exist, or the
* value if it does.
*/
template<template<class...> typename range_type>
auto find_range(const range_type<key_type>& key_range)
-> std::vector<std::pair<key_type, std::optional<value_type>>>
template<typename range_type>
auto find_range(const range_type& key_range) -> std::vector<std::pair<key_type, std::optional<value_type>>>
{
std::vector<std::pair<key_type, std::optional<value_type>>> output;
output.reserve(std::size(key_range));
Expand Down
8 changes: 4 additions & 4 deletions inc/cappuccino/ut_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ class ut_set
* @param key_range The keys to delete from the set.
* @return The number of items deleted from the set.
*/
template<template<class...> typename range_type>
auto erase_range(const range_type<key_type>& key_range) -> size_t
template<typename range_type>
auto erase_range(const range_type& key_range) -> size_t
{
size_t deleted{0};
std::lock_guard guard{m_lock};
Expand Down Expand Up @@ -166,8 +166,8 @@ class ut_set
* @param key_range A container with the set of keys to lookup.
* @return All input keys with a bool indicating if it exists.
*/
template<template<class...> typename range_type>
auto find_range(const range_type<key_type>& key_range) -> std::vector<std::pair<key_type, bool>>
template<typename range_type>
auto find_range(const range_type& key_range) -> std::vector<std::pair<key_type, bool>>
{
std::vector<std::pair<key_type, bool>> output;
output.reserve(std::size(key_range));
Expand Down
12 changes: 6 additions & 6 deletions inc/cappuccino/utlru_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ class utlru_cache
* @param key_range The keys to delete from the cache.
* @return The number of items deleted from the cache.
*/
template<template<class...> typename range_type>
auto erase_range(const range_type<key_type>& key_range) -> size_t
template<typename range_type>
auto erase_range(const range_type& key_range) -> size_t
{
size_t deleted_elements{0};

Expand Down Expand Up @@ -189,8 +189,8 @@ class utlru_cache
* @param peek Should the find act like all the items were not used?
* @return All input keys to either a std::nullopt if it doesn't exist, or the value if it does.
*/
template<template<class...> typename range_type>
auto find_range(const range_type<key_type>& key_range, peek peek = peek::no)
template<typename range_type>
auto find_range(const range_type& key_range, peek peek = peek::no)
-> std::vector<std::pair<key_type, std::optional<value_type>>>
{
std::vector<std::pair<key_type, std::optional<value_type>>> output;
Expand Down Expand Up @@ -323,8 +323,8 @@ class utlru_cache
{
// If the item has expired and this is INSERT then allow the
// insert to proceed, this can just be an update in place.
const auto& [key, element_idx] = *keyed_position;
element& e = m_elements[element_idx];
const auto& [k, element_idx] = *keyed_position;
element& e = m_elements[element_idx];
if (now >= e.m_expire_time)
{
do_update(keyed_position, std::move(value), expire_time);
Expand Down
8 changes: 6 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.5)
project(libcappuccino_tests)

set(LIBCAPPUCCINO_TEST_SOURCE_FILES
Expand All @@ -16,7 +16,11 @@ set(LIBCAPPUCCINO_TEST_SOURCE_FILES
)

add_executable(${PROJECT_NAME} main.cpp ${LIBCAPPUCCINO_TEST_SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} PRIVATE cappuccino pthread)
target_link_libraries(${PROJECT_NAME} PRIVATE cappuccino)

if(NOT MSVC)
target_link_libraries(${PROJECT_NAME} PRIVATE pthread)
endif()

if(CAPPUCCINO_CODE_COVERAGE)
target_compile_options(${PROJECT_NAME} PRIVATE --coverage)
Expand Down

0 comments on commit 451cda6

Please sign in to comment.