Skip to content

Commit

Permalink
Merge pull request #131 from MarcDirven/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
MarcDirven authored Nov 11, 2022
2 parents 42cc850 + 3f5f178 commit 184909f
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 38 deletions.
6 changes: 4 additions & 2 deletions include/Lz/Lz.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -59,7 +61,7 @@ class IterView;
* @return An iterator view object.
*/
template<LZ_CONCEPT_ITERATOR Iterator>
LZ_CONSTEXPR_CXX_20 IterView<Iterator> toIterRange(Iterator begin, Iterator end) {
LZ_CONSTEXPR_CXX_20 IterView<Iterator> chainRange(Iterator begin, Iterator end) {
return lz::IterView<Iterator>(std::move(begin), std::move(end));
}

Expand All @@ -70,7 +72,7 @@ LZ_CONSTEXPR_CXX_20 IterView<Iterator> toIterRange(Iterator begin, Iterator end)
*/
template<LZ_CONCEPT_ITERABLE Iterable>
LZ_CONSTEXPR_CXX_20 IterView<internal::IterTypeFromIterable<Iterable>> chain(Iterable&& iterable) {
return toIterRange(internal::begin(std::forward<Iterable>(iterable)), internal::end(std::forward<Iterable>(iterable)));
return chainRange(internal::begin(std::forward<Iterable>(iterable)), internal::end(std::forward<Iterable>(iterable)));
}

// End of group
Expand Down
55 changes: 29 additions & 26 deletions include/Lz/StringSplitter.hpp
Original file line number Diff line number Diff line change
@@ -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 <Lz/CString.hpp>
# endif

# include "detail/BasicIteratorView.hpp"
# include "detail/SplitIterator.hpp"

namespace lz {
template<class SubString, class String, class StringType>
Expand All @@ -29,13 +33,13 @@ class StringSplitter final : public internal::BasicIteratorView<internal::SplitI
* @{
*/

#if defined(LZ_HAS_STRING_VIEW)
# if defined(LZ_HAS_STRING_VIEW)
template<class SubString = std::string_view>
#elif defined(LZ_STANDALONE)
template<class SubString = std::string>
#else
# elif defined(LZ_STANDALONE)
template<class SubString = lz::CString<char, false>>
# else
template<class SubString = fmt::string_view>
#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
Expand All @@ -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<class SubString = std::string_view>
#elif defined(LZ_STANDALONE)
template<class SubString = std::string>
#else
# elif defined(LZ_STANDALONE)
template<class SubString = lz::CString<char, false>>
# else
template<class SubString = fmt::string_view>
#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
Expand All @@ -72,25 +76,25 @@ LZ_NODISCARD LZ_CONSTEXPR_CXX_20 StringSplitter<SubString, std::string, char> sp
return { str, delimiter };
}

#if defined(LZ_HAS_STRING_VIEW)
# if defined(LZ_HAS_STRING_VIEW)
template<class SubString = std::string_view>
#elif defined(LZ_STANDALONE)
# elif defined(LZ_STANDALONE)
template<class SubString = std::string>
#else
# else
template<class SubString = fmt::string_view>
#endif
# endif
StringSplitter<SubString, std::string, char> split(std::string&& str, char delimiter) = delete;

#if defined(LZ_HAS_STRING_VIEW)
# if defined(LZ_HAS_STRING_VIEW)
template<class SubString = std::string_view>
#elif defined(LZ_STANDALONE)
template<class SubString = std::string>
#else
# elif defined(LZ_STANDALONE)
template<class SubString = lz::CString<char, false>>
# else
template<class SubString = fmt::string_view>
#endif
# endif
StringSplitter<SubString, std::string, std::string> 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.
Expand All @@ -106,8 +110,7 @@ split(const std::string_view& str, std::string delimiter) {
}

template<class SubString = std::string_view>
LZ_NODISCARD constexpr StringSplitter<SubString, std::string_view, char>
split(const std::string_view& str, char delimiter) {
LZ_NODISCARD constexpr StringSplitter<SubString, std::string_view, char> split(const std::string_view& str, char delimiter) {
return { str, delimiter };
}

Expand All @@ -116,7 +119,7 @@ StringSplitter<SubString, std::string_view, std::string> split(std::string_view&

template<class SubString = std::string_view>
StringSplitter<SubString, std::string_view, std::string> split(std::string_view&& str, std::string delimiter) = delete;
#endif // LZ_HAS_STRING_VIEW
# endif // LZ_HAS_STRING_VIEW

// End of group
/**
Expand Down
6 changes: 3 additions & 3 deletions include/Lz/detail/CStringIterator.hpp
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -122,4 +122,4 @@ class CStringIterator {
} // namespace internal
} // namespace lz

#endif
#endif // LZ_C_STRING_ITERATOR_HPP
12 changes: 9 additions & 3 deletions include/Lz/detail/RangeIterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace lz {
namespace internal {
# ifdef __cpp_if_constexpr
template<class ValueType>
std::ptrdiff_t plusImpl(const ValueType difference, const ValueType step) noexcept(!std::is_floating_point_v<ValueType>) {
std::ptrdiff_t LZ_CONSTEXPR_CXX_20 plusImpl(const ValueType difference, const ValueType step) noexcept(!std::is_floating_point_v<ValueType>) {
if constexpr (std::is_floating_point_v<ValueType>) {
return static_cast<std::ptrdiff_t>(std::ceil(difference / step));
}
Expand Down Expand Up @@ -79,10 +79,16 @@ class RangeIterator {
}

LZ_NODISCARD friend difference_type
operator-(const RangeIterator& a, const RangeIterator& b) noexcept(!std::is_floating_point<Arithmetic>::value) {
LZ_CONSTEXPR_CXX_20 operator-(const RangeIterator& a, const RangeIterator& b) noexcept(!std::is_floating_point<Arithmetic>::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<Arithmetic>(difference), a._step));
const auto result = plusImpl(static_cast<Arithmetic>(difference), a._step);
if LZ_CONSTEXPR_IF (std::is_floating_point<Arithmetic>::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 {
Expand Down
6 changes: 3 additions & 3 deletions include/Lz/detail/ZipLongestIterator.hpp
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -312,4 +312,4 @@ class ZipLongestIterator<true /*is random access*/, Iterators...> {
};
} // namespace internal
} // namespace lz
#endif
#endif // LZ_ZIP_LONGEST_ITERATOR_HPP
2 changes: 1 addition & 1 deletion tests/standalone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ TEST_CASE("Overall tests with LZ_STANDALONE defined") {
#ifdef LZ_HAS_CXX_17
REQUIRE(std::is_same_v<decltype(*splitter.begin()), std::string_view>);
#else
REQUIRE(std::is_same<decltype(*splitter.begin()), std::string>::value);
REQUIRE(std::is_same<decltype(*splitter.begin()), lz::CString<char, false>>::value);
#endif

std::array<double, 4> vec = { 1.1, 2.2, 3.3, 4.4 };
Expand Down

0 comments on commit 184909f

Please sign in to comment.