util/IterableSplitString: add noexcept

This commit is contained in:
Max Kellermann 2022-06-30 20:33:03 +02:00
parent 0f4bf5569a
commit aadd32c973

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2013-2016 Max Kellermann <max.kellermann@gmail.com> * Copyright 2013-2022 Max Kellermann <max.kellermann@gmail.com>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -27,8 +27,7 @@
* OF THE POSSIBILITY OF SUCH DAMAGE. * OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef ITERABLE_SPLIT_STRING_HXX #pragma once
#define ITERABLE_SPLIT_STRING_HXX
#include "StringView.hxx" #include "StringView.hxx"
@ -53,7 +52,7 @@ class BasicIterableSplitString {
public: public:
constexpr BasicIterableSplitString(StringView _s, constexpr BasicIterableSplitString(StringView _s,
value_type _separator) value_type _separator) noexcept
:s(_s), separator(_separator) {} :s(_s), separator(_separator) {}
class Iterator final { class Iterator final {
@ -63,15 +62,17 @@ public:
value_type separator; value_type separator;
Iterator(StringView _s, value_type _separator) constexpr Iterator(StringView _s,
:rest(_s), separator(_separator) { value_type _separator) noexcept
:rest(_s), separator(_separator)
{
Next(); Next();
} }
constexpr Iterator(std::nullptr_t n) constexpr Iterator(std::nullptr_t n) noexcept
:current(n), rest(n), separator(0) {} :current(n), rest(n), separator(0) {}
void Next() { constexpr void Next() noexcept {
if (rest == nullptr) if (rest == nullptr)
current = nullptr; current = nullptr;
else { else {
@ -91,24 +92,24 @@ public:
public: public:
using iterator_category = std::forward_iterator_tag; using iterator_category = std::forward_iterator_tag;
Iterator &operator++() { constexpr Iterator &operator++() noexcept{
Next(); Next();
return *this; return *this;
} }
constexpr bool operator==(Iterator other) const { constexpr bool operator==(Iterator other) const noexcept {
return current.data == other.current.data; return current.data == other.current.data;
} }
constexpr bool operator!=(Iterator other) const { constexpr bool operator!=(Iterator other) const noexcept {
return !(*this == other); return !(*this == other);
} }
constexpr StringView operator*() const { constexpr StringView operator*() const noexcept {
return current; return current;
} }
constexpr const StringView *operator->() const { constexpr const StringView *operator->() const noexcept {
return &current; return &current;
} }
}; };
@ -116,11 +117,11 @@ public:
using iterator = Iterator; using iterator = Iterator;
using const_iterator = Iterator; using const_iterator = Iterator;
const_iterator begin() const { constexpr const_iterator begin() const noexcept {
return {s, separator}; return {s, separator};
} }
constexpr const_iterator end() const { constexpr const_iterator end() const noexcept {
return {nullptr}; return {nullptr};
} }
}; };
@ -133,5 +134,3 @@ using TIterableSplitString = WIterableSplitString;
#else #else
using TIterableSplitString = IterableSplitString; using TIterableSplitString = IterableSplitString;
#endif #endif
#endif