From ba484cff1e4ac3225b6eb87dc94272daca88e613 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Wed, 21 Aug 2024 17:58:55 +0200 Subject: [PATCH] Use C++20 --- configure.ac | 10 +++++----- src/curses/window.h | 1 - src/gcc.h | 29 ----------------------------- src/interfaces.h | 1 - src/lyrics_fetcher.cpp | 8 +++++--- src/mpdpp.h | 8 +++++++- src/ncmpcpp.cpp | 5 ++++- src/regex_filter.h | 2 +- src/settings.cpp | 4 ++-- src/statusbar.h | 1 - src/utility/conversion.h | 7 +++---- src/utility/string.h | 1 - 12 files changed, 27 insertions(+), 50 deletions(-) delete mode 100644 src/gcc.h diff --git a/configure.ac b/configure.ac index 3d49c71c..c144ab28 100644 --- a/configure.ac +++ b/configure.ac @@ -70,15 +70,15 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]])], ) CXXFLAGS="$old_CXXFLAGS $fast_math" -# -std=c++14 -AC_MSG_CHECKING([whether compiler supports -std=c++14]) +# -std=c++20 +AC_MSG_CHECKING([whether compiler supports -std=c++20]) old_CXXFLAGS="$CXXFLAGS" -CXXFLAGS="-std=c++14" +CXXFLAGS="-std=c++20" AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]])], AC_MSG_RESULT([yes]) - std_cpp14="-std=c++14", + std_cpp14="-std=c++20", AC_MSG_RESULT([no]) - AC_MSG_ERROR([[Your compiler doesn't seem to support C++14, please upgrade (GCC >= 5)]]) + AC_MSG_ERROR([[Your compiler doesn't seem to support C++20, please upgrade]]) ) CXXFLAGS="$old_CXXFLAGS $std_cpp14" diff --git a/src/curses/window.h b/src/curses/window.h index 15728c41..edb93cfe 100644 --- a/src/curses/window.h +++ b/src/curses/window.h @@ -26,7 +26,6 @@ #include "config.h" #include "curses.h" -#include "gcc.h" #include #include diff --git a/src/gcc.h b/src/gcc.h deleted file mode 100644 index 0a2cbd92..00000000 --- a/src/gcc.h +++ /dev/null @@ -1,29 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008-2021 by Andrzej Rybczak * - * andrzej@rybczak.net * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#if defined(__GNUC__) && __GNUC__ >= 3 -# define GNUC_NORETURN __attribute__((noreturn)) -# define GNUC_UNUSED __attribute__((unused)) -# define GNUC_PRINTF(a, b) __attribute__((format(printf, a, b))) -#else -# define GNUC_NORETURN -# define GNUC_UNUSED -# define GNUC_PRINTF(a, b) -#endif diff --git a/src/interfaces.h b/src/interfaces.h index abbc31e0..869a2fc7 100644 --- a/src/interfaces.h +++ b/src/interfaces.h @@ -25,7 +25,6 @@ #include #include #include "enums.h" -#include "gcc.h" #include "screens/screen.h" #include "song.h" diff --git a/src/lyrics_fetcher.cpp b/src/lyrics_fetcher.cpp index 0f30f40d..8a7d2f51 100644 --- a/src/lyrics_fetcher.cpp +++ b/src/lyrics_fetcher.cpp @@ -134,9 +134,11 @@ void LyricsFetcher::postProcess(std::string &data) const boost::split(lines, data, boost::is_any_of("\n")); for (auto &line : lines) boost::trim(line); - std::unique(lines.begin(), lines.end(), [](std::string &a, std::string &b) { - return a.empty() && b.empty(); - }); + auto last = std::unique( + lines.begin(), + lines.end(), + [](std::string &a, std::string &b) { return a.empty() && b.empty(); }); + lines.erase(last, lines.end()); data = boost::algorithm::join(lines, "\n"); boost::trim(data); } diff --git a/src/mpdpp.h b/src/mpdpp.h index ce23c835..902606d7 100644 --- a/src/mpdpp.h +++ b/src/mpdpp.h @@ -353,8 +353,14 @@ private: }; template -struct Iterator: std::iterator +struct Iterator { + using iterator_category = std::input_iterator_tag; + using value_type = ObjectT; + using difference_type = std::ptrdiff_t; + using pointer = ObjectT *; + using reference = ObjectT &; + // shared state of the iterator struct State { diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 87bd5447..533b31b5 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -219,7 +219,10 @@ int main(int argc, char **argv) try { auto k = Bindings.get(input); - std::any_of(k.first, k.second, std::bind(&Binding::execute, ph::_1)); + [[maybe_unused]] bool executed = std::any_of( + k.first, + k.second, + std::bind(&Binding::execute, ph::_1)); } catch (ConversionError &e) { diff --git a/src/regex_filter.h b/src/regex_filter.h index a5372126..0e09721d 100644 --- a/src/regex_filter.h +++ b/src/regex_filter.h @@ -93,7 +93,7 @@ inline Regex make(StringT &&s, template inline bool search(const std::basic_string &s, const Regex &rx, - GNUC_UNUSED bool ignore_diacritics) + [[maybe_unused]] bool ignore_diacritics) { try { #ifdef BOOST_REGEX_ICU diff --git a/src/settings.cpp b/src/settings.cpp index 8315062e..d3c94b73 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -472,10 +472,10 @@ bool Configuration::read(const std::vector &config_paths, bool igno } return fetcher; }); - auto it = std::remove_if( + auto last = std::remove_if( lyrics_fetchers.begin(), lyrics_fetchers.end(), [](const auto &f) { return f.get() == nullptr; }); - lyrics_fetchers.resize(it - lyrics_fetchers.begin()); + lyrics_fetchers.erase(last, lyrics_fetchers.end()); if (lyrics_fetchers.empty()) invalid_value(v); }); diff --git a/src/statusbar.h b/src/statusbar.h index 0cadaf56..b14c2137 100644 --- a/src/statusbar.h +++ b/src/statusbar.h @@ -24,7 +24,6 @@ #include #include "curses/window.h" #include "settings.h" -#include "gcc.h" #include "interfaces.h" namespace Progressbar { diff --git a/src/utility/conversion.h b/src/utility/conversion.h index 80d0a839..109d161e 100644 --- a/src/utility/conversion.h +++ b/src/utility/conversion.h @@ -26,7 +26,6 @@ #include #include "config.h" -#include "gcc.h" struct ConversionError { @@ -44,21 +43,21 @@ struct OutOfBounds : std::exception const std::string &errorMessage() { return m_error_message; } template - GNUC_NORETURN static void raise(const Type &value, const Type &lbound, const Type &ubound) + [[noreturn]] static void raise(const Type &value, const Type &lbound, const Type &ubound) { throw OutOfBounds((boost::format( "value is out of bounds ([%1%, %2%] expected, %3% given)") % lbound % ubound % value).str()); } template - GNUC_NORETURN static void raiseLower(const Type &value, const Type &lbound) + [[noreturn]] static void raiseLower(const Type &value, const Type &lbound) { throw OutOfBounds((boost::format( "value is out of bounds ([%1%, ->) expected, %2% given)") % lbound % value).str()); } template - GNUC_NORETURN static void raiseUpper(const Type &value, const Type &ubound) + [[noreturn]] static void raiseUpper(const Type &value, const Type &ubound) { throw OutOfBounds((boost::format( "value is out of bounds ((<-, %1%] expected, %2% given)") % ubound % value).str()); diff --git a/src/utility/string.h b/src/utility/string.h index e86ddeb8..75d65767 100644 --- a/src/utility/string.h +++ b/src/utility/string.h @@ -25,7 +25,6 @@ #include #include #include -#include "gcc.h" template size_t const_strlen(const char (&)[N]) { return N-1;