From b596330093d3fa5d80e3ffc185771df77a02393b Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Sat, 16 May 2015 00:05:23 +0200 Subject: [PATCH] Fix compilation with boost 1.58 Newer boost versions use complicated type traits for boost::next and boost::prior, which do not work with the RandomAccessList iterators. The long term solution is to use std::next and std::prev, for now supply simple replacements for compilers that do not support C++11 yet. --- boost/extract.sh | 1 - src/Compare.cpp | 7 +++---- src/Cursor.cpp | 2 +- src/CutAndPaste.cpp | 10 +++++----- src/FontList.cpp | 6 ++---- src/Row.cpp | 6 ++---- src/Text.cpp | 13 ++++++------- src/Text2.cpp | 9 ++++----- src/Text3.cpp | 9 ++++----- src/lyxfind.cpp | 1 - src/mathed/MathData.cpp | 4 ++-- src/output_docbook.cpp | 7 +++---- src/output_latex.cpp | 11 +++++------ src/support/lyxalgo.h | 26 ++++++++++++++++++++++++++ 14 files changed, 63 insertions(+), 49 deletions(-) diff --git a/boost/extract.sh b/boost/extract.sh index dbe280b07d..297cbc5575 100755 --- a/boost/extract.sh +++ b/boost/extract.sh @@ -29,7 +29,6 @@ bcp --boost=$1 \ boost/function.hpp \ boost/functional.hpp \ boost/lexical_cast.hpp \ - boost/next_prior.hpp \ boost/noncopyable.hpp \ boost/regex.hpp \ boost/scoped_array.hpp \ diff --git a/src/Compare.cpp b/src/Compare.cpp index 72510e908b..048feba4db 100644 --- a/src/Compare.cpp +++ b/src/Compare.cpp @@ -20,10 +20,9 @@ #include "insets/InsetText.h" #include "support/lassert.h" +#include "support/lyxalgo.h" #include "support/qstring_helpers.h" -#include - using namespace std; using namespace lyx::support; @@ -423,8 +422,8 @@ static void getParagraphList(DocRange const & range, pit_type startpit = range.from.pit(); pit_type endpit = range.to.pit(); ParagraphList const & ps_ = range.text()->paragraphs(); - ParagraphList tmp_pars(boost::next(ps_.begin(), startpit), - boost::next(ps_.begin(), endpit + 1)); + ParagraphList tmp_pars(next(ps_.begin(), startpit), + next(ps_.begin(), endpit + 1)); // Remove the end of the last paragraph; afterwards, remove the // beginning of the first paragraph. Keep this order - there may only diff --git a/src/Cursor.cpp b/src/Cursor.cpp index 45720973ed..17ee74e9c1 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -132,7 +132,7 @@ bool bruteFind(Cursor & cursor, // Get an iterator after the last paragraph in the cache DocIterator et(inset); et.push_back(CursorSlice(inset)); - et.pit() = boost::prior(cache.end())->first; + et.pit() = prev(cache.end(), 1)->first; if (et.pit() >= et.lastpit()) et = doc_iterator_end(inset); else diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index 6333892cd6..0bfd3ad4e9 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -60,6 +60,7 @@ #include "support/lassert.h" #include "support/limited_stack.h" #include "support/lstrings.h" +#include "support/lyxalgo.h" #include "support/TempFile.h" #include "frontends/alert.h" @@ -67,7 +68,6 @@ #include "frontends/Selection.h" #include -#include #include @@ -387,7 +387,7 @@ pasteSelectionHelper(DocIterator const & cur, ParagraphList const & parlist, // Paste it! if (empty) { - pars.insert(boost::next(pars.begin(), pit), + pars.insert(next(pars.begin(), pit), insertion.begin(), insertion.end()); @@ -395,7 +395,7 @@ pasteSelectionHelper(DocIterator const & cur, ParagraphList const & parlist, mergeParagraph(buffer.params(), pars, pit + insertion.size() - 1); } else { - pars.insert(boost::next(pars.begin(), pit + 1), + pars.insert(next(pars.begin(), pit + 1), insertion.begin(), insertion.end()); @@ -599,8 +599,8 @@ void copySelectionHelper(Buffer const & buf, Text const & text, LASSERT(startpit != endpit || start <= end, return); // Clone the paragraphs within the selection. - ParagraphList copy_pars(boost::next(pars.begin(), startpit), - boost::next(pars.begin(), endpit + 1)); + ParagraphList copy_pars(next(pars.begin(), startpit), + next(pars.begin(), endpit + 1)); // Remove the end of the last paragraph; afterwards, remove the // beginning of the first paragraph. Keep this order - there may only diff --git a/src/FontList.cpp b/src/FontList.cpp index 1c763e161e..e5a86dbb29 100644 --- a/src/FontList.cpp +++ b/src/FontList.cpp @@ -20,9 +20,7 @@ #include "FontList.h" -#include - -#include +#include "support/lyxalgo.h" using namespace std; @@ -72,7 +70,7 @@ void FontList::erase(pos_type pos) iterator beg = list_.begin(); if (it != list_.end() && it->pos() == pos && (pos == 0 - || (it != list_.begin() && boost::prior(it)->pos() == pos - 1))) { + || (it != list_.begin() && prev(it, 1)->pos() == pos - 1))) { // If it is a multi-character font // entry, we just make it smaller diff --git a/src/Row.cpp b/src/Row.cpp index 4a2f2e5848..57f02e2987 100644 --- a/src/Row.cpp +++ b/src/Row.cpp @@ -24,12 +24,10 @@ #include "support/debug.h" #include "support/lassert.h" +#include "support/lyxalgo.h" -#include #include -#include - using namespace std; namespace lyx { @@ -417,7 +415,7 @@ void Row::shortenIfNeeded(pos_type const keep, int const w) end_ = cit->endpos; dim_.wid = left_margin + cit->dim.wid; // If there are other elements, they should be removed. - elements_.erase(boost::next(cit), end); + elements_.erase(next(cit, 1), end); } } diff --git a/src/Text.cpp b/src/Text.cpp index 06700a48c8..5e92dd09bb 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -66,10 +66,9 @@ #include "support/gettext.h" #include "support/lassert.h" #include "support/lstrings.h" +#include "support/lyxalgo.h" #include "support/textutils.h" -#include - #include #include @@ -137,7 +136,7 @@ void breakParagraphConservative(BufferParams const & bparams, ParagraphList & pars, pit_type par_offset, pos_type pos) { // create a new paragraph - Paragraph & tmp = *pars.insert(boost::next(pars.begin(), par_offset + 1), + Paragraph & tmp = *pars.insert(next(pars.begin(), par_offset + 1), Paragraph()); Paragraph & par = pars[par_offset]; @@ -193,7 +192,7 @@ void mergeParagraph(BufferParams const & bparams, // move the change of the end-of-paragraph character par.setChange(par.size(), change); - pars.erase(boost::next(pars.begin(), par_offset + 1)); + pars.erase(lyx::next(pars.begin(), par_offset + 1)); } @@ -663,7 +662,7 @@ static void breakParagraph(Text & text, pit_type par_offset, pos_type pos, ParagraphList & pars = text.paragraphs(); // create a new paragraph, and insert into the list ParagraphList::iterator tmp = - pars.insert(boost::next(pars.begin(), par_offset + 1), + pars.insert(next(pars.begin(), par_offset + 1), Paragraph()); Paragraph & par = pars[par_offset]; @@ -1641,14 +1640,14 @@ bool Text::backspacePos0(Cursor & cur) if (cur.lastpos() == 0 || (cur.lastpos() == 1 && par.isSeparator(0))) { cur.recordUndo(prevcur.pit()); - plist.erase(boost::next(plist.begin(), cur.pit())); + plist.erase(next(plist.begin(), cur.pit())); needsUpdate = true; } // is previous par empty? else if (prevcur.lastpos() == 0 || (prevcur.lastpos() == 1 && prevpar.isSeparator(0))) { cur.recordUndo(prevcur.pit()); - plist.erase(boost::next(plist.begin(), prevcur.pit())); + plist.erase(next(plist.begin(), prevcur.pit())); needsUpdate = true; } // Pasting is not allowed, if the paragraphs have different diff --git a/src/Text2.cpp b/src/Text2.cpp index 676dc1dfa3..7b3d4da8c6 100644 --- a/src/Text2.cpp +++ b/src/Text2.cpp @@ -50,10 +50,9 @@ #include "support/lassert.h" #include "support/debug.h" #include "support/gettext.h" +#include "support/lyxalgo.h" #include "support/textutils.h" -#include - #include using namespace std; @@ -395,7 +394,7 @@ bool Text::cursorTop(Cursor & cur) bool Text::cursorBottom(Cursor & cur) { LBUFERR(this == cur.text()); - return setCursor(cur, cur.lastpit(), boost::prior(paragraphs().end())->size()); + return setCursor(cur, cur.lastpit(), prev(paragraphs().end(), 1)->size()); } @@ -905,7 +904,7 @@ bool Text::deleteEmptyParagraphMechanism(Cursor & cur, min(old.pit() + 1, old.lastpit())); ParagraphList & plist = old.text()->paragraphs(); bool const soa = oldpar.params().startOfAppendix(); - plist.erase(boost::next(plist.begin(), old.pit())); + plist.erase(next(plist.begin(), old.pit())); // do not lose start of appendix marker (bug 4212) if (soa && old.pit() < pit_type(plist.size())) plist[old.pit()].params().startOfAppendix(true); @@ -969,7 +968,7 @@ void Text::deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool tra continue; if (par.empty() || (par.size() == 1 && par.isLineSeparator(0))) { - pars_.erase(boost::next(pars_.begin(), pit)); + pars_.erase(next(pars_.begin(), pit)); --pit; --last; continue; diff --git a/src/Text3.cpp b/src/Text3.cpp index 5c9b812ef5..ca74d9d680 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -72,6 +72,7 @@ #include "support/gettext.h" #include "support/lassert.h" #include "support/lstrings.h" +#include "support/lyxalgo.h" #include "support/lyxtime.h" #include "support/os.h" #include "support/regex.h" @@ -79,8 +80,6 @@ #include "mathed/InsetMathHull.h" #include "mathed/MathMacroTemplate.h" -#include - #include #include @@ -370,7 +369,7 @@ static void outline(OutlineOp mode, Cursor & cur) ParagraphList & pars = buf.text().paragraphs(); ParagraphList::iterator const bgn = pars.begin(); // The first paragraph of the area to be copied: - ParagraphList::iterator start = boost::next(bgn, pit); + ParagraphList::iterator start = next(bgn, pit); // The final paragraph of area to be copied: ParagraphList::iterator finish = start; ParagraphList::iterator const end = pars.end(); @@ -421,7 +420,7 @@ static void outline(OutlineOp mode, Cursor & cur) // Nothing to move. return; // Go one down from *this* header: - ParagraphList::iterator dest = boost::next(finish, 1); + ParagraphList::iterator dest = next(finish, 1); // Go further down to find header to insert in front of: for (; dest != end; ++dest) { toclevel = buf.text().getTocLevel(distance(bgn, dest)); @@ -799,7 +798,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) ParagraphList & pars = buf.text().paragraphs(); ParagraphList::iterator bgn = pars.begin(); // The first paragraph of the area to be selected: - ParagraphList::iterator start = boost::next(bgn, pit); + ParagraphList::iterator start = next(bgn, pit); // The final paragraph of area to be selected: ParagraphList::iterator finish = start; ParagraphList::iterator end = pars.end(); diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index e0a786837e..2c686b3c88 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -51,7 +51,6 @@ #include "support/lstrings.h" #include "support/regex.h" -#include using namespace std; using namespace lyx::support; diff --git a/src/mathed/MathData.cpp b/src/mathed/MathData.cpp index 6daf096137..d591bfacc3 100644 --- a/src/mathed/MathData.cpp +++ b/src/mathed/MathData.cpp @@ -38,7 +38,7 @@ #include "support/gettext.h" #include "support/lassert.h" -#include +#include "support/lyxalgo.h" #include @@ -901,7 +901,7 @@ MathData::size_type MathData::x2pos(BufferView const * bv, int targetx, int glue * See bug 1918 for details. **/ if (it != begin() && currx >= targetx - && ((*boost::prior(it))->asNestInset() + && ((*prev(it, 1))->asNestInset() || abs(lastx - targetx) < abs(currx - targetx))) { --it; } diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp index 86527f3f55..48b2f605e7 100644 --- a/src/output_docbook.cpp +++ b/src/output_docbook.cpp @@ -30,8 +30,7 @@ #include "support/lassert.h" #include "support/debug.h" #include "support/lstrings.h" - -#include +#include "support/lyxalgo.h" using namespace std; using namespace lyx::support; @@ -329,8 +328,8 @@ void docbookParagraphs(Text const & text, // if only part of the paragraphs will be outputed if (runparams.par_begin != runparams.par_end) { - par = boost::next(paragraphs.begin(), runparams.par_begin); - pend = boost::next(paragraphs.begin(), runparams.par_end); + par = next(paragraphs.begin(), runparams.par_begin); + pend = next(paragraphs.begin(), runparams.par_end); // runparams will be passed to nested paragraphs, so // we have to reset the range parameters. const_cast(runparams).par_begin = 0; diff --git a/src/output_latex.cpp b/src/output_latex.cpp index d4a627ec49..6df77f1b66 100644 --- a/src/output_latex.cpp +++ b/src/output_latex.cpp @@ -33,12 +33,11 @@ #include "support/convert.h" #include "support/debug.h" #include "support/lstrings.h" +#include "support/lyxalgo.h" #include "support/textutils.h" #include -#include -#include #include using namespace std; @@ -130,7 +129,7 @@ static TeXEnvironmentData prepareEnvironment(Buffer const & buf, ParagraphList const & paragraphs = text.paragraphs(); ParagraphList::const_iterator const priorpit = - pit == paragraphs.begin() ? pit : boost::prior(pit); + pit == paragraphs.begin() ? pit : prev(pit, 1); OutputState * state = getOutputState(); bool const use_prev_env_language = state->prev_env_language_ != 0 @@ -470,9 +469,9 @@ void latexArgInsets(ParagraphList const & pars, ParagraphList::const_iterator pi // get the first paragraph in sequence with this layout and depth pit_type offset = 0; while (true) { - if (boost::prior(pit, offset) == pars.begin()) + if (prev(pit, offset) == pars.begin()) break; - ParagraphList::const_iterator priorpit = boost::prior(pit, offset + 1); + ParagraphList::const_iterator priorpit = prev(pit, offset + 1); if (priorpit->layout() == current_layout && priorpit->params().depth() == current_depth) ++offset; @@ -480,7 +479,7 @@ void latexArgInsets(ParagraphList const & pars, ParagraphList::const_iterator pi break; } - ParagraphList::const_iterator spit = boost::prior(pit, offset); + ParagraphList::const_iterator spit = prev(pit, offset); for (; spit != pars.end(); ++spit) { if (spit->layout() != current_layout || spit->params().depth() < current_depth) diff --git a/src/support/lyxalgo.h b/src/support/lyxalgo.h index f747e27c8a..410bf75933 100644 --- a/src/support/lyxalgo.h +++ b/src/support/lyxalgo.h @@ -83,6 +83,32 @@ void eliminate_duplicates(C & c) c.erase(std::unique(c.begin(), c.end()), c.end()); } + +#if __cplusplus >= 201103L +using std::next; +#else +/// Replacement of std::next for older compilers +template +inline It next(It i, Diff n = 1) +{ + std::advance(i, n); + return i; +} +#endif + + +#if __cplusplus >= 201103L +using std::prev; +#else +/// Replacement of std::prev for older compilers +template +inline It prev(It i, Diff n = 1) +{ + std::advance(i, -n); + return i; +} +#endif + } // namespace lyx #endif // LYX_ALGO_H