diff --git a/include/Lz/Lz.hpp b/include/Lz/Lz.hpp index ade977db..3bb79855 100644 --- a/include/Lz/Lz.hpp +++ b/include/Lz/Lz.hpp @@ -6,6 +6,7 @@ # include "Lz/CartesianProduct.hpp" # include "Lz/ChunkIf.hpp" # include "Lz/Chunks.hpp" +# include "Lz/CString.hpp" # include "Lz/Enumerate.hpp" # include "Lz/Except.hpp" # include "Lz/Exclude.hpp" @@ -21,6 +22,7 @@ # include "Lz/Rotate.hpp" # include "Lz/TakeEvery.hpp" # include "Lz/Unique.hpp" +# include "Lz/ZipLongest.hpp" // Function tools includes: // Concatenate.hpp // Filter.hpp @@ -59,7 +61,7 @@ class IterView; * @return An iterator view object. */ template -LZ_CONSTEXPR_CXX_20 IterView toIterRange(Iterator begin, Iterator end) { +LZ_CONSTEXPR_CXX_20 IterView chainRange(Iterator begin, Iterator end) { return lz::IterView(std::move(begin), std::move(end)); } @@ -70,7 +72,7 @@ LZ_CONSTEXPR_CXX_20 IterView toIterRange(Iterator begin, Iterator end) */ template LZ_CONSTEXPR_CXX_20 IterView> chain(Iterable&& iterable) { - return toIterRange(internal::begin(std::forward(iterable)), internal::end(std::forward(iterable))); + return chainRange(internal::begin(std::forward(iterable)), internal::end(std::forward(iterable))); } // End of group diff --git a/include/Lz/StringSplitter.hpp b/include/Lz/StringSplitter.hpp index 2368d794..c692c90d 100644 --- a/include/Lz/StringSplitter.hpp +++ b/include/Lz/StringSplitter.hpp @@ -1,10 +1,14 @@ #pragma once #ifndef LZ_STRING_SPLITTER_HPP -#define LZ_STRING_SPLITTER_HPP +# define LZ_STRING_SPLITTER_HPP -#include "detail/BasicIteratorView.hpp" -#include "detail/SplitIterator.hpp" +# if !defined(LZ_HAS_STRING_VIEW) && defined(LZ_STANDALONE) +# include +# endif + +# include "detail/BasicIteratorView.hpp" +# include "detail/SplitIterator.hpp" namespace lz { template @@ -29,13 +33,13 @@ class StringSplitter final : public internal::BasicIteratorView -#elif defined(LZ_STANDALONE) -template -#else +# elif defined(LZ_STANDALONE) +template> +# else template -#endif +# endif /** * @brief This is a lazy evaluated string splitter function. It splits a string using `delimiter`. * @tparam SubString The string type of the substring. If C++17, this will default to `std::string_view`. If `LZ_STANDALONE` is @@ -51,13 +55,13 @@ split(const std::string& str, std::string delimiter) { return { str, std::move(delimiter) }; } -#if defined(LZ_HAS_STRING_VIEW) +# if defined(LZ_HAS_STRING_VIEW) template -#elif defined(LZ_STANDALONE) -template -#else +# elif defined(LZ_STANDALONE) +template> +# else template -#endif +# endif /** * @brief This is a lazy evaluated string splitter function. It splits a string using `delimiter`. * @tparam SubString The string type of the substring. If C++17, this will default to `std::string_view`. If `LZ_STANDALONE` is @@ -72,25 +76,25 @@ LZ_NODISCARD LZ_CONSTEXPR_CXX_20 StringSplitter sp return { str, delimiter }; } -#if defined(LZ_HAS_STRING_VIEW) +# if defined(LZ_HAS_STRING_VIEW) template -#elif defined(LZ_STANDALONE) +# elif defined(LZ_STANDALONE) template -#else +# else template -#endif +# endif StringSplitter split(std::string&& str, char delimiter) = delete; -#if defined(LZ_HAS_STRING_VIEW) +# if defined(LZ_HAS_STRING_VIEW) template -#elif defined(LZ_STANDALONE) -template -#else +# elif defined(LZ_STANDALONE) +template> +# else template -#endif +# endif StringSplitter split(std::string&& str, std::string delimiter) = delete; -#ifdef LZ_HAS_STRING_VIEW +# ifdef LZ_HAS_STRING_VIEW /** * @brief This is a lazy evaluated string splitter function. It splits a string using `delimiter`. * @tparam SubString The string type of the substring. @@ -106,8 +110,7 @@ split(const std::string_view& str, std::string delimiter) { } template -LZ_NODISCARD constexpr StringSplitter -split(const std::string_view& str, char delimiter) { +LZ_NODISCARD constexpr StringSplitter split(const std::string_view& str, char delimiter) { return { str, delimiter }; } @@ -116,7 +119,7 @@ StringSplitter split(std::string_view& template StringSplitter split(std::string_view&& str, std::string delimiter) = delete; -#endif // LZ_HAS_STRING_VIEW +# endif // LZ_HAS_STRING_VIEW // End of group /** diff --git a/include/Lz/detail/CStringIterator.hpp b/include/Lz/detail/CStringIterator.hpp index 1d8ce068..a4cfa63b 100644 --- a/include/Lz/detail/CStringIterator.hpp +++ b/include/Lz/detail/CStringIterator.hpp @@ -1,7 +1,7 @@ #pragma once -#ifndef LZ_REPEAT_ITERATOR_HPP -# define LZ_REPEAT_ITERATOR_HPP +#ifndef LZ_C_STRING_ITERATOR_HPP +# define LZ_C_STRING_ITERATOR_HPP # include "LzTools.hpp" @@ -122,4 +122,4 @@ class CStringIterator { } // namespace internal } // namespace lz -#endif \ No newline at end of file +#endif // LZ_C_STRING_ITERATOR_HPP \ No newline at end of file diff --git a/include/Lz/detail/RangeIterator.hpp b/include/Lz/detail/RangeIterator.hpp index e12e371c..34ca2800 100644 --- a/include/Lz/detail/RangeIterator.hpp +++ b/include/Lz/detail/RangeIterator.hpp @@ -10,7 +10,7 @@ namespace lz { namespace internal { # ifdef __cpp_if_constexpr template -std::ptrdiff_t plusImpl(const ValueType difference, const ValueType step) noexcept(!std::is_floating_point_v) { +std::ptrdiff_t LZ_CONSTEXPR_CXX_20 plusImpl(const ValueType difference, const ValueType step) noexcept(!std::is_floating_point_v) { if constexpr (std::is_floating_point_v) { return static_cast(std::ceil(difference / step)); } @@ -79,10 +79,16 @@ class RangeIterator { } LZ_NODISCARD friend difference_type - operator-(const RangeIterator& a, const RangeIterator& b) noexcept(!std::is_floating_point::value) { + LZ_CONSTEXPR_CXX_20 operator-(const RangeIterator& a, const RangeIterator& b) noexcept(!std::is_floating_point::value) { LZ_ASSERT(a._step == b._step, "incompatible iterator types: difference step size"); const auto difference = a._iterator - b._iterator; - return std::abs(plusImpl(static_cast(difference), a._step)); + const auto result = plusImpl(static_cast(difference), a._step); + if LZ_CONSTEXPR_IF (std::is_floating_point::value) { + return std::abs(result); + } + else { + return result < 0 ? -result : result; + } } LZ_NODISCARD LZ_CONSTEXPR_CXX_20 reference operator[](const difference_type offset) const noexcept { diff --git a/include/Lz/detail/ZipLongestIterator.hpp b/include/Lz/detail/ZipLongestIterator.hpp index 171dc75e..dc14bdd2 100644 --- a/include/Lz/detail/ZipLongestIterator.hpp +++ b/include/Lz/detail/ZipLongestIterator.hpp @@ -1,7 +1,7 @@ #pragma once -#ifndef LZ_ZIP_ITERATOR_HPP -# define LZ_ZIP_ITERATOR_HPP +#ifndef LZ_ZIP_LONGEST_ITERATOR_HPP +# define LZ_ZIP_LONGEST_ITERATOR_HPP # include "LzTools.hpp" # include "Optional.hpp" @@ -312,4 +312,4 @@ class ZipLongestIterator { }; } // namespace internal } // namespace lz -#endif \ No newline at end of file +#endif // LZ_ZIP_LONGEST_ITERATOR_HPP \ No newline at end of file diff --git a/tests/standalone.cpp b/tests/standalone.cpp index b5bae08e..29637fbf 100644 --- a/tests/standalone.cpp +++ b/tests/standalone.cpp @@ -24,7 +24,7 @@ TEST_CASE("Overall tests with LZ_STANDALONE defined") { #ifdef LZ_HAS_CXX_17 REQUIRE(std::is_same_v); #else - REQUIRE(std::is_same::value); + REQUIRE(std::is_same>::value); #endif std::array vec = { 1.1, 2.2, 3.3, 4.4 };