I pushed this my mistake obviously. I was about the revert, and then I got confused by the fact that this supposedly fixes compilation with MSVC 2019. Can somebody enlighten me on whether this patch is needed with relevant versions of MSVC?

JMarc


-------- Message transféré --------
Sujet : [LyX/2.3.x] Fix a number of issues that were stopping compilation with MSVC 19.
Date : Mon,  5 Feb 2024 21:53:55 +0100 (CET)
De : Jean-Marc Lasgouttes <lasgout...@lyx.org>
Répondre à : lyx-devel@lists.lyx.org
Pour : lyx-...@lists.lyx.org

commit 5969f0e7d113734b7859ab89e5edd05233afc8d1
Author: Richard Kimberly Heck <rikih...@lyx.org>
Date:   Mon May 4 19:41:18 2020 -0400

    Fix a number of issues that were stopping compilation with MSVC 19.
Patch from Thibaut Cuvelier, modified slightly by me (mostly for style). (cherry picked from commit c506f304bc522ea91ad5a7e97cd4e3c7d54376b0)
---
 lib/generate_contributions.py     |    8 +++++
 src/BiblioInfo.cpp                |   12 ++-----
 src/BranchList.cpp                |    7 +---
 src/Format.cpp                    |   47 +++++++++++++++++----------
 src/Format.h                      |    2 +
 src/Lexer.cpp                     |   28 +++++++---------
src/TextClass.cpp | 64 +++++++++++++++++++-----------------
 src/TextClass.h                   |    6 +++-
 src/frontends/qt4/GuiDocument.cpp |    1 -
 src/frontends/tests/biblio.cpp    |    2 +-
 src/insets/InsetCommandParams.cpp |    2 +-
 src/lyxfind.cpp                   |    2 +-
 12 files changed, 99 insertions(+), 82 deletions(-)

diff --git a/lib/generate_contributions.py b/lib/generate_contributions.py
index e549ab2..0b49a02 100755
--- a/lib/generate_contributions.py
+++ b/lib/generate_contributions.py
@@ -607,6 +607,14 @@ contributors = [
                  "20 Sep 2007",
                  u"Advanced search feature"),
 +     contributor(u"Thibaut Cuvelier",
+                 "dourouc05 () gmail ! com",
+                 "GPL",
+ "Re: Patches to improve compatibility with modern C++ standard",
+                 "msg211215",
+                 "4 May 2020",
+                 u"Windows compatibility patches"),
+
      contributor(u"Matthias Kalle Dalheimer",
                  "kalle () kdab ! net",
                  "GPL",
diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp
index f45d370..678312a 100644
--- a/src/BiblioInfo.cpp
+++ b/src/BiblioInfo.cpp
@@ -1149,13 +1149,9 @@ docstring BibTeXInfo::getValueForKey(string const & oldkey, Buffer const & buf,
 namespace {
  // A functor for use with sort, leading to case insensitive sorting
-class compareNoCase: public binary_function<docstring, docstring, bool>
-{
-public:
-       bool operator()(docstring const & s1, docstring const & s2) const {
-               return compare_no_case(s1, s2) < 0;
-       }
-};
+bool compareNoCase(const docstring & a, const docstring & b) {
+       return compare_no_case(a, b) < 0;
+}
  } // namespace
 @@ -1206,7 +1202,7 @@ vector<docstring> const BiblioInfo::getKeys() const
        BiblioInfo::const_iterator it  = begin();
        for (; it != end(); ++it)
                bibkeys.push_back(it->first);
-       sort(bibkeys.begin(), bibkeys.end(), compareNoCase());
+       sort(bibkeys.begin(), bibkeys.end(), &compareNoCase);
        return bibkeys;
 }
 diff --git a/src/BranchList.cpp b/src/BranchList.cpp
index ec6a413..855a82c 100644
--- a/src/BranchList.cpp
+++ b/src/BranchList.cpp
@@ -150,9 +150,7 @@ bool BranchList::add(docstring const & s)
                else
                        name = s.substr(i, j - i);
                // Is this name already in the list?
-               bool const already =
-                       find_if(list.begin(), list.end(),
-                                    BranchNamesEqual(name)) != list.end();
+               bool const already = find(name) != nullptr;
                if (!already) {
                        added = true;
                        Branch br;
@@ -182,8 +180,7 @@ bool BranchList::rename(docstring const & oldname,
 {
        if (newname.empty())
                return false;
-       if (find_if(list.begin(), list.end(),
-                   BranchNamesEqual(newname)) != list.end()) {
+       if (find(newname)) {
                // new name already taken
                if (merge)
                      return remove(oldname);
diff --git a/src/Format.cpp b/src/Format.cpp
index da93457..3da2120 100644
--- a/src/Format.cpp
+++ b/src/Format.cpp
@@ -181,6 +181,19 @@ Format const * Formats::getFormat(string const & name) const
 }
  +Format * Formats::getFormat(string const & name)
+{
+       FormatList::iterator it =
+               find_if(formatlist_.begin(), formatlist_.end(),
+                               [name](Format const & f) { return f.name() == 
name; });
+
+       if (it != formatlist_.end())
+               return &(*it);
+
+       return nullptr;
+}
+
+
 namespace {
  /** Guess the file format name (as in Format::name()) from contents.
@@ -611,15 +624,13 @@ void Formats::add(string const & name, string const & extensions,
                  string const & viewer, string const & editor,
                  string const & mime, int flags)
 {
-       FormatList::iterator it =
-               find_if(formatlist_.begin(), formatlist_.end(),
-                       FormatNamesEqual(name));
-       if (it == formatlist_.end())
-               formatlist_.push_back(Format(name, extensions, prettyname,
-                                           shortcut, viewer, editor, mime, 
flags));
+       Format * format = getFormat(name);
+       if (format)
+               *format = Format(name, extensions, prettyname, shortcut, viewer,
+                                editor, mime, flags);
        else
-               *it = Format(name, extensions, prettyname, shortcut, viewer,
-                            editor, mime, flags);
+               formatlist_.push_back(Format(name, extensions, prettyname,
+                                               shortcut, viewer, editor, mime, 
flags));
 }
  @@ -642,22 +653,22 @@ void Formats::sort()
 void Formats::setViewer(string const & name, string const & command)
 {
        add(name);
-       FormatList::iterator it =
-               find_if(formatlist_.begin(), formatlist_.end(),
-                       FormatNamesEqual(name));
-       if (it != formatlist_.end())
-               it->setViewer(command);
+       Format * format = getFormat(name);
+       if (format)
+               format->setViewer(command);
+       else
+               LYXERR0("Unable to set viewer for non-existent format: " << 
name);
 }
   void Formats::setEditor(string const & name, string const & command)
 {
        add(name);
-       FormatList::iterator it =
-               find_if(formatlist_.begin(), formatlist_.end(),
-                       FormatNamesEqual(name));
-       if (it != formatlist_.end())
-               it->setEditor(command);
+       Format * format = getFormat(name);
+       if (format)
+               format->setEditor(command);
+       else
+               LYXERR0("Unable to set editor for non-existent format: " << 
name);
 }
  diff --git a/src/Format.h b/src/Format.h
index 4fcd3c9..495d9b1 100644
--- a/src/Format.h
+++ b/src/Format.h
@@ -152,6 +152,8 @@ public:
        Format & get(FormatList::size_type i) { return formatlist_[i]; }
        /// \returns format named \p name if it exists, otherwise 0
        Format const * getFormat(std::string const & name) const;
+       /// \returns format named \p name if it exists, otherwise 0
+       Format * getFormat(std::string const & name);
        /*!
         * Get the format of \p filename from file contents or, if this
         * fails, from file extension.
diff --git a/src/Lexer.cpp b/src/Lexer.cpp
index 098faa9..47d57c3 100644
--- a/src/Lexer.cpp
+++ b/src/Lexer.cpp
@@ -132,25 +132,21 @@ private:
 };
  -
 namespace {
 -class CompareTags
-       : public binary_function<LexerKeyword, LexerKeyword, bool> {
-public:
-       // used by lower_bound, sort and sorted
-       bool operator()(LexerKeyword const & a, LexerKeyword const & b) const
-       {
-               // we use the ascii version, because in turkish, 'i'
-               // is not the lowercase version of 'I', and thus
-               // turkish locale breaks parsing of tags.
-               return compare_ascii_no_case(a.tag, b.tag) < 0;
-       }
-};
+// used by lower_bound, sort and sorted
+bool compareTags(LexerKeyword const & a, LexerKeyword const & b)
+{
+       // we use the ascii version, because in turkish, 'i'
+       // is not the lowercase version of 'I', and thus
+       // turkish locale breaks parsing of tags.
+       return compare_ascii_no_case(a.tag, b.tag) < 0;
+}
  } // namespace
  +
 Lexer::Pimpl::Pimpl(LexerKeyword * tab, int num)
        : is(&fb_), table(tab), no_items(num),
          status(0), lineno(0), commentChar('#')
@@ -196,14 +192,14 @@ void Lexer::Pimpl::verifyTable()
 {
        // Check if the table is sorted and if not, sort it.
        if (table
-           && !lyx::sorted(table, table + no_items, CompareTags())) {
+           && !lyx::sorted(table, table + no_items, &compareTags)) {
                lyxerr << "The table passed to Lexer is not sorted!\n"
                       << "Tell the developers to fix it!" << endl;
                // We sort it anyway to avoid problems.
                lyxerr << "\nUnsorted:" << endl;
                printTable(lyxerr);
 -              sort(table, table + no_items, CompareTags());
+               sort(table, table + no_items, &compareTags);
                lyxerr << "\nSorted:" << endl;
                printTable(lyxerr);
        }
@@ -440,7 +436,7 @@ int Lexer::Pimpl::searchKeyword(char const * const tag) const
        LexerKeyword search_tag = { tag, 0 };
        LexerKeyword * res =
                lower_bound(table, table + no_items,
-                           search_tag, CompareTags());
+                           search_tag, &compareTags);
        // use the compare_ascii_no_case instead of compare_no_case,
        // because in turkish, 'i' is not the lowercase version of 'I',
        // and thus turkish locale breaks parsing of tags.
diff --git a/src/TextClass.cpp b/src/TextClass.cpp
index 56a5952..9c9a3ea 100644
--- a/src/TextClass.cpp
+++ b/src/TextClass.cpp
@@ -72,20 +72,6 @@ int const LYXFILE_LAYOUT_FORMAT = LAYOUT_FORMAT;
  namespace {
 -class LayoutNamesEqual : public unary_function<Layout, bool> {
-public:
-       LayoutNamesEqual(docstring const & name)
-               : name_(name)
-       {}
-       bool operator()(Layout const & c) const
-       {
-               return c.name() == name_;
-       }
-private:
-       docstring name_;
-};
-
-
 bool layout2layout(FileName const & filename, FileName const & tempfile,
                    int const format = LAYOUT_FORMAT)
 {
@@ -1438,10 +1424,7 @@ string const & TextClass::prerequisites(string const & sep) const
 bool TextClass::hasLayout(docstring const & n) const
 {
        docstring const name = n.empty() ? defaultLayoutName() : n;
-
-       return find_if(layoutlist_.begin(), layoutlist_.end(),
-                      LayoutNamesEqual(name))
-               != layoutlist_.end();
+       return getLayout(name) != nullptr;
 }
@@ -1458,10 +1441,8 @@ Layout const & TextClass::operator[](docstring const & name) const
 {
        LATTEST(!name.empty());
 -      const_iterator it =
-               find_if(begin(), end(), LayoutNamesEqual(name));
-
-       if (it == end()) {
+       Layout const * c = getLayout(name);
+       if (!c) {
                LYXERR0("We failed to find the layout '" << name
                       << "' in the layout list. You MUST investigate!");
                for (const_iterator cit = begin(); cit != end(); ++cit)
@@ -1472,7 +1453,7 @@ Layout const & TextClass::operator[](docstring const & name) const
                LASSERT(false, return dummy);
        }
 -      return *it;
+       return *c;
 }
@@ -1481,9 +1462,8 @@ Layout & TextClass::operator[](docstring const & name)
        LATTEST(!name.empty());
        // Safe to continue, given what we do below.
 -      iterator it = find_if(begin(), end(), LayoutNamesEqual(name));
-
-       if (it == end()) {
+       Layout * c = getLayout(name);
+       if (!c) {
                LYXERR0("We failed to find the layout '" << to_utf8(name)
                       << "' in the layout list. You MUST investigate!");
                for (const_iterator cit = begin(); cit != end(); ++cit)
@@ -1493,10 +1473,10 @@ Layout & TextClass::operator[](docstring const & name)
                LATTEST(false);
                // we are here only in release mode
                layoutlist_.push_back(createBasicLayout(name, true));
-               it = find_if(begin(), end(), LayoutNamesEqual(name));
+               c = getLayout(name);
        }
 -      return *it;
+       return *c;
 }
@@ -1507,9 +1487,9 @@ bool TextClass::deleteLayout(docstring const & name)
        LayoutList::iterator it =
                remove_if(layoutlist_.begin(), layoutlist_.end(),
-                         LayoutNamesEqual(name));
+                       [name](const Layout &c) { return c.name() == name; });
 -      LayoutList::iterator end = layoutlist_.end();
+       LayoutList::iterator const end = layoutlist_.end();
        bool const ret = (it != end);
        layoutlist_.erase(it, end);
        return ret;
@@ -1550,6 +1530,30 @@ bool TextClass::load(string const & path) const
 }
  +Layout const * TextClass::getLayout(docstring const & name) const
+{
+       LayoutList::const_iterator cit =
+               find_if(begin(), end(),
+                       [name](const Layout &c) { return c.name() == name; });
+       if (cit == layoutlist_.end())
+               return nullptr;
+
+       return &(*cit);
+}
+
+
+Layout * TextClass::getLayout(docstring const & name)
+{
+       LayoutList::iterator it =
+               find_if(layoutlist_.begin(), layoutlist_.end(),
+                       [name](const Layout &c) { return c.name() == name; });
+       if (it == layoutlist_.end())
+               return nullptr;
+
+       return &(*it);
+}
+
+
 bool DocumentClass::addLayoutIfNeeded(docstring const & n) const
 {
        if (hasLayout(n))
diff --git a/src/TextClass.h b/src/TextClass.h
index 570e67f..0b95f52 100644
--- a/src/TextClass.h
+++ b/src/TextClass.h
@@ -211,7 +211,11 @@ public:
        bool hasOutputFormat() const { return has_output_format_; }
        /// Return the non-localised names for the toc types.
        std::map<std::string, docstring> const &
-       outlinerNames() const { return outliner_names_; }
+               outlinerNames() const { return outliner_names_; }
+       /// \returns Layout named \p name if it exists, otherwise 0
+       Layout const * getLayout(docstring const & name) const;
+       /// \returns Layout named \p name if it exists, otherwise 0
+       Layout * getLayout(docstring const & name);
  protected:
        /// Protect construction
diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp
index 68b6c6b..386a2f6 100644
--- a/src/frontends/qt4/GuiDocument.cpp
+++ b/src/frontends/qt4/GuiDocument.cpp
@@ -169,7 +169,6 @@ bool forced_fontspec_activation;
 namespace {
 // used when sorting the textclass list.
 class less_textclass_avail_desc
-       : public binary_function<string, string, int>
 {
 public:
        bool operator()(string const & lhs, string const & rhs) const
diff --git a/src/frontends/tests/biblio.cpp b/src/frontends/tests/biblio.cpp
index 067cc9b..4cd7d45 100644
--- a/src/frontends/tests/biblio.cpp
+++ b/src/frontends/tests/biblio.cpp
@@ -40,7 +40,7 @@ typedef map<string, string> InfoMap;
 // data entry matches the required regex_
// This class is unfortunately copied from ../frontend_helpers.cpp, so we should
 // try to make sure to keep the two in sync.
-class RegexMatch : public unary_function<string, bool>
+class RegexMatch
 {
 public:
        // re is used to construct an instance of lyx::regex.
diff --git a/src/insets/InsetCommandParams.cpp b/src/insets/InsetCommandParams.cpp
index 09a76a1..4393534 100644
--- a/src/insets/InsetCommandParams.cpp
+++ b/src/insets/InsetCommandParams.cpp
@@ -593,7 +593,7 @@ docstring InsetCommandParams::getFirstNonOptParam() const
 {
        ParamInfo::const_iterator it =
                find_if(info_.begin(), info_.end(),
-                       not1(mem_fun_ref(&ParamInfo::ParamData::isOptional)));
+                       [](ParamInfo::ParamData const & d) { return 
!d.isOptional(); });
        LASSERT(it != info_.end(), return docstring());
        return (*this)[it->name()];
 }
diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp
index 12ac16a..34364f5 100644
--- a/src/lyxfind.cpp
+++ b/src/lyxfind.cpp
@@ -72,7 +72,7 @@ bool parse_bool(docstring & howto)
 }
  -class MatchString : public binary_function<Paragraph, pos_type, int>
+class MatchString
 {
 public:
        MatchString(docstring const & str, bool cs, bool mw)
--
lyx-cvs mailing list
lyx-...@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-cvs
--
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to