diff options
author | Thorsten Behrens <tbehrens@novell.com> | 2011-02-08 20:25:25 +0100 |
---|---|---|
committer | Thorsten Behrens <tbehrens@novell.com> | 2011-02-08 20:26:26 +0100 |
commit | b14a690506b0786083714489099bc995a464df97 (patch) | |
tree | 669783a5393d0fcc14b15308127e0c5053d85b75 /o3tl | |
parent | 52c63c207dc0d6f5569953bb351f2cbf2cd3c33d (diff) |
Added iota to stl compat header, switch canvas to use that
Diffstat (limited to 'o3tl')
-rw-r--r-- | o3tl/inc/o3tl/compat_functional.hxx | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/o3tl/inc/o3tl/compat_functional.hxx b/o3tl/inc/o3tl/compat_functional.hxx index 40c78ff9b449..00ae33cb23bb 100644 --- a/o3tl/inc/o3tl/compat_functional.hxx +++ b/o3tl/inc/o3tl/compat_functional.hxx @@ -25,7 +25,8 @@ */ /* - * Lifted and paraphrased from STLport + * Lifted and paraphrased from STLport - with additions from Fridrich + * Strba and Thorsten Behrens */ #ifndef INCLUDED_O3TL_COMPAT_FUNCTIONAL_HXX @@ -36,6 +37,7 @@ namespace o3tl { +/// Identity functor - return the input value template<class T> struct identity : public std::unary_function<T, T> { @@ -45,6 +47,7 @@ struct identity : public std::unary_function<T, T> } }; +/// Functor, given two parameters, return the first template<class T1,class T2> struct project1st : public std::binary_function<T1, T2, T1> { @@ -54,6 +57,7 @@ struct project1st : public std::binary_function<T1, T2, T1> } }; +/// Functor, given two parameters, return the second template<class T1,class T2> struct project2nd : public std::binary_function<T1, T2, T2> { @@ -63,6 +67,7 @@ struct project2nd : public std::binary_function<T1, T2, T2> } }; +/// Select first value of a pair template<class P> struct select1st : public std::unary_function<P, typename P::first_type> { @@ -72,6 +77,7 @@ struct select1st : public std::unary_function<P, typename P::first_type> } }; +/// Select second value of a pair template<class P> struct select2nd : public std::unary_function<P, typename P::second_type> { @@ -81,6 +87,7 @@ struct select2nd : public std::unary_function<P, typename P::second_type> } }; +/// Call F1 with the result of F2 applied to the one input parameter template<class F1, class F2> class unary_compose : public std::unary_function<typename F2::argument_type, typename F1::result_type> { @@ -97,12 +104,14 @@ class unary_compose : public std::unary_function<typename F2::argument_type, typ F2 ftor2; }; +/// Create functor that calls F1 with the result of F2 applied to the one input parameter template<class F1, class F2> inline unary_compose<F1, F2> compose1(const F1& fnction1, const F2& fnction2) { return (unary_compose<F1, F2>(fnction1, fnction2)); } +/// Calls F2 and F3 for the two args of F1, respectively template<class F1, class F2, class F3> class binary_compose : public std::unary_function<typename F2::argument_type,typename F1::result_type> { @@ -120,12 +129,21 @@ class binary_compose : public std::unary_function<typename F2::argument_type,typ F3 ftor3; }; +/// Creates functor that calls F2 and F3 for the two args of F1, respectively template<class F1, class F2, class F3> inline binary_compose<F1, F2, F3> compose2(const F1& fnction1, const F2& fnction2, const F3& fnction3) { return (binary_compose<F1, F2, F3>(fnction1, fnction2, fnction3)); } +/// Algo that assigns val, val+1, ... to the given range +template<typename FwdIter, typename ValueType> +inline void iota(FwdIter first, FwdIter last, ValueType val) +{ + while(first != last) + *first++ = val++; +} + } // namespace o3tl #endif |