瀏覽代碼

refactor: loosen some concepts

Sam Jaffe 2 月之前
父節點
當前提交
c9d452e5e3
共有 2 個文件被更改,包括 7 次插入3 次删除
  1. 6 2
      include/iterator/concepts.h
  2. 1 1
      include/iterator/recursive_iterator.h

+ 6 - 2
include/iterator/concepts.h

@@ -11,6 +11,8 @@
 #include <concepts>
 #include <ranges>
 #include <string_view>
+#include <tuple>
+#include <type_traits>
 
 namespace iterator {
 template <typename It>
@@ -106,10 +108,12 @@ template <typename C>
 concept Range = (not String<C>) && std::ranges::range<C>;
 
 template <typename V>
-concept Assoc = std::is_const_v<typename V::first_type>;
+concept Assoc =
+    std::is_const_v<std::remove_reference_t<std::tuple_element_t<0, V>>>;
 
 template <typename V>
-concept AssocRange = Assoc<V> && Range<typename V::second_type>;
+concept AssocRange = Assoc<V> && (std::tuple_size_v<V> == 2) &&
+                     Range<std::decay_t<std::tuple_element_t<1, V>>>;
 
 template <typename C>
 using iterator_t = decltype(std::begin(std::declval<C &>()));

+ 1 - 1
include/iterator/recursive_iterator.h

@@ -22,7 +22,7 @@ namespace iterator {
 template <typename... Ts>
 using tuple_cat_t = decltype(std::tuple_cat(std::declval<Ts>()...));
 
-template <typename It, typename MaxDepth = unbounded, size_t N = 0,
+template <typename It, typename MaxDepth, size_t N = 0,
           typename V = std::iter_value_t<It>>
 struct tuple_expander {
   using iterator_tuple = std::tuple<end_aware_iterator<It>>;