Use C++20

This commit is contained in:
Andrzej Rybczak
2024-08-21 17:58:55 +02:00
parent 603735d80e
commit ba484cff1e
12 changed files with 27 additions and 50 deletions

View File

@@ -70,15 +70,15 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]])],
) )
CXXFLAGS="$old_CXXFLAGS $fast_math" CXXFLAGS="$old_CXXFLAGS $fast_math"
# -std=c++14 # -std=c++20
AC_MSG_CHECKING([whether compiler supports -std=c++14]) AC_MSG_CHECKING([whether compiler supports -std=c++20])
old_CXXFLAGS="$CXXFLAGS" old_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="-std=c++14" CXXFLAGS="-std=c++20"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]])], AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]])],
AC_MSG_RESULT([yes]) AC_MSG_RESULT([yes])
std_cpp14="-std=c++14", std_cpp14="-std=c++20",
AC_MSG_RESULT([no]) 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" CXXFLAGS="$old_CXXFLAGS $std_cpp14"

View File

@@ -26,7 +26,6 @@
#include "config.h" #include "config.h"
#include "curses.h" #include "curses.h"
#include "gcc.h"
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <functional> #include <functional>

View File

@@ -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

View File

@@ -25,7 +25,6 @@
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>
#include <string> #include <string>
#include "enums.h" #include "enums.h"
#include "gcc.h"
#include "screens/screen.h" #include "screens/screen.h"
#include "song.h" #include "song.h"

View File

@@ -134,9 +134,11 @@ void LyricsFetcher::postProcess(std::string &data) const
boost::split(lines, data, boost::is_any_of("\n")); boost::split(lines, data, boost::is_any_of("\n"));
for (auto &line : lines) for (auto &line : lines)
boost::trim(line); boost::trim(line);
std::unique(lines.begin(), lines.end(), [](std::string &a, std::string &b) { auto last = std::unique(
return a.empty() && b.empty(); 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"); data = boost::algorithm::join(lines, "\n");
boost::trim(data); boost::trim(data);
} }

View File

@@ -353,8 +353,14 @@ private:
}; };
template <typename ObjectT> template <typename ObjectT>
struct Iterator: std::iterator<std::input_iterator_tag, ObjectT> 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 // shared state of the iterator
struct State struct State
{ {

View File

@@ -219,7 +219,10 @@ int main(int argc, char **argv)
try try
{ {
auto k = Bindings.get(input); 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) catch (ConversionError &e)
{ {

View File

@@ -93,7 +93,7 @@ inline Regex make(StringT &&s,
template <typename CharT> template <typename CharT>
inline bool search(const std::basic_string<CharT> &s, inline bool search(const std::basic_string<CharT> &s,
const Regex &rx, const Regex &rx,
GNUC_UNUSED bool ignore_diacritics) [[maybe_unused]] bool ignore_diacritics)
{ {
try { try {
#ifdef BOOST_REGEX_ICU #ifdef BOOST_REGEX_ICU

View File

@@ -472,10 +472,10 @@ bool Configuration::read(const std::vector<std::string> &config_paths, bool igno
} }
return fetcher; return fetcher;
}); });
auto it = std::remove_if( auto last = std::remove_if(
lyrics_fetchers.begin(), lyrics_fetchers.end(), lyrics_fetchers.begin(), lyrics_fetchers.end(),
[](const auto &f) { return f.get() == nullptr; }); [](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()) if (lyrics_fetchers.empty())
invalid_value(v); invalid_value(v);
}); });

View File

@@ -24,7 +24,6 @@
#include <boost/format.hpp> #include <boost/format.hpp>
#include "curses/window.h" #include "curses/window.h"
#include "settings.h" #include "settings.h"
#include "gcc.h"
#include "interfaces.h" #include "interfaces.h"
namespace Progressbar { namespace Progressbar {

View File

@@ -26,7 +26,6 @@
#include <boost/type_traits/is_unsigned.hpp> #include <boost/type_traits/is_unsigned.hpp>
#include "config.h" #include "config.h"
#include "gcc.h"
struct ConversionError struct ConversionError
{ {
@@ -44,21 +43,21 @@ struct OutOfBounds : std::exception
const std::string &errorMessage() { return m_error_message; } const std::string &errorMessage() { return m_error_message; }
template <typename Type> template <typename Type>
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( throw OutOfBounds((boost::format(
"value is out of bounds ([%1%, %2%] expected, %3% given)") % lbound % ubound % value).str()); "value is out of bounds ([%1%, %2%] expected, %3% given)") % lbound % ubound % value).str());
} }
template <typename Type> template <typename Type>
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( throw OutOfBounds((boost::format(
"value is out of bounds ([%1%, ->) expected, %2% given)") % lbound % value).str()); "value is out of bounds ([%1%, ->) expected, %2% given)") % lbound % value).str());
} }
template <typename Type> template <typename Type>
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( throw OutOfBounds((boost::format(
"value is out of bounds ((<-, %1%] expected, %2% given)") % ubound % value).str()); "value is out of bounds ((<-, %1%] expected, %2% given)") % ubound % value).str());

View File

@@ -25,7 +25,6 @@
#include <locale> #include <locale>
#include <string> #include <string>
#include <vector> #include <vector>
#include "gcc.h"
template <size_t N> size_t const_strlen(const char (&)[N]) { template <size_t N> size_t const_strlen(const char (&)[N]) {
return N-1; return N-1;