Commit 973c5bb8 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Mark BitIterator with the category of the base

Summary:
[Folly] Mark `BitIterator<BaseIterator>` with the iterator category of `BitIterator`.

As one benefit, using `std::distance` to find the distance between two `BitIterator`s gotten from a random access container such as `std::vector` is now constant-time.

Fixes #1026.

Reviewed By: ot

Differential Revision: D14294852

fbshipit-source-id: 2345bc73dec169803ae41b9391687e89ad77207b
parent 40df9484
......@@ -80,7 +80,8 @@ struct BitIteratorBase {
BitIterator<BaseIter>, // Derived
BaseIter, // Base
bool, // Value
boost::use_default, // CategoryOrTraversal
typename std::iterator_traits<
BaseIter>::iterator_category, // CategoryOrTraversal
bititerator_detail::BitReference<
typename std::iterator_traits<BaseIter>::reference,
typename std::iterator_traits<BaseIter>::value_type>, // Reference
......
......@@ -16,7 +16,9 @@
#include <folly/container/BitIterator.h>
#include <forward_list>
#include <limits>
#include <list>
#include <type_traits>
#include <vector>
......@@ -84,3 +86,25 @@ TEST(BitIterator, Const) {
checkIt(0x10, bi);
checkIt(0x42, bi);
}
TEST(BitIterator, IteratorCategory) {
EXPECT_TRUE( //
(std::is_same<
std::iterator_traits<BitIterator<uint64_t*>>::iterator_category,
std::random_access_iterator_tag>::value));
EXPECT_TRUE(
(std::is_same<
std::iterator_traits<
BitIterator<std::vector<uint64_t>::iterator>>::iterator_category,
std::random_access_iterator_tag>::value));
EXPECT_TRUE(
(std::is_same<
std::iterator_traits<
BitIterator<std::list<uint64_t>::iterator>>::iterator_category,
std::bidirectional_iterator_tag>::value));
EXPECT_TRUE( //
(std::is_same<
std::iterator_traits<BitIterator<
std::forward_list<uint64_t>::iterator>>::iterator_category,
std::forward_iterator_tag>::value));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment