title: Check if there's duplicate element in an container in compile time with C++20
body: <p>One simple way of doing this prior to C++20 is to do a nested loop:</p>
  <pre class="lang-cpp prettyprint-override"><code>template&lt;typename Container&gt;
  constexpr bool has_duplicate(Container&amp;&amp; container)
  {
      for (auto it1 = container.cbegin(); it1 != container.cend(); ++it1)
          for(auto it2 = container.cbegin(); it2 != it1; ++it2)
              if (*it1 == *it2)
                  return 1;
      return 0;
  }
  </code></pre>
  <p>With the addition of init-statement in range-based for loop, and the introduction of <code>ranges::subrange</code>, I believe this function could be rewritten with range-based for loop:</p>
  <pre class="lang-cpp prettyprint-override"><code>template&lt;std::ranges::input_range Container&gt;
  constexpr bool has_duplicate(Container&amp;&amp; container)
  {
      for(auto it = container.cbegin(); const auto&amp; obj1 : container)
          for(const auto&amp; obj2 : std::ranges::subrange(container.cbegin(), it++))
              if(obj1 == obj2) 
                  return 1;
      return 0;
  }
  </code></pre>
  <p>While it worked fine on gcc, it fails to compile with clang, unless I manually set it with libc++: <a href="https://godbolt.org/z/KM4a9zazs" rel="nofollow noreferrer">https://godbolt.org/z/KM4a9zazs</a>, with the following error:</p>
  <pre><code>/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.0/../../../../include/c++/12.0.0/bits/iterator_concepts.h:982:13: error: no matching function for call to '__begin'
          = decltype(ranges::__cust_access::__begin(std::declval&lt;_Tp&amp;&gt;()));
  </code></pre>
  <ul>
  <li>Am I doing something wrong, or was it clang?</li>
  </ul>
  <hr />
  <p>I've also tried:</p>
  <pre class="lang-cpp prettyprint-override"><code>template&lt;std::ranges::input_range Container&gt;
  constexpr bool has_duplicate(Container&amp;&amp; container)
  {
      for(auto index = 0ull; const auto&amp; obj1 : container)
          for(const auto&amp; obj2 : container | std::ranges::views::take(index++))
              if(obj1 == obj2) return 1;
      return 0;
  }
  </code></pre>
  <p>Once again gcc worked with no problem, but clang failed with either libraries.</p>