3 Commits e71ac12592 ... 3e8d5e328f

Author SHA1 Message Date
  namark 3e8d5e328f Generic copy algorithm, that doesn't care about overlap. 7 months ago
  namark 94175cb640 Fixed a bunch of warnings. 7 months ago
  namark 4cfefe8cf3 Range wrapper for mismatch algorithm. 7 months ago

+ 46 - 0
source/simple/support/algorithm/copy.hpp

@@ -0,0 +1,46 @@
+#ifndef SIMPLE_SUPPORT_ALGORITHM_COPY_HPP
+#define SIMPLE_SUPPORT_ALGORITHM_COPY_HPP
+
+#include <utility> // std::pair std::move
+
+#include "traits.hpp" // is_range_v
+#include "adl_helper.hpp" // adl_helper::adl_begin adl_helper::adl_end
+#include "reaches.hpp" // reaches
+
+namespace simple::support
+{
+
+	// you can duplicate a pattern from a beginning of a range via a single copy
+	// copy_n(pattern_begin, num_copies * pattern_size, pattern_end)
+	// this comes up in lz77 decompression
+	// unfortunately std is too clever for that (order not guaranteed)
+	// threw in 'reaches' abstraction as well
+
+	template <typename I, typename E, typename O>
+	constexpr std::pair<I,O> copy(I i, E i_end, O o)
+	{
+		for(; not reaches(i, i_end); ++i, ++o)
+			*o = *i;
+		return {std::move(i), std::move(o)};
+	}
+
+	template <typename I, typename O>
+	constexpr std::pair<I,O> copy_n(I i, std::size_t n, O o)
+	{
+		for(; n --> 0; ++i, ++o)
+			*o = *i;
+		return {std::move(i), std::move(o)};
+	}
+
+	// TODO: conflicts with copy in range_wrappers.hpp
+	// similar situation with find.hpp, but too lazy to update use cases rn
+	// template <typename Range, typename OutIt,
+	// 	std::enable_if_t<is_range_v<Range>>* = nullptr>
+	// constexpr auto copy(const Range& range, OutIt out)
+	// {
+	// 	return support::copy(adl_helper::adl_begin(range), adl_helper::adl_end(range), out);
+	// }
+
+} // namespace simple::support
+
+#endif /* end of include guard */

+ 12 - 1
source/simple/support/algorithm/mismatch.hpp

@@ -3,7 +3,8 @@
 
 #include <utility> // std::pair std::move
 #include <type_traits> // std::enable_if_t
-#include "traits.hpp" // is_iterable_v
+#include <iterator> // std::begin std::end
+#include "traits.hpp" // is_iterable_v is_range_v
 
 namespace simple::support
 {
@@ -38,6 +39,16 @@ namespace simple::support
 		return {std::move(begin),std::move(begin2)};
 	}
 
+	template <typename Range, typename Range2,
+		std::enable_if_t<is_range_v<Range> && is_range_v<Range2>>* = nullptr>
+	[[nodiscard]] constexpr
+	auto mismatch(Range&& r, Range2&& r2)
+	// TODO: noexcept(...)
+	{
+		using std::begin; using std::end;
+		return support::mismatch(begin(r), end(r), begin(r2), end(r2));
+	}
+
 } // namespace simple::support
 
 #endif /* end of include guard */

+ 1 - 1
source/simple/support/iterator/match.hpp

@@ -61,7 +61,7 @@ namespace simple::support
 			match_state<Matcher>& state;
 
 			proxy(Matcher& matcher, match_state<Matcher>& state) : matcher(matcher), state(state) {}
-			friend class match_iterator;
+			friend struct match_iterator;
 			public:
 			proxy() = delete;
 			proxy(const proxy&) = delete;

+ 3 - 1
source/simple/support/iterator/offset_expander.hpp

@@ -55,6 +55,7 @@ namespace simple::support
 			else
 				assert(&array == &other.array);
 			offset = other.offset;
+			return *this;
 		}
 		offset_expander& operator=(offset_expander&& other)
 		{
@@ -63,6 +64,7 @@ namespace simple::support
 			else
 				assert(&array == &other.array);
 			offset = other.offset;
+			return *this;
 		}
 
 		friend bool operator==(const offset_expander& one, const offset_expander& other)
@@ -91,7 +93,7 @@ namespace simple::support
 			offset_type offset;
 
 			proxy(Array& array, offset_type offset) : array(array), offset(offset) {}
-			friend class offset_expander;
+			friend struct offset_expander;
 			public:
 			proxy() = delete;
 			proxy(const proxy&) = delete;

+ 1 - 1
source/simple/support/iterator/out_accumulate.hpp

@@ -42,7 +42,7 @@ namespace simple::support
 
 			proxy(Accumulator& accumulator, Op& operation)
 				: accumulator(accumulator), operation(operation) {}
-			friend class out_accumulate;
+			friend struct out_accumulate;
 			public:
 			proxy() = delete;
 			proxy(const proxy&) = delete;

+ 1 - 1
source/simple/support/iterator/out_filter.hpp

@@ -35,7 +35,7 @@ namespace simple::support
 			Predicate& predicate;
 
 			proxy(It& out, Predicate& predicate) : out(out), predicate(predicate) {}
-			friend class out_filter;
+			friend struct out_filter;
 			public:
 			proxy() = delete;
 			proxy(const proxy&) = delete;

+ 1 - 1
source/simple/support/iterator/out_flatten_range.hpp

@@ -32,7 +32,7 @@ namespace simple::support
 			It& out;
 
 			proxy(It& out) : out(out) {}
-			friend class out_flatten_range;
+			friend struct out_flatten_range;
 			public:
 			proxy() = delete;
 			proxy(const proxy&) = delete;

+ 1 - 1
source/simple/support/iterator/out_flatten_tuple.hpp

@@ -33,7 +33,7 @@ namespace simple::support
 			It& out;
 
 			proxy(It& out) : out(out) {}
-			friend class out_flatten_tuple;
+			friend struct out_flatten_tuple;
 			public:
 			proxy() = delete;
 			proxy(const proxy&) = delete;

+ 1 - 1
source/simple/support/iterator/out_invoke.hpp

@@ -36,7 +36,7 @@ namespace simple::support
 			Function& function;
 
 			proxy(Function& function) : function(function) {}
-			friend class out_invoke;
+			friend struct out_invoke;
 			public:
 			proxy() = delete;
 			proxy(const proxy&) = delete;

+ 0 - 0
source/simple/support/iterator/out_partition.hpp


Some files were not shown because too many files changed in this diff