On Thu, Jul 22, 2004 at 08:11:32PM +0200, Lars Gullik Bjønnes wrote: > > Cleaning up my numerous lyx trees I found this. > > What where the objections again?
One of the objections was that neither - sort(formats.begin(), formats.end(), compare_format()); + + sort(formats.begin(), formats.end(), + bind(less<Format>(), + bind(deref<Format>, _1), + bind(deref<Format>, _2))); // Update the font table. FontTable search_font(pos, LyXFont()); nor - for (FontList::iterator it = lower_bound(fontlist.begin(), - fontlist.end(), - search_font, matchFT()); - it != fontlist.end(); ++it) - { +#if 1 + FontList::iterator it = + lower_bound(fontlist.begin(), + fontlist.end(), + search_font, + bind(less<pos_type>(), + bind(&FontTable::pos, _1), + bind(&FontTable::pos, _2))); +#else + FontList::iterator it = lower_bound( + make_transform_iterator(fontlist.begin(), + bind(&FontTable::pos, _1)), + make_transform_iterator(fontlist.begin(), + bind(&FontTable::pos, _1)), + pos); +#endif + for (; it != fontlist.end(); ++it) { it->pos(it->pos() + 1); } looks like anything close to an improvement in my eyes. But before we'll repeat this discussion, just commit what you have and go on to the next problem... Andre' @@ -316,10 +334,23 @@ void Paragraph::Pimpl::eraseIntern(pos_t // Erase entries in the tables. FontTable search_font(pos, LyXFont()); +#if 1 FontList::iterator it = lower_bound(fontlist.begin(), fontlist.end(), - search_font, matchFT()); + search_font, + bind(less<pos_type>(), + bind(&FontTable::pos, _1), + bind(&FontTable::pos, _2))); +#else + FontList::iterator it = + find_if(fontlist.begin(), + fontlist.end(), + search_font, + bind(less<pos_type>(), + bind(&FontTable::pos, _1), + bind(&FontTable::pos, _2))); +#endif if (it != fontlist.end() && it->pos() == pos && (pos == 0 || (it != fontlist.begin() Index: src/paragraph_pimpl.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_pimpl.h,v retrieving revision 1.43 diff -u -p -r1.43 paragraph_pimpl.h --- src/paragraph_pimpl.h 25 Mar 2004 09:16:21 -0000 1.43 +++ src/paragraph_pimpl.h 22 Jul 2004 18:01:53 -0000 @@ -124,16 +124,6 @@ struct Paragraph::Pimpl { /// static ShareContainer<LyXFont> container; }; - /// - friend struct matchFT; - /// - struct matchFT { - /// used by lower_bound and upper_bound - inline - int operator()(FontTable const & a, FontTable const & b) const { - return a.pos() < b.pos(); - } - }; /// typedef std::vector<FontTable> FontList; Index: src/texrow.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/texrow.C,v retrieving revision 1.32 diff -u -p -r1.32 texrow.C --- src/texrow.C 8 Sep 2003 00:33:25 -0000 1.32 +++ src/texrow.C 22 Jul 2004 18:01:53 -0000 @@ -15,26 +15,14 @@ #include "texrow.h" #include "debug.h" -#include <algorithm> - -using std::find_if; +#include <boost/bind.hpp> +#include <algorithm> -namespace { - -/// function object returning true when row number is found -class same_rownumber { -public: - same_rownumber(int row) : row_(row) {} - bool operator()(TexRow::RowList::value_type const & vt) const { - return vt.rownumber() == row_; - } - -private: - int row_; -}; +using boost::bind; -} // namespace anon +using std::equal_to; +using std::find_if; void TexRow::reset() @@ -65,7 +53,9 @@ bool TexRow::getIdFromRow(int row, int & { RowList::const_iterator cit = find_if(rowlist.begin(), rowlist.end(), - same_rownumber(row)); + bind(equal_to<int>(), + bind(&RowList::value_type::rownumber, _1), + row)); if (cit != rowlist.end()) { id = cit->id(); Index: src/frontends/controllers/ControlCommandBuffer.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlCommandBuffer.C,v retrieving revision 1.21 diff -u -p -r1.21 ControlCommandBuffer.C --- src/frontends/controllers/ControlCommandBuffer.C 19 May 2004 15:11:30 -0000 1.21 +++ src/frontends/controllers/ControlCommandBuffer.C 22 Jul 2004 18:01:53 -0000 @@ -25,8 +25,16 @@ #include "support/lyxalgo.h" #include "support/lstrings.h" -using std::back_inserter; -using std::transform; +#include <boost/bind.hpp> +#include <boost/iterator/filter_iterator.hpp> +#include <boost/iterator/transform_iterator.hpp> + +using lyx::support::prefixIs; + +using boost::bind; +using boost::make_filter_iterator; +using boost::make_transform_iterator; + using std::string; using std::vector; @@ -36,25 +44,16 @@ using support::prefixIs; namespace frontend { -namespace { - -struct prefix_p { - string p; - prefix_p(string const & s) - : p(s) {} - bool operator()(string const & s) const { - return prefixIs(s, p); - } -}; - -} // end of anon namespace - - ControlCommandBuffer::ControlCommandBuffer(LyXView & lv) : lv_(lv), history_pos_(history_.end()) { - transform(lyxaction.func_begin(), lyxaction.func_end(), - back_inserter(commands_), firster()); + typedef LyXAction::func_map::value_type Pair; + + commands_.assign( + make_transform_iterator(lyxaction.func_begin(), + bind(&Pair::first, _1)), + make_transform_iterator(lyxaction.func_end(), + bind(&Pair::first, _1))); } @@ -87,10 +86,12 @@ string const ControlCommandBuffer::getCu vector<string> const ControlCommandBuffer::completions(string const & prefix, string & new_prefix) { - vector<string> comp; - - copy_if(commands_.begin(), commands_.end(), - back_inserter(comp), prefix_p(prefix)); + vector<string> comp(make_filter_iterator(bind(prefixIs, _1, prefix), + commands_.begin(), + commands_.end()), + make_filter_iterator(bind(prefixIs, _1, prefix), + commands_.begin(), + commands_.end())); if (comp.empty()) { new_prefix = prefix; @@ -108,9 +109,13 @@ ControlCommandBuffer::completions(string if (tmp.length() > test.length()) test += tmp[test.length()]; while (test.length() < tmp.length()) { - vector<string> vtmp; - copy_if(comp.begin(), comp.end(), - back_inserter(vtmp), prefix_p(test)); + vector<string> vtmp( + make_filter_iterator(bind(prefixIs, _1, test), + comp.begin(), + comp.end()), + make_filter_iterator(bind(prefixIs, _1, test), + comp.begin(), + comp.end())); if (vtmp.size() != comp.size()) { test.erase(test.length() - 1); break; Index: src/frontends/controllers/ControlExternal.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlExternal.C,v retrieving revision 1.56 diff -u -p -r1.56 ControlExternal.C --- src/frontends/controllers/ControlExternal.C 19 May 2004 15:11:30 -0000 1.56 +++ src/frontends/controllers/ControlExternal.C 22 Jul 2004 18:01:53 -0000 @@ -132,9 +132,7 @@ int ControlExternal::getTemplateNumber(s external::Template ControlExternal::getTemplate(int i) const { external::TemplateManager::Templates::const_iterator i1 - = external::TemplateManager::get().getTemplates().begin(); - - advance(i1, i); + = boost::next(external::TemplateManager::get().getTemplates().begin(), i); return i1->second; } Index: src/frontends/controllers/biblio.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/biblio.C,v retrieving revision 1.67 diff -u -p -r1.67 biblio.C --- src/frontends/controllers/biblio.C 19 May 2004 15:11:31 -0000 1.67 +++ src/frontends/controllers/biblio.C 22 Jul 2004 18:01:53 -0000 @@ -20,6 +20,7 @@ #include "support/lstrings.h" #include "support/std_sstream.h" +#include <boost/bind.hpp> #include <boost/regex.hpp> #include <algorithm> @@ -27,6 +28,7 @@ using std::string; using std::ostringstream; using std::vector; +using std::less; namespace lyx { @@ -266,19 +268,6 @@ string const getYear(InfoMap const & map } -namespace { - -// A functor for use with std::sort, leading to case insensitive sorting -struct compareNoCase: public std::binary_function<string, string, bool> -{ - bool operator()(string const & s1, string const & s2) const { - return compare_ascii_no_case(s1, s2) < 0; - } -}; - -} // namespace anon - - vector<string> const getKeys(InfoMap const & map) { vector<string> bibkeys; @@ -288,7 +277,11 @@ vector<string> const getKeys(InfoMap con bibkeys.push_back(it->first); } - std::sort(bibkeys.begin(), bibkeys.end(), compareNoCase()); + // Do a no-case-sensitive sort + std::sort(bibkeys.begin(), bibkeys.end(), + bind(less<int>(), + bind(compare_ascii_no_case, _1, _2), + 0)); return bibkeys; } Index: src/frontends/controllers/frnt_lang.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/frnt_lang.C,v retrieving revision 1.16 diff -u -p -r1.16 frnt_lang.C --- src/frontends/controllers/frnt_lang.C 19 May 2004 15:11:31 -0000 1.16 +++ src/frontends/controllers/frnt_lang.C 22 Jul 2004 18:01:53 -0000 @@ -15,9 +15,14 @@ #include "gettext.h" #include "language.h" +#include <boost/bind.hpp> + #include <algorithm> +using boost::bind; + +using std::less; using std::string; using std::vector; @@ -25,21 +30,6 @@ using std::vector; namespace lyx { namespace frontend { -namespace { - -struct Sorter - : public std::binary_function<LanguagePair, - LanguagePair, bool> -{ - bool operator()(LanguagePair const & lhs, - LanguagePair const & rhs) const { - return lhs.first < rhs.first; - } -}; - -} // namespace anon - - vector<LanguagePair> const getLanguageData(bool character_dlg) { vector<LanguagePair>::size_type const size = character_dlg ? @@ -66,7 +56,10 @@ vector<LanguagePair> const getLanguageDa vector<LanguagePair>::iterator begin = character_dlg ? langs.begin() + 2 : langs.begin(); - std::sort(begin, langs.end(), Sorter()); + std::sort(begin, langs.end(), + bind(less<string>(), + bind(&LanguagePair::first, _1), + bind(&LanguagePair::first, _2))); return langs; } Index: src/frontends/controllers/helper_funcs.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/helper_funcs.h,v retrieving revision 1.24 diff -u -p -r1.24 helper_funcs.h --- src/frontends/controllers/helper_funcs.h 19 May 2004 15:11:31 -0000 1.24 +++ src/frontends/controllers/helper_funcs.h 22 Jul 2004 18:01:54 -0000 @@ -13,6 +13,8 @@ #define HELPERFUNCS_H #include <boost/bind.hpp> +#include <boost/iterator/transform_iterator.hpp> + #include <utility> #include <vector> #include <string> @@ -79,17 +81,16 @@ browseDir(std::string const & pathname, /// Returns a vector of units that can be used to create a valid LaTeX length. std::vector<std::string> const getLatexUnits(); - -/** Functions to extract vectors of the first and second elems from a - vector<pair<A,B> > -*/ template<class Pair> std::vector<typename Pair::first_type> const getFirst(std::vector<Pair> const & pr) { - std::vector<typename Pair::first_type> tmp(pr.size()); - std::transform(pr.begin(), pr.end(), tmp.begin(), - boost::bind(&Pair::first, _1)); + std::vector<typename Pair::first_type> tmp( + boost::make_transform_iterator(pr.begin(), + boost::bind(&Pair::first, _1)), + boost::make_transform_iterator(pr.end(), + boost::bind(&Pair::first, _1)) + ); return tmp; } @@ -97,9 +98,12 @@ template<class Pair> std::vector<typename Pair::second_type> const getSecond(std::vector<Pair> const & pr) { - std::vector<typename Pair::second_type> tmp(pr.size()); - std::transform(pr.begin(), pr.end(), tmp.begin(), - boost::bind(&Pair::second, _1)); + std::vector<typename Pair::second_type> tmp( + boost::make_transform_iterator(pr.begin(), + boost::bind(&Pair::second, _1)), + boost::make_transform_iterator(pr.end(), + boost::bind(&Pair::second, _1)) + ); return tmp; } Index: src/frontends/gnome/Dialogs3.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/gnome/Dialogs3.C,v retrieving revision 1.3 diff -u -p -r1.3 Dialogs3.C --- src/frontends/gnome/Dialogs3.C 3 Apr 2004 08:37:09 -0000 1.3 +++ src/frontends/gnome/Dialogs3.C 22 Jul 2004 18:01:54 -0000 @@ -49,6 +49,11 @@ #include "gnomeBC.h" #include "ButtonController.h" +#include <boost/bind.hpp> + +using boost::bind; + +using std::equal_to; typedef ButtonController<OkCancelPolicy, gnomeBC> OkCancelBC; @@ -69,23 +74,15 @@ char const * const dialognames[] = { "bi char const * const * const end_dialognames = dialognames + (sizeof(dialognames) / sizeof(char *)); -struct cmpCStr { - cmpCStr(char const * name) : name_(name) {} - bool operator()(char const * other) { - return strcmp(other, name_) == 0; - } -private: - char const * name_; -}; - - } // namespace anon bool Dialogs::isValidName(string const & name) const { return std::find_if(dialognames, end_dialognames, - cmpCStr(name.c_str())) != end_dialognames; + bind(equal_to<string>(), + _1, + name)) != end_dialognames; } Index: src/frontends/gtk/Dialogs.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/gtk/Dialogs.C,v retrieving revision 1.18 diff -u -p -r1.18 Dialogs.C --- src/frontends/gtk/Dialogs.C 19 May 2004 15:11:32 -0000 1.18 +++ src/frontends/gtk/Dialogs.C 22 Jul 2004 18:01:54 -0000 @@ -113,9 +113,14 @@ #include "ams_nrel.xbm" #include "ams_ops.xbm" +#include <boost/bind.hpp> #include <boost/assert.hpp> + #include <vector> +using boost::bind; + +using std::equal_to; using std::string; using namespace lyx::frontend; @@ -150,22 +155,15 @@ char const * const dialognames[] = { char const * const * const end_dialognames = dialognames + (sizeof(dialognames) / sizeof(char *)); -struct cmpCStr { - cmpCStr(char const * name) : name_(name) {} - bool operator()(char const * other) { - return strcmp(other, name_) == 0; - } -private: - char const * name_; -}; - } // namespace anon bool Dialogs::isValidName(string const & name) const { return std::find_if(dialognames, end_dialognames, - cmpCStr(name.c_str())) != end_dialognames; + bind(equal_to<string>(), + _1, + name)) != end_dialognames; } Index: src/frontends/qt2/Dialogs.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/Dialogs.C,v retrieving revision 1.111 diff -u -p -r1.111 Dialogs.C --- src/frontends/qt2/Dialogs.C 19 May 2004 15:11:33 -0000 1.111 +++ src/frontends/qt2/Dialogs.C 22 Jul 2004 18:01:54 -0000 @@ -91,8 +91,11 @@ #include "qt_helpers.h" +#include <boost/bind.hpp> #include <boost/assert.hpp> +using boost::bind; +using std::equal_to; using std::string; using namespace lyx::frontend; @@ -115,23 +118,15 @@ char const * const dialognames[] = { char const * const * const end_dialognames = dialognames + (sizeof(dialognames) / sizeof(char *)); -struct cmpCStr { - cmpCStr(char const * name) : name_(name) {} - bool operator()(char const * other) { - return strcmp(other, name_) == 0; - } -private: - char const * name_; -}; - - } // namespace anon bool Dialogs::isValidName(string const & name) const { return std::find_if(dialognames, end_dialognames, - cmpCStr(name.c_str())) != end_dialognames; + bind(equal_to<string>(), + _1, + name)) != end_dialognames; } Index: src/frontends/qt2/QLImage.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QLImage.C,v retrieving revision 1.33 diff -u -p -r1.33 QLImage.C --- src/frontends/qt2/QLImage.C 20 May 2004 09:36:27 -0000 1.33 +++ src/frontends/qt2/QLImage.C 22 Jul 2004 18:01:54 -0000 @@ -20,16 +20,19 @@ #include "graphics/GraphicsParams.h" #include "support/lstrings.h" // lowercase -#include "support/lyxfunctional.h" // compare_memfun #include <qimage.h> #include <qpainter.h> +#include <boost/bind.hpp> #include <boost/tuple/tuple.hpp> using lyx::support::lowercase; +using boost::bind; + using std::endl; +using std::equal_to; using std::find_if; using std::string; @@ -75,7 +78,10 @@ Image::FormatList QLImage::loadableForma ext = "jpg"; Formats::const_iterator fit = - find_if(begin, end, lyx::compare_memfun(&Format::extension, ext)); + find_if(begin, end, + bind(equal_to<string>(), + bind(&Format::extension, _1), + ext)); if (fit != end) fmts.push_back(fit->name()); } Index: src/frontends/xforms/Dialogs.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/Dialogs.C,v retrieving revision 1.132 diff -u -p -r1.132 Dialogs.C --- src/frontends/xforms/Dialogs.C 19 May 2004 15:11:35 -0000 1.132 +++ src/frontends/xforms/Dialogs.C 22 Jul 2004 18:01:54 -0000 @@ -109,9 +109,12 @@ #include "ams_nrel.xbm" #include "ams_ops.xbm" +#include <boost/bind.hpp> #include <boost/assert.hpp> +using boost::bind; +using std::equal_to; using std::string; using namespace lyx::frontend; @@ -146,22 +149,15 @@ char const * const dialognames[] = { char const * const * const end_dialognames = dialognames + (sizeof(dialognames) / sizeof(char *)); -struct cmpCStr { - cmpCStr(char const * name) : name_(name) {} - bool operator()(char const * other) { - return strcmp(other, name_) == 0; - } -private: - char const * name_; -}; - } // namespace anon bool Dialogs::isValidName(string const & name) const { return std::find_if(dialognames, end_dialognames, - cmpCStr(name.c_str())) != end_dialognames; + bind(equal_to<string>(), + _1, + name)) != end_dialognames; } Index: src/frontends/xforms/FormDocument.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/FormDocument.C,v retrieving revision 1.173 diff -u -p -r1.173 FormDocument.C --- src/frontends/xforms/FormDocument.C 19 May 2004 15:11:35 -0000 1.173 +++ src/frontends/xforms/FormDocument.C 22 Jul 2004 18:01:55 -0000 @@ -1032,7 +1032,7 @@ bool FormDocument::options_apply(BufferP params.cite_engine = biblio::ENGINE_JURABIB; break; } - + params.use_bibtopic = fl_get_button(options_->check_bibtopic); int tmpchar = int(fl_get_counter_value(options_->counter_secnumdepth)); Index: src/frontends/xforms/FormVSpace.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/FormVSpace.C,v retrieving revision 1.8 diff -u -p -r1.8 FormVSpace.C --- src/frontends/xforms/FormVSpace.C 19 May 2004 15:11:36 -0000 1.8 +++ src/frontends/xforms/FormVSpace.C 22 Jul 2004 18:01:55 -0000 @@ -38,7 +38,6 @@ using boost::bind; using std::remove_if; - using std::vector; using std::string; Index: src/frontends/xforms/RadioButtonGroup.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/RadioButtonGroup.C,v retrieving revision 1.31 diff -u -p -r1.31 RadioButtonGroup.C --- src/frontends/xforms/RadioButtonGroup.C 19 May 2004 15:11:36 -0000 1.31 +++ src/frontends/xforms/RadioButtonGroup.C 22 Jul 2004 18:01:55 -0000 @@ -17,13 +17,15 @@ #include "debug.h" -#include "support/lyxfunctional.h" - #include "lyx_forms.h" #include <boost/assert.hpp> +#include <boost/bind.hpp> + +using boost::bind; using std::endl; +using std::equal_to; namespace lyx { namespace frontend { @@ -43,8 +45,9 @@ void RadioButtonGroup::set(size_type val { ButtonValueMap::const_iterator it = find_if(map.begin(), map.end(), - lyx::equal_2nd_in_pair<ButtonValuePair>(value)); - + bind(equal_to<size_type>(), + bind(&ButtonValueMap::value_type::second, _1), + value)); if (it != map.end()) { fl_set_button(it->first, 1); } else { Index: src/frontends/xforms/xformsImage.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/xformsImage.C,v retrieving revision 1.37 diff -u -p -r1.37 xformsImage.C --- src/frontends/xforms/xformsImage.C 19 May 2004 15:11:37 -0000 1.37 +++ src/frontends/xforms/xformsImage.C 22 Jul 2004 18:01:56 -0000 @@ -20,7 +20,6 @@ #include "graphics/GraphicsParams.h" #include "support/lstrings.h" -#include "support/lyxfunctional.h" // compare_memfun #include "support/lyxlib.h" #include "lyx_forms.h" @@ -33,6 +32,7 @@ # endif #endif +#include <boost/bind.hpp> #include <boost/tuple/tuple.hpp> using lyx::frontend::getRGBColor; @@ -41,6 +41,9 @@ using lyx::support::float_equal; using lyx::support::prefixIs; using lyx::support::rtrim; +using boost::bind; + +using std::equal_to; using std::find_if; using std::string; @@ -104,7 +107,9 @@ Image::FormatList xformsImage::loadableF Formats::const_iterator it = find_if(begin, end, - lyx::compare_memfun(&Format::extension, ext)); + bind(equal_to<string>(), + bind(&Format::extension, _1), + ext)); if (it != end) fmts.push_back(it->name()); } Index: src/graphics/PreviewLoader.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/graphics/PreviewLoader.C,v retrieving revision 1.77 diff -u -p -r1.77 PreviewLoader.C --- src/graphics/PreviewLoader.C 16 Apr 2004 14:34:41 -0000 1.77 +++ src/graphics/PreviewLoader.C 22 Jul 2004 18:01:56 -0000 @@ -43,7 +43,10 @@ namespace support = lyx::support; +using boost::bind; + using std::endl; +using std::equal_to; using std::find; using std::fill; using std::find_if; @@ -79,18 +82,6 @@ Converter const * setConverter(); void setAscentFractions(vector<double> & ascent_fractions, string const & metrics_file); -class FindFirst : public std::unary_function<StrPair, bool> { -public: - FindFirst(string const & comp) : comp_(comp) {} - bool operator()(StrPair const & sp) const - { - return sp.first == comp_; - } -private: - string const comp_; -}; - - /// Store info on a currently executing, forked process. struct InProgress { /// @@ -356,7 +347,10 @@ public: BitmapFile const & snippets = process.second.snippets; BitmapFile::const_iterator beg = snippets.begin(); BitmapFile::const_iterator end = snippets.end(); - return find_if(beg, end, FindFirst(snippet_)) != end; + return find_if(beg, end, + bind(equal_to<string>(), + bind(&StrPair::first, _1), + snippet_)) != end; } private: @@ -407,6 +401,9 @@ void PreviewLoader::Impl::add(string con namespace { +// Is this really nice? A functor with side effects! +// should be split into two operations: one to find what to erase, +// and the other doing the actual erase. (Lgb) struct EraseSnippet { EraseSnippet(string const & s) : snippet_(s) {} void operator()(InProgressProcess & process) @@ -415,9 +412,12 @@ struct EraseSnippet { BitmapFile::iterator it = snippets.begin(); BitmapFile::iterator end = snippets.end(); - it = find_if(it, end, FindFirst(snippet_)); + it = find_if(it, end, + bind(equal_to<string>(), + bind(&StrPair::first, _1), + snippet_)); if (it != end) - snippets.erase(it, it+1); + snippets.erase(it); } private: Index: src/support/Makefile.am =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/Makefile.am,v retrieving revision 1.74 diff -u -p -r1.74 Makefile.am --- src/support/Makefile.am 27 May 2004 07:41:51 -0000 1.74 +++ src/support/Makefile.am 22 Jul 2004 18:01:56 -0000 @@ -44,7 +44,6 @@ libsupport_la_SOURCES = \ lstrings.C \ lstrings.h \ lyxalgo.h \ - lyxfunctional.h \ lyxlib.h \ lyxmanip.h \ lyxtime.C \ Index: src/support/forkedcontr.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/forkedcontr.C,v retrieving revision 1.22 diff -u -p -r1.22 forkedcontr.C --- src/support/forkedcontr.C 27 Mar 2004 18:50:49 -0000 1.22 +++ src/support/forkedcontr.C 22 Jul 2004 18:01:57 -0000 @@ -16,10 +16,9 @@ #include "forkedcontr.h" #include "forkedcall.h" -#include "lyxfunctional.h" - #include "debug.h" +#include <boost/bind.hpp> #include <boost/iterator/indirect_iterator.hpp> #include <cerrno> @@ -28,6 +27,7 @@ #include <sys/wait.h> using std::endl; +using std::equal_to; using std::find_if; using std::string; @@ -229,8 +229,9 @@ ForkedcallsController::iterator Forkedca iterator begin = boost::make_indirect_iterator(forkedCalls.begin()); iterator end = boost::make_indirect_iterator(forkedCalls.end()); iterator it = find_if(begin, end, - lyx::compare_memfun(&Forkedcall::pid, pid)); - + bind(equal_to<pid_t>(), + bind(&Forkedcall::pid, _1), + pid)); return it.base(); } Index: src/support/lstrings.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/lstrings.C,v retrieving revision 1.85 diff -u -p -r1.85 lstrings.C --- src/support/lstrings.C 1 Feb 2004 12:46:13 -0000 1.85 +++ src/support/lstrings.C 22 Jul 2004 18:01:57 -0000 @@ -19,6 +19,7 @@ #include <boost/tokenizer.hpp> #include <boost/assert.hpp> +#include <boost/bind.hpp> #include <boost/format.hpp> #include <algorithm> @@ -26,6 +27,8 @@ #include <cctype> #include <cstdlib> +using boost::bind; + using std::transform; using std::string; using std::vector; @@ -236,39 +239,37 @@ char uppercase(char c) namespace { // since we cannot use std::tolower and std::toupper directly in the -// calls to std::transform yet, we use these helper clases. (Lgb) +// calls to std::transform yet, we use these helper funcs. (Lgb) +// (I'd like to see a nice explanation why this is. (Lgb)) -struct local_lowercase { - char operator()(char c) const { - return tolower(c); - } -}; +inline +char my_tolower(char c) +{ + return tolower(c); +} -struct local_uppercase { - char operator()(char c) const { - return toupper(c); - } -}; -struct local_ascii_lowercase { - char operator()(char c) const { - return ascii_tolower(c); - } -}; +inline +char my_toupper(char c) +{ + return toupper(c); +} } // end of anon namespace string const lowercase(string const & a) { string tmp(a); - transform(tmp.begin(), tmp.end(), tmp.begin(), local_lowercase()); + transform(tmp.begin(), tmp.end(), tmp.begin(), + my_tolower); return tmp; } string const uppercase(string const & a) { string tmp(a); - transform(tmp.begin(), tmp.end(), tmp.begin(), local_uppercase()); + transform(tmp.begin(), tmp.end(), tmp.begin(), + my_toupper); return tmp; } @@ -277,7 +278,7 @@ string const ascii_lowercase(string cons { string tmp(a); transform(tmp.begin(), tmp.end(), tmp.begin(), - local_ascii_lowercase()); + ascii_tolower); return tmp; } Index: src/support/lyxalgo.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/lyxalgo.h,v retrieving revision 1.15 diff -u -p -r1.15 lyxalgo.h --- src/support/lyxalgo.h 31 Jan 2004 15:30:24 -0000 1.15 +++ src/support/lyxalgo.h 22 Jul 2004 18:01:57 -0000 @@ -14,7 +14,6 @@ #ifndef LYX_ALGO_H #define LYX_ALGO_H -#include <utility> #include <iterator> #include <algorithm> @@ -46,14 +45,6 @@ bool sorted(For first, For last, Cmp cmp } return true; } - - -struct firster { - template <class P1, class P2> - P1 operator()(std::pair<P1, P2> const & p) { - return p.first; - } -}; /** Index: src/support/lyxfunctional.h =================================================================== RCS file: src/support/lyxfunctional.h diff -N src/support/lyxfunctional.h --- src/support/lyxfunctional.h 23 Aug 2003 00:16:57 -0000 1.17 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,215 +0,0 @@ -// -*- C++ -*- -/** - * \file lyxfunctional.h - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Lars Gullik Bjønnes - * - * Full author contact details are available in file CREDITS. - * - * \brief Convenient function objects for use with LyX - * - * This is currently a small collection of small function objects for use - * together with std::algorithms. - */ - - -#ifndef LYX_FUNCTIONAL_H -#define LYX_FUNCTIONAL_H - -#include <iterator> - -namespace lyx { - -template <class Cont, class Type, class MemRet> -class back_insert_fun_iterator { -protected: - Cont * container; - MemRet(Type::*pmf)(); -public: - typedef Cont container_type; - typedef std::output_iterator_tag iterator_category; - typedef void value_type; - typedef void difference_type; - typedef void pointer; - typedef void reference; - - back_insert_fun_iterator(Cont & x, MemRet(Type::*p)()) - : container(&x), pmf(p) {} - - back_insert_fun_iterator & - operator=(Type * val) { - container->push_back((val->*pmf)()); - return *this; - } - - back_insert_fun_iterator & - operator=(Type & val) { - container->push_back((val.*pmf)()); - return *this; - } - - back_insert_fun_iterator & operator*() { - return *this; - } - back_insert_fun_iterator & operator++() { // prefix ++ - return *this; - } - back_insert_fun_iterator & operator++(int) { // postfix ++ - return *this; - } -}; - - -template <class Cont, class Type, class MemRet> -class const_back_insert_fun_iterator { -protected: - Cont * container; - MemRet(Type::*pmf)() const; -public: - typedef Cont container_type; - typedef std::output_iterator_tag iterator_category; - typedef void value_type; - typedef void difference_type; - typedef void pointer; - typedef void reference; - - const_back_insert_fun_iterator(Cont & x, MemRet(Type::*p)() const) - : container(&x), pmf(p) {} - - ~const_back_insert_fun_iterator() {} - - const_back_insert_fun_iterator & - operator=(Type const * val) { - container->push_back((val->*pmf)()); - return *this; - } - - const_back_insert_fun_iterator & - operator=(Type const & val) { - container->push_back((val.*pmf)()); - return *this; - } - - const_back_insert_fun_iterator & operator*() { - return *this; - } - const_back_insert_fun_iterator & operator++() { // prefix ++ - return *this; - } - const_back_insert_fun_iterator & operator++(int) { // postfix ++ - return *this; - } -}; - - -template <class Cont, class Type, class MemRet> -back_insert_fun_iterator<Cont, Type, MemRet> -back_inserter_fun(Cont & cont, MemRet(Type::*p)()) -{ - return back_insert_fun_iterator<Cont, Type, MemRet>(cont, p); -} - - -template <class Cont, class Type, class MemRet> -const_back_insert_fun_iterator<Cont, Type, MemRet> -back_inserter_fun(Cont & cont, MemRet(Type::*p)() const) -{ - return const_back_insert_fun_iterator<Cont, Type, MemRet>(cont, p); -} - - -template <class R, class C, class A> -class compare_memfun_t { -public: - compare_memfun_t(R(C::*p)(), A const & a) - : pmf(p), arg(a) {} - bool operator()(C * c) { - return (c->*pmf)() == arg; - } - bool operator()(C & c) { - return (c.*pmf)() == arg; - } -private: - R(C::*pmf)(); - A const & arg; -}; - - -template <class R, class C, class A> -class const_compare_memfun_t { -public: - const_compare_memfun_t(R(C::*p)() const, A const & a) - : pmf(p), arg(a) {} - bool operator()(C const * c) { - return (c->*pmf)() == arg; - } - bool operator()(C const & c) { - return (c.*pmf)() == arg; - } -private: - R(C::*pmf)() const; - A const & arg; -}; - - -template <class R, class C, class A> -compare_memfun_t<R, C, A> -compare_memfun(R(C::*p)(), A const & a) -{ - return compare_memfun_t<R, C, A>(p, a); -} - - -template <class R, class C, class A> -const_compare_memfun_t<R, C, A> -compare_memfun(R(C::*p)() const, A const & a) -{ - return const_compare_memfun_t<R, C, A>(p, a); -} - - -// Functors used in the template. - -/// -template<typename T> -class equal_1st_in_pair { -public: - /// - typedef typename T::first_type first_type; - /// - typedef T pair_type; - /// - equal_1st_in_pair(first_type const & value) : value_(value) {} - /// - bool operator() (pair_type const & p) const { - return p.first == value_; - } -private: - /// - first_type const & value_; -}; - - -/// -template<typename T> -class equal_2nd_in_pair { -public: - /// - typedef typename T::second_type second_type; - /// - typedef T pair_type; - /// - equal_2nd_in_pair(second_type const & value) : value_(value) {} - /// - bool operator() (pair_type const & p) const { - return p.second == value_; - } -private: - /// - second_type const & value_; -}; - -} // end of namespace lyx -#endif Index: src/support/translator.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/translator.h,v retrieving revision 1.20 diff -u -p -r1.20 translator.h --- src/support/translator.h 25 Sep 2003 10:49:13 -0000 1.20 +++ src/support/translator.h 22 Jul 2004 18:01:57 -0000 @@ -14,12 +14,13 @@ #include <boost/assert.hpp> +#include <boost/bind.hpp> + #include <vector> #include <utility> #include <algorithm> #include <functional> -#include "support/lyxfunctional.h" /** * This class template is used to translate between two elements, specifically * it was worked out to translate between an enum and strings when reading @@ -62,7 +63,9 @@ public: // For explanation see the next find() function. typename Map::const_iterator it = std::find_if(map.begin(), map.end(), - lyx::equal_1st_in_pair<MapPair>(first) + boost::bind(std::equal_to<T1>(), + boost::bind(&MapPair::first, _1), + first) ); if (it != map.end()) { @@ -89,7 +92,9 @@ public: // equal_to(select2nd(pair) , second) typename Map::const_iterator it = std::find_if(map.begin(), map.end(), - lyx::equal_2nd_in_pair<MapPair>(second) + boost::bind(std::equal_to<T2>(), + boost::bind(&MapPair::second, _1), + second) ); if (it != map.end()) Index: src/tex2lyx/text.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/tex2lyx/text.C,v retrieving revision 1.38 diff -u -p -r1.38 text.C --- src/tex2lyx/text.C 28 Jun 2004 06:53:12 -0000 1.38 +++ src/tex2lyx/text.C 22 Jul 2004 18:02:02 -0000 @@ -21,6 +21,8 @@ #include "support/tostr.h" #include "support/filetools.h" +#include <boost/iterator/indirect_iterator.hpp> + #include <iostream> #include <map> #include <sstream> @@ -31,9 +33,10 @@ using lyx::support::suffixIs; using lyx::support::contains; using lyx::support::subst; +using boost::make_indirect_iterator; + using std::cerr; using std::endl; - using std::map; using std::ostream; using std::ostringstream; @@ -325,11 +328,11 @@ void handle_comment(ostream & os, string } -class isLayout : public std::unary_function<LyXLayout_ptr, bool> { +class isLayout : public std::unary_function<LyXLayout, bool> { public: isLayout(string const name) : name_(name) {} - bool operator()(LyXLayout_ptr const & ptr) const { - return ptr->latexname() == name_; + bool operator()(LyXLayout const & ll) const { + return ll.latexname() == name_; } private: string const name_; @@ -341,9 +344,10 @@ LyXLayout_ptr findLayout(LyXTextClass co { LyXTextClass::const_iterator beg = textclass.begin(); LyXTextClass::const_iterator end = textclass.end(); - LyXTextClass::const_iterator - it = std::find_if(beg, end, isLayout(name)); + it = std::find_if(make_indirect_iterator(it), + make_indirect_iterator(end), + isLayout(name)).base(); return (it == end) ? LyXLayout_ptr() : *it; } > > > -- > Lgb --