2 Commits a6969b647a ... 529b0b377c

Author SHA1 Message Date
  namark 529b0b377c Really tempted to keep this just to embarrass clang. 2 months ago
  namark 70cf79a391 Some say this forwarding was a compiler bug, so fix just in case. 2 months ago
2 changed files with 5 additions and 95 deletions
  1. 4 75
      source/simple/support/misc.hpp
  2. 1 20
      unit_tests/misc.cpp

+ 4 - 75
source/simple/support/misc.hpp

@@ -200,12 +200,14 @@ namespace simple::support
 
 		constexpr offset_range() = default;
 
+		template <typename A,
+			std::enable_if_t<std::is_same_v<A,Anchor>>* = nullptr>
 		constexpr explicit offset_range
 		(
-			Anchor&& anchor,
+			A&& anchor,
 			range<Size> i = range<Size>::limit()
 		) :
-			anchor(std::forward<Anchor>(anchor)),
+			anchor(std::forward<A>(anchor)),
 			i(i)
 		{}
 
@@ -259,79 +261,6 @@ namespace simple::support
 	template <typename Size, typename Anchor>
 	offset_range(Anchor&&, range<Size>) -> offset_range<Size, Anchor>;
 
-	// A bit unrealisitic to expect ::limit() for generic range, but oh well...
-	template <template<typename...> typename Range, typename Size = void>
-	class with_range
-	{
-		public:
-		template <typename Container>
-		class index
-		{
-			public:
-			using container_type = Container;
-			using size_type = std::conditional_t<
-				std::is_same_v<Size,void>,
-					typename container_type::size_type,
-					Size
-			>;
-
-			constexpr index() = default;
-
-			constexpr explicit index
-			(
-				Container container,
-				Range<size_type> i = Range<size_type>::limit()
-			) :
-				container(std::move(container)),
-				i(i)
-			{}
-
-			constexpr auto begin() const
-			{ return iter_at(i.lower()); }
-			constexpr auto end() const
-			{ return iter_at(i.upper()); }
-
-			constexpr auto begin()
-			{ return iter_at(i.lower()); }
-			constexpr auto end()
-			{ return iter_at(i.upper()); }
-
-			private:
-			Container container;
-			Range<size_type> i;
-
-			constexpr auto iter_at(size_type index) const
-			{
-				using std::begin;
-				using std::end;
-				using std::clamp;
-
-				auto begin_ = begin(container);
-				auto end_ = end(container);
-
-				// TODO: use container.size() if available
-				return begin_ + clamp(index, size_type{},
-					static_cast<size_type>(end_ - begin_)); // good cast, since container can not have negative size
-			}
-
-			constexpr auto iter_at(size_type index)
-			{
-				using std::begin;
-				using std::end;
-				using std::clamp;
-
-				auto begin_ = begin(container);
-				auto end_ = end(container);
-
-				// TODO: use container.size() if available
-				return begin_ + clamp(index, size_type{},
-					static_cast<size_type>(end_ - begin_)); // good cast, since container can not have negative size
-			}
-
-		};
-
-	};
-
 	template <typename I>
 	[[nodiscard]] auto deref(I&& i) -> decltype(auto)
 	{

+ 1 - 20
unit_tests/misc.cpp

@@ -113,20 +113,7 @@ void RangeReference()
 	assert( std::equal(begin(temporef), end(temporef),
 		begin(prefix), end(prefix)) );
 
-#ifdef __clang__ // https://bugs.llvm.org/show_bug.cgi?id=33489
-	using strrefrange = range_reference<std::string>;
-	with_range<range>::index<strrefrange> permaref{
-#else
-	with_range<range>::index permaref{
-#endif
-		range_reference(stuff),
-		make_range(stuff) - begin(stuff)
-	};
-
-	// this is just better, dunno what I was thinking with that nested template stuff
-	// I mean I do know, I was working towards making the index independent of support::range, in it's own header, but I was under the delusion that the support::range (with lower() and upper()) is somehow a concept that anyone else would ever implement... now how realistic is that?
-	// also you can just have a reference member, and it's copyable... just not assignable, is fine
-	offset_range permaref2{
+	offset_range permaref{
 		stuff,
 		make_range(stuff) - begin(stuff)
 	};
@@ -134,9 +121,6 @@ void RangeReference()
 	assert( std::equal(begin(permaref), end(permaref),
 		begin(prefix), end(prefix)) );
 
-	assert( std::equal(begin(permaref2), end(permaref2),
-		begin(prefix), end(prefix)) );
-
 	stuff += " now this a really really long long paragraph of text, that should by all means cause reallocation and stuff, so the iterators in temporef range will be invalidated, while permaref that uses indices will remain valid and usable... though it doesn't really matter if it actually relocates since there is no way to check any of this, you'll just have to believe me and trust me and never ever let me go...";
 
 	// can't do this anymore
@@ -151,9 +135,6 @@ void RangeReference()
 	assert( std::equal(begin(permaref), end(permaref),
 		begin(prefix), end(prefix)) );
 
-	assert( std::equal(begin(permaref2), end(permaref2),
-		begin(prefix), end(prefix)) );
-
 }
 
 void Deref()