tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

iterator_traits.h (2410B)


      1 // Copyright 2025 The Abseil Authors
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //     https://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 //
     15 // -----------------------------------------------------------------------------
     16 // File: internal/iterator_traits.h
     17 // -----------------------------------------------------------------------------
     18 //
     19 // Helpers for querying traits of iterators, for implementing containers, etc.
     20 
     21 #ifndef ABSL_BASE_INTERNAL_ITERATOR_TRAITS_H_
     22 #define ABSL_BASE_INTERNAL_ITERATOR_TRAITS_H_
     23 
     24 #include <iterator>
     25 #include <type_traits>
     26 
     27 #include "absl/base/config.h"
     28 #include "absl/meta/type_traits.h"
     29 
     30 namespace absl {
     31 ABSL_NAMESPACE_BEGIN
     32 namespace base_internal {
     33 
     34 template <typename Iterator, typename = void>
     35 struct IteratorCategory {};
     36 
     37 template <typename Iterator>
     38 struct IteratorCategory<
     39    Iterator,
     40    absl::void_t<typename std::iterator_traits<Iterator>::iterator_category>> {
     41  using type = typename std::iterator_traits<Iterator>::iterator_category;
     42 };
     43 
     44 template <typename Iterator, typename = void>
     45 struct IteratorConceptImpl : IteratorCategory<Iterator> {};
     46 
     47 template <typename Iterator>
     48 struct IteratorConceptImpl<
     49    Iterator,
     50    absl::void_t<typename std::iterator_traits<Iterator>::iterator_concept>> {
     51  using type = typename std::iterator_traits<Iterator>::iterator_concept;
     52 };
     53 
     54 // The newer `std::iterator_traits<Iterator>::iterator_concept` if available,
     55 // else `std::iterator_traits<Iterator>::iterator_category`.
     56 template <typename Iterator>
     57 using IteratorConcept = typename IteratorConceptImpl<Iterator>::type;
     58 
     59 template <typename IteratorTag, typename Iterator>
     60 using IsAtLeastIterator =
     61    std::is_convertible<IteratorConcept<Iterator>, IteratorTag>;
     62 
     63 template <typename Iterator>
     64 using IsAtLeastForwardIterator =
     65    IsAtLeastIterator<std::forward_iterator_tag, Iterator>;
     66 
     67 }  // namespace base_internal
     68 ABSL_NAMESPACE_END
     69 }  // namespace absl
     70 
     71 #endif  // ABSL_BASE_INTERNAL_ITERATOR_TRAITS_H_