From 4549604a18e83e7016b15fe112ade77cf06fb89f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=8B=E8=B1=A1=E4=B9=8B=E5=BD=A2?= <976999484@qq.com> Date: Wed, 17 Apr 2024 17:20:30 +0800 Subject: [PATCH] fix(*): fix all compile errors --- CMakeLists.txt | 2 +- cmake/Utils.cmake | 101 ++++++++++-------- include/stdsharp/containers/concepts.h | 2 +- include/stdsharp/default_operator.h | 35 +++--- include/stdsharp/functional/invocables.h | 11 +- include/stdsharp/functional/pipeable.h | 18 +++- include/stdsharp/iterator/basic_iterator.h | 54 ++++++---- include/stdsharp/memory/pointer_traits.h | 46 ++++++-- include/stdsharp/type_traits/indexed_traits.h | 57 +++++----- include/stdsharp/type_traits/object.h | 16 +-- include/stdsharp/type_traits/type_sequence.h | 16 ++- include/stdsharp/type_traits/value_sequence.h | 10 +- include/stdsharp/utility/forward_cast.h | 2 - tests/.clang-tidy | 2 +- tests/CMakeLists.txt | 78 ++++++-------- tests/src/default_operator.cpp | 17 +-- tests/src/functional/sequenced_invocables.cpp | 1 - tests/src/memory/box.cpp | 56 +++++----- tests/src/memory/single_stack_allocator.cpp | 19 ---- tests/src/synchronizer.cpp | 2 +- tests/src/type_traits/type_sequence.cpp | 3 +- tests/src/type_traits/value_sequence.cpp | 4 +- 22 files changed, 285 insertions(+), 267 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1969397..1843720 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.24) # project( stdsharp - VERSION 0.8.8 + VERSION 0.9.0 LANGUAGES CXX) include(cmake/Utils.cmake) diff --git a/cmake/Utils.cmake b/cmake/Utils.cmake index 95ca210..ccf0a04 100644 --- a/cmake/Utils.cmake +++ b/cmake/Utils.cmake @@ -5,11 +5,11 @@ option( set(CMAKE_COLOR_DIAGNOSTICS ON) -if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-fdiagnostics-show-template-tree) endif() -if("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC") +if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") add_compile_options(/utf-8 /diagnostics:caret) endif() @@ -37,9 +37,7 @@ function(target_include_as_system target_name) ${included}) endfunction() -# # Create static or shared library, setup header and source files -# function(config_lib lib_name lib_type) message("Configuring target library ${lib_name}") @@ -85,7 +83,7 @@ function(config_lib lib_name lib_type) if(ARG_STD) target_compile_features(${lib_name} ${inc_tag} cxx_std_${ARG_STD}) - message(STATUS "Using c++ ${ARG_STD}.\n") + message(STATUS "Using c++ ${ARG_STD}") endif() target_include_directories( @@ -99,9 +97,7 @@ function(config_lib lib_name lib_type) set_target_properties(${lib_name} PROPERTIES VERSION "${ARG_VER}") endfunction() -# # Create executable, setup header and source files -# function(config_exe exe_name) cmake_parse_arguments(ARG "" "STD;VER" "EXE_SRC" ${ARGN}) @@ -119,13 +115,11 @@ function(config_exe exe_name) if(ARG_STD) target_compile_features(${exe_name} PUBLIC cxx_std_${ARG_STD}) - message(STATUS "Using c++ ${ARG_STD}.\n") + message(STATUS "Using c++ ${ARG_STD}.") endif() endfunction() -# -# Create executable, setup header and source files -# +# install library function(target_install target) include(CMakePackageConfigHelpers) include(GNUInstallDirs) @@ -235,33 +229,44 @@ include($\{CMAKE_CURRENT_LIST_DIR}/${target}Targets.cmake)" COMPONENT "${target}_Development") endfunction() -function(target_enable_clang_tidy target) +function(target_clang_tidy target) find_program(CLANG_TIDY clang-tidy) - if(CLANG_TIDY) - message(STATUS "found clang-tidy: ${CLANG_TIDY}") - get_target_property(bin_dir ${target} BINARY_DIR) - set(report_folder "${bin_dir}/clang-tidy-report") + if(NOT EXISTS "${CLANG_TIDY}") + message(STATUS "clang-tidy not found") + return() + endif() - set_target_properties( - ${target} - PROPERTIES - CXX_CLANG_TIDY - "${CLANG_TIDY};--enable-check-profile;--store-check-profile=${report_folder}" - ) + message(STATUS "found clang-tidy: ${CLANG_TIDY}") - add_custom_target( - ${target}ClangTidyClean ALL - COMMAND ${CMAKE_COMMAND} -E rm -rf ${report_folder}/ - USES_TERMINAL) + get_target_property(bin_dir ${target} BINARY_DIR) + set(report_folder "${bin_dir}/clang-tidy-report") - add_dependencies(${target} ${target}ClangTidyClean) - else() - message(STATUS "clang-tidy not found") + if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + message(STATUS "Add extra MSVC arg for clang-tidy") + set(MSVC_TIDY + ";--extra-arg=/EHsc;--extra-arg=/std:c++latest;--extra-arg=-Wno-unknown-warning-option" + ) endif() + + set_target_properties( + ${target} + PROPERTIES + CXX_CLANG_TIDY + "${CLANG_TIDY}; +--enable-check-profile; +--store-check-profile=${report_folder} +${MSVC_TIDY}") + + add_custom_target( + ${target}ClangTidyClean ALL + COMMAND ${CMAKE_COMMAND} -E rm -rf ${report_folder}/ + USES_TERMINAL) + + add_dependencies(${target} ${target}ClangTidyClean) endfunction() -function(target_enable_clang_sanitizer target type) +function(target_clang_sanitizer target type) cmake_parse_arguments(ARG "" "" "SANITIZER" ${ARGN}) foreach(sanitizer ${ARG_SANITIZER}) @@ -279,28 +284,37 @@ function(target_enable_clang_sanitizer target type) "SHELL: $<${clang_debug_only}:${sanitizer_options}>") endfunction() -function(target_coverage target_name) +function(target_llvm_coverage target_name) message(STATUS "enable code coverage for ${target_name}") find_program(llvm_profdata "llvm-profdata") find_program(llvm_cov "llvm-cov") - if(NOT (${CMAKE_CXX_COMPILER_ID} MATCHES "(Apple)?[Cc]lang")) + if(NOT CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang") message( STATUS - "C++ Compiler should be Clang, ${CMAKE_CXX_COMPILER_ID} is not supported.\n" + "C++ Compiler should be Clang, ${CMAKE_CXX_COMPILER_ID} is not supported." ) return() endif() if(NOT EXISTS "${llvm_profdata}" OR NOT EXISTS "${llvm_cov}") - message(STATUS "llvm-profdata or llvm-cov not found.\n") + message(STATUS "llvm-profdata or llvm-cov not found.") return() endif() message(STATUS "found llvm-profdata at: ${llvm_profdata}") message(STATUS "found llvm-cov at: ${llvm_cov}") - cmake_parse_arguments(ARG "" "FORMAT;PROFILE_FILE" "DEPENDS" ${ARGN}) + cmake_parse_arguments(ARG "" "FORMAT" "DEPENDS" ${ARGN}) + + set(profile_file "${target_name}.profraw") + + # Run first to generate profraw file + add_custom_command( + OUTPUT ${profile_file} + DEPENDS ${target_name} + COMMAND ${CMAKE_COMMAND} -E env LLVM_PROFILE_FILE=${profile_file} + $ || exit 0) set(options -fprofile-instr-generate -fcoverage-mapping) @@ -310,28 +324,23 @@ function(target_coverage target_name) set(profdata_file_name "${target_name}.profdata") if(${ARG_FORMAT} STREQUAL text) - set(coverage_file json) + set(coverage_file_ext json) elseif(${ARG_FORMAT} STREQUAL lcov) - set(coverage_file lcov) + set(coverage_file_ext lcov) else() message(FATAL_ERROR "unknown format ${ARG_FORMAT}") endif() - if(NOT DEFINED ARG_PROFILE_FILE) - set(ARG_PROFILE_FILE "$ENV{LLVM_PROFILE_FILE}") - endif() - - set(coverage_file "${target_name}Coverage.${coverage_file}") + set(coverage_file_ext "${target_name}Coverage.${coverage_file_ext}") add_custom_target( ${target_name}CoverageReport ALL - DEPENDS ${target_name} ${ARG_DEPENDS} - COMMAND ${CMAKE_COMMAND} -E rm -f "${profdata_file_name}" "${coverage_file}" + DEPENDS ${profile_file} COMMAND "${llvm_profdata}" merge --sparse -o="${profdata_file_name}" - "${ARG_PROFILE_FILE}" + "${profile_file}" COMMAND "${llvm_cov}" export -format=${ARG_FORMAT} -object="$" - -instr-profile="${profdata_file_name}" > "${coverage_file}" + -instr-profile="${profdata_file_name}" > "${coverage_file_ext}" USES_TERMINAL) endfunction() diff --git a/include/stdsharp/containers/concepts.h b/include/stdsharp/containers/concepts.h index bd5253e..04d2add 100644 --- a/include/stdsharp/containers/concepts.h +++ b/include/stdsharp/containers/concepts.h @@ -450,7 +450,7 @@ namespace stdsharp::details if constexpr(count > 0) res = res && self(std::make_index_sequence{}); - return res; + return res; }(std::make_index_sequence{}); }; } diff --git a/include/stdsharp/default_operator.h b/include/stdsharp/default_operator.h index 104ccf3..08bf61d 100644 --- a/include/stdsharp/default_operator.h +++ b/include/stdsharp/default_operator.h @@ -62,17 +62,17 @@ namespace stdsharp::default_operator } }; -#define STDSHARP_ARITH_OP(name, op) \ - struct name##_commutative \ - { \ - [[nodiscard]] friend constexpr decltype(auto) operator op( \ - not_decay_derived auto&& u, \ - decay_derived auto&& t \ - ) noexcept(noexcept(cpp_forward(t) op cpp_forward(u))) \ - requires requires { cpp_forward(t) op cpp_forward(u); } \ - { \ - return cpp_forward(t) op cpp_forward(u); \ - } \ +#define STDSHARP_ARITH_OP(name, op) \ + struct name##_commutative \ + { \ + template T> \ + [[nodiscard]] friend constexpr decltype(auto \ + ) operator op(T&& u, decay_derived auto&& t) \ + noexcept(noexcept(cpp_forward(t) op cpp_forward(u))) \ + requires requires { cpp_forward(t) op cpp_forward(u); } \ + { \ + return cpp_forward(t) op cpp_forward(u); \ + } \ } STDSHARP_ARITH_OP(plus, +); @@ -90,6 +90,7 @@ namespace stdsharp::default_operator struct subscript { + // TODO: multidimensional subscript #if __cpp_multidimensional_subscript >= 202110L [[nodiscard]] constexpr decltype(auto ) operator[](this auto&& t, auto&& first_arg, auto&&... args) @@ -106,17 +107,19 @@ namespace stdsharp::default_operator struct arrow { - [[nodiscard]] constexpr auto* operator->(this dereferenceable auto&& t) + template + [[nodiscard]] constexpr auto* operator->(this T&& t) noexcept(noexcept(std::addressof(*cpp_forward(t)))) { return std::addressof(*cpp_forward(t)); } - [[nodiscard]] constexpr auto operator->*(this dereferenceable auto&& t, auto&& ptr) - noexcept(noexcept((*cpp_forward(t)).*cpp_forward(ptr))) - requires requires { (*cpp_forward(t)).*cpp_forward(ptr); } + template + [[nodiscard]] constexpr auto operator->*(this T&& t, auto&& ptr) + noexcept(noexcept((*cpp_forward(t)).*(cpp_forward(ptr)))) + requires requires { (*cpp_forward(t)).*(cpp_forward(ptr)); } { - return (*cpp_forward(t)).*cpp_forward(ptr); + return (*cpp_forward(t)).*(cpp_forward(ptr)); } }; } \ No newline at end of file diff --git a/include/stdsharp/functional/invocables.h b/include/stdsharp/functional/invocables.h index 9aa2f3e..a03206d 100644 --- a/include/stdsharp/functional/invocables.h +++ b/include/stdsharp/functional/invocables.h @@ -46,16 +46,17 @@ namespace stdsharp::details return forward_cast>>(self).get(); } - template + template constexpr decltype(auto) cget(this const Self&& self) noexcept { - return forward_cast>>(self).cget(); + return forward_cast>>(self).cget(); } - template - constexpr forward_cast_t> cget(this const Self& self) noexcept + template + constexpr decltype(auto) cget(this const Self& self) noexcept { - return forward_cast>>(self).cget(); + return forward_cast>>(self).cget( + ); } }; } diff --git a/include/stdsharp/functional/pipeable.h b/include/stdsharp/functional/pipeable.h index ebfc5cd..a5efa53 100644 --- a/include/stdsharp/functional/pipeable.h +++ b/include/stdsharp/functional/pipeable.h @@ -16,22 +16,30 @@ namespace stdsharp }; template - struct pipeable_base + struct pipeable_base; + + template<> + struct pipeable_base { - static constexpr auto pipe_mode = Mode; + static constexpr auto pipe_mode = pipe_mode::left; private: template Pipe> - requires(Mode == pipe_mode::left) + requires decay_derived friend constexpr decltype(auto) operator|(Arg&& arg, Pipe&& pipe) noexcept(nothrow_invocable) { return invoke(cpp_forward(pipe), cpp_forward(arg)); } + }; + + template<> + struct pipeable_base + { + static constexpr auto pipe_mode = pipe_mode::right; template Pipe> - requires(Mode == pipe_mode::right) - friend constexpr decltype(auto) operator|(Pipe&& pipe, Arg&& arg) + constexpr decltype(auto) operator|(this Pipe&& pipe, Arg&& arg) noexcept(nothrow_invocable) { return invoke(cpp_forward(pipe), cpp_forward(arg)); diff --git a/include/stdsharp/iterator/basic_iterator.h b/include/stdsharp/iterator/basic_iterator.h index d3f303d..a7bccc0 100644 --- a/include/stdsharp/iterator/basic_iterator.h +++ b/include/stdsharp/iterator/basic_iterator.h @@ -4,6 +4,15 @@ #include "../compilation_config_in.h" +namespace stdsharp::details +{ + template + concept iterator_has_mem_data = requires(T& v, const T& const_v) { + v.data(); + const_v.data(); + }; +} + namespace stdsharp { struct STDSHARP_EBO basic_iterator : @@ -15,61 +24,66 @@ namespace stdsharp template using difference_type = std::iter_difference_t().data())>; +// TODO: multidimensional subscript +#if __cpp_multidimensional_subscript >= 202110L using subscript::operator[]; +#endif + using increase::operator++; using increase::operator--; using arithmetic::operator-; - constexpr auto& operator++(this auto& t) noexcept(noexcept(++t.data())) + template + constexpr auto& operator++(this T& t) noexcept(noexcept(++t.data())) requires requires { ++t.data(); } { ++t.data(); return t; } - constexpr auto& operator--(this auto& t) noexcept(noexcept(--t.data())) + template + constexpr auto& operator--(this T& t) noexcept(noexcept(--t.data())) requires requires { --t.data(); } { --t.data(); return t; } - constexpr auto& operator+=(this auto& t, const difference_type& diff) noexcept + template + constexpr auto& operator+=(this T& t, const difference_type& diff) noexcept requires requires { t.data() += diff; } { t.data() += diff; return t; } - constexpr auto& operator-=(this auto& t, const difference_type& diff) noexcept + template + constexpr auto& operator-=(this T& t, const difference_type& diff) noexcept requires requires { t.data() -= diff; } { t.data() -= diff; return t; } - [[nodiscard]] constexpr decltype(auto) operator-( // - this const auto& left, - decltype(left) right - ) noexcept(noexcept(left.data() - right.data())) + template + [[nodiscard]] constexpr decltype(auto) operator-(this const T& left, decltype(left) right) + noexcept(noexcept(left.data() - right.data())) requires requires { left.data() - right.data(); } { return left.data() - right.data(); } - [[nodiscard]] constexpr decltype(auto) operator<=>( // - this const auto& left, - decltype(left) right - ) noexcept(noexcept(left.data() <=> right.data())) + template + [[nodiscard]] constexpr decltype(auto) operator<=>(this const T& left, decltype(left) right) + noexcept(noexcept(left.data() <=> right.data())) requires requires { left.data() <=> right.data(); } { return left.data() <=> right.data(); } - [[nodiscard]] constexpr decltype(auto) operator==( // - this const auto& left, - decltype(left) right - ) noexcept(noexcept(left.data() == right.data())) + template + [[nodiscard]] constexpr decltype(auto) operator==(this const T& left, decltype(left) right) + noexcept(noexcept(left.data() == right.data())) requires requires { left.data() == right.data(); } { return left.data() == right.data(); @@ -84,7 +98,8 @@ namespace stdsharp static constexpr void not_null(const auto& /*unused*/) noexcept {} public: - [[nodiscard]] constexpr decltype(auto) operator*(this const auto& t) + template + [[nodiscard]] constexpr decltype(auto) operator*(this const T& t) noexcept(noexcept(*(t.data()))) requires requires { *(t.data()); } { @@ -93,9 +108,10 @@ namespace stdsharp return *ptr; } + template [[nodiscard]] constexpr decltype(auto) operator[]( // - this const auto& t, - const difference_type& diff + this const T& t, + const difference_type& diff ) noexcept(noexcept(*(t.data() + diff))) requires requires { *(t.data() + diff); } { diff --git a/include/stdsharp/memory/pointer_traits.h b/include/stdsharp/memory/pointer_traits.h index 3e2e14a..07dfd57 100644 --- a/include/stdsharp/memory/pointer_traits.h +++ b/include/stdsharp/memory/pointer_traits.h @@ -59,12 +59,37 @@ namespace stdsharp::details ); private: - struct std_to_address + struct traits_to_address + { + void pointer_test(auto*); + + [[nodiscard]] constexpr decltype(auto) operator()(const pointer& p) const noexcept + requires requires { std_traits::to_address(p); } + { + return std_traits::to_address(p); + } + }; + + struct cast_to_address + { + static constexpr auto cast_to_pointer(auto* p) noexcept { return p; } + + [[nodiscard]] constexpr decltype(auto) operator()(const pointer& p) const noexcept + requires requires { + cast_to_pointer(p); + requires !function; + } + { + return std::to_address(cast_to_pointer(p)); + } + }; + + struct operator_to_address { [[nodiscard]] constexpr decltype(auto) operator()(const pointer& p) const noexcept - requires requires { std::to_address(p); } + requires requires { std::to_address(p.operator->()); } { - return std::to_address(p); + return std::to_address(p.operator->()); } }; @@ -78,8 +103,11 @@ namespace stdsharp::details }; public: - using to_address_fn = - nodiscard_invocable>; + using to_address_fn = nodiscard_invocable>; static constexpr to_address_fn to_address{}; @@ -145,7 +173,7 @@ namespace stdsharp::details }; template< - typename = decltype(get_element_type())::type, + typename = typename decltype(get_element_type())::type, typename = decltype(get_raw_pointer())> struct pointer_to_fn_t { @@ -198,13 +226,13 @@ namespace stdsharp::details struct dereference_to_pointer { [[nodiscard]] constexpr pointer operator()(const RawPtr p) const - noexcept(noexcept(pointer_to(*p), pointer{})) + noexcept(noexcept(pointer_to_fn_t<>::pointer_to(*p), pointer{})) requires requires { requires nullable_pointer; - pointer_to(*p); + pointer_to_fn_t<>::pointer_to(*p); } { - return p == nullptr ? pointer{} : pointer_to(*p); + return p == nullptr ? pointer{} : pointer_to_fn_t<>::pointer_to(*p); } }; diff --git a/include/stdsharp/type_traits/indexed_traits.h b/include/stdsharp/type_traits/indexed_traits.h index 8baa23d..3a924ad 100644 --- a/include/stdsharp/type_traits/indexed_traits.h +++ b/include/stdsharp/type_traits/indexed_traits.h @@ -7,37 +7,29 @@ namespace stdsharp::details { + template + struct invalid_type_indexer + { + }; + + template struct type_indexer { - template - struct filter - { - [[nodiscard]] consteval type_constant get() const noexcept { return {}; } - }; + using size_t = std::size_t; + - template - struct invalid + template> + struct t; + + template + struct t> : + std::conditional_t, invalid_type_indexer>... { }; public: - template - static consteval auto impl( - const std::index_sequence /*unused*/, - const basic_type_sequence /*unused*/ - ) - { - constexpr struct : std::conditional_t, invalid>... - { - } f{}; - - return f; - } - - template - using type = typename decltype( // - impl(std::index_sequence_for{}, basic_type_sequence{}).get() - )::type; + template + using type = t::type; }; } @@ -49,7 +41,7 @@ namespace stdsharp }; template - using type_at = details::type_indexer::type; + using type_at = details::type_indexer::template type; } namespace stdsharp::details @@ -68,21 +60,22 @@ namespace stdsharp::details using index_sequence = std::index_sequence; template - constexpr forward_cast_t> get(this Self&& self) noexcept + constexpr decltype(auto) get(this Self&& self) noexcept { return forward_cast>>(self).get(); } - template - constexpr forward_cast_t> cget(this const Self&& self) noexcept + template + constexpr decltype(auto) cget(this const Self&& self) noexcept { - return forward_cast>>(self).cget(); + return forward_cast>>(self).cget(); } - template - constexpr forward_cast_t> cget(this const Self& self) noexcept + template + constexpr decltype(auto) cget(this const Self& self) noexcept { - return forward_cast>>(self).cget(); + return forward_cast>>(self).cget( + ); } }; } diff --git a/include/stdsharp/type_traits/object.h b/include/stdsharp/type_traits/object.h index 090b9b6..1f02788 100644 --- a/include/stdsharp/type_traits/object.h +++ b/include/stdsharp/type_traits/object.h @@ -134,21 +134,7 @@ namespace stdsharp }; [[nodiscard]] constexpr lifetime_req - minimize(const lifetime_req left, const lifetime_req right) noexcept - { - return { - std::min(left.default_construct, right.default_construct), - std::min(left.move_construct, right.move_construct), - std::min(left.copy_construct, right.copy_construct), - std::min(left.move_assign, right.move_assign), - std::min(left.copy_assign, right.copy_assign), - std::min(left.destruct, right.destruct), - std::min(left.swap, right.swap) - }; - } - - [[nodiscard]] constexpr lifetime_req - maximize(const lifetime_req left, const lifetime_req right) noexcept + at_least(const lifetime_req left, const lifetime_req right) noexcept { return { std::max(left.default_construct, right.default_construct), diff --git a/include/stdsharp/type_traits/type_sequence.h b/include/stdsharp/type_traits/type_sequence.h index 3c568e4..b119985 100644 --- a/include/stdsharp/type_traits/type_sequence.h +++ b/include/stdsharp/type_traits/type_sequence.h @@ -61,8 +61,13 @@ namespace stdsharp struct insert { template - static consteval regular_type_sequence..., Others..., type...> - impl(std::index_sequence, std::index_sequence); + static consteval auto impl(std::index_sequence, std::index_sequence) + { + return regular_type_sequence< + type_sequence::type..., + Others..., + type_sequence::type...>{}; + } template using type = decltype( // @@ -177,11 +182,12 @@ namespace stdsharp::details static constexpr auto indices_pair = get_indices(std::make_index_sequence{}); + static constexpr auto indices = indices_pair.first; + static constexpr auto indices_size = indices_pair.second; template - static consteval regular_type_sequence...> + static consteval regular_type_sequence...> apply_indices(std::index_sequence); using type = decltype(apply_indices(std::make_index_sequence{})); @@ -208,7 +214,7 @@ namespace std template struct tuple_element> { - using type = ::stdsharp::type_sequence::template type; + using type = typename ::stdsharp::type_sequence::template type; }; } diff --git a/include/stdsharp/type_traits/value_sequence.h b/include/stdsharp/type_traits/value_sequence.h index 6923617..f770cfe 100644 --- a/include/stdsharp/type_traits/value_sequence.h +++ b/include/stdsharp/type_traits/value_sequence.h @@ -106,8 +106,10 @@ namespace stdsharp struct insert { template - static consteval regular_value_sequence()..., Others..., get()...> - impl(std::index_sequence, std::index_sequence); + static consteval auto impl(std::index_sequence, std::index_sequence) + { + return regular_value_sequence()..., Others..., get()...>{}; + } template using type = decltype( // @@ -533,10 +535,12 @@ namespace stdsharp::details static constexpr auto indices_pair = get_indices(std::make_index_sequence{}); + static constexpr auto indices = indices_pair.first; + static constexpr auto indices_size = indices_pair.second; template - static consteval regular_value_sequence()...> + static consteval regular_value_sequence()...> apply_indices(std::index_sequence); using type = decltype(apply_indices(std::make_index_sequence{})); diff --git a/include/stdsharp/utility/forward_cast.h b/include/stdsharp/utility/forward_cast.h index 59c6046..92f8c05 100644 --- a/include/stdsharp/utility/forward_cast.h +++ b/include/stdsharp/utility/forward_cast.h @@ -1,14 +1,12 @@ #pragma once #include "../concepts/type.h" -#include "../macros.h" #include "../type_traits/type.h" #include "../compilation_config_in.h" namespace stdsharp { - template using forward_cast_t = apply_qualifiers< To, diff --git a/tests/.clang-tidy b/tests/.clang-tidy index c1b5991..b7ba13a 100644 --- a/tests/.clang-tidy +++ b/tests/.clang-tidy @@ -1,3 +1,3 @@ --- -InheritParentConfig: false +InheritParentConfig: true Checks: '-*-magic-numbers,-*-chained-comparison,-*-move-const-arg,-*-const-correctness' \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a347286..29f5717 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -15,29 +15,29 @@ set(src src/algorithm/algorithm.cpp src/containers/actions.cpp src/containers/concepts.cpp - # src/filesystem/filesystem.cpp - # src/functional/forward_bind.cpp + src/filesystem/filesystem.cpp + src/functional/forward_bind.cpp src/functional/invocables.cpp - # src/functional/pipeable.cpp + src/functional/pipeable.cpp src/functional/sequenced_invocables.cpp - # src/functional/symmetric_operations.cpp - # src/memory/box.cpp - # src/memory/composed_allocator.cpp - # src/memory/pointer_traits.cpp - # src/memory/single_stack_allocator.cpp - # src/memory/soo.cpp - # src/type_traits/indexed_traits.cpp - # src/type_traits/member.cpp - # src/type_traits/type_sequence.cpp - # src/type_traits/value_sequence.cpp + src/functional/symmetric_operations.cpp + src/memory/box.cpp + src/memory/composed_allocator.cpp + src/memory/pointer_traits.cpp + src/memory/single_stack_allocator.cpp + src/memory/soo.cpp + src/type_traits/indexed_traits.cpp + src/type_traits/member.cpp + src/type_traits/type_sequence.cpp + src/type_traits/value_sequence.cpp + src/utility/dispatcher.cpp src/utility/forward_cast.cpp - # src/utility/dispatcher.cpp - # src/utility/utility.cpp - # src/utility/value_wrapper.cpp - # src/lazy.cpp - # src/pattern_match.cpp - # src/synchronizer.cpp - ) + src/utility/utility.cpp + src/utility/value_wrapper.cpp + src/default_operator.cpp + src/lazy.cpp + src/pattern_match.cpp + src/synchronizer.cpp) config_lib(${PROJECT_NAME}Lib INTERFACE) @@ -49,49 +49,33 @@ config_exe(${PROJECT_NAME} EXE_SRC ${src}) target_compile_options( ${PROJECT_NAME} PUBLIC $<$:/W4 /wd4459> - $<$:-Qunused-arguments -ftime-trace -ftemplate-backtrace-limit=0>) -target_enable_clang_sanitizer(${PROJECT_NAME} PUBLIC SANITIZER address - undefined) -target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}Lib) + $<$:-Qunused-arguments -ftime-trace + -ftemplate-backtrace-limit=0>) set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_WARNING_AS_ERROR ON) +target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}Lib) + +target_clang_sanitizer(${PROJECT_NAME} PUBLIC SANITIZER address undefined) + # # Configure clang-tidy # option(ENABLE_CLANG_TIDY "Enable clang-tidy" OFF) -if(${ENABLE_CLANG_TIDY} AND (${CMAKE_CXX_COMPILER_ID} MATCHES "(Apple)?[Cc]lang")) +if(${ENABLE_CLANG_TIDY}) message(STATUS "clang-tidy is enabled") - target_enable_clang_tidy(${PROJECT_NAME}) + target_clang_tidy(${PROJECT_NAME}) endif() -catch_discover_tests(${PROJECT_NAME}) - # # Configure code coverage # set(CODE_COVERAGE_EXT CACHE STRING "Enable code coverage") if(CODE_COVERAGE_EXT) - set(PROFILE_FILE "${PROJECT_NAME}.profraw") - - add_custom_command( - OUTPUT ${PROFILE_FILE} - DEPENDS ${PROJECT_NAME} - COMMAND ${CMAKE_COMMAND} -E rm -f ${PROFILE_FILE} - COMMAND ${CMAKE_COMMAND} -E env LLVM_PROFILE_FILE=${PROFILE_FILE} - $ || exit 0 # Run first to generate - # profraw file - ) - - target_coverage( - ${PROJECT_NAME} - FORMAT - ${CODE_COVERAGE_EXT} - DEPENDS - ${PROFILE_FILE} - PROFILE_FILE - ${PROFILE_FILE}) + target_llvm_coverage(${PROJECT_NAME} FORMAT ${CODE_COVERAGE_EXT}) endif() + +catch_discover_tests(${PROJECT_NAME}) diff --git a/tests/src/default_operator.cpp b/tests/src/default_operator.cpp index 48e306d..4a3c4de 100644 --- a/tests/src/default_operator.cpp +++ b/tests/src/default_operator.cpp @@ -21,7 +21,7 @@ void arithmetic_test() } template -void inverse_arithmetic_test() +void commutative_arithmetic_test() { [[maybe_unused]] T v{}; @@ -35,7 +35,6 @@ void inverse_arithmetic_test() STATIC_REQUIRE(requires { 1 ^ v; }); STATIC_REQUIRE(requires { 1 << v; }); STATIC_REQUIRE(requires { 1 >> v; }); - STATIC_REQUIRE(requires { -v; }); STATIC_REQUIRE(requires { +v; }); } @@ -82,6 +81,7 @@ SCENARIO("arithmetic", "[default operator]") { arithmetic_test(); } struct comm : arith, + unary_plus, plus_commutative, minus_commutative, multiply_commutative, @@ -93,12 +93,14 @@ struct comm : bitwise_left_shift_commutative, bitwise_right_shift_commutative { + using arith::operator+; + using unary_plus::operator+; }; SCENARIO("commutative arithmetic", "[default operator]") { arithmetic_test(); - inverse_arithmetic_test(); + commutative_arithmetic_test(); } SCENARIO("commutative arithmetic with int", "[default operator]") @@ -109,7 +111,7 @@ SCENARIO("commutative arithmetic with int", "[default operator]") }; arithmetic_test(); - inverse_arithmetic_test(); + commutative_arithmetic_test(); } SCENARIO("arrow", "[default operator]") @@ -132,6 +134,8 @@ SCENARIO("arrow", "[default operator]") STATIC_REQUIRE(requires { v->*mem_ptr; }); } +// TODO: multidimensional subscript +#if __cpp_multidimensional_subscript >= 202110L SCENARIO("subscript", "[default operator]") { [[maybe_unused]] struct : subscript @@ -141,7 +145,6 @@ SCENARIO("subscript", "[default operator]") [[nodiscard]] auto operator[](const int /*unused*/) const { return *this; } } v{}; -#if __cpp_multidimensional_subscript >= 202110L STATIC_REQUIRE(requires { v[0, 1]; }); -#endif -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/tests/src/functional/sequenced_invocables.cpp b/tests/src/functional/sequenced_invocables.cpp index 71758f2..9e044e1 100644 --- a/tests/src/functional/sequenced_invocables.cpp +++ b/tests/src/functional/sequenced_invocables.cpp @@ -1,4 +1,3 @@ -#include "stdsharp/functional/empty_invoke.h" #include "stdsharp/functional/sequenced_invocables.h" #include "test.h" diff --git a/tests/src/memory/box.cpp b/tests/src/memory/box.cpp index 0c44a0e..e118fe8 100644 --- a/tests/src/memory/box.cpp +++ b/tests/src/memory/box.cpp @@ -3,35 +3,35 @@ using allocator_t = allocator; -SCENARIO("box basic requirements", "[memory][box]") // NOLINT -{ - using normal_t = normal_box; - using unique_t = unique_box; - using worst_t = box_for; +// SCENARIO("box basic requirements", "[memory][box]") // NOLINT +// { +// using normal_t = normal_box; +// using unique_t = unique_box; +// using worst_t = box_for; - STATIC_REQUIRE(default_initializable>); - STATIC_REQUIRE(default_initializable>); - STATIC_REQUIRE(default_initializable); - STATIC_REQUIRE(default_initializable); - STATIC_REQUIRE(default_initializable); +// STATIC_REQUIRE(default_initializable>); +// STATIC_REQUIRE(default_initializable>); +// STATIC_REQUIRE(default_initializable); +// STATIC_REQUIRE(default_initializable); +// STATIC_REQUIRE(default_initializable); - allocation_type_requirement_test(); -} +// allocation_type_requirement_test(); +// } -SCENARIO("box assign value", "[memory][box]") // NOLINT -{ - allocation_functionality_test>(); -} +// SCENARIO("box assign value", "[memory][box]") // NOLINT +// { +// allocation_functionality_test>(); +// } -SCENARIO("constexpr box", "[memory][box]") // NOLINT -{ - STATIC_REQUIRE( - [] - { - trivial_box> b{}; - auto& value = b.emplace(1); - value = 42; - return b.get(); - }() == 42 - ); -} \ No newline at end of file +// SCENARIO("constexpr box", "[memory][box]") // NOLINT +// { +// STATIC_REQUIRE( +// [] +// { +// trivial_box> b{}; +// auto& value = b.emplace(1); +// value = 42; +// return b.get(); +// }() == 42 +// ); +// } \ No newline at end of file diff --git a/tests/src/memory/single_stack_allocator.cpp b/tests/src/memory/single_stack_allocator.cpp index 32f59da..ca0136d 100644 --- a/tests/src/memory/single_stack_allocator.cpp +++ b/tests/src/memory/single_stack_allocator.cpp @@ -62,23 +62,4 @@ SCENARIO("single stack allocator", "[memory][single_stack_allocator]") // NOLINT REQUIRE_THROWS_AS(allocator.allocate(decltype(allocator)::size + 1), bad_alloc); } } - -#if __cpp_constexpr >= 202306L - GIVEN("allocator with 4 * sizeof(int), constexpr allocate and deallocate") - { - STATIC_REQUIRE( - [] - { - single_stack_buffer<4 * sizeof(int)> rsc; - auto allocator = make_single_stack_allocator(rsc); - const auto p1 = allocator.allocate(1); - const bool is_null = p1 == nullptr; - - allocator.deallocate(p1, 1); - - return !is_null; - }() - ); - } -#endif } diff --git a/tests/src/synchronizer.cpp b/tests/src/synchronizer.cpp index f0ea285..1ca234e 100644 --- a/tests/src/synchronizer.cpp +++ b/tests/src/synchronizer.cpp @@ -33,5 +33,5 @@ SCENARIO("synchronizer", "[synchronizer]") // NOLINT synchronizer syn; int i{}; - auto&& [value, lock] = syn.read_with(i); + [[maybe_unused]] auto&& [value, lock] = syn.read_with(i); } \ No newline at end of file diff --git a/tests/src/type_traits/type_sequence.cpp b/tests/src/type_traits/type_sequence.cpp index 3403ca2..13710ff 100644 --- a/tests/src/type_traits/type_sequence.cpp +++ b/tests/src/type_traits/type_sequence.cpp @@ -33,8 +33,7 @@ SCENARIO("type sequence apply", "[type traits][type sequence]") // NOLINT namespace { - inline constexpr auto type_sequence_invoker = - [](const basic_type_constant) consteval {}; + inline constexpr auto type_sequence_invoker = [](const basic_type_constant) {}; } TEMPLATE_TEST_CASE( // NOLINT diff --git a/tests/src/type_traits/value_sequence.cpp b/tests/src/type_traits/value_sequence.cpp index bac88f6..ee6a280 100644 --- a/tests/src/type_traits/value_sequence.cpp +++ b/tests/src/type_traits/value_sequence.cpp @@ -216,7 +216,7 @@ SCENARIO("Scenario: value adjacent find", "[type traits]") // NOLINT STATIC_REQUIRE( // invocable< value_sequence_algo::adjacent_find_fn, - sequenced_invocables> // + sequenced_invocables, always_false_fn>> // ); } @@ -230,7 +230,7 @@ TEMPLATE_TEST_CASE_SIG( // NOLINT { STATIC_REQUIRE( // same_as< - value_sequence_algo::unique_t>, + value_sequence_algo::unique_t, always_false_fn>>, Expect> // ); }