From aadd32c9734c1e6a022b0d15a86de70bfa2d9232 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 30 Jun 2022 20:33:03 +0200 Subject: [PATCH] util/IterableSplitString: add `noexcept` --- src/util/IterableSplitString.hxx | 33 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/util/IterableSplitString.hxx b/src/util/IterableSplitString.hxx index f50feb4ba..a8388b63f 100644 --- a/src/util/IterableSplitString.hxx +++ b/src/util/IterableSplitString.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2016 Max Kellermann + * Copyright 2013-2022 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,8 +27,7 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ITERABLE_SPLIT_STRING_HXX -#define ITERABLE_SPLIT_STRING_HXX +#pragma once #include "StringView.hxx" @@ -53,7 +52,7 @@ class BasicIterableSplitString { public: constexpr BasicIterableSplitString(StringView _s, - value_type _separator) + value_type _separator) noexcept :s(_s), separator(_separator) {} class Iterator final { @@ -63,15 +62,17 @@ public: value_type separator; - Iterator(StringView _s, value_type _separator) - :rest(_s), separator(_separator) { + constexpr Iterator(StringView _s, + value_type _separator) noexcept + :rest(_s), separator(_separator) + { Next(); } - constexpr Iterator(std::nullptr_t n) + constexpr Iterator(std::nullptr_t n) noexcept :current(n), rest(n), separator(0) {} - void Next() { + constexpr void Next() noexcept { if (rest == nullptr) current = nullptr; else { @@ -91,24 +92,24 @@ public: public: using iterator_category = std::forward_iterator_tag; - Iterator &operator++() { + constexpr Iterator &operator++() noexcept{ Next(); return *this; } - constexpr bool operator==(Iterator other) const { + constexpr bool operator==(Iterator other) const noexcept { return current.data == other.current.data; } - constexpr bool operator!=(Iterator other) const { + constexpr bool operator!=(Iterator other) const noexcept { return !(*this == other); } - constexpr StringView operator*() const { + constexpr StringView operator*() const noexcept { return current; } - constexpr const StringView *operator->() const { + constexpr const StringView *operator->() const noexcept { return ¤t; } }; @@ -116,11 +117,11 @@ public: using iterator = Iterator; using const_iterator = Iterator; - const_iterator begin() const { + constexpr const_iterator begin() const noexcept { return {s, separator}; } - constexpr const_iterator end() const { + constexpr const_iterator end() const noexcept { return {nullptr}; } }; @@ -133,5 +134,3 @@ using TIterableSplitString = WIterableSplitString; #else using TIterableSplitString = IterableSplitString; #endif - -#endif