diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 738a89d9..be458248 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -12,7 +12,7 @@ on: env: DEBIAN_FRONTEND: noninteractive CMAKE_GENERATOR: Ninja - DEFAULT_CXX_STANDARD: 20 + DEFAULT_CXX_STANDARD: 23 DEFAULT_LLVM_VERSION: 21 DEFAULT_GCC_VERSION: 14 MULL_LLVM_MAJOR_VERSION: 19 @@ -31,8 +31,8 @@ jobs: fail-fast: false matrix: compiler: [clang, gcc] - version: [12, 13, 14, 16, 17, 18, 19, 20, 21] - cxx_standard: [17, 20] + version: [12, 13, 14, 18, 19, 20, 21] + cxx_standard: [23] stdlib: [libstdc++, libc++] build_type: [Debug] include: @@ -76,24 +76,6 @@ jobs: stdlib: libc++ install: sudo apt update && sudo apt install -y clang-18 libc++-18-dev libc++abi-18-dev cxx_flags: "-stdlib=libc++" - - version: 17 - compiler: clang - install: sudo apt update && sudo apt install -y clang-17 - toolchain_root: "/usr/lib/llvm-17" - - version: 17 - compiler: clang - stdlib: libc++ - install: sudo apt update && sudo apt install -y clang-17 libc++-17-dev libc++abi-17-dev - cxx_flags: "-stdlib=libc++" - - version: 16 - compiler: clang - install: sudo apt update && sudo apt install -y clang-16 - toolchain_root: "/usr/lib/llvm-16" - - version: 16 - compiler: clang - stdlib: libc++ - install: sudo apt update && sudo apt install -y clang-16 libc++-16-dev libc++abi-16-dev - cxx_flags: "-stdlib=libc++" - compiler: gcc toolchain_root: "/usr" cxx_flags: "" @@ -122,10 +104,6 @@ jobs: version: 19 - compiler: gcc version: 18 - - compiler: gcc - version: 17 - - compiler: gcc - version: 16 - compiler: clang version: 14 - compiler: clang @@ -183,92 +161,6 @@ jobs: working-directory: ${{github.workspace}}/build run: ctest --output-on-failure -j $(nproc) -C ${{matrix.build_type}} - build_and_test_22: - runs-on: ${{ github.repository_owner == 'intel' && 'intel-' || '' }}ubuntu-22.04 - strategy: - fail-fast: false - matrix: - compiler: [clang] - version: [14, 15] - cxx_standard: [17, 20] - stdlib: [libstdc++, libc++] - build_type: [Debug] - include: - - compiler: clang - cc: "clang" - cxx: "clang++" - cxx_flags: "-stdlib=libstdc++" - - version: 15 - compiler: clang - install: sudo apt update && sudo apt install -y clang-15 - toolchain_root: "/usr/lib/llvm-15" - - version: 15 - compiler: clang - stdlib: libc++ - install: sudo apt update && sudo apt install -y clang-15 libc++-15-dev libc++abi-15-dev - cxx_flags: "-stdlib=libc++" - - version: 14 - compiler: clang - install: sudo apt update && sudo apt install -y clang-14 - toolchain_root: "/usr/lib/llvm-14" - - version: 14 - compiler: clang - stdlib: libc++ - install: sudo apt update && sudo apt install -y clang-14 libc++-14-dev libc++abi-14-dev - cxx_flags: "-stdlib=libc++" - exclude: - - compiler: clang - version: 14 - stdlib: libstdc++ - - steps: - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - - name: Install build tools - run: | - ${{ matrix.install }} - sudo apt install -y ninja-build python3-venv python3-pip - - - name: Restore CPM cache - env: - cache-name: cpm-cache-0 - id: cpm-cache-restore - uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3 - with: - path: ~/cpm-cache - key: ${{runner.os}}-${{env.cache-name}}-${{ hashFiles('**/CMakeLists.txt', 'cmake/**') }} - restore-keys: | - ${{runner.os}}-${{env.cache-name}}- - - - name: Configure CMake - env: - CC: ${{matrix.toolchain_root}}/bin/${{matrix.cc}} - CXX: ${{matrix.toolchain_root}}/bin/${{matrix.cxx}} - run: cmake -B ${{github.workspace}}/build -DCMAKE_CXX_STANDARD=${{matrix.cxx_standard}} -DCMAKE_CXX_FLAGS_INIT=${{matrix.cxx_flags}} -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCPM_SOURCE_CACHE=~/cpm-cache - - - name: Save CPM cache - env: - cache-name: cpm-cache-0 - if: steps.cpm-cache-restore.outputs.cache-hit != 'true' - uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3 - with: - path: ~/cpm-cache - key: ${{runner.os}}-${{env.cache-name}}-${{ hashFiles('**/CMakeLists.txt', 'cmake/**') }} - - - name: Install python test requirements - run: | - python3 -m venv ${{github.workspace}}/test_venv - source ${{github.workspace}}/test_venv/bin/activate - pip install -r ${{github.workspace}}/requirements.txt - echo "${{github.workspace}}/test_venv/bin" >> $GITHUB_PATH - - - name: Build Unit Tests - run: cmake --build ${{github.workspace}}/build --config ${{matrix.build_type}} -v -t build_unit_tests - - - name: Test - working-directory: ${{github.workspace}}/build - run: ctest --output-on-failure -j $(nproc) -C ${{matrix.build_type}} - quality_checks_pass: runs-on: ${{ github.repository_owner == 'intel' && 'intel-' || '' }}ubuntu-24.04 steps: @@ -530,7 +422,7 @@ jobs: merge_ok: runs-on: ${{ github.repository_owner == 'intel' && 'intel-' || '' }}ubuntu-24.04 - needs: [build_and_test_24, build_and_test_22, mutate, quality_checks_pass, sanitize, valgrind] + needs: [build_and_test_24, mutate, quality_checks_pass, sanitize, valgrind] if: ${{ !cancelled() }} steps: - name: Enable merge diff --git a/.github/workflows/usage_test.yml b/.github/workflows/usage_test.yml index b4e7b18f..cc451c9b 100644 --- a/.github/workflows/usage_test.yml +++ b/.github/workflows/usage_test.yml @@ -16,7 +16,7 @@ env: jobs: usage_test: - runs-on: ${{ github.repository_owner == 'intel' && 'intel-' || '' }}ubuntu-22.04 + runs-on: ${{ github.repository_owner == 'intel' && 'intel-' || '' }}ubuntu-24.04 strategy: fail-fast: false matrix: @@ -26,8 +26,8 @@ jobs: - compiler: clang cc: "clang" cxx: "clang++" - install: sudo apt update && sudo apt install -y clang-14 - toolchain_root: "/usr/lib/llvm-14" + install: sudo apt update && sudo apt install -y clang-18 + toolchain_root: "/usr/lib/llvm-18" - compiler: gcc cc: "gcc-12" cxx: "g++-12" @@ -44,16 +44,17 @@ jobs: - name: Install cmake run: | - pip3 install --upgrade pip - pip3 install --force cmake==${{env.USER_CMAKE_VERSION}} + python3 -m venv ${{github.workspace}}/test_venv + source ${{github.workspace}}/test_venv/bin/activate + pip install cmake==${{env.USER_CMAKE_VERSION}} - - name: Configure CMake + - name: Configure cmake env: CC: ${{matrix.toolchain_root}}/bin/${{matrix.cc}} CXX: ${{matrix.toolchain_root}}/bin/${{matrix.cxx}} working-directory: ${{github.workspace}}/usage_test - run: ~/.local/bin/cmake -B build -DCPP_IMPLEMENTATION=${{matrix.cpp_implementation}} + run: ${{github.workspace}}/test_venv/bin/cmake -B build -DCPP_IMPLEMENTATION=${{matrix.cpp_implementation}} - name: Build working-directory: ${{github.workspace}}/usage_test - run: ~/.local/bin/cmake --build build + run: ${{github.workspace}}/test_venv/bin/cmake --build build diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d7df848..8e46dddb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,11 +15,11 @@ else() endif() add_versioned_package("gh:boostorg/mp11#boost-1.83.0") -fmt_recipe(11.1.3) +fmt_recipe(12.1.0) add_versioned_package("gh:intel/cpp-baremetal-concurrency#06e5901") if(NOT DEFINED CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 20) + set(CMAKE_CXX_STANDARD 23) endif() add_library(stdx INTERFACE) diff --git a/README.md b/README.md index 469d7658..674c5592 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,21 @@ *stdx* is a C++ header-only library that: -- backports to C++17 some standard library features from C++20 and beyond +- backports to C++N some standard library features from C++(>N) and beyond - adds some useful extra utilities that are missing from the standard - -Some of the extras are available only with C++20 or later. - -*stdx* supports: - -- clang 14 through 21 -- gcc 12 through 14 See the [full documentation](https://intel.github.io/cpp-std-extensions/). + +C++ standard support is as follows: + +- C++23: [main branch](https://github.com/intel/cpp-std-extensions/tree/main) (active development) +- C++20: [cpp20 branch](https://github.com/intel/cpp-std-extensions/tree/main) (supported) +- C++17: unsupported, but many features in the [cpp20 branch](https://github.com/intel/cpp-std-extensions/tree/cpp20) will work with C++17 also. + +Compiler support: + +| Branch | GCC versions | Clang versions | +| --- | --- | --- | +| [main](https://github.com/intel/cpp-baremetal-concurrency/tree/main) | 12 thru 14 | 18 thru 21 | +| [cpp20](https://github.com/intel/cpp-baremetal-concurrency/tree/cpp20) | 12 thru 14 | 14 thru 21 | + diff --git a/include/stdx/functional.hpp b/include/stdx/functional.hpp index 18e71323..8005f9e3 100644 --- a/include/stdx/functional.hpp +++ b/include/stdx/functional.hpp @@ -1,18 +1,11 @@ #pragma once +#include #include #include #include -#if __cpp_lib_bind_front < 202306L or __cpp_lib_bind_back < 202306L -#if __cplusplus >= 202002L -#include -#else -#include -#endif -#endif - namespace stdx { inline namespace v1 { @@ -34,20 +27,10 @@ template with_result_of(F) -> with_result_of; #endif namespace detail { -#if __cpp_lib_bind_front < 202306L or __cpp_lib_bind_back < 202306L -#if __cplusplus >= 202002L template using bind_tuple_t = stdx::tuple; using stdx::get; -#else -template using bind_tuple_t = std::tuple; -using std::get; -#endif -#endif } // namespace detail -#if __cpp_lib_bind_front >= 201907L -using std::bind_front; -#else namespace detail { template struct bind_front_t; @@ -77,9 +60,7 @@ constexpr auto bind_front(F &&f, Args &&...args) { std::decay_t...>{ std::forward(f), {std::forward(args)...}}; } -#endif -#if __cpp_lib_bind_front < 202306L namespace detail { template struct bind_front_value_t; @@ -106,11 +87,6 @@ template constexpr auto bind_front(Args &&...args) { {std::forward(args)...}}; } -#endif - -#if __cpp_lib_bind_back >= 202202L -using std::bind_back; -#else namespace detail { template struct bind_back_t; @@ -140,9 +116,7 @@ constexpr auto bind_back(F &&f, Args &&...args) { std::decay_t...>{ std::forward(f), {std::forward(args)...}}; } -#endif -#if __cpp_lib_bind_back < 202306L namespace detail { template struct bind_back_value_t; @@ -169,8 +143,6 @@ template constexpr auto bind_back(Args &&...args) { {std::forward(args)...}}; } -#endif - // NOLINTBEGIN(modernize-use-constraints) template struct unary_plus { template ())), detail::value_t>::value; -#if __cpp_lib_forward_like < 202207L template [[nodiscard]] constexpr auto forward_like(U &&u) noexcept -> decltype(auto) { constexpr auto t_is_const = std::is_const_v>; @@ -113,7 +112,7 @@ template if constexpr (t_is_const) { return std::as_const(u); } else { - return (u); + return static_cast(u); // NOLINT(readability-redundant-casting) } } else { if constexpr (t_is_const) { @@ -123,11 +122,9 @@ template } } } -#else -using std::forward_like; -#endif + template -using forward_like_t = decltype(forward_like(std::declval())); +using forward_like_t = decltype(stdx::forward_like(std::declval())); template , int> = 0> [[nodiscard]] constexpr auto as_unsigned(T t) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1ecbafd5..5f36f3fc 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -31,20 +31,25 @@ add_tests( bitset byterator cached + call_by_need callable compiler concepts conditional ct_conversions + ct_format + ct_string cx_map cx_multimap cx_queue cx_set cx_vector default_panic + env for_each_n_args function_traits functional + indexed_tuple intrusive_forward_list intrusive_list intrusive_list_properties @@ -63,6 +68,8 @@ add_tests( rollover span to_underlying + tuple + tuple_algorithms type_bitset type_map type_traits @@ -78,28 +85,16 @@ target_compile_definitions( atomic_override_test PRIVATE -DATOMIC_CFG="${CMAKE_CURRENT_LIST_DIR}/detail/atomic_cfg.hpp") -if(${CMAKE_CXX_STANDARD} GREATER_EQUAL 20) - add_tests( - FILES - call_by_need - ct_format - ct_string - env - indexed_tuple - tuple - tuple_algorithms) - - add_unit_test( - "ct_format_freestanding_test" - CATCH2 - FILES - "ct_format.cpp" - LIBRARIES - warnings - stdx) - target_compile_definitions(ct_format_freestanding_test - PRIVATE STDX_FREESTANDING) -endif() +add_unit_test( + "ct_format_freestanding_test" + CATCH2 + FILES + "ct_format.cpp" + LIBRARIES + warnings + stdx) +target_compile_definitions(ct_format_freestanding_test + PRIVATE STDX_FREESTANDING) add_subdirectory(fail) add_subdirectory(pbt) diff --git a/test/fail/CMakeLists.txt b/test/fail/CMakeLists.txt index 09edb365..c39f7b56 100644 --- a/test/fail/CMakeLists.txt +++ b/test/fail/CMakeLists.txt @@ -7,10 +7,16 @@ endfunction() add_fail_tests( as_signed_bool as_unsigned_bool + atomic_bool_dec bitset_mixed_enumeration bitset_nonintegral_bit_places bitset_signed_storage bitset_to_uint64_over_64_bits + call_by_need + ct_format_mismatch + dynamic_container_no_ct_capacity + dynamic_std_span_no_ct_capacity + dynamic_stdx_span_no_ct_capacity for_each_n_args_bad_size optional_without_tombstone optional_integral_with_tombstone_traits @@ -25,23 +31,13 @@ add_fail_tests( subspan_too_big subspan_wrapping template_for_each_not_list - to_address_undefined_on_function) - -if(${CMAKE_CXX_STANDARD} GREATER_EQUAL 20) - add_fail_tests( - atomic_bool_dec - call_by_need - ct_format_mismatch - dynamic_container_no_ct_capacity - dynamic_std_span_no_ct_capacity - dynamic_stdx_span_no_ct_capacity - tuple_index_out_of_bounds - tuple_equality_mismatch - tuple_equality_with_element - tuple_spaceship_mismatch - tuple_spaceship_with_element - tuple_type_not_found) -endif() + to_address_undefined_on_function + tuple_index_out_of_bounds + tuple_equality_mismatch + tuple_equality_with_element + tuple_spaceship_mismatch + tuple_spaceship_with_element + tuple_type_not_found) function(add_test_by_compiler CPP_NAME CXX_VERSION COMPILER_ID COMPILER_VERSION) if("cxx_std_${CXX_VERSION}" IN_LIST CMAKE_CXX_COMPILE_FEATURES) diff --git a/test/pbt/tuple.py b/test/pbt/tuple.py index 0f96039e..128ce217 100644 --- a/test/pbt/tuple.py +++ b/test/pbt/tuple.py @@ -89,12 +89,18 @@ def test_get_by_index(compile, l, i): constexpr auto t = {t}; constexpr auto expected = {expected_v}; - - static_assert(stdx::get<{i}>(t) == expected); - static_assert(get<{i}>(t) == expected); - static_assert(t[{i}_idx] == expected); - static_assert(t[stdx::index<{i}>] == expected); + constexpr auto x1 = stdx::get<{i}>(t); + static_assert(x1 == expected); + + constexpr auto x2 = get<{i}>(t); + static_assert(x2 == expected); + + constexpr auto x3 = t[{i}_idx]; + static_assert(x3 == expected); + + constexpr auto x4 = t[stdx::index<{i}>]; + static_assert(x4 == expected); int main() {{ return 0; diff --git a/usage_test/CMakeLists.txt b/usage_test/CMakeLists.txt index 0ff84f49..cda38df6 100644 --- a/usage_test/CMakeLists.txt +++ b/usage_test/CMakeLists.txt @@ -6,6 +6,10 @@ message(STATUS "Actual cmake version: ${CMAKE_VERSION}") project(stdx_usage) +if(NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 23) +endif() + include(${CMAKE_CURRENT_LIST_DIR}/../cmake/get_cpm.cmake) cpmaddpackage(NAME stdx SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/.." GIT_TAG HEAD)