Skip to content

Commit 7d8a987

Browse files
authored
Merge pull request #175 from Kaaserne/dev
Module improvements & catch 3.9
2 parents 2dd9dff + f17af6a commit 7d8a987

File tree

110 files changed

+389
-458
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+389
-458
lines changed

.github/workflows/ci.yml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ on:
1616

1717
env:
1818
CTEST_OUTPUT_ON_FAILURE: 1
19-
CATCH_VERSION: '2.13.10'
19+
CATCH_VERSION: '3.9.0'
2020

2121
jobs:
2222
gcc:
@@ -218,4 +218,40 @@ jobs:
218218
-D CMAKE_BUILD_TYPE:STRING=Release
219219

220220
- name: Build
221-
run: cmake --build build/examples -j $(nproc)
221+
run: cmake --build build/examples -j $(nproc)
222+
223+
module_tests:
224+
runs-on: ubuntu-latest
225+
226+
steps:
227+
- name: Checkout repo
228+
uses: actions/checkout@v1
229+
230+
- name: Install Ninja
231+
uses: seanmiddleditch/gha-setup-ninja@master
232+
233+
- name: Add LLVM apt repo and install Clang 18
234+
run: |
235+
sudo apt-get update
236+
sudo apt-get install -y wget lsb-release gnupg
237+
wget https://apt.llvm.org/llvm.sh
238+
chmod +x llvm.sh
239+
sudo ./llvm.sh 18
240+
clang++-18 --version
241+
242+
- name: Configure tests
243+
env:
244+
CC: clang-18
245+
CXX: clang++-18
246+
run: cmake -S tests/module_tests -B tests/module_tests/build -G Ninja
247+
-D CMAKE_CXX_STANDARD:STRING=20
248+
-D CPP-LAZY_USE_MODULES=ON
249+
-D CMAKE_CXX_COMPILER=clang++-18
250+
-D CMAKE_C_COMPILER=clang-18
251+
252+
- name: Build
253+
run: cmake --build tests/module_tests/build
254+
255+
- name: Run tests
256+
working-directory: tests/module_tests/build
257+
run: ./module_test

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches: [ "master" ]
88

99
env:
10-
CATCH_VERSION: '2.13.10'
10+
CATCH_VERSION: '3.9.0'
1111

1212
jobs:
1313
analyze:

CMakeLists.txt

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ endif()
3131
option(CPP-LAZY_DEBUG_ASSERTIONS "Debug assertions" ${CPP-LAZY_DEBUG_ASSERTIONS})
3232

3333
if (CPP-LAZY_USE_MODULES)
34+
message(STATUS "cpp-lazy: using C++20 modules")
3435
set(CPP-LAZY_SOURCE_FILES "src/lz.cppm")
3536
set(CPP-LAZY_LINK_VISIBILITY "PUBLIC")
3637
set(CPP-LAZY_COMPILE_FEATURES_VISIBLITY "PUBLIC")
3738
set(CPP-LAZY_COMPILE_DEFINITIONS_VISIBLITY "PRIVATE")
3839
set(CPP-LAZY_COMPILE_INCLUDE_VISIBLITY "PUBLIC")
40+
set(CMAKE_CXX_SCAN_FOR_MODULES ON)
3941
else()
4042
set(CPP-LAZY_LIB_TYPE "INTERFACE")
4143
set(CPP-LAZY_LINK_VISIBILITY "INTERFACE")
@@ -73,6 +75,10 @@ message(STATUS "cpp-lazy: Debug assertions: ${CPP-LAZY_DEBUG_ASSERTIONS}.")
7375
add_library(cpp-lazy ${CPP-LAZY_LIB_TYPE} "${CPP-LAZY_SOURCE_FILES}")
7476
add_library(cpp-lazy::cpp-lazy ALIAS cpp-lazy)
7577

78+
if (CPP-LAZY_USE_MODULES)
79+
target_sources(cpp-lazy PUBLIC FILE_SET cxx_modules TYPE CXX_MODULES FILES "${CPP-LAZY_SOURCE_FILES}")
80+
endif()
81+
7682
# Link lib stacktrace if debug assertions are enabled, on Linux with C++23 or later
7783
set(IS_CXX_23 $<VERSION_GREATER_EQUAL:${CMAKE_CXX_STANDARD},23>)
7884
set(IS_LINUX_COMPILER $<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>)
@@ -89,25 +95,6 @@ target_compile_definitions(cpp-lazy
8995
$<$<BOOL:${CPP-LAZY_USE_STANDALONE}>:LZ_STANDALONE>
9096
$<$<BOOL:${CPP-LAZY_DEBUG_ASSERTIONS}>:LZ_DEBUG_ASSERTIONS>
9197
)
92-
if (CPP-LAZY_USE_MODULES)
93-
set(FMT_MODULE "ON" CACHE STRING "")
94-
if (MSVC)
95-
set(BMI "${CMAKE_CURRENT_BINARY_DIR}/lz.ifc")
96-
target_compile_options(cpp-lazy
97-
PRIVATE
98-
/interface /ifcOutput "${BMI}"
99-
INTERFACE
100-
/reference lz="${BMI}"
101-
)
102-
endif()
103-
set_target_properties(cpp-lazy
104-
PROPERTIES
105-
ADDITIONAL_CLEAN_FILES "${BMI}"
106-
DEBUG_POSTFIX
107-
"d"
108-
)
109-
set_source_files_properties("${BMI}" PROPERTIES GENERATED ON)
110-
endif()
11198

11299
target_compile_features(cpp-lazy
113100
${CPP-LAZY_COMPILE_FEATURES_VISIBLITY}
@@ -127,10 +114,19 @@ set(cpp-lazy_directory "cpp-lazy")
127114
set(cpp-lazy_include_directory "${CMAKE_INSTALL_INCLUDEDIR}/${cpp-lazy_directory}")
128115
set(cpp-lazy_install_cmakedir "${CMAKE_INSTALL_LIBDIR}/cmake/${cpp-lazy_directory}")
129116

130-
install(TARGETS cpp-lazy
117+
if (CPP-LAZY_USE_MODULES)
118+
install(TARGETS cpp-lazy
131119
EXPORT cpp-lazyTargets
132120
INCLUDES
133-
DESTINATION "${cpp-lazy_include_directory}")
121+
DESTINATION "${cpp-lazy_include_directory}"
122+
FILE_SET cxx_modules DESTINATION "${cpp-lazy_include_directory}"
123+
)
124+
else ()
125+
install(TARGETS cpp-lazy
126+
EXPORT cpp-lazyTargets
127+
INCLUDES
128+
DESTINATION "${cpp-lazy_include_directory}")
129+
endif ()
134130

135131
write_basic_package_version_file(
136132
cpp-lazyConfigVersion.cmake
@@ -164,4 +160,4 @@ if (CPP-LAZY_BUILD_ESSENTIALS_ZIP)
164160
DEPENDS include/;CMakeLists.txt;LICENSE.md;cmake/
165161
)
166162
add_custom_target(${PROJECT_NAME}_package DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-src.zip")
167-
endif ()
163+
endif ()

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,23 @@ The library uses one optional dependency: the library `{fmt}`, more of which can
1313

1414
# Features
1515
- C++11/14/17/20 compatible
16+
- C++20's module compatible
1617
- Easy printing/formatting using `lz::format`, `fmt::print` or `std::cout`
17-
- Tested with `-Wpedantic -Wextra -Wall -Wshadow -Wno-unused-function -Werror -Wconversion` and `/WX` for MSVC
1818
- One optional dependency ([`{fmt}`](https://github.com/fmtlib/fmt)), can be turned off by using option `CPP-LAZY_USE_STANDALONE=TRUE`/`set(CPP-LAZY_USE_STANDALONE TRUE)` in CMake
1919
- STL compatible (if the input iterable is not sentinelled, otherwise use `lz::*` equivalents)
2020
- Little overhead, as little data usage as possible
2121
- Any compiler with at least C++11 support should be suitable
2222
- [Easy installation](https://github.com/Kaaserne/cpp-lazy#installation)
2323
- [Clear Examples](https://github.com/Kaaserne/cpp-lazy/tree/master/examples)
2424
- Piping/chaining using `|` operator
25+
<details>
26+
<summary>Tested with GCC's warning flags</summary>
27+
28+
```
29+
-Wpedantic -Wextra -Wall -Wshadow -Werror -Wconversion -Wcast-qual -Wcomma-subscript -Wctor-dtor-privacy -Wdeprecated-copy-dtor -Wdouble-promotion -Wduplicated-branches -Wduplicated-cond -Wenum-conversion -Wextra-semi -Wfloat-equal -Wformat-overflow=2 -Wformat-signedness -Wformat=2 -Wlogical-op -Wmismatched-tags -Wmultichar -Wnon-virtual-dtor -Woverloaded-virtual -Wpointer-arith -Wrange-loop-construct -Wrestrict -Wstrict-null-sentinel -Wsuggest-attribute=format -Wsuggest-attribute=malloc -Wuninitialized -Wvla -Wvolatile -Wwrite-strings
30+
```
31+
32+
</details>
2533

2634
# What is lazy?
2735
Lazy evaluation is an evaluation strategy which holds the evaluation of an expression until its value is needed. In this library, all the iterators are lazy evaluated. Suppose you want to have a sequence of `n` random numbers. You could write a for loop:
@@ -103,11 +111,13 @@ int main() {
103111
// the sequence will be traversed to get the size using lz::eager_size. The iterable will be documented
104112
// appropriately if this requires a sized iterable. Example:
105113
auto zipper1 = lz::zip(lz::c_string("ab"), lz::c_string("cd")); // Calling .end() will take O(n) time
106-
auto zipper2 = lz::zip(sized, sized); // Takes O(1) time
114+
auto zipper2 = lz::zip(sized, sized); // Calling .end() will take O(1) time
107115

108-
// You can cache the size if you need to (more about when to do that in the appropriate iterable documentation):
109-
auto cached_sizes = lz::zip(lz::c_string("ab") | lz::cache_size, lz::c_string("cd") | lz::cache_size); // Takes O(n) time
110-
// However cached_sizes.end() will now take O(1) time
116+
// You can cache the size if you need to.
117+
// More about when to do that in the appropriate iterable documentation
118+
// lz:c_string isn't sized, so in order to make it sized, we can use lz::cache_size:
119+
auto cached_sizes = lz::zip(lz::c_string("ab") | lz::cache_size, lz::c_string("cd") | lz::cache_size);
120+
// cached_sizes.end() will now take O(1) time, instead of zipper1's O(n) time.
111121
}
112122
```
113123

include/Lz/algorithm.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
#include <numeric> // std::accumulate
1414
#endif // LZ_HAS_CXX_20
1515

16-
namespace lz {
17-
18-
LZ_MODULE_EXPORT_SCOPE_BEGIN
16+
LZ_MODULE_EXPORT namespace lz {
1917

2018
/**
2119
* Checks whether [begin, end) is empty.
@@ -739,8 +737,6 @@ LZ_NODISCARD LZ_CONSTEXPR_CXX_14 bool is_sorted(Iterable&& iterable, BinaryPredi
739737
std::forward<BinaryPredicate>(binary_predicate));
740738
}
741739

742-
LZ_MODULE_EXPORT_SCOPE_END
743-
744740
} // namespace lz
745741

746742
#endif // LZ_ALGORITHM_HPP

include/Lz/basic_iterable.hpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ class sized_iterable_impl : public lazy_view {
114114
}
115115
};
116116
} // namespace detail
117+
} // namespace lz
117118

118-
LZ_MODULE_EXPORT_SCOPE_BEGIN
119-
119+
LZ_MODULE_EXPORT namespace lz {
120120
/**
121121
* @brief A class that can be converted to any container. It only contains the iterators and
122122
* can be used in pipe expressions, converted to a container with `to<Container>()`, used in algorithms, for-each loops, etc...
@@ -148,10 +148,11 @@ template<class I, class S>
148148
LZ_NODISCARD constexpr basic_iterable<I, S> make_basic_iterable(I begin, S end) {
149149
return { std::move(begin), std::move(end) };
150150
}
151+
}
151152

152-
LZ_MODULE_EXPORT_SCOPE_END
153-
153+
namespace lz {
154154
namespace detail {
155+
155156
template<LZ_CONCEPT_ITERABLE Iterable, class Container, class = void>
156157
struct prealloc_container {
157158
LZ_CONSTEXPR_CXX_14 void try_reserve(const Iterable&, const Container&) const noexcept {
@@ -227,11 +228,11 @@ struct has_push<Container, void_t<decltype(0, std::declval<Container>().push(std
227228
* };
228229
* ```
229230
*/
230-
template<class Container, class = void>
231+
LZ_MODULE_EXPORT template<class Container, class = void>
231232
struct custom_copier_for;
232233

233234
// std::array doesnt have push_back, insert, insert_after... etc, so just use copy
234-
template<class T, std::size_t N>
235+
LZ_MODULE_EXPORT template<class T, std::size_t N>
235236
struct custom_copier_for<std::array<T, N>> {
236237
template<class Iterable>
237238
LZ_CONSTEXPR_CXX_14 void copy(Iterable&& iterable, std::array<T, N>& container) const {
@@ -409,8 +410,9 @@ struct template_combiner {
409410
}
410411
};
411412
} // namespace detail
413+
} // namespace lz
412414

413-
LZ_MODULE_EXPORT_SCOPE_BEGIN
415+
LZ_MODULE_EXPORT namespace lz {
414416

415417
// clang-format off
416418

@@ -623,20 +625,14 @@ to(Iterable&& iterable, Args&&... args) {
623625
*/
624626
using detail::custom_copier_for;
625627

626-
LZ_MODULE_EXPORT_SCOPE_END
627-
628628
} // namespace lz
629629

630-
LZ_MODULE_EXPORT_SCOPE_BEGIN
631-
632-
template<class Iterable, class Adaptor>
630+
LZ_MODULE_EXPORT template<class Iterable, class Adaptor>
633631
constexpr auto operator|(Iterable&& iterable, Adaptor&& adaptor)
634632
-> lz::detail::enable_if<lz::detail::is_adaptor<lz::detail::remove_cvref<Adaptor>>::value &&
635633
lz::detail::is_iterable<Iterable>::value,
636634
decltype(std::forward<Adaptor>(adaptor)(std::forward<Iterable>(iterable)))> {
637635
return std::forward<Adaptor>(adaptor)(std::forward<Iterable>(iterable));
638636
}
639637

640-
LZ_MODULE_EXPORT_SCOPE_END
641-
642638
#endif // LZ_BASIC_ITERATOR_VIEW_HPP

include/Lz/c_string.hpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
#include <Lz/basic_iterable.hpp>
77
#include <Lz/detail/adaptors/c_string.hpp>
88

9-
namespace lz {
10-
11-
LZ_MODULE_EXPORT_SCOPE_BEGIN
12-
9+
LZ_MODULE_EXPORT namespace lz {
1310
/**
1411
* @brief This adaptor is used to create a c forward iterable cstring iterable object. Its end() function will return a sentinel,
1512
* rather than an actual iterator. This iterable does not contain a .size() method. Example:
@@ -34,8 +31,6 @@ LZ_INLINE_VAR constexpr detail::c_string_adaptor c_string{};
3431
template<class CharT>
3532
using c_string_iterable = detail::c_string_iterable<CharT>;
3633

37-
LZ_MODULE_EXPORT_SCOPE_END
38-
3934
} // namespace lz
4035

4136
#endif

include/Lz/cached_size.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
#include <Lz/basic_iterable.hpp>
77
#include <Lz/detail/adaptors/cached_size.hpp>
88

9-
namespace lz {
10-
11-
LZ_MODULE_EXPORT_SCOPE_BEGIN
9+
LZ_MODULE_EXPORT namespace lz {
1210

1311
/**
1412
* @brief Creates an iterable with a size method. Gets the size eagerly (using `lz::eager_size`). Some iterables will traverse
@@ -57,8 +55,6 @@ LZ_INLINE_VAR constexpr detail::cached_size_adaptor cache_size{};
5755
template<class Iterable>
5856
using cached_size_iterable = detail::cached_size_iterable<Iterable>;
5957

60-
LZ_MODULE_EXPORT_SCOPE_END
61-
6258
} // namespace lz
6359

6460
#endif

include/Lz/cartesian_product.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
#include <Lz/basic_iterable.hpp>
77
#include <Lz/detail/adaptors/cartesian_product.hpp>
88

9-
namespace lz {
10-
11-
LZ_MODULE_EXPORT_SCOPE_BEGIN
9+
LZ_MODULE_EXPORT namespace lz {
1210

1311
/**
1412
* @brief Performs a cartesian product on the given iterables. This means that it will return all possible combinations
@@ -38,8 +36,6 @@ LZ_INLINE_VAR constexpr detail::cartesian_product_adaptor cartesian_product{};
3836
template<class... Iterables>
3937
using cartesian_product_iterable = detail::cartesian_product_iterable<Iterables...>;
4038

41-
LZ_MODULE_EXPORT_SCOPE_END
42-
4339
} // namespace lz
4440

4541
#endif // LZ_CARTESIAN_PRODUCT_HPP

include/Lz/chunk_if.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
#include <Lz/detail/adaptors/chunk_if.hpp>
88
#include <Lz/string_view.hpp>
99

10-
namespace lz {
11-
12-
LZ_MODULE_EXPORT_SCOPE_BEGIN
10+
LZ_MODULE_EXPORT namespace lz {
1311

1412
#ifdef LZ_HAS_CXX_11
1513

@@ -134,8 +132,6 @@ using chunk_if_iterable = detail::chunk_if_iterable<basic_iterable<iter_t<Iterab
134132
template<class ValueType, class Iterable, class UnaryPredicate>
135133
using t_chunk_if_iterable = detail::chunk_if_iterable<ValueType, Iterable, UnaryPredicate>;
136134

137-
LZ_MODULE_EXPORT_SCOPE_END
138-
139135
} // namespace lz
140136

141137
#endif // LZ_CHUNK_IF_HPP

0 commit comments

Comments
 (0)