Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions hist/histv7/inc/ROOT/RBinIndexRange.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public:

friend bool operator!=(const RBinIndexRange &lhs, const RBinIndexRange &rhs) { return !(lhs == rhs); }

/// %Iterator over RBinIndex.
class Iterator final {
/// Iterator over RBinIndex.
class RIterator final {
/// The current bin index
RBinIndex fIndex;
/// The number of normal bins, after which iteration advances to RBinIndex::Overflow()
Expand All @@ -78,10 +78,10 @@ public:
using reference = RBinIndex;
using iterator_category = std::input_iterator_tag;

Iterator() = default;
Iterator(RBinIndex index, std::size_t nNormalBins) : fIndex(index), fNNormalBins(nNormalBins) {}
RIterator() = default;
RIterator(RBinIndex index, std::size_t nNormalBins) : fIndex(index), fNNormalBins(nNormalBins) {}

Iterator &operator++()
RIterator &operator++()
{
if (fIndex.IsUnderflow()) {
fIndex = 0;
Expand All @@ -98,25 +98,25 @@ public:
}
return *this;
}
Iterator operator++(int)
RIterator operator++(int)
{
Iterator old = *this;
RIterator old = *this;
operator++();
return old;
}

RBinIndex operator*() const { return fIndex; }
const RBinIndex *operator->() const { return &fIndex; }

friend bool operator==(const Iterator &lhs, const Iterator &rhs)
friend bool operator==(const RIterator &lhs, const RIterator &rhs)
{
return lhs.fIndex == rhs.fIndex && lhs.fNNormalBins == rhs.fNNormalBins;
}
friend bool operator!=(const Iterator &lhs, const Iterator &rhs) { return !(lhs == rhs); }
friend bool operator!=(const RIterator &lhs, const RIterator &rhs) { return !(lhs == rhs); }
};

Iterator begin() const { return Iterator(fBegin, fNNormalBins); }
Iterator end() const { return Iterator(fEnd, fNNormalBins); }
RIterator begin() const { return RIterator(fBegin, fNNormalBins); }
RIterator end() const { return RIterator(fEnd, fNNormalBins); }
};

namespace Internal {
Expand Down
21 changes: 21 additions & 0 deletions hist/histv7/test/hist_index.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,27 @@ TEST(RBinIndexRange, ConstructorCreate)
EXPECT_EQ(range01.GetEnd(), RBinIndex(1));
}

TEST(RBinIndexRange, Equality)
{
const auto index0 = RBinIndex(0);
const auto index1 = RBinIndex(1);
const auto empty = CreateBinIndexRange(index0, index0, 0);
const auto empty0 = CreateBinIndexRange(index0, index0, 0);
const auto empty1 = CreateBinIndexRange(index1, index1, 0);
EXPECT_EQ(empty, empty0);
EXPECT_NE(empty0, empty1);

const auto range01 = CreateBinIndexRange(index0, index1, 0);
EXPECT_NE(empty, range01);

const auto underflow = RBinIndex::Underflow();
const RBinIndex invalid;
const auto full1 = CreateBinIndexRange(underflow, invalid, /*nNormalBins=*/1);
const auto full2 = CreateBinIndexRange(underflow, invalid, /*nNormalBins=*/2);
EXPECT_NE(range01, full1);
EXPECT_NE(full1, full2);
}

TEST(RBinIndexRange, Empty)
{
const auto index0 = RBinIndex(0);
Expand Down
Loading