From 491ed2fc3dfc3de5ca41c7050b24a917ebf9044e Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Sat, 6 Mar 2021 21:32:08 -0500 Subject: [PATCH 01/40] copied the .gitignore from j project. --- .gitignore | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 147 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 49f5923..29ba96a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,147 @@ -#clion build folders. -cmake-build-*/* -#clion settings. -.idea/* \ No newline at end of file +#vscode +.vscode/ + +# unix +*.o +*.so +!asm/*.o + +# temp scripts used for debugging +*makevs/jdll/*.ijs +jj.ijs + +# windows - most output files go to %userprofile%\jbld\jout +# some end up in the project folder and are marked here +# sometimes entire project subfolders are created that should not be in repo +*.sdf +*.opensdf +*.suo +**/jconsole/.vs/ +**/jdll/**/.vs/ +**/tsdll/**/.vs/ +*.ilk +*.pdb +*.exp + +# following are no longer required and prevent template folders +# **/jconsole/**/ +# **/jdll/**/ +# **/tsdll/**/ + +# windows - need to run with different versions of vs +# following files are in repo for vs2013 +# but are not pushed to avoid getting unwanted user specific changes +# clone will have to copy from .template files to work +*.sln* +*.vcxproj* +!*.template +.vs/ + +# mac +.DS_Store + +#android +android/libs/ +android/obj/ +android/jni/jsrc +android/jni/clapack +android/jni/pcre +android/jni/pcre2 +android/jni/tsdll +android/jni/hostdefs +android/jni/netdefs +clapack/ +pcre/ + +release +/test/temp.ijs + +# build folders +out/ +build/ +bin/ +make2/ +/jlibrary/addons +/jlibrary/bin +/jlibrary/bin32 +/jlibrary/tools + +# clion's cmake creates cmake-build-release, cmake-build-debug, etc... +cmake-build-*/ +# clion's settings folder. keep or not up to you. can be useful for spellcheck etc. +.idea + +# QtCreator config files +# A listing of all the files included in the project +*.files + +# Include directories +*.includes + +# Project configuration settings like predefined Macros +*.config + +# Qt Creator settings +*.creator + +# User project settings +*.creator.user* + +# Qt Creator backups +*.autosave + +# Flags for Clang Code Model +*.cxxflags +*.cflags + +# Meson Build System files +# subproject directories +/subprojects/* +!/subprojects/*.wrap + +# Meson Directories +meson-logs +meson-private + +# Meson Files +meson_benchmark_setup.dat +meson_test_setup.dat +sanitycheckcpp.cc # C++ specific +sanitycheckcpp.exe # C++ specific + +# Ninja +build.ninja +.ninja_deps +.ninja_logs + +# Misc +compile_commands.json +# Prerequisites +*.d + +# Precompiled Headers +*.gch +*.pch + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# doxygen +docs/doxygen +docs/latex +docs/html +docs/make.bat +docs/xml +docs/_build +docs/Makefile + +#python in clion +venv/* From fe92c89e9e099a0e24c9f89eb2fe852d7b4210e8 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Sun, 7 Mar 2021 23:10:10 -0500 Subject: [PATCH 02/40] set library to c++20 This should only effect projects with cpp files. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c06a14..6197b90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.18) project(An-Algorithm-Library C CXX) -set(CMAKE_CXX_STANDARD 17) ## Supported values are 98, 11, 14, 17, and 20. +set(CMAKE_CXX_STANDARD 20) ## Supported values are 98, 11, 14, 17, and 20. set(CMAKE_CXX_STANDARD_REQUIRED ON) ## the value of the CXX_STANDARD target property is treated as a requirement set(CMAKE_CXX_EXTENSIONS OFF) ## on g++ this ensures: -std=c++11 and not -std=gnu++11 set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) ## automatically create a module definition (.def) file with all global From 282e48b1ca43a1479fc7984843e2325968e7cab7 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Mon, 8 Mar 2021 10:10:58 -0500 Subject: [PATCH 03/40] create tests --- CMakeLists.txt | 3 +- tests/CMakeLists.txt | 7 ++ tests/algorithm_test.cpp | 154 +++++++++++++++++++++++++++++++++++++++ tests/ut.cmake | 13 ++++ 4 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/algorithm_test.cpp create mode 100644 tests/ut.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 6197b90..fd49f4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,4 +7,5 @@ set(CMAKE_CXX_EXTENSIONS OFF) ## on g++ this ensures: -std=c++11 and not -std=gn set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) ## automatically create a module definition (.def) file with all global ## symbols found in the input .obj files for a SHARED library on Windows. -add_subdirectory(src) \ No newline at end of file +add_subdirectory(src) +add_subdirectory(tests) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..8fc2115 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,7 @@ +include(ut.cmake) + + +add_executable(${PROJECT_NAME}_algorithm_test + algorithm_test.cpp) +target_link_libraries(${PROJECT_NAME}_algorithm_test PRIVATE Boost::ut ${PROJECT_NAME}_aal) +add_test(${PROJECT_NAME}_ALGORITHM_TEST ${PROJECT_NAME}_algorithm_test) \ No newline at end of file diff --git a/tests/algorithm_test.cpp b/tests/algorithm_test.cpp new file mode 100644 index 0000000..28e2ee6 --- /dev/null +++ b/tests/algorithm_test.cpp @@ -0,0 +1,154 @@ +#include // single header +// import boost.ut; // single module (C++20) +#include "aal/algorithm.hpp" +#include +#include +/** + * multiply all the parameter pack values together + * @note if sizeof...(a) == 1 it returns a. + */ +static constexpr auto multiply = [](auto const &...a) { return (a * ...); }; +/** + * add all the parameter pack values together + * @note if sizeof...(a) == 1 it returns a. + */ +static constexpr auto plus = [](auto const &...a) { return (a + ...); }; +/** + * are all the parameter pack values equal? + * @param first value + * @param rest of values. + */ +static constexpr auto equal_to = [](auto const &first, + auto const &...rest) -> bool { + static_assert(sizeof...(rest) != 0); + return ((first == rest) || ...); +}; +/** + * are any of the parameter pack values not equal? + * @param first value + * @param rest of values. + */ +static constexpr auto not_equal_to = [](auto const &first, + auto const &...rest) -> bool { + static_assert(sizeof...(rest) != 0); + return ((first != rest) || ...); +}; + +/** + * Transform values to signed types and pass to op + * @param op operation that is performed that returns a value. + * @param a values + */ +static constexpr auto make_signed = [](const auto &op, auto const &...a) { + static_assert((std::is_integral_v> && ...)); + return op(static_cast>>(a)...); +}; +/** + * Transform values to unsigned types and pass to op + * @param op operation that is performed that returns a value. + * @param a values + */ +static constexpr auto make_unsigned = [](const auto &op, auto const &...a) { + static_assert((std::is_integral_v> && ...)); + return op( + (static_cast>>(a))...); +}; +/** + * Eagar transform and output to rvalue range + * @tparam I first range iterator type + * @tparam Is other range iterators type + * @tparam O output range r-value type + * @tparam Op operation type + * @param op operation + * @param o output range r-value + * @param f first range iterator begin + * @param l first range iterator end + * @param fs other range iterator begins + * @return returns output range post transform. + */ +template +[[nodiscard]] constexpr auto transform(Op const op, O &&o, I f, I const l, + Is... fs) { + aal::var::transform(op, std::ranges::begin(o), f, l, fs...); + return o; +} +int main() { + using namespace boost::ut::literals; + using namespace boost::ut::operators::terse; + using namespace boost::ut; + [[maybe_unused]] suite tests = [] { + static constexpr std::array input{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + }; + static constexpr auto b = std::ranges::begin(input); + static constexpr auto e = std::ranges::end(input); + "equal_to"_test = [&] { + expect(constant); + expect(equal_to(0.0, 0)); + expect(make_signed(equal_to, 0U, 0)); + expect(make_unsigned(equal_to, 0U, 0)); + expect(make_signed(equal_to, 3, 3U, 3U, 3)); + expect(make_signed(equal_to, 3, 3U, 3)); + expect(make_unsigned(equal_to, 3, 3U, 3, char(3))); + }; + "not_equal_to"_test = [&] { + expect(constant); + expect(make_signed(not_equal_to, -3, 3U, 6U, '5', 3)); + expect(!make_signed(not_equal_to, 3, 3U, 3U, 3, char(3))); + expect(!make_signed(not_equal_to, 3, 3U, 3)); + expect(!make_unsigned(not_equal_to, 3, 3U, 3)); + }; + "find"_test = [&] { + static constexpr auto result = aal::var::find( + [&](const auto &...a) { return equal_to(3, a...); }, b, e); + expect(constant(result)>); + expect(constant<3 == *std::get<0>(result)>); + }; + "found"_test = [&] { + static constexpr auto result = aal::var::found( + [&](const auto &...a) { return equal_to(3, a...); }, b, e); + expect(constant); + }; + + "transform == 3"_test = [&] { + std::array output{}; + const auto result = aal::var::transform( + [&](const auto &...a) { return equal_to(3, a...); }, + std::ranges::begin(output), b, e); + expect(output[3]); + expect(!*result); + }; + "transform == 3 constexpr"_test = [&] { + constexpr auto result = + transform([&](const auto &...a) { return equal_to(3, a...); }, + std::array(), b, e); + expect(constant); + }; + "transform + 3"_test = [&] { + std::array result{}; + aal::var::transform([&](const auto &...a) { return plus(3, a...); }, + std::ranges::begin(result), b, e); + expect(result[3] == 6_i); + }; + "transform == 3 constexpr"_test = [&] { + constexpr auto result = + transform([&](const auto &...a) { return plus(3, a...); }, + std::array(), b, e); + expect(constant); + }; + "transform + 2x"_test = [&] { + std::array result{}; + aal::var::transform(plus, std::ranges::begin(result), b, e, b); + expect(result[3] == 6_i); + expect(result[2] == 4_i); + expect(result[1] == 2_i); + }; + "transform + 2x constexpr"_test = [&] { + constexpr auto result = + transform(plus, std::array(), b, e, b); + expect(constant); + expect(constant); + expect(constant); + }; + }; +} \ No newline at end of file diff --git a/tests/ut.cmake b/tests/ut.cmake new file mode 100644 index 0000000..2c0768c --- /dev/null +++ b/tests/ut.cmake @@ -0,0 +1,13 @@ +enable_testing() +include(FetchContent) +FetchContent_Declare( + ut + GIT_REPOSITORY https://github.com/boost-ext/ut.git + GIT_TAG origin/master +) +#FetchContent_MakeAvailable(ut) +FetchContent_GetProperties(ut) +if(NOT ut_POPULATED) + FetchContent_Populate(ut) + add_subdirectory(${ut_SOURCE_DIR} ${ut_BINARY_DIR} EXCLUDE_FROM_ALL) +endif() \ No newline at end of file From 493f5c49c326fe8eba988896cda7873babaeeecb Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Mon, 8 Mar 2021 12:52:35 -0500 Subject: [PATCH 04/40] Added compiler-warnings and rearranged files. added a couple tests --- tests/CMakeLists.txt | 8 +-- tests/cmake/compiler_warnings.cmake | 82 +++++++++++++++++++++++++++++ tests/{ => cmake}/ut.cmake | 0 tests/{ => src}/algorithm_test.cpp | 18 ++++++- 4 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 tests/cmake/compiler_warnings.cmake rename tests/{ => cmake}/ut.cmake (100%) rename tests/{ => src}/algorithm_test.cpp (89%) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8fc2115..391cfa9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,7 +1,7 @@ -include(ut.cmake) - - +include(cmake/compiler_warnings.cmake) +include(cmake/ut.cmake) add_executable(${PROJECT_NAME}_algorithm_test - algorithm_test.cpp) + src/algorithm_test.cpp) +set_project_warnings(${PROJECT_NAME}_algorithm_test ON) target_link_libraries(${PROJECT_NAME}_algorithm_test PRIVATE Boost::ut ${PROJECT_NAME}_aal) add_test(${PROJECT_NAME}_ALGORITHM_TEST ${PROJECT_NAME}_algorithm_test) \ No newline at end of file diff --git a/tests/cmake/compiler_warnings.cmake b/tests/cmake/compiler_warnings.cmake new file mode 100644 index 0000000..5f06735 --- /dev/null +++ b/tests/cmake/compiler_warnings.cmake @@ -0,0 +1,82 @@ +# from here: +# https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md +# https://github.com/lefticus/cpp_starter_project/blob/master/cmake/CompilerWarnings.cmake +# lefticus/cpp_starter_project is licensed under the The Unlicense +# A license with no conditions whatsoever which dedicates works to the public domain. Unlicensed works, modifications, +# and larger works may be distributed under different terms and without source code. + +function(set_project_warnings project_name) + option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" TRUE) + + set(MSVC_WARNINGS + /W4 # Baseline reasonable warnings + /w14242 # 'identifier': conversion from 'type1' to 'type1', possible loss of data + /w14254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data + /w14263 # 'function': member function does not override any base class virtual member function + /w14265 # 'classname': class has virtual functions, but destructor is not virtual instances of this class may not + # be destructed correctly + /w14287 # 'operator': unsigned/negative constant mismatch + /we4289 # nonstandard extension used: 'variable': loop control variable declared in the for-loop is used outside + # the for-loop scope + /w14296 # 'operator': expression is always 'boolean_value' + /w14311 # 'variable': pointer truncation from 'type1' to 'type2' + /w14545 # expression before comma evaluates to a function which is missing an argument list + /w14546 # function call before comma missing argument list + /w14547 # 'operator': operator before comma has no effect; expected operator with side-effect + /w14549 # 'operator': operator before comma has no effect; did you intend 'operator'? + /w14555 # expression has no effect; expected expression with side- effect + /w14619 # pragma warning: there is no warning number 'number' + /w14640 # Enable warning on thread un-safe static member initialization + /w14826 # Conversion from 'type1' to 'type_2' is sign-extended. This may cause unexpected runtime behavior. + /w14905 # wide string literal cast to 'LPSTR' + /w14906 # string literal cast to 'LPWSTR' + /w14928 # illegal copy-initialization; more than one user-defined conversion has been implicitly applied + /permissive- # standards conformance mode for MSVC compiler. + ) + + set(CLANG_WARNINGS + -Wall + -Wextra # reasonable and standard + -Wshadow # warn the user if a variable declaration shadows one from a parent context + -Wnon-virtual-dtor # warn the user if a class with virtual functions has a non-virtual destructor. This helps + # catch hard to track down memory errors + -Wold-style-cast # warn for c-style casts + -Wcast-align # warn for potential performance problem casts + -Wunused # warn on anything being unused + -Woverloaded-virtual # warn if you overload (not override) a virtual function + -Wpedantic # warn if non-standard C++ is used + -Wconversion # warn on type conversions that may lose data + -Wsign-conversion # warn on sign conversions + -Wnull-dereference # warn if a null dereference is detected + -Wdouble-promotion # warn if float is implicit promoted to double + -Wformat=2 # warn on security issues around functions that format output (ie printf) + ) + + if (WARNINGS_AS_ERRORS) + message(STATUS "Warnings as errors: enabled") + set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror) + set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX) + endif () + + set(GCC_WARNINGS + ${CLANG_WARNINGS} + -Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist + -Wduplicated-cond # warn if if / else chain has duplicated conditions + -Wduplicated-branches # warn if if / else branches have duplicated code + -Wlogical-op # warn about logical operations being used where bitwise were probably wanted + -Wuseless-cast # warn if you perform a cast to the same type + ) + + if (MSVC) + set(PROJECT_WARNINGS ${MSVC_WARNINGS}) + elseif (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") + set(PROJECT_WARNINGS ${CLANG_WARNINGS}) + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(PROJECT_WARNINGS ${GCC_WARNINGS}) + else () + message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.") + endif () + + target_compile_options(${project_name} INTERFACE ${PROJECT_WARNINGS}) + +endfunction() diff --git a/tests/ut.cmake b/tests/cmake/ut.cmake similarity index 100% rename from tests/ut.cmake rename to tests/cmake/ut.cmake diff --git a/tests/algorithm_test.cpp b/tests/src/algorithm_test.cpp similarity index 89% rename from tests/algorithm_test.cpp rename to tests/src/algorithm_test.cpp index 28e2ee6..a0d006a 100644 --- a/tests/algorithm_test.cpp +++ b/tests/src/algorithm_test.cpp @@ -54,7 +54,7 @@ static constexpr auto make_unsigned = [](const auto &op, auto const &...a) { (static_cast>>(a))...); }; /** - * Eagar transform and output to rvalue range + * Eager transform and output to rvalue range * @tparam I first range iterator type * @tparam Is other range iterators type * @tparam O output range r-value type @@ -135,6 +135,8 @@ int main() { transform([&](const auto &...a) { return plus(3, a...); }, std::array(), b, e); expect(constant); + expect(constant); + expect(constant); }; "transform + 2x"_test = [&] { std::array result{}; @@ -150,5 +152,19 @@ int main() { expect(constant); expect(constant); }; + "transform + 3x"_test = [&] { + std::array result{}; + aal::var::transform(plus, std::ranges::begin(result), b, e, b,b); + expect(result[3] == 9_i); + expect(result[2] == 6_i); + expect(result[1] == 3_i); + }; + "transform + 3x constexpr"_test = [&] { + constexpr auto result = + transform(plus, std::array(), b, e, b,b); + expect(constant); + expect(constant); + expect(constant); + }; }; } \ No newline at end of file From 61199376ae39f26cbdc2e5ce3989ddce72047083 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Mon, 8 Mar 2021 13:16:07 -0500 Subject: [PATCH 05/40] east const and added some tests reworded test names. changed custom transform to consteval --- tests/src/algorithm_test.cpp | 68 +++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/tests/src/algorithm_test.cpp b/tests/src/algorithm_test.cpp index a0d006a..45477ff 100644 --- a/tests/src/algorithm_test.cpp +++ b/tests/src/algorithm_test.cpp @@ -7,19 +7,19 @@ * multiply all the parameter pack values together * @note if sizeof...(a) == 1 it returns a. */ -static constexpr auto multiply = [](auto const &...a) { return (a * ...); }; +static constexpr auto multiply = [](const auto &...a) { return (a * ...); }; /** * add all the parameter pack values together * @note if sizeof...(a) == 1 it returns a. */ -static constexpr auto plus = [](auto const &...a) { return (a + ...); }; +static constexpr auto plus = [](const auto &...a) { return (a + ...); }; /** * are all the parameter pack values equal? * @param first value * @param rest of values. */ -static constexpr auto equal_to = [](auto const &first, - auto const &...rest) -> bool { +static constexpr auto equal_to = [](const auto &first, + const auto &...rest) -> bool { static_assert(sizeof...(rest) != 0); return ((first == rest) || ...); }; @@ -28,8 +28,8 @@ static constexpr auto equal_to = [](auto const &first, * @param first value * @param rest of values. */ -static constexpr auto not_equal_to = [](auto const &first, - auto const &...rest) -> bool { +static constexpr auto not_equal_to = [](const auto &first, + const auto &...rest) -> bool { static_assert(sizeof...(rest) != 0); return ((first != rest) || ...); }; @@ -39,7 +39,7 @@ static constexpr auto not_equal_to = [](auto const &first, * @param op operation that is performed that returns a value. * @param a values */ -static constexpr auto make_signed = [](const auto &op, auto const &...a) { +static constexpr auto make_signed = [](const auto &op, const auto &...a) { static_assert((std::is_integral_v> && ...)); return op(static_cast>>(a)...); }; @@ -48,7 +48,7 @@ static constexpr auto make_signed = [](const auto &op, auto const &...a) { * @param op operation that is performed that returns a value. * @param a values */ -static constexpr auto make_unsigned = [](const auto &op, auto const &...a) { +static constexpr auto make_unsigned = [](const auto &op, const auto &...a) { static_assert((std::is_integral_v> && ...)); return op( (static_cast>>(a))...); @@ -65,9 +65,9 @@ static constexpr auto make_unsigned = [](const auto &op, auto const &...a) { * @param l first range iterator end * @param fs other range iterator begins * @return returns output range post transform. - */ +*/ template -[[nodiscard]] constexpr auto transform(Op const op, O &&o, I f, I const l, +[[nodiscard]] consteval auto transform(const Op op, O &&o, I f, const I l, Is... fs) { aal::var::transform(op, std::ranges::begin(o), f, l, fs...); return o; @@ -82,7 +82,19 @@ int main() { }; static constexpr auto b = std::ranges::begin(input); static constexpr auto e = std::ranges::end(input); - "equal_to"_test = [&] { + "plus"_test = []{ + expect(1_i == plus(1)); + expect(0_i == plus(1,-1)); + expect(3_i == plus(1,1,1)); + expect(957_i == plus(100,158,699)); + }; + "multiply"_test = []{ + expect(1_i == multiply(1)); + expect(-1_i == multiply(1,-1)); + expect(1_i == multiply(1,1,1)); + expect(11044200_i == multiply(100,158,699)); + }; + "equal_to"_test = [] { expect(constant); expect(equal_to(0.0, 0)); expect(make_signed(equal_to, 0U, 0)); @@ -91,26 +103,26 @@ int main() { expect(make_signed(equal_to, 3, 3U, 3)); expect(make_unsigned(equal_to, 3, 3U, 3, char(3))); }; - "not_equal_to"_test = [&] { + "not_equal_to"_test = [] { expect(constant); expect(make_signed(not_equal_to, -3, 3U, 6U, '5', 3)); expect(!make_signed(not_equal_to, 3, 3U, 3U, 3, char(3))); expect(!make_signed(not_equal_to, 3, 3U, 3)); expect(!make_unsigned(not_equal_to, 3, 3U, 3)); }; - "find"_test = [&] { + "find"_test = [] { static constexpr auto result = aal::var::find( [&](const auto &...a) { return equal_to(3, a...); }, b, e); expect(constant(result)>); expect(constant<3 == *std::get<0>(result)>); }; - "found"_test = [&] { + "found"_test = [] { static constexpr auto result = aal::var::found( [&](const auto &...a) { return equal_to(3, a...); }, b, e); expect(constant); }; - "transform == 3"_test = [&] { + "transform == 3"_test = [] { std::array output{}; const auto result = aal::var::transform( [&](const auto &...a) { return equal_to(3, a...); }, @@ -118,13 +130,13 @@ int main() { expect(output[3]); expect(!*result); }; - "transform == 3 constexpr"_test = [&] { + "transform == 3 constexpr"_test = [] { constexpr auto result = transform([&](const auto &...a) { return equal_to(3, a...); }, std::array(), b, e); expect(constant); }; - "transform + 3"_test = [&] { + "transform plus 3"_test = [&] { std::array result{}; aal::var::transform([&](const auto &...a) { return plus(3, a...); }, std::ranges::begin(result), b, e); @@ -138,33 +150,47 @@ int main() { expect(constant); expect(constant); }; - "transform + 2x"_test = [&] { + "transform plus 2 times"_test = [] { std::array result{}; aal::var::transform(plus, std::ranges::begin(result), b, e, b); expect(result[3] == 6_i); expect(result[2] == 4_i); expect(result[1] == 2_i); }; - "transform + 2x constexpr"_test = [&] { + "transform plus 2 times constexpr"_test = [] { constexpr auto result = transform(plus, std::array(), b, e, b); expect(constant); expect(constant); expect(constant); }; - "transform + 3x"_test = [&] { + "transform plus 3 times"_test = [] { std::array result{}; aal::var::transform(plus, std::ranges::begin(result), b, e, b,b); expect(result[3] == 9_i); expect(result[2] == 6_i); expect(result[1] == 3_i); }; - "transform + 3x constexpr"_test = [&] { + "transform plus 3 times constexpr"_test = [] { constexpr auto result = transform(plus, std::array(), b, e, b,b); expect(constant); expect(constant); expect(constant); }; + "transform multiply 3 times"_test = [] { + std::array result{}; + aal::var::transform(multiply, std::ranges::begin(result), b, e, b,b); + expect(result[3] == 27_i); + expect(result[2] == 8_i); + expect(result[1] == 1_i); + }; + "transform multiply 3 times constexpr"_test = [] { + constexpr auto result = + transform(multiply, std::array(), b, e, b,b); + expect(constant); + expect(constant); + expect(constant); + }; }; } \ No newline at end of file From 525554c396b37c2f340f51696d343db6a55b9956 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Mon, 8 Mar 2021 13:57:27 -0500 Subject: [PATCH 06/40] instead of baking in a initializer list of numbers I wrote a consteval iota. Though maybe iota::view would work better. it only works in gcc i think. --- tests/src/algorithm_test.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/src/algorithm_test.cpp b/tests/src/algorithm_test.cpp index 45477ff..fb148ec 100644 --- a/tests/src/algorithm_test.cpp +++ b/tests/src/algorithm_test.cpp @@ -3,6 +3,7 @@ #include "aal/algorithm.hpp" #include #include +#include /** * multiply all the parameter pack values together * @note if sizeof...(a) == 1 it returns a. @@ -72,14 +73,26 @@ template aal::var::transform(op, std::ranges::begin(o), f, l, fs...); return o; } +/** + * Eager constant time construct a std::array of numbers using iota. + * @tparam start number + * @tparam count of values + * @return std::array from start to start+count + */ +template +requires(count < std::numeric_limits::max()-start) +[[nodiscard]] consteval auto iota() +{ + auto ret = std::array{}; + std::iota(std::ranges::begin(ret),std::ranges::end(ret), start); + return ret; +} int main() { using namespace boost::ut::literals; using namespace boost::ut::operators::terse; using namespace boost::ut; [[maybe_unused]] suite tests = [] { - static constexpr std::array input{ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - }; + static constexpr auto input = iota<0,10U>(); static constexpr auto b = std::ranges::begin(input); static constexpr auto e = std::ranges::end(input); "plus"_test = []{ From 6adbf47431fbd3ccfbe2cf448838aeb6c2c641e2 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Mon, 8 Mar 2021 14:17:26 -0500 Subject: [PATCH 07/40] copied .clang-format to project from j. ran clang format on algorithm_test.cpp --- .clang-format | 155 ++++++++++++++++++ tests/src/algorithm_test.cpp | 300 ++++++++++++++++++----------------- 2 files changed, 310 insertions(+), 145 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..2787041 --- /dev/null +++ b/.clang-format @@ -0,0 +1,155 @@ +--- +# Refer to the following link for the explanation of each params: +# http://releases.llvm.org/8.0.0/tools/clang/docs/ClangFormatStyleOptions.html +Language: Cpp +# BasedOnStyle: Google +AccessModifierOffset: -1 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: true +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Left +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: true +AllowShortFunctionsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: true +AllowShortLoopsOnASingleLine: true +# This is deprecated +AlwaysBreakAfterDefinitionReturnType: All +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: Yes +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + # disabling the below splits, else, they'll just add to the vertical length of source files! + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 120 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true +# Kept the below 2 to be the same as `IndentWidth` to keep everything uniform +ConstructorInitializerIndentWidth: 2 +ContinuationIndentWidth: 2 +Cpp11BracedListStyle: true +DerivePointerAlignment: true +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^' + Priority: 2 + - Regex: '^<.*\.h>' + Priority: 1 + - Regex: '^<.*' + Priority: 2 + - Regex: '.*' + Priority: 3 +IncludeIsMainRegex: '([-_](test|unittest))?$' +IndentCaseLabels: true +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Never +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +PointerAlignment: Left +RawStringFormats: + - Language: Cpp + Delimiters: + - cc + - CC + - cpp + - Cpp + - CPP + - 'c++' + - 'C++' + CanonicalDelimiter: '' + - Language: TextProto + Delimiters: + - pb + - PB + - proto + - PROTO + EnclosingFunctions: + - EqualsProto + - EquivToProto + - PARSE_PARTIAL_TEXT_PROTO + - PARSE_TEST_PROTO + - PARSE_TEXT_PROTO + - ParseTextOrDie + - ParseTextProtoOrDie + CanonicalDelimiter: '' + BasedOnStyle: google +# Enabling comment reflow causes doxygen comments to be messed up in their formats! +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: c++20 +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +# Be consistent with indent-width, even for people who use tab for indentation! +TabWidth: 3 +UseTab: Never diff --git a/tests/src/algorithm_test.cpp b/tests/src/algorithm_test.cpp index fb148ec..39db506 100644 --- a/tests/src/algorithm_test.cpp +++ b/tests/src/algorithm_test.cpp @@ -1,38 +1,39 @@ -#include // single header +#include // single header // import boost.ut; // single module (C++20) -#include "aal/algorithm.hpp" #include -#include #include +#include +#include "aal/algorithm.hpp" /** * multiply all the parameter pack values together * @note if sizeof...(a) == 1 it returns a. */ static constexpr auto multiply = [](const auto &...a) { return (a * ...); }; + /** * add all the parameter pack values together * @note if sizeof...(a) == 1 it returns a. */ static constexpr auto plus = [](const auto &...a) { return (a + ...); }; + /** * are all the parameter pack values equal? * @param first value * @param rest of values. */ -static constexpr auto equal_to = [](const auto &first, - const auto &...rest) -> bool { - static_assert(sizeof...(rest) != 0); - return ((first == rest) || ...); +static constexpr auto equal_to = [](const auto &first, const auto &...rest) -> bool { + static_assert(sizeof...(rest) != 0); + return ((first == rest) || ...); }; + /** * are any of the parameter pack values not equal? * @param first value * @param rest of values. */ -static constexpr auto not_equal_to = [](const auto &first, - const auto &...rest) -> bool { - static_assert(sizeof...(rest) != 0); - return ((first != rest) || ...); +static constexpr auto not_equal_to = [](const auto &first, const auto &...rest) -> bool { + static_assert(sizeof...(rest) != 0); + return ((first != rest) || ...); }; /** @@ -41,19 +42,20 @@ static constexpr auto not_equal_to = [](const auto &first, * @param a values */ static constexpr auto make_signed = [](const auto &op, const auto &...a) { - static_assert((std::is_integral_v> && ...)); - return op(static_cast>>(a)...); + static_assert((std::is_integral_v> && ...)); + return op(static_cast>>(a)...); }; + /** * Transform values to unsigned types and pass to op * @param op operation that is performed that returns a value. * @param a values */ static constexpr auto make_unsigned = [](const auto &op, const auto &...a) { - static_assert((std::is_integral_v> && ...)); - return op( - (static_cast>>(a))...); + static_assert((std::is_integral_v> && ...)); + return op((static_cast>>(a))...); }; + /** * Eager transform and output to rvalue range * @tparam I first range iterator type @@ -66,144 +68,152 @@ static constexpr auto make_unsigned = [](const auto &op, const auto &...a) { * @param l first range iterator end * @param fs other range iterator begins * @return returns output range post transform. -*/ + */ + template -[[nodiscard]] consteval auto transform(const Op op, O &&o, I f, const I l, - Is... fs) { - aal::var::transform(op, std::ranges::begin(o), f, l, fs...); - return o; +[[nodiscard]] consteval auto +transform(const Op op, O &&o, I f, const I l, Is... fs) { + aal::var::transform(op, std::ranges::begin(o), f, l, fs...); + return o; } + /** * Eager constant time construct a std::array of numbers using iota. * @tparam start number * @tparam count of values * @return std::array from start to start+count */ -template -requires(count < std::numeric_limits::max()-start) -[[nodiscard]] consteval auto iota() -{ - auto ret = std::array{}; - std::iota(std::ranges::begin(ret),std::ranges::end(ret), start); - return ret; +template +requires(count < std::numeric_limits::max() - start) [[nodiscard]] consteval auto iota() { + auto ret = std::array{}; + std::iota(std::ranges::begin(ret), std::ranges::end(ret), start); + return ret; } -int main() { - using namespace boost::ut::literals; - using namespace boost::ut::operators::terse; - using namespace boost::ut; - [[maybe_unused]] suite tests = [] { - static constexpr auto input = iota<0,10U>(); - static constexpr auto b = std::ranges::begin(input); - static constexpr auto e = std::ranges::end(input); - "plus"_test = []{ - expect(1_i == plus(1)); - expect(0_i == plus(1,-1)); - expect(3_i == plus(1,1,1)); - expect(957_i == plus(100,158,699)); - }; - "multiply"_test = []{ - expect(1_i == multiply(1)); - expect(-1_i == multiply(1,-1)); - expect(1_i == multiply(1,1,1)); - expect(11044200_i == multiply(100,158,699)); - }; - "equal_to"_test = [] { - expect(constant); - expect(equal_to(0.0, 0)); - expect(make_signed(equal_to, 0U, 0)); - expect(make_unsigned(equal_to, 0U, 0)); - expect(make_signed(equal_to, 3, 3U, 3U, 3)); - expect(make_signed(equal_to, 3, 3U, 3)); - expect(make_unsigned(equal_to, 3, 3U, 3, char(3))); - }; - "not_equal_to"_test = [] { - expect(constant); - expect(make_signed(not_equal_to, -3, 3U, 6U, '5', 3)); - expect(!make_signed(not_equal_to, 3, 3U, 3U, 3, char(3))); - expect(!make_signed(not_equal_to, 3, 3U, 3)); - expect(!make_unsigned(not_equal_to, 3, 3U, 3)); - }; - "find"_test = [] { - static constexpr auto result = aal::var::find( - [&](const auto &...a) { return equal_to(3, a...); }, b, e); - expect(constant(result)>); - expect(constant<3 == *std::get<0>(result)>); - }; - "found"_test = [] { - static constexpr auto result = aal::var::found( - [&](const auto &...a) { return equal_to(3, a...); }, b, e); - expect(constant); - }; - "transform == 3"_test = [] { - std::array output{}; - const auto result = aal::var::transform( - [&](const auto &...a) { return equal_to(3, a...); }, - std::ranges::begin(output), b, e); - expect(output[3]); - expect(!*result); - }; - "transform == 3 constexpr"_test = [] { - constexpr auto result = - transform([&](const auto &...a) { return equal_to(3, a...); }, - std::array(), b, e); - expect(constant); - }; - "transform plus 3"_test = [&] { - std::array result{}; - aal::var::transform([&](const auto &...a) { return plus(3, a...); }, - std::ranges::begin(result), b, e); - expect(result[3] == 6_i); - }; - "transform == 3 constexpr"_test = [&] { - constexpr auto result = - transform([&](const auto &...a) { return plus(3, a...); }, - std::array(), b, e); - expect(constant); - expect(constant); - expect(constant); - }; - "transform plus 2 times"_test = [] { - std::array result{}; - aal::var::transform(plus, std::ranges::begin(result), b, e, b); - expect(result[3] == 6_i); - expect(result[2] == 4_i); - expect(result[1] == 2_i); - }; - "transform plus 2 times constexpr"_test = [] { - constexpr auto result = - transform(plus, std::array(), b, e, b); - expect(constant); - expect(constant); - expect(constant); - }; - "transform plus 3 times"_test = [] { - std::array result{}; - aal::var::transform(plus, std::ranges::begin(result), b, e, b,b); - expect(result[3] == 9_i); - expect(result[2] == 6_i); - expect(result[1] == 3_i); - }; - "transform plus 3 times constexpr"_test = [] { - constexpr auto result = - transform(plus, std::array(), b, e, b,b); - expect(constant); - expect(constant); - expect(constant); - }; - "transform multiply 3 times"_test = [] { - std::array result{}; - aal::var::transform(multiply, std::ranges::begin(result), b, e, b,b); - expect(result[3] == 27_i); - expect(result[2] == 8_i); - expect(result[1] == 1_i); - }; - "transform multiply 3 times constexpr"_test = [] { - constexpr auto result = - transform(multiply, std::array(), b, e, b,b); - expect(constant); - expect(constant); - expect(constant); +int +main() { + using namespace boost::ut::literals; + using namespace boost::ut::operators::terse; + using namespace boost::ut; + [[maybe_unused]] suite tests = [] { + static constexpr auto input = iota<0, 10U>(); + static constexpr auto b = std::ranges::begin(input); + static constexpr auto e = std::ranges::end(input); + + "plus"_test = [] { + expect(1_i == plus(1)); + expect(0_i == plus(1, -1)); + expect(3_i == plus(1, 1, 1)); + expect(957_i == plus(100, 158, 699)); + }; + + "multiply"_test = [] { + expect(1_i == multiply(1)); + expect(-1_i == multiply(1, -1)); + expect(1_i == multiply(1, 1, 1)); + expect(11044200_i == multiply(100, 158, 699)); + }; + + "equal_to"_test = [] { + expect(constant); + expect(equal_to(0.0, 0)); + expect(make_signed(equal_to, 0U, 0)); + expect(make_unsigned(equal_to, 0U, 0)); + expect(make_signed(equal_to, 3, 3U, 3U, 3)); + expect(make_signed(equal_to, 3, 3U, 3)); + expect(make_unsigned(equal_to, 3, 3U, 3, char(3))); + }; + + "not_equal_to"_test = [] { + expect(constant); + expect(make_signed(not_equal_to, -3, 3U, 6U, '5', 3)); + expect(!make_signed(not_equal_to, 3, 3U, 3U, 3, char(3))); + expect(!make_signed(not_equal_to, 3, 3U, 3)); + expect(!make_unsigned(not_equal_to, 3, 3U, 3)); + }; + + "find"_test = [] { + static constexpr auto result = aal::var::find([&](const auto &...a) { return equal_to(3, a...); }, b, e); + expect(constant(result)>); + expect(constant<3 == *std::get<0>(result)>); + }; + + "found"_test = [] { + static constexpr auto result = aal::var::found([&](const auto &...a) { return equal_to(3, a...); }, b, e); + expect(constant); + }; + + "transform == 3"_test = [] { + std::array output{}; + const auto result = aal::var::transform( + [&](const auto &...a) { return equal_to(3, a...); }, std::ranges::begin(output), b, e); + expect(output[3]); + expect(!*result); + }; + + "transform == 3 constexpr"_test = [] { + constexpr auto result = + transform([&](const auto &...a) { return equal_to(3, a...); }, std::array(), b, e); + expect(constant); + }; + + "transform plus 3"_test = [&] { + std::array result{}; + aal::var::transform([&](const auto &...a) { return plus(3, a...); }, std::ranges::begin(result), b, e); + expect(result[3] == 6_i); + }; + + "transform == 3 constexpr"_test = [&] { + constexpr auto result = + transform([&](const auto &...a) { return plus(3, a...); }, std::array(), b, e); + expect(constant); + expect(constant); + expect(constant); + }; + + "transform plus 2 times"_test = [] { + std::array result{}; + aal::var::transform(plus, std::ranges::begin(result), b, e, b); + expect(result[3] == 6_i); + expect(result[2] == 4_i); + expect(result[1] == 2_i); + }; + + "transform plus 2 times constexpr"_test = [] { + constexpr auto result = transform(plus, std::array(), b, e, b); + expect(constant); + expect(constant); + expect(constant); + }; + + "transform plus 3 times"_test = [] { + std::array result{}; + aal::var::transform(plus, std::ranges::begin(result), b, e, b, b); + expect(result[3] == 9_i); + expect(result[2] == 6_i); + expect(result[1] == 3_i); + }; + + "transform plus 3 times constexpr"_test = [] { + constexpr auto result = transform(plus, std::array(), b, e, b, b); + expect(constant); + expect(constant); + expect(constant); + }; + + "transform multiply 3 times"_test = [] { + std::array result{}; + aal::var::transform(multiply, std::ranges::begin(result), b, e, b, b); + expect(result[3] == 27_i); + expect(result[2] == 8_i); + expect(result[1] == 1_i); + }; + + "transform multiply 3 times constexpr"_test = [] { + constexpr auto result = transform(multiply, std::array(), b, e, b, b); + expect(constant); + expect(constant); + expect(constant); + }; }; - }; } \ No newline at end of file From 865d822b3f7e7df9e7332a888a2b97b694a7bccd Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Mon, 8 Mar 2021 14:53:58 -0500 Subject: [PATCH 08/40] Create CONTRIBUTING.md based on the jsource one. --- CONTRIBUTING.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..c794aaf --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,29 @@ +### Getting Started & Building: +1. Prerequisites: + * CMake version 3.17.0+ -> Ubuntu systems seem to have a problem getting the latest version, please build from sources or use another package such as snap. + * [Ubuntu CMake update instructions](https://apt.kitware.com/) + * Ninja +2. Checkout the repository: + ```sh + git clone https://github.com/codereport/An-Algorithm-Library.git + ``` +3. Build An Algorithm Library: + * Run cmake: + ```sh + cd An-Algorithm-Library + mkdir build + cmake -G "Ninja Multi-Config" -B build + ``` + * To build debug: + ```sh + ninja -C build + ``` + * To build release: + ```sh + ninja -C build -f build-Release.ninja + ``` +4. Run tests: + `wip i'm not sure why this command isn't working.` + ```sh + #ninja -C build test + ``` \ No newline at end of file From c39ee5906b8fedff757400a4437211f99048673f Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Mon, 8 Mar 2021 14:54:28 -0500 Subject: [PATCH 09/40] I guess there is supposed to be a NAME and COMMAND word on this . --- tests/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 391cfa9..97a7287 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -4,4 +4,6 @@ add_executable(${PROJECT_NAME}_algorithm_test src/algorithm_test.cpp) set_project_warnings(${PROJECT_NAME}_algorithm_test ON) target_link_libraries(${PROJECT_NAME}_algorithm_test PRIVATE Boost::ut ${PROJECT_NAME}_aal) -add_test(${PROJECT_NAME}_ALGORITHM_TEST ${PROJECT_NAME}_algorithm_test) \ No newline at end of file +add_test( + NAME ${PROJECT_NAME}_ALGORITHM_TEST COMMAND ${PROJECT_NAME}_algorithm_test +) \ No newline at end of file From 0c9c9d1bd29f3ca732a4291e20c764e11dc34a56 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Mon, 8 Mar 2021 15:09:50 -0500 Subject: [PATCH 10/40] enable_testing() needs to be in the root CMakeLists.txt or included via a .cmake file into the root. --- CMakeLists.txt | 1 + tests/cmake/ut.cmake | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fd49f4f..fb9635e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,4 +8,5 @@ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) ## automatically create a module defini ## symbols found in the input .obj files for a SHARED library on Windows. add_subdirectory(src) +enable_testing() add_subdirectory(tests) diff --git a/tests/cmake/ut.cmake b/tests/cmake/ut.cmake index 2c0768c..c0b7a4b 100644 --- a/tests/cmake/ut.cmake +++ b/tests/cmake/ut.cmake @@ -1,4 +1,3 @@ -enable_testing() include(FetchContent) FetchContent_Declare( ut From 585083bc19037eb5f160026ed972e3cbfb4c7136 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Mon, 8 Mar 2021 15:12:12 -0500 Subject: [PATCH 11/40] removed note about command not working as it's working now. --- CONTRIBUTING.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c794aaf..35a210f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -23,7 +23,6 @@ ninja -C build -f build-Release.ninja ``` 4. Run tests: - `wip i'm not sure why this command isn't working.` ```sh #ninja -C build test ``` \ No newline at end of file From 3fdc814514ddd39fa3148a444bbdc0ac40148a1f Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Mon, 8 Mar 2021 15:12:51 -0500 Subject: [PATCH 12/40] remove command # --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 35a210f..f52c6ed 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,5 +24,5 @@ ``` 4. Run tests: ```sh - #ninja -C build test + ninja -C build test ``` \ No newline at end of file From 7e356cf24d8d6b5c55e1a44c4e8159ad03772140 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Mon, 8 Mar 2021 15:25:40 -0500 Subject: [PATCH 13/40] add command for verbose output from tests --- CONTRIBUTING.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f52c6ed..a1edb93 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -25,4 +25,10 @@ 4. Run tests: ```sh ninja -C build test - ``` \ No newline at end of file + ``` + * For more verbose output: + + ```sh + cd build && ctest -C debug --verbose && cd .. + ``` + \ No newline at end of file From ced0dcda8605486949922afd48bf32cc98defdce Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Mon, 8 Mar 2021 15:36:15 -0500 Subject: [PATCH 14/40] add a custom executable name to algorithm_test --- tests/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 97a7287..fe54a59 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -4,6 +4,7 @@ add_executable(${PROJECT_NAME}_algorithm_test src/algorithm_test.cpp) set_project_warnings(${PROJECT_NAME}_algorithm_test ON) target_link_libraries(${PROJECT_NAME}_algorithm_test PRIVATE Boost::ut ${PROJECT_NAME}_aal) +set_target_properties(${PROJECT_NAME}_algorithm_test PROPERTIES OUTPUT_NAME "algorithm_test") add_test( NAME ${PROJECT_NAME}_ALGORITHM_TEST COMMAND ${PROJECT_NAME}_algorithm_test ) \ No newline at end of file From cf24ca0c242bcc63c1d5a1d449f14a68b898a5dc Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Mon, 8 Mar 2021 18:13:24 -0500 Subject: [PATCH 15/40] Create appveyor.yml If you wanna try appveyor. I tried this build script out. It worked and ran tests. I'm not an expert though, so some of these commands might not be required. --- appveyor.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..d7d6ac5 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,13 @@ +version: 1.0.{build} +image: Ubuntu2004 +init: +- sh: "sudo update-alternatives --remove-all gcc \nsudo update-alternatives --remove-all g++\nsudo apt-get update\nsudo apt-get install apt-transport-https ca-certificates gnupg software-properties-common wget\nwget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null\nsudo add-apt-repository ppa:ubuntu-toolchain-r/test\nsudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main'\nsudo apt-get -y update\nsudo apt-get -y install gcc-10 g++-10 ninja-build cmake\n#sudo apt-get -y upgrade\nsudo update-alternatives --remove-all gcc\nsudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 90\nsudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 90\nsudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30\nsudo update-alternatives --set cc /usr/bin/gcc\nsudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30\nsudo update-alternatives --set c++ /usr/bin/g++\nsudo apt -y autoremove" +build_script: +- sh: >- + mkdir build + + cmake -G "Ninja Multi-Config" -B build + + ninja -C build +test_script: +- sh: cd build && ctest -C debug --verbose && cd .. \ No newline at end of file From eaf9897d07a6e1e9f76286f27d5f7a1175e75d2f Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Mon, 8 Mar 2021 19:30:03 -0500 Subject: [PATCH 16/40] you have to use the PRIVATE keyword for each library you include --- tests/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fe54a59..3b71fbd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,7 +3,9 @@ include(cmake/ut.cmake) add_executable(${PROJECT_NAME}_algorithm_test src/algorithm_test.cpp) set_project_warnings(${PROJECT_NAME}_algorithm_test ON) -target_link_libraries(${PROJECT_NAME}_algorithm_test PRIVATE Boost::ut ${PROJECT_NAME}_aal) +target_link_libraries(${PROJECT_NAME}_algorithm_test + PRIVATE Boost::ut + PRIVATE ${PROJECT_NAME}_aal) set_target_properties(${PROJECT_NAME}_algorithm_test PROPERTIES OUTPUT_NAME "algorithm_test") add_test( NAME ${PROJECT_NAME}_ALGORITHM_TEST COMMAND ${PROJECT_NAME}_algorithm_test From 100f21f33c273188174c642cac23a9dab569f822 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Tue, 9 Mar 2021 22:04:56 -0500 Subject: [PATCH 17/40] fixed compiler warnings. seems the warnings have to be added to a interface library to work correctly. I also had to block the shadow errors to compile ut. --- tests/CMakeLists.txt | 8 +++++--- tests/cmake/compiler_warnings.cmake | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3b71fbd..4ee0a37 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,11 +1,13 @@ include(cmake/compiler_warnings.cmake) +add_library(${PROJECT_NAME}_project_warnings INTERFACE) +set_project_warnings(${PROJECT_NAME}_project_warnings ON) include(cmake/ut.cmake) add_executable(${PROJECT_NAME}_algorithm_test src/algorithm_test.cpp) -set_project_warnings(${PROJECT_NAME}_algorithm_test ON) target_link_libraries(${PROJECT_NAME}_algorithm_test - PRIVATE Boost::ut - PRIVATE ${PROJECT_NAME}_aal) + PUBLIC Boost::ut + PRIVATE ${PROJECT_NAME}_aal + PRIVATE ${PROJECT_NAME}_project_warnings) set_target_properties(${PROJECT_NAME}_algorithm_test PROPERTIES OUTPUT_NAME "algorithm_test") add_test( NAME ${PROJECT_NAME}_ALGORITHM_TEST COMMAND ${PROJECT_NAME}_algorithm_test diff --git a/tests/cmake/compiler_warnings.cmake b/tests/cmake/compiler_warnings.cmake index 5f06735..80ba6f7 100644 --- a/tests/cmake/compiler_warnings.cmake +++ b/tests/cmake/compiler_warnings.cmake @@ -38,6 +38,7 @@ function(set_project_warnings project_name) -Wall -Wextra # reasonable and standard -Wshadow # warn the user if a variable declaration shadows one from a parent context + -Wno-error=shadow # ut has a lot of shadows. This prevents errors from that. -Wnon-virtual-dtor # warn the user if a class with virtual functions has a non-virtual destructor. This helps # catch hard to track down memory errors -Wold-style-cast # warn for c-style casts From cb5b84df49d904b5f679ff98bea708fbb21b0796 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Tue, 9 Mar 2021 22:06:26 -0500 Subject: [PATCH 18/40] Should probably be private, though for executables it probably doesn't matter. --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4ee0a37..292b0e7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,7 +5,7 @@ include(cmake/ut.cmake) add_executable(${PROJECT_NAME}_algorithm_test src/algorithm_test.cpp) target_link_libraries(${PROJECT_NAME}_algorithm_test - PUBLIC Boost::ut + PRIVATE Boost::ut PRIVATE ${PROJECT_NAME}_aal PRIVATE ${PROJECT_NAME}_project_warnings) set_target_properties(${PROJECT_NAME}_algorithm_test PROPERTIES OUTPUT_NAME "algorithm_test") From 7f9019a6e17a21b5b6f6fd505cfc53f15c32cc41 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Tue, 9 Mar 2021 22:36:54 -0500 Subject: [PATCH 19/40] herwinw pointed out we don't need to build anything. Though I'm using the verbose output, and it needs to build. --- CONTRIBUTING.md | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a1edb93..ccf4ae1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,21 +7,12 @@ ```sh git clone https://github.com/codereport/An-Algorithm-Library.git ``` -3. Build An Algorithm Library: - * Run cmake: +3. Run cmake: ```sh cd An-Algorithm-Library mkdir build cmake -G "Ninja Multi-Config" -B build ``` - * To build debug: - ```sh - ninja -C build - ``` - * To build release: - ```sh - ninja -C build -f build-Release.ninja - ``` 4. Run tests: ```sh ninja -C build test @@ -29,6 +20,6 @@ * For more verbose output: ```sh - cd build && ctest -C debug --verbose && cd .. + ninja -C build && cd build && ctest -C debug --verbose && cd .. ``` \ No newline at end of file From 586b7515b1d566ca1ca5e077fcefa51af6257af6 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Tue, 9 Mar 2021 22:40:48 -0500 Subject: [PATCH 20/40] remove j .gitignore entries. --- .gitignore | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/.gitignore b/.gitignore index 29ba96a..e0aaec6 100644 --- a/.gitignore +++ b/.gitignore @@ -6,28 +6,16 @@ *.so !asm/*.o -# temp scripts used for debugging -*makevs/jdll/*.ijs -jj.ijs - # windows - most output files go to %userprofile%\jbld\jout # some end up in the project folder and are marked here # sometimes entire project subfolders are created that should not be in repo *.sdf *.opensdf *.suo -**/jconsole/.vs/ -**/jdll/**/.vs/ -**/tsdll/**/.vs/ *.ilk *.pdb *.exp -# following are no longer required and prevent template folders -# **/jconsole/**/ -# **/jdll/**/ -# **/tsdll/**/ - # windows - need to run with different versions of vs # following files are in repo for vs2013 # but are not pushed to avoid getting unwanted user specific changes @@ -61,10 +49,6 @@ out/ build/ bin/ make2/ -/jlibrary/addons -/jlibrary/bin -/jlibrary/bin32 -/jlibrary/tools # clion's cmake creates cmake-build-release, cmake-build-debug, etc... cmake-build-*/ From 315085091a999cec13be5a9dd8748d439d4e7e70 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Wed, 10 Mar 2021 09:38:31 -0500 Subject: [PATCH 21/40] wrap tests in if statement per "modern-cmake" I found https://cliutils.gitlab.io/modern-cmake/chapters/testing.html We need to put if statements around the enable testing and the add subdirectory. --- CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fb9635e..db1b8d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,5 +8,10 @@ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) ## automatically create a module defini ## symbols found in the input .obj files for a SHARED library on Windows. add_subdirectory(src) -enable_testing() +# see https://cliutils.gitlab.io/modern-cmake/chapters/testing.html +if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + include(CTest) +endif () +if ((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) AND BUILD_TESTING) add_subdirectory(tests) +endif () \ No newline at end of file From 330ae6e62d5f3c6142f5303026ebe4fc75bb3183 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Wed, 10 Mar 2021 10:42:43 -0500 Subject: [PATCH 22/40] Setting target specific settings instead of global --- CMakeLists.txt | 6 ------ tests/CMakeLists.txt | 8 +++++++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index db1b8d5..a25ffc8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,6 @@ cmake_minimum_required(VERSION 3.18) project(An-Algorithm-Library C CXX) -set(CMAKE_CXX_STANDARD 20) ## Supported values are 98, 11, 14, 17, and 20. -set(CMAKE_CXX_STANDARD_REQUIRED ON) ## the value of the CXX_STANDARD target property is treated as a requirement -set(CMAKE_CXX_EXTENSIONS OFF) ## on g++ this ensures: -std=c++11 and not -std=gnu++11 -set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) ## automatically create a module definition (.def) file with all global - ## symbols found in the input .obj files for a SHARED library on Windows. - add_subdirectory(src) # see https://cliutils.gitlab.io/modern-cmake/chapters/testing.html if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 292b0e7..768b30c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,7 +8,13 @@ target_link_libraries(${PROJECT_NAME}_algorithm_test PRIVATE Boost::ut PRIVATE ${PROJECT_NAME}_aal PRIVATE ${PROJECT_NAME}_project_warnings) -set_target_properties(${PROJECT_NAME}_algorithm_test PROPERTIES OUTPUT_NAME "algorithm_test") +#https://cliutils.gitlab.io/modern-cmake/chapters/features/cpp11.html +target_compile_features(${PROJECT_NAME}_algorithm_test PRIVATE cxx_std_20) +set_target_properties(${PROJECT_NAME}_algorithm_test PROPERTIES + OUTPUT_NAME "algorithm_test" + CXX_EXTENSIONS OFF + CXX_STANDARD_REQUIRED ON + WINDOWS_EXPORT_ALL_SYMBOLS OFF) add_test( NAME ${PROJECT_NAME}_ALGORITHM_TEST COMMAND ${PROJECT_NAME}_algorithm_test ) \ No newline at end of file From 177327d02573ccd490d7038d06deb23271338b20 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Wed, 10 Mar 2021 11:55:08 -0500 Subject: [PATCH 23/40] appveyor to now build on visual studio 2019 --- appveyor.yml | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index d7d6ac5..d60d2db 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,13 +1,21 @@ version: 1.0.{build} -image: Ubuntu2004 -init: -- sh: "sudo update-alternatives --remove-all gcc \nsudo update-alternatives --remove-all g++\nsudo apt-get update\nsudo apt-get install apt-transport-https ca-certificates gnupg software-properties-common wget\nwget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null\nsudo add-apt-repository ppa:ubuntu-toolchain-r/test\nsudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main'\nsudo apt-get -y update\nsudo apt-get -y install gcc-10 g++-10 ninja-build cmake\n#sudo apt-get -y upgrade\nsudo update-alternatives --remove-all gcc\nsudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 90\nsudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 90\nsudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30\nsudo update-alternatives --set cc /usr/bin/gcc\nsudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30\nsudo update-alternatives --set c++ /usr/bin/g++\nsudo apt -y autoremove" -build_script: -- sh: >- - mkdir build - - cmake -G "Ninja Multi-Config" -B build - - ninja -C build -test_script: -- sh: cd build && ctest -C debug --verbose && cd .. \ No newline at end of file +image: + - Visual Studio 2019 + - Ubuntu2004 +for: + - matrix: + only: + - image: Ubuntu2004 + init: + - sh: "sudo update-alternatives --remove-all gcc \nsudo update-alternatives --remove-all g++\nsudo apt-get update\nsudo apt-get install apt-transport-https ca-certificates gnupg software-properties-common wget\nwget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null\nsudo add-apt-repository ppa:ubuntu-toolchain-r/test\nsudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main'\nsudo apt-get -y update\nsudo apt-get -y install gcc-10 g++-10 ninja-build cmake\n#sudo apt-get -y upgrade\nsudo update-alternatives --remove-all gcc\nsudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 90\nsudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 90\nsudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30\nsudo update-alternatives --set cc /usr/bin/gcc\nsudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30\nsudo update-alternatives --set c++ /usr/bin/g++\nsudo apt -y autoremove" + build_script: + - sh: "mkdir build\ncmake -G \"Ninja Multi-Config\" -B build\nninja -C build" + test_script: + - sh: "cd build && ctest -C debug --verbose && cd .." + - matrix: + only: + - image: Visual Studio 2019 + build_script: + - cmd: "mkdir build\ncmake -G \"Visual Studio 16 2019\" -B build\nMSBuild build\\ALL_BUILD.vcxproj" + test_script: + - cmd: "cd build\nctest -C debug --verbose\ncd .." \ No newline at end of file From 6a0eaa23ec2944f3dc87e232b21faae4db80fbe4 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Wed, 10 Mar 2021 23:07:09 -0500 Subject: [PATCH 24/40] add clang to CI this is some trial and error. It seemed to work on my code except clang doesn't have so it errored on that. --- appveyor.yml | 55 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index d60d2db..b3ec1ce 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,21 +1,38 @@ version: 1.0.{build} -image: - - Visual Studio 2019 - - Ubuntu2004 +environment: + matrix: + - job_name: Windows MSVC build + appveyor_build_worker_image: Visual Studio 2019 + + - job_name: Linux GCC build + appveyor_build_worker_image: Ubuntu2004 + + - job_name: Linux Clang build + appveyor_build_worker_image: Ubuntu2004 for: - - matrix: - only: - - image: Ubuntu2004 - init: - - sh: "sudo update-alternatives --remove-all gcc \nsudo update-alternatives --remove-all g++\nsudo apt-get update\nsudo apt-get install apt-transport-https ca-certificates gnupg software-properties-common wget\nwget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null\nsudo add-apt-repository ppa:ubuntu-toolchain-r/test\nsudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main'\nsudo apt-get -y update\nsudo apt-get -y install gcc-10 g++-10 ninja-build cmake\n#sudo apt-get -y upgrade\nsudo update-alternatives --remove-all gcc\nsudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 90\nsudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 90\nsudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30\nsudo update-alternatives --set cc /usr/bin/gcc\nsudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30\nsudo update-alternatives --set c++ /usr/bin/g++\nsudo apt -y autoremove" - build_script: - - sh: "mkdir build\ncmake -G \"Ninja Multi-Config\" -B build\nninja -C build" - test_script: - - sh: "cd build && ctest -C debug --verbose && cd .." - - matrix: - only: - - image: Visual Studio 2019 - build_script: - - cmd: "mkdir build\ncmake -G \"Visual Studio 16 2019\" -B build\nMSBuild build\\ALL_BUILD.vcxproj" - test_script: - - cmd: "cd build\nctest -C debug --verbose\ncd .." \ No newline at end of file + - matrix: + only: + - job_name: Linux Clang build + init: + - sh: "\nsudo apt-get update\nsudo apt-get install apt-transport-https ca-certificates gnupg software-properties-common wget\nwget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null\nsudo add-apt-repository ppa:ubuntu-toolchain-r/test\nsudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main'\nsudo apt-get -y update\nsudo apt-get -y install clang-11 clang++-11 ninja-build cmake\n#sudo apt-get -y upgrade\nsudo update-alternatives --remove-all clang\nsudo update-alternatives --remove-all clang++\nsudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-11 90\nsudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-11 90\nsudo apt -y autoremove\nexport CC=clang\nexport CXX=clang++" + build_script: + - sh: "mkdir build\ncmake -G \"Ninja Multi-Config\" -B build\nninja -C build" + test_script: + - sh: "cd build && ctest -C debug --verbose && cd .." + + - matrix: + only: + - job_name: Linux GCC build + init: + - sh: "sudo update-alternatives --remove-all gcc \nsudo update-alternatives --remove-all g++\nsudo apt-get update\nsudo apt-get install apt-transport-https ca-certificates gnupg software-properties-common wget\nwget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null\nsudo add-apt-repository ppa:ubuntu-toolchain-r/test\nsudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main'\nsudo apt-get -y update\nsudo apt-get -y install gcc-10 g++-10 ninja-build cmake\n#sudo apt-get -y upgrade\nsudo update-alternatives --remove-all gcc\nsudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 90\nsudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 90\nsudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30\nsudo update-alternatives --set cc /usr/bin/gcc\nsudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30\nsudo update-alternatives --set c++ /usr/bin/g++\nsudo apt -y autoremove" + build_script: + - sh: "mkdir build\ncmake -G \"Ninja Multi-Config\" -B build\nninja -C build" + test_script: + - sh: "cd build && ctest -C debug --verbose && cd .." + - matrix: + only: + - job_name: Windows MSVC build + build_script: + - cmd: "mkdir build\ncmake -G \"Visual Studio 16 2019\" -B build\nMSBuild build\\ALL_BUILD.vcxproj" + test_script: + - cmd: "cd build\nctest -C debug --verbose\ncd .." \ No newline at end of file From 2f097cb1ab83401de0783e575878d000b097123c Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Wed, 10 Mar 2021 23:18:36 -0500 Subject: [PATCH 25/40] clang failed because it lacked and we could probably swap out ranges code in places. though I am using a concept from ranges to check for a range. --- appveyor.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index b3ec1ce..b26672a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,8 +7,9 @@ environment: - job_name: Linux GCC build appveyor_build_worker_image: Ubuntu2004 - - job_name: Linux Clang build - appveyor_build_worker_image: Ubuntu2004 +# - job_name: Linux Clang build +# appveyor_build_worker_image: Ubuntu2004 +# clang is missing and for: - matrix: only: @@ -24,7 +25,7 @@ for: only: - job_name: Linux GCC build init: - - sh: "sudo update-alternatives --remove-all gcc \nsudo update-alternatives --remove-all g++\nsudo apt-get update\nsudo apt-get install apt-transport-https ca-certificates gnupg software-properties-common wget\nwget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null\nsudo add-apt-repository ppa:ubuntu-toolchain-r/test\nsudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main'\nsudo apt-get -y update\nsudo apt-get -y install gcc-10 g++-10 ninja-build cmake\n#sudo apt-get -y upgrade\nsudo update-alternatives --remove-all gcc\nsudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 90\nsudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 90\nsudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30\nsudo update-alternatives --set cc /usr/bin/gcc\nsudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30\nsudo update-alternatives --set c++ /usr/bin/g++\nsudo apt -y autoremove" + - sh: "sudo update-alternatives --remove-all gcc \nsudo update-alternatives --remove-all g++\nsudo apt-get update\nsudo apt-get install apt-transport-https ca-certificates gnupg software-properties-common wget\nwget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null\nsudo add-apt-repository ppa:ubuntu-toolchain-r/test\nsudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main'\nsudo apt-get -y update\nsudo apt-get -y install gcc-10 g++-10 ninja-build cmake\n#sudo apt-get -y upgrade\nsudo update-alternatives --remove-all gcc\nsudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 90\nsudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 90\nsudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30\nsudo update-alternatives --set cc /usr/bin/gcc\nsudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30\nsudo update-alternatives --set c++ /usr/bin/g++\nsudo apt -y autoremove\nexport CC=gcc\nexport CXX=g++" build_script: - sh: "mkdir build\ncmake -G \"Ninja Multi-Config\" -B build\nninja -C build" test_script: From 921be4ae321d34848c537d0195b9965264ed8d1b Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Thu, 11 Mar 2021 06:47:30 -0500 Subject: [PATCH 26/40] fix clang? removed ranges. though I can't get clang to fail on my computer so maybe it will on the CI --- appveyor.yml | 4 ++-- tests/src/algorithm_test.cpp | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index b26672a..a04fe49 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,8 +7,8 @@ environment: - job_name: Linux GCC build appveyor_build_worker_image: Ubuntu2004 -# - job_name: Linux Clang build -# appveyor_build_worker_image: Ubuntu2004 + - job_name: Linux Clang build + appveyor_build_worker_image: Ubuntu2004 # clang is missing and for: - matrix: diff --git a/tests/src/algorithm_test.cpp b/tests/src/algorithm_test.cpp index 39db506..c2daf78 100644 --- a/tests/src/algorithm_test.cpp +++ b/tests/src/algorithm_test.cpp @@ -2,7 +2,6 @@ // import boost.ut; // single module (C++20) #include #include -#include #include "aal/algorithm.hpp" /** * multiply all the parameter pack values together @@ -70,10 +69,14 @@ static constexpr auto make_unsigned = [](const auto &op, const auto &...a) { * @return returns output range post transform. */ -template +template +requires requires (O && o) +{ + std::begin(o); +} [[nodiscard]] consteval auto transform(const Op op, O &&o, I f, const I l, Is... fs) { - aal::var::transform(op, std::ranges::begin(o), f, l, fs...); + aal::var::transform(op, std::begin(o), f, l, fs...); return o; } @@ -86,7 +89,7 @@ transform(const Op op, O &&o, I f, const I l, Is... fs) { template requires(count < std::numeric_limits::max() - start) [[nodiscard]] consteval auto iota() { auto ret = std::array{}; - std::iota(std::ranges::begin(ret), std::ranges::end(ret), start); + std::iota(std::begin(ret), std::end(ret), start); return ret; } @@ -97,8 +100,8 @@ main() { using namespace boost::ut; [[maybe_unused]] suite tests = [] { static constexpr auto input = iota<0, 10U>(); - static constexpr auto b = std::ranges::begin(input); - static constexpr auto e = std::ranges::end(input); + static constexpr auto b = std::begin(input); + static constexpr auto e = std::end(input); "plus"_test = [] { expect(1_i == plus(1)); @@ -146,7 +149,7 @@ main() { "transform == 3"_test = [] { std::array output{}; const auto result = aal::var::transform( - [&](const auto &...a) { return equal_to(3, a...); }, std::ranges::begin(output), b, e); + [&](const auto &...a) { return equal_to(3, a...); }, std::begin(output), b, e); expect(output[3]); expect(!*result); }; @@ -159,7 +162,7 @@ main() { "transform plus 3"_test = [&] { std::array result{}; - aal::var::transform([&](const auto &...a) { return plus(3, a...); }, std::ranges::begin(result), b, e); + aal::var::transform([&](const auto &...a) { return plus(3, a...); }, std::begin(result), b, e); expect(result[3] == 6_i); }; @@ -173,7 +176,7 @@ main() { "transform plus 2 times"_test = [] { std::array result{}; - aal::var::transform(plus, std::ranges::begin(result), b, e, b); + aal::var::transform(plus, std::begin(result), b, e, b); expect(result[3] == 6_i); expect(result[2] == 4_i); expect(result[1] == 2_i); @@ -188,7 +191,7 @@ main() { "transform plus 3 times"_test = [] { std::array result{}; - aal::var::transform(plus, std::ranges::begin(result), b, e, b, b); + aal::var::transform(plus, std::begin(result), b, e, b, b); expect(result[3] == 9_i); expect(result[2] == 6_i); expect(result[1] == 3_i); @@ -203,7 +206,7 @@ main() { "transform multiply 3 times"_test = [] { std::array result{}; - aal::var::transform(multiply, std::ranges::begin(result), b, e, b, b); + aal::var::transform(multiply, std::begin(result), b, e, b, b); expect(result[3] == 27_i); expect(result[2] == 8_i); expect(result[1] == 1_i); From cf4cc518126da0b00c695bcf7d286a4864f79cf7 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Thu, 11 Mar 2021 07:13:05 -0500 Subject: [PATCH 27/40] custom iota to fix clang? --- tests/src/algorithm_test.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/src/algorithm_test.cpp b/tests/src/algorithm_test.cpp index c2daf78..312013e 100644 --- a/tests/src/algorithm_test.cpp +++ b/tests/src/algorithm_test.cpp @@ -70,8 +70,7 @@ static constexpr auto make_unsigned = [](const auto &op, const auto &...a) { */ template -requires requires (O && o) -{ +requires requires(O &&o) { std::begin(o); } [[nodiscard]] consteval auto @@ -88,9 +87,14 @@ transform(const Op op, O &&o, I f, const I l, Is... fs) { */ template requires(count < std::numeric_limits::max() - start) [[nodiscard]] consteval auto iota() { - auto ret = std::array{}; - std::iota(std::begin(ret), std::end(ret), start); - return ret; + // std::iota is not constexpr in clang. + std::array iota_range{}; + auto i = start; + aal::var::transform([&i]([[maybe_unused]] const auto &input) { return i++; }, + std::begin(iota_range), + std::begin(iota_range), + std::end(iota_range)); + return iota_range; } int @@ -148,8 +152,8 @@ main() { "transform == 3"_test = [] { std::array output{}; - const auto result = aal::var::transform( - [&](const auto &...a) { return equal_to(3, a...); }, std::begin(output), b, e); + const auto result = + aal::var::transform([&](const auto &...a) { return equal_to(3, a...); }, std::begin(output), b, e); expect(output[3]); expect(!*result); }; From 810928ce72214cf94e2a1804b0ff0237711a442d Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Thu, 11 Mar 2021 07:35:16 -0500 Subject: [PATCH 28/40] just realized ninja command should be used to build msvc. --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index a04fe49..6331c20 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -34,6 +34,6 @@ for: only: - job_name: Windows MSVC build build_script: - - cmd: "mkdir build\ncmake -G \"Visual Studio 16 2019\" -B build\nMSBuild build\\ALL_BUILD.vcxproj" + - cmd: "mkdir build\ncmake -G \"Visual Studio 16 2019\" -B build\nninja -C build" #MSBuild build\\ALL_BUILD.vcxproj test_script: - cmd: "cd build\nctest -C debug --verbose\ncd .." \ No newline at end of file From be708027b1c643b47c94aa9d0ee638ec7079e679 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Thu, 11 Mar 2021 07:36:31 -0500 Subject: [PATCH 29/40] Revert "just realized ninja command should be used to build msvc." This reverts commit dd5b38da2550832257242544098d44641ec7cf44. --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 6331c20..a04fe49 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -34,6 +34,6 @@ for: only: - job_name: Windows MSVC build build_script: - - cmd: "mkdir build\ncmake -G \"Visual Studio 16 2019\" -B build\nninja -C build" #MSBuild build\\ALL_BUILD.vcxproj + - cmd: "mkdir build\ncmake -G \"Visual Studio 16 2019\" -B build\nMSBuild build\\ALL_BUILD.vcxproj" test_script: - cmd: "cd build\nctest -C debug --verbose\ncd .." \ No newline at end of file From a7b6141a51bddc6f45be262de8928ad02f54b904 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Thu, 11 Mar 2021 08:50:13 -0500 Subject: [PATCH 30/40] add Windows instructions to the Contributing.md Really though if you're on msvc you're probably opening the project with a gui. Though we have linux commandline so I added the windows one. I found out on the CI if you use the same ninja commands as linux ninja will use clang for windows. --- CONTRIBUTING.md | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ccf4ae1..51d8b08 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,25 +1,50 @@ ### Getting Started & Building: + 1. Prerequisites: - * CMake version 3.17.0+ -> Ubuntu systems seem to have a problem getting the latest version, please build from sources or use another package such as snap. - * [Ubuntu CMake update instructions](https://apt.kitware.com/) - * Ninja + * CMake version 3.18.0+ -> Ubuntu systems seem to have a problem getting the latest version, please build from + sources or use another package such as snap. + * [Ubuntu CMake update instructions](https://apt.kitware.com/) + * Ninja 2. Checkout the repository: ```sh git clone https://github.com/codereport/An-Algorithm-Library.git ``` -3. Run cmake: + +#### Linux or Windows w/ Clang + +1. Run cmake: ```sh cd An-Algorithm-Library mkdir build cmake -G "Ninja Multi-Config" -B build ``` -4. Run tests: +2. Run tests: ```sh ninja -C build test ``` - * For more verbose output: + * For more verbose output: + + ```sh + # On linux you can combine these lines with && + ninja -C build + cd build + ctest -C debug --verbose + cd .. + ``` + +#### Windows MSVC +1. Run cmake: ```sh - ninja -C build && cd build && ctest -C debug --verbose && cd .. + cd An-Algorithm-Library + mkdir build + cmake -G "Visual Studio 16 2019" -B build ``` - \ No newline at end of file +2. Run tests: + * For more verbose output: + ```sh + MSBuild build\ALL_BUILD.vcxproj + cd build + ctest -C debug --verbose + cd .. + ``` \ No newline at end of file From 70e393a07af38212c9e35b7cf56d482fa7c1af3a Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Thu, 11 Mar 2021 08:53:39 -0500 Subject: [PATCH 31/40] add how to swap between compilers on linux. There might be a better way? I just put what I found seems to work. --- CONTRIBUTING.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 51d8b08..2f83eec 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,7 +11,17 @@ ``` #### Linux or Windows w/ Clang - +0. Switch between GCC or Clang (linux): + * GCC + ```sh + export CC=gcc + export CXX=g++ + ``` + * Clang + ```sh + export CC=clang + export CXX=clang++ + ``` 1. Run cmake: ```sh cd An-Algorithm-Library From f386da24992dd02ef188a813d3b911a48dda4ab6 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Thu, 11 Mar 2021 08:54:52 -0500 Subject: [PATCH 32/40] formatted the md --- CONTRIBUTING.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2f83eec..49b7ebd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,13 +11,14 @@ ``` #### Linux or Windows w/ Clang + 0. Switch between GCC or Clang (linux): - * GCC + * GCC ```sh export CC=gcc export CXX=g++ ``` - * Clang + * Clang ```sh export CC=clang export CXX=clang++ From 818872846f7916885905f26c24d837e6022cb2bc Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Thu, 11 Mar 2021 08:56:25 -0500 Subject: [PATCH 33/40] reformated the end of this line. --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 49b7ebd..2edc38a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -12,7 +12,7 @@ #### Linux or Windows w/ Clang -0. Switch between GCC or Clang (linux): +0. Switch between GCC or Clang, on linux: * GCC ```sh export CC=gcc From 3f018b07379bde050dad6eca0beadc390c98d41b Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Thu, 11 Mar 2021 11:46:11 -0500 Subject: [PATCH 34/40] created add_test_common function to cmake. wrapped up the code used for making tests into a function so it's easier to add new tests. --- tests/CMakeLists.txt | 18 ++---------------- tests/cmake/add_test_common.cmake | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-) create mode 100644 tests/cmake/add_test_common.cmake diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 768b30c..a9a88dc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,19 +2,5 @@ include(cmake/compiler_warnings.cmake) add_library(${PROJECT_NAME}_project_warnings INTERFACE) set_project_warnings(${PROJECT_NAME}_project_warnings ON) include(cmake/ut.cmake) -add_executable(${PROJECT_NAME}_algorithm_test - src/algorithm_test.cpp) -target_link_libraries(${PROJECT_NAME}_algorithm_test - PRIVATE Boost::ut - PRIVATE ${PROJECT_NAME}_aal - PRIVATE ${PROJECT_NAME}_project_warnings) -#https://cliutils.gitlab.io/modern-cmake/chapters/features/cpp11.html -target_compile_features(${PROJECT_NAME}_algorithm_test PRIVATE cxx_std_20) -set_target_properties(${PROJECT_NAME}_algorithm_test PROPERTIES - OUTPUT_NAME "algorithm_test" - CXX_EXTENSIONS OFF - CXX_STANDARD_REQUIRED ON - WINDOWS_EXPORT_ALL_SYMBOLS OFF) -add_test( - NAME ${PROJECT_NAME}_ALGORITHM_TEST COMMAND ${PROJECT_NAME}_algorithm_test -) \ No newline at end of file +include(cmake/add_test_common.cmake) +add_test_common(algorithm_test) \ No newline at end of file diff --git a/tests/cmake/add_test_common.cmake b/tests/cmake/add_test_common.cmake new file mode 100644 index 0000000..25bd760 --- /dev/null +++ b/tests/cmake/add_test_common.cmake @@ -0,0 +1,14 @@ +function(add_test_common file_name) + add_executable(${PROJECT_NAME}_${file_name} + src/${file_name}.cpp) + target_link_libraries(${PROJECT_NAME}_${file_name} + PRIVATE Boost::ut + PRIVATE ${PROJECT_NAME}_aal + PRIVATE ${PROJECT_NAME}_project_warnings + ) + target_include_directories(${PROJECT_NAME}_${file_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src) + set_target_properties(${PROJECT_NAME}_${file_name} PROPERTIES OUTPUT_NAME "${file_name}") + add_test( + NAME ${PROJECT_NAME}_${file_name} COMMAND ${PROJECT_NAME}_${file_name} + ) +endfunction() \ No newline at end of file From a32a43f66bd0d515a974240228fd874ee42e889c Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Thu, 11 Mar 2021 18:40:06 -0500 Subject: [PATCH 35/40] added /wd4505 suppress unreferenced local function has been removed. I had this issue where one test was using a function and another wasn't so visual studio wasn't compiling because I have all warnings are errors turned on. In gcc adding `[[maybe_unused]]` was enough to fix this kind of issue but that didn't help in msvc. --- tests/cmake/compiler_warnings.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/cmake/compiler_warnings.cmake b/tests/cmake/compiler_warnings.cmake index 80ba6f7..309e1fa 100644 --- a/tests/cmake/compiler_warnings.cmake +++ b/tests/cmake/compiler_warnings.cmake @@ -32,6 +32,7 @@ function(set_project_warnings project_name) /w14906 # string literal cast to 'LPWSTR' /w14928 # illegal copy-initialization; more than one user-defined conversion has been implicitly applied /permissive- # standards conformance mode for MSVC compiler. + /wd4505 # suppress unreferenced local function has been removed. ) set(CLANG_WARNINGS From a35d87582d29762c3009e71a4cb8dafb8a8143dd Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Tue, 16 Mar 2021 11:20:26 -0400 Subject: [PATCH 36/40] comment out warning suppression probably won't need this warning suppressed. But the code is there if we end up needing it. --- tests/cmake/compiler_warnings.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cmake/compiler_warnings.cmake b/tests/cmake/compiler_warnings.cmake index 309e1fa..3e4a862 100644 --- a/tests/cmake/compiler_warnings.cmake +++ b/tests/cmake/compiler_warnings.cmake @@ -32,7 +32,7 @@ function(set_project_warnings project_name) /w14906 # string literal cast to 'LPWSTR' /w14928 # illegal copy-initialization; more than one user-defined conversion has been implicitly applied /permissive- # standards conformance mode for MSVC compiler. - /wd4505 # suppress unreferenced local function has been removed. + #/wd4505 # suppress unreferenced local function has been removed. ) set(CLANG_WARNINGS From 62507dc9da88f4448d14f1ade83cb8a126bf5c51 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Thu, 18 Mar 2021 07:40:56 -0400 Subject: [PATCH 37/40] change found to any_of in the test. --- tests/src/algorithm_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/src/algorithm_test.cpp b/tests/src/algorithm_test.cpp index 312013e..42c937b 100644 --- a/tests/src/algorithm_test.cpp +++ b/tests/src/algorithm_test.cpp @@ -145,8 +145,8 @@ main() { expect(constant<3 == *std::get<0>(result)>); }; - "found"_test = [] { - static constexpr auto result = aal::var::found([&](const auto &...a) { return equal_to(3, a...); }, b, e); + "any_of"_test = [] { + static constexpr auto result = aal::var::any_of([&](const auto &...a) { return equal_to(3, a...); }, b, e); expect(constant); }; From b6488b3c722fe8b81f06c07889595c9278384ee6 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Mon, 22 Mar 2021 15:57:12 -0400 Subject: [PATCH 38/40] clang 12 build script --- appveyor.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index a04fe49..5b3e116 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -8,14 +8,13 @@ environment: appveyor_build_worker_image: Ubuntu2004 - job_name: Linux Clang build - appveyor_build_worker_image: Ubuntu2004 -# clang is missing and + appveyor_build_worker_image: Ubuntu1604 for: - matrix: only: - job_name: Linux Clang build init: - - sh: "\nsudo apt-get update\nsudo apt-get install apt-transport-https ca-certificates gnupg software-properties-common wget\nwget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null\nsudo add-apt-repository ppa:ubuntu-toolchain-r/test\nsudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main'\nsudo apt-get -y update\nsudo apt-get -y install clang-11 clang++-11 ninja-build cmake\n#sudo apt-get -y upgrade\nsudo update-alternatives --remove-all clang\nsudo update-alternatives --remove-all clang++\nsudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-11 90\nsudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-11 90\nsudo apt -y autoremove\nexport CC=clang\nexport CXX=clang++" + - sh: "#update cmake!\nsudo apt-get update\nsudo apt-get install apt-transport-https ca-certificates gnupg software-properties-common wget\nwget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null\nsudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ xenial main'\nsudo apt-get -y update\nsudo apt-get -y install kitware-archive-keyring\nsudo rm /etc/apt/trusted.gpg.d/kitware.gpg\nsudo apt-get -y install cmake\nsudo apt-get -y install ninja-build\n#update clang++!\nwget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -\n# Fingerprint: 6084 F3CF 814B 57C1 CF12 EFD5 15CF 4D18 AF4F 7421\n# i386 not available\n#sudo add-apt-repository 'deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial main'\n#sudo add-apt-repository 'deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial main'\n# 11\n#sudo add-apt-repository 'deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-11 main'\n#sudo add-apt-repository 'deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-11 main'\n# 12\nsudo add-apt-repository 'deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-12 main'\n#sudo add-apt-repository 'deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-12 main'\nsudo apt-get -y update\nsudo apt-get -y -f install clang-12 clang-tools-12 clang-12-doc libclang-common-12-dev libclang-12-dev libclang1-12 clang-format-12 clangd-12\nsudo apt-get -y autoremove\nsudo apt-get -y autoclean\nsudo apt-get -y -f install libc++abi1-12 libc++abi-12-dev libc++1-12 libc++-12-dev\n#set clang++ to specific version:\nsudo update-alternatives --remove-all clang\nsudo update-alternatives --remove-all clang++\nsudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-12 90\nsudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-12 90\nexport CC=clang\nexport CXX=clang++" build_script: - sh: "mkdir build\ncmake -G \"Ninja Multi-Config\" -B build\nninja -C build" test_script: From 3ac57bd561b46ffa1dca9047961ed909b06cecd2 Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Mon, 22 Mar 2021 16:02:50 -0400 Subject: [PATCH 39/40] move project_warnings library into the .cmake file and added clang compat cmake code. --- tests/CMakeLists.txt | 3 +-- tests/cmake/add_test_common.cmake | 1 + tests/cmake/clang_compat.cmake | 12 ++++++++++++ tests/cmake/compiler_warnings.cmake | 3 +++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 tests/cmake/clang_compat.cmake diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a9a88dc..297ffd8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,5 @@ include(cmake/compiler_warnings.cmake) -add_library(${PROJECT_NAME}_project_warnings INTERFACE) -set_project_warnings(${PROJECT_NAME}_project_warnings ON) +include(cmake/clang_compat.cmake) include(cmake/ut.cmake) include(cmake/add_test_common.cmake) add_test_common(algorithm_test) \ No newline at end of file diff --git a/tests/cmake/add_test_common.cmake b/tests/cmake/add_test_common.cmake index 25bd760..abdb832 100644 --- a/tests/cmake/add_test_common.cmake +++ b/tests/cmake/add_test_common.cmake @@ -5,6 +5,7 @@ function(add_test_common file_name) PRIVATE Boost::ut PRIVATE ${PROJECT_NAME}_aal PRIVATE ${PROJECT_NAME}_project_warnings + PRIVATE ${PROJECT_NAME}_clang_compat ) target_include_directories(${PROJECT_NAME}_${file_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src) set_target_properties(${PROJECT_NAME}_${file_name} PROPERTIES OUTPUT_NAME "${file_name}") diff --git a/tests/cmake/clang_compat.cmake b/tests/cmake/clang_compat.cmake new file mode 100644 index 0000000..8454ef1 --- /dev/null +++ b/tests/cmake/clang_compat.cmake @@ -0,0 +1,12 @@ +function(set_clang_compat project_name) + if (MSVC) + elseif (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") + target_compile_options(${project_name} INTERFACE -stdlib=libc++) + target_link_options(${project_name} INTERFACE -stdlib=libc++ -lc++abi) + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + else () + endif () +endfunction() + +add_library(${PROJECT_NAME}_clang_compat INTERFACE) +set_clang_compat(${PROJECT_NAME}_clang_compat) diff --git a/tests/cmake/compiler_warnings.cmake b/tests/cmake/compiler_warnings.cmake index 3e4a862..52cf4e9 100644 --- a/tests/cmake/compiler_warnings.cmake +++ b/tests/cmake/compiler_warnings.cmake @@ -82,3 +82,6 @@ function(set_project_warnings project_name) target_compile_options(${project_name} INTERFACE ${PROJECT_WARNINGS}) endfunction() + +add_library(${PROJECT_NAME}_project_warnings INTERFACE) +set_project_warnings(${PROJECT_NAME}_project_warnings ON) \ No newline at end of file From bd516ac1d33b89e7e6c9c392e35668e31d401c7a Mon Sep 17 00:00:00 2001 From: Sebanisu Date: Mon, 29 Mar 2021 08:02:17 -0400 Subject: [PATCH 40/40] add GIT_REMOTE_UPDATE_STRATEGY https://cmake.org/cmake/help/v3.18/module/ExternalProject.html because if you make local changes the default behavior is to stash them and pop the stash after pulling the update. So it'll cause an error if there is a merge conflict. --- tests/cmake/ut.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/cmake/ut.cmake b/tests/cmake/ut.cmake index c0b7a4b..519fa62 100644 --- a/tests/cmake/ut.cmake +++ b/tests/cmake/ut.cmake @@ -3,6 +3,7 @@ FetchContent_Declare( ut GIT_REPOSITORY https://github.com/boost-ext/ut.git GIT_TAG origin/master + GIT_REMOTE_UPDATE_STRATEGY CHECKOUT # this discards local changes before pulling the new data. ) #FetchContent_MakeAvailable(ut) FetchContent_GetProperties(ut)