]> git.lyx.org Git - lyx.git/blobdiff - src/support/lyxfunctional.h
remove !NEW_INSETS cruft
[lyx.git] / src / support / lyxfunctional.h
index 262ca4e007120b44c8503635641e01e8e978671b..94c8504418471879ae2d75c7cafa2db4d9f50ae4 100644 (file)
@@ -3,7 +3,17 @@
 #ifndef LYX_FUNCTIONAL_H
 #define LYX_FUNCTIONAL_H
 
-//namespace lyx {
+/** \file lyxfunctional.h
+    \brief Convenient function objects for use with LyX
+    
+    This is currently a small collection of small function objects for use
+    together with std::algorithms.
+**/
+
+#include <iterator>
+
+namespace lyx {
+
 
 template<class R, class C, class A>
 class class_fun_t {
@@ -32,7 +42,16 @@ private:
        void(C::*cmf)(A);
 };
 
-       
+
+/// Use to call a class method with a container element.
+/** Most easily used as a functor to std::algoritms.
+    Small example:
+    \verbatim
+    A a; // class that have a int print(string const &) method
+    vector<string> vs;
+    for_each(vs.begin(), vs.end(), class_fun(int, vs, &A::print);
+    \endverbatim
+**/
 template <class R, class C, class A> class_fun_t<R, C, A>
 class_fun(C & c, R(C::*f)(A))
 {
@@ -50,21 +69,28 @@ class_fun(C & c, void(C::*f)(A))
 template <class Cont, class Type, class MemRet>
 class back_insert_fun_iterator {
 protected:
-       Cont & container;
+       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) {}
+               : container(&x), pmf(p) {}
 
        back_insert_fun_iterator &
        operator=(Type * val) {
-               container.push_back((val->*pmf)());
+               container->push_back((val->*pmf)());
                return *this;
        }
 
        back_insert_fun_iterator &
        operator=(Type & val) {
-               container.push_back((val.*pmf)());
+               container->push_back((val.*pmf)());
                return *this;
        }
 
@@ -83,21 +109,30 @@ public:
 template <class Cont, class Type, class MemRet>
 class const_back_insert_fun_iterator {
 protected:
-       Cont & container;
+       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) {}
-
+               : container(&x), pmf(p) {}
+       
+       ~const_back_insert_fun_iterator() {}
+      
        const_back_insert_fun_iterator &
        operator=(Type const * val) {
-               container.push_back((val->*pmf)());
+               container->push_back((val->*pmf)());
                return *this;
        }
 
        const_back_insert_fun_iterator &
        operator=(Type const & val) {
-               container.push_back((val.*pmf)());
+               container->push_back((val.*pmf)());
                return *this;
        }
 
@@ -216,6 +251,5 @@ private:
        T2 const & value_;
 };
 
-
-// }  // end of namespace lyx
+}  // end of namespace lyx
 #endif