vector.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002     
00003     vector.hpp -- template class vector definition and relative operations.
00004 
00005     This file is a part of the Arageli library.
00006 
00007     Copyright (C) Nikolai Yu. Zolotykh, 1999--2006
00008     Copyright (C) Sergey S. Lyalin, 2005
00009     University of Nizhni Novgorod, Russia
00010 
00011 *****************************************************************************/
00012 
00013 
00027 #ifndef _ARAGELI_vector_hpp_
00028 #define _ARAGELI_vector_hpp_
00029 
00030 #include "config.hpp"
00031 
00032 #include <cstddef>
00033 #include <vector>
00034 #include <iostream>
00035 #include <fstream>  // for temporary implementation of input/output
00036 #include <sstream>  // for temporary implementation of input/output
00037 #include <limits>
00038 #include <cmath>
00039 #include <algorithm>
00040 
00041 #include "frwrddecl.hpp"
00042 
00043 #include "type_opers.hpp"
00044 #include "type_traits.hpp"
00045 #include "type_pair_traits.hpp"
00046 #include "function_traits.hpp"
00047 #include "mixcomp.hpp"
00048 #include "exception.hpp"
00049 #include "vecalg.hpp"
00050 #include "refcntr.hpp"
00051 #include "_utility.hpp"
00052 #include "factory.hpp"
00053 #include "cmp.hpp"
00054 #include "io.hpp"
00055 #include "functional.hpp"
00056 #include "big_int.hpp"
00057 
00058 #include "subvector/indexed.hpp"
00059 
00060 #include "std_import.hpp"
00061 
00062 
00063 namespace Arageli
00064 {
00065 
00066 
00067 struct fromseq_t {};
00068 const fromseq_t fromseq = fromseq_t();
00069 
00070 struct fromval_t {};
00071 const fromval_t fromval = fromval_t();
00072 
00073 struct fromvec_t {};
00074 const fromvec_t fromvec = fromvec_t();
00075 
00076 struct fromsize_t {};
00077 const fromsize_t fromsize = fromsize_t();
00078 
00079 struct fromstr_t {};
00080 const fromstr_t fromstr = fromstr_t();
00081 
00082 
00083 template <typename T, bool REFCNT, typename Index>
00084 struct binary_function_traits
00085     <function_tag::subscript, vector<T, REFCNT>, Index>
00086         : public vec_binary_function_traits
00087             <vector<T, REFCNT>, Index>
00088 {};
00089 
00090 template <typename T, bool REFCNT, typename Index>
00091 struct binary_function_traits
00092     <function_tag::subscript, const vector<T, REFCNT>, Index>
00093         : public vec_binary_function_traits
00094             <const vector<T, REFCNT>, Index>
00095 {};
00096 
00097 template <typename T, bool REFCNT, typename Index>
00098 struct binary_function_traits
00099     <function_tag::parentheses_1, vector<T, REFCNT>, Index>
00100         : public binary_function_traits
00101             <function_tag::subscript, vector<T, REFCNT>, Index>
00102 {};
00103 
00104 template <typename T, bool REFCNT, typename Index>
00105 struct binary_function_traits
00106     <function_tag::parentheses_1, const vector<T, REFCNT>, Index>
00107         : public binary_function_traits
00108             <function_tag::subscript, const vector<T, REFCNT>, Index>
00109 {};
00110 
00111 
00112 
00113 template <typename X, bool is_assignable> struct _element_type_vec_val_1
00114 { typedef typename X::element_type type; };
00115 
00116 template <typename X> struct _element_type_vec_val_1<X, true>
00117 { typedef X type; };
00118 
00119 template <typename T, typename X> struct _element_type_vec_val
00120 {
00121     typedef typename _element_type_vec_val_1
00122         <X, type_pair_traits<X, T>::is_assignable>::type type;
00123 };
00124 
00125 
00127 
00129 template
00130 <
00131     typename T,
00132     bool REFCNT
00133 >
00134 class vector
00135 {
00136     template <typename T1, bool REFCNT1>
00137     friend class vector;
00138     
00139     // Rep -- the internal representation of vector values;
00140     // std::vector -- temporary decision, we need more light-weight
00141     // vector contatiner (like native array of std::valarray).
00142     
00143     typedef std::vector<T> Rep;
00144 
00145 public:
00146 
00147 
00148     // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00150 
00151 
00153 
00155     typedef typename Rep::value_type value_type;
00156     
00158     typedef typename Rep::value_type element_type;
00159 
00161     typedef typename Rep::reference reference;
00162 
00164     typedef typename Rep::const_reference const_reference;
00165     
00167 
00168     typedef typename Rep::size_type size_type;
00169 
00171     typedef typename Rep::difference_type difference_type;
00172     
00174     typedef typename Rep::pointer pointer;
00175 
00177     typedef typename Rep::const_pointer const_pointer;
00178 
00180     typedef typename Rep::iterator iterator;
00181 
00183     typedef typename Rep::const_iterator const_iterator;
00184 
00186     //typedef typename Rep::reverse_iterator reverse_iterator;
00187 
00189     //typedef typename Rep::const_reverse_iterator const_reverse_iterator;
00190 
00192 
00193 
00195     template <typename T1> struct other_element_type
00196     { typedef vector<T1, REFCNT> type; };
00197 
00199     template <typename T1, bool REFCNT1> struct other_element_type_refcnt
00200     { typedef vector<T1, REFCNT1> type; };
00201 
00203 
00204     static const bool refcounting = REFCNT;
00205 
00206 
00207     // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00209     
00210     
00212 
00214     vector () {}
00215 
00216     // BE CAREFUL! There is one more constructor. It is automaticaly generated
00217     // copy-constructor. Worry about its meaning is being belonged to other
00218     // constructors during modifications.
00219 
00220     // ---------------------------------
00221     
00223     vector (std::size_t size_a, const fromsize_t& select)
00224     { assign_fromsize(size_a); }
00225 
00227     vector (const char* s, const fromstr_t& select)
00228     { assign_fromstr(s); }
00229 
00231     template <typename Vec>
00232     vector (const Vec& vec, const fromvec_t& select)
00233     { assign_fromvec(vec); }
00234 
00236     template <typename X>
00237     vector (const X& x)
00238     { assign(x); }
00239 
00240     // ---------------------------------
00241 
00243     template <typename Val>
00244     vector (std::size_t size_a, const Val& val, const fromval_t& select)
00245     { assign_fromval(size_a, val); }
00246 
00248 
00249     template <typename Seq>
00250     vector (std::size_t size_a, const Seq& seq, const fromseq_t& select)
00251     { assign_fromseq(size_a, seq); }
00252 
00254     template <typename X>
00255     vector (std::size_t size_a, const X& x)
00256     { assign(size_a, x); }
00257 
00258 
00260 
00261 
00262     // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00264 
00265 
00267 
00268 
00270     void assign ()
00271     { if(unique_clear())rep().clear(); }
00272     
00274     void assign_fromsize (size_type size_a)
00275     {
00276         unique_clear();
00277         rep().assign(size_a, factory<T>::null());
00278     }
00279 
00281     void assign_fromstr (const char* s);
00282 
00284     template <typename Vec>
00285     void assign_fromvec (const Vec& vec)
00286     {
00287         unique_clear();
00288 
00289         ARAGELI_ASSERT_0
00290         (
00291             reinterpret_cast<const void*>(this) !=
00292             reinterpret_cast<const void*>(&vec)
00293         );
00294 
00295         rep().assign(vec.begin(), vec.end());
00296     }
00297 
00298 
00300     template <typename X>
00301     void assign (const X& x)
00302     { _assign_from_size_str_vec(x, type_traits<X>::category_value); }
00303 
00304 private:
00305 
00306     template <typename Size>
00307     void _assign_from_size_str_vec
00308     (const Size& size_a, const type_category::integer&)
00309     { assign_fromsize(size_a); }
00310 
00311     template <typename Str>
00312     void _assign_from_size_str_vec
00313     (const Str& s, const type_category::string&)
00314     { assign_fromstr(s); }
00315 
00316     template <typename Vec>
00317     void _assign_from_size_str_vec
00318     (const Vec& vec, const type_category::vector&)
00319     { assign_fromvec(vec); }
00320 
00321 public:
00322 
00324     template <typename X>
00325     vector& operator= (const X& x)
00326     {
00327         _assign_from_val_str_vec
00328         (
00329             x, type_traits<X>::category_value,
00330             bool_type<type_pair_traits<X, T>::is_assignable>::value
00331         );
00332         
00333         return *this;
00334     }
00335 
00336 private:
00337 
00338     template <typename Val>
00339     void _assign_from_val_str_vec
00340     (const Val& val, const type_category::type&, const true_type&)
00341     { fill_fromval(val); }
00342 
00343     template <typename Str>
00344     void _assign_from_val_str_vec
00345     (const Str& str, const type_category::string&, const false_type&)
00346     { assign_fromstr(str); }
00347 
00348     template <typename Vec>
00349     void _assign_from_val_str_vec
00350     (const Vec& vec, const type_category::vector&, const false_type&)
00351     { assign_fromvec(vec); }
00352 
00353 public:
00354 
00355     // -------------------------------------
00356 
00358     template <typename Val>
00359     void assign_fromval (size_type size_a, const Val& val)
00360     {
00361         unique_clear();
00362         rep().assign(size_a, val);
00363     }
00364 
00365 
00367     template <typename Seq>
00368     void assign_fromseq (size_type size_a, Seq seq)
00369     {
00370         unique_clear();
00371         Seq last = seq;
00372         // TODO: Make the following unrestricted.
00373         std::advance(last, size_a); // WARNING! Temporary solution.
00374         rep().assign(seq, last);
00375     }
00376 
00377 
00379     template <typename X>
00380     void assign (size_type size_a, const X& x)
00381     {
00382         _assign_from_val_seq
00383         (
00384             size_a, x,
00385             bool_type<type_pair_traits<X, T>::is_convertible>::value
00386         );
00387     }
00388 
00389     
00390 private:
00391 
00392     template <typename Val>
00393     void _assign_from_val_seq
00394     (size_type size_a, const Val& val, const true_type&)
00395     { assign_fromval(size_a, val); }
00396 
00397 
00398     template <typename Seq>
00399     void _assign_from_val_seq
00400     (size_type size_a, const Seq& seq, const false_type&)
00401     { assign_fromseq(size_a, seq); }
00402 
00403 public:
00404 
00405     // TODO: Make it faster.
00407     template <typename Val>
00408     void fill_fromval (const Val& val)
00409     { assign_fromval(size(), val); }
00410 
00411     // TODO: Make it faster.
00413     template <typename Seq>
00414     void fill_fromseq (const Seq& seq)
00415     { assign_fromseq(size(), seq); }
00416 
00417     // TODO: Make it faster.
00419     template <typename X>
00420     void fill (const X& x)
00421     {
00422         // WARNING! TEMPORARY SOLUTION!
00423         assign(size(), x);
00424     }
00425 
00426 
00428 
00429 
00430     // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00431     // @name Element access.
00432 
00433 
00435 
00437 
00438     const_reference el (size_type i) const
00439     {
00440         ARAGELI_ASSERT_0(i < size());
00441         return rep(i);
00442     }
00443     
00445 
00446     reference el (size_type i)
00447     {
00448         ARAGELI_ASSERT_0(i < size());
00449         unique();
00450         return rep(i);
00451     }
00452 
00454 
00456     const_reference at (size_type i) const
00457     {
00458         if(i > size())throw out_of_range();
00459         return el(i);
00460     }
00461     
00463 
00465     reference at (size_type i)
00466     {
00467         if(i > size())throw out_of_range();
00468         return el(i);
00469     }
00470 
00472     value_type take (size_type i)
00473     {
00474         value_type t = el(i);
00475         erase(i);
00476     }
00477 
00478     // ---------------------------------------------------------------------
00479 
00480     template <typename Vec>
00481     indexed_subvector<const vector, Vec> subvector (const Vec& vec) const
00482     { return indexed_subvector<const vector, Vec>(this, vec); }
00483     
00484     template <typename Vec>
00485     indexed_subvector<vector, Vec> subvector (const Vec& vec)
00486     { return indexed_subvector<vector, Vec>(this, vec); }
00487 
00488     template <typename Vec>
00489     indexed_subvector<const vector, Vec> subvector_at (const Vec& vec) const
00490     {
00491         if(all_in_range(vec, size_type(0), size_type(size()-1)))
00492             return subvector(vec);
00493         else
00494             throw out_of_range();
00495     }
00496     
00497     template <typename Vec>
00498     indexed_subvector<vector, Vec> subvector_at (const Vec& vec)
00499     {
00500         if(all_in_range(vec, size_type(0), size_type(size()-1)))
00501             return subvector(vec);
00502         else
00503             throw out_of_range();
00504     }
00505 
00506     // ---------------------------------------------------------------------
00507 
00509 
00510     template <typename X>
00511     typename binary_function_traits<function_tag::subscript, const vector, X>::result_type
00512     operator[] (const X& x) const
00513     {
00514         //return _operator_sqbrackets_index_vector
00515         //  (x, type_traits<X>::category_value);
00516         return vec_operator_sqbrackets_index_vector
00517             (this, x, type_traits<X>::category_value);
00518     }
00519     
00520 
00522 
00523     template <typename X>
00524     typename binary_function_traits<function_tag::subscript, vector, X>::result_type
00525     operator[] (const X& x)
00526     {
00527         //return _operator_sqbrackets_index_vector
00528         //  (x, type_traits<X>::category_value);
00529         return vec_operator_sqbrackets_index_vector
00530             (this, x, type_traits<X>::category_value);
00531     }
00532 
00533 
00535 
00536     template <typename X>
00537     typename binary_function_traits
00538         <function_tag::parentheses_1, const vector, X>::result_type
00539     operator() (const X& x) const
00540     { return operator[](x); }
00541     
00542 
00544 
00545     template <typename X>
00546     typename binary_function_traits
00547         <function_tag::parentheses_1, vector, X>::result_type
00548     operator() (const X& x)
00549     { return operator[](x); }
00550 
00551 
00552     const_reference front () const { return rep().front(); }
00553     reference front () { unique(); return rep().front(); }
00554     const_reference back () const { return rep().back(); }
00555     reference back () { unique(); return rep().back(); }
00556 
00558 
00559 
00560     // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00561     // @name Subvector access.
00562 
00564 
00566 
00569     template <typename SV, typename V>
00570     V& take_subvector (const SV& sv, V& res)
00571     {
00572         copy_subvector(sv, res);
00573         erase_subvector(sv);
00574         return res;
00575     }
00576 
00578 
00580     template <typename SV>
00581     vector<T, true> take_subvector (const SV& sv)
00582     {
00583         vector<T, true> res;
00584         return take_subvector(sv, res);
00585     }
00586 
00588     template <typename SV, typename V>
00589     V& copy_subvector (const SV& sv, V& res) const;
00590 
00592     template <typename SV>
00593     vector<T, true> copy_subvector (const SV& sv) const
00594     {
00595         vector<T, true> res;
00596         return copy_subvector(sv, res);
00597     }
00598 
00600     template <typename SV>
00601     void erase_subvector (const SV& sv);
00602 
00603     // fill_subvector
00604     // assign_subvector
00605     // apply_subvector
00606     // insert_subvector
00607     // And special versions of some functions for sorted indexes.
00608 
00610 
00611 
00612     // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00613     // Some properties access.
00614 
00615 
00617     size_type size () const { return rep().size(); }
00618 
00620 
00621     size_type length () const { return size(); }
00622     
00624 
00626     bool is_empty () const { return rep().empty(); }
00627 
00629 
00632     bool is_null () const;
00633 
00635 
00638     bool is_unit () const;
00639 
00641 
00644     bool is_opposite_unit () const;
00645 
00646 
00647     // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00648     // Capacity managing.
00649 
00650 
00652     size_type capacity () const { return rep().capacity(); }
00653 
00655     void reserve (size_type n)
00656     {
00657         unique();
00658         rep().reserve(n);
00659     }
00660 
00662 
00664     bool pack ()
00665     {
00666         if(size() != capacity())
00667         {
00668             do_pack();
00669             return true;
00670         }
00671         else return false;
00672     }
00673 
00674 
00675     // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00676     // Some modificatory operations.
00677 
00678 
00680 
00682     vector& opposite ();
00683 
00685 
00687     vector& inverse ();
00688 
00690 
00692     vector& bitwise_not ();
00693 
00695 
00697     vector& logical_not ();
00698 
00699 
00700     // TODO: Make it faster.
00702 
00703     void resize (size_type sz) { unique(); rep().resize(sz, T()); }
00704 
00705 
00706     // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00707 
00708 
00715 
00716 
00717     template <typename UOp>
00718     vector& apply (UOp f)
00719     {
00720         apply1_wores_vec(*this, f);
00721         return *this;
00722     }
00723 
00724     template <typename Val, typename BinAsnOp>
00725     vector& right_apply_val (const Val& val, BinAsnOp f)
00726     {
00727         apply2_wores_vec_by_val(*this, val, f);
00728         return *this;
00729     }
00730     
00731     template <typename Val, typename BinAsnOp>
00732     vector& left_apply_val (const Val& val, BinAsnOp f)
00733     {
00734         apply2_wores_val_by_vec(val, *this, f);
00735         return *this;
00736     }
00737 
00738     template <typename Vec, typename BinAsnOp>
00739     vector& right_apply_vec (const Vec& vec, BinAsnOp f)
00740     {
00741         apply2_wores_vec_by_vec(*this, vec, f);
00742         return *this;
00743     }
00744     
00745     template <typename Vec, typename BinAsnOp>
00746     vector& left_apply_vec (const Vec& vec, BinAsnOp f)
00747     {
00748         apply2_wores_vec_by_vec(vec, *this, f);
00749         return *this;
00750     }
00751 
00752     template <typename X, typename BinAsnOp>
00753     vector& right_apply (const X& x, BinAsnOp f)
00754     {
00755         return _right_apply_val_vec
00756         (
00757             x, f,
00758             bool_type<type_pair_traits<X, T>::is_assignable>::value
00759         );
00760     }
00761 
00762 private:
00763 
00764     template <typename X, typename BinAsnOp>
00765     vector& _right_apply_val_vec (const X& x, BinAsnOp f, const true_type&)
00766     { return right_apply_val(x, f); }
00767 
00768     template <typename X, typename BinAsnOp>
00769     vector& _right_apply_val_vec (const X& x, BinAsnOp f, const false_type&)
00770     { return right_apply_vec(x, f); }
00771 
00772 public:
00773     
00774     template <typename X, typename Binop>
00775     vector& left_apply (const X& x, Binop f)
00776     {
00777         return _left_apply_val_vec
00778         (
00779             x, f,
00780             bool_type<type_pair_traits<X, T>::is_assignable>::value
00781         );
00782     }
00783 
00784 private:
00785 
00786     template <typename X, typename BinAsnOp>
00787     vector& _left_apply_val_vec (const X& x, BinAsnOp f, const true_type&)
00788     { return left_apply_val(x, f); }
00789 
00790     template <typename X, typename BinAsnOp>
00791     vector& _left_apply_val_vec (const X& x, BinAsnOp f, const false_type&)
00792     { return left_apply_vec(x, f); }
00793 
00794 public:
00795 
00796 
00797     #define _ARAGELI_VECTOR_ASSIGN_FUNC(MNEM, OPER)                                 \
00798         template <typename Val> vector& right_assign_##MNEM##_val (const Val& val)  \
00799         { return right_apply_val(val, func::right_assign_##MNEM<T, Val, T&>()); }   \
00800         template <typename Val> vector& left_assign_##MNEM##_val (const Val& val)   \
00801         { return left_apply_val(val, func::left_assign_##MNEM<Val, T, T&>()); } \
00802         template <typename Val> vector& assign_##MNEM##_val (const Val& val)        \
00803         { return right_apply_val(val, func::assign_##MNEM<T, Val, T&>()); }     \
00804                                                                                     \
00805         template <typename Vec> vector& right_assign_##MNEM##_vec (const Vec& vec)  \
00806         { return right_apply_vec(vec, func::right_assign_##MNEM<T,                  \
00807             typename type_traits<Vec>::element_type, T&>()); }                      \
00808                                                                                     \
00809         template <typename Vec> vector& left_assign_##MNEM##_vec (const Vec& vec)   \
00810         { return left_apply_vec(vec, func::left_assign_##MNEM                       \
00811             <typename type_traits<Vec>::element_type, T, T&>()); }                  \
00812                                                                                     \
00813         template <typename Vec> vector& assign_##MNEM##_vec (const Vec& vec)        \
00814         { return right_apply_vec(vec, func::assign_##MNEM<T,                        \
00815             typename type_traits<Vec>::element_type, T&>()); }                      \
00816                                                                                     \
00817         template <typename X> vector& right_assign_##MNEM (const X& x)              \
00818         { return left_apply(x, func::right_assign_##MNEM<T,                     \
00819             typename _element_type_vec_val<T, X>::type, T&>()); }                   \
00820                                                                                     \
00821         template <typename X> vector& left_assign_##MNEM (const X& x)               \
00822         { return right_apply(x, func::left_assign_##MNEM                            \
00823             <typename _element_type_vec_val<T, X>::type, T, T&>()); }               \
00824                                                                                     \
00825         template <typename X> vector& assign_##MNEM (const X& x)                    \
00826         { return right_apply(x, func::assign_##MNEM<T,                              \
00827             typename _element_type_vec_val<T, X>::type, T&>()); }                   \
00828                                                                                     \
00829         template <typename X> vector& operator OPER (const X& x)                    \
00830         { return assign_##MNEM(x); }
00831 
00832         
00833     _ARAGELI_VECTOR_ASSIGN_FUNC(plus, +=);
00834     _ARAGELI_VECTOR_ASSIGN_FUNC(minus, -=);
00835     _ARAGELI_VECTOR_ASSIGN_FUNC(multiplies, *=);
00836     _ARAGELI_VECTOR_ASSIGN_FUNC(divides, /=);
00837     _ARAGELI_VECTOR_ASSIGN_FUNC(modulus, %=);
00838     _ARAGELI_VECTOR_ASSIGN_FUNC(bitwise_or, |=);
00839     _ARAGELI_VECTOR_ASSIGN_FUNC(bitwise_and, &=);
00840     _ARAGELI_VECTOR_ASSIGN_FUNC(bitwise_xor, ^=);
00841     _ARAGELI_VECTOR_ASSIGN_FUNC(shift_left, <<=);
00842     _ARAGELI_VECTOR_ASSIGN_FUNC(shift_right, >>=);
00843 
00844 
00846 
00847 
00848     // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00849 
00850 
00852 
00853     vector operator- () const
00854     {
00855         vector res(*this);
00856         return res.opposite();
00857     }
00858     
00860     const vector& operator+ () const { return *this; }
00861 
00863     vector operator~ () const
00864     {
00865         vector res(*this);
00866         return res.bitwise_not();
00867     }
00868 
00870     bool operator! () const { return is_null(); }
00871 
00872     vector& operator++ ()
00873     {
00874         apply1_wores_vec(*this, func::prefix_increment<T, T&>());
00875         return *this;
00876     }
00877 
00878     vector operator++ (int) { vector t = *this; operator++(); return t; }
00879 
00880     vector& operator-- ()
00881     {
00882         apply1_wores_vec(*this, func::prefix_decrement<T, T&>());
00883         return *this;
00884     }
00885 
00886     vector operator-- (int) { vector t = *this; operator--(); return t; }
00887 
00888 
00890 
00897     bool unique () { return store.unique(); }
00898     
00900 
00905     bool unique_clear () { return store.unique_clear(); }
00906     
00907 
00908     // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00910 
00915     // @{
00916 
00918 
00919     iterator begin () { unique(); return rep().begin(); }
00920     
00922 
00923     iterator end () { unique(); return rep().end(); }
00924 
00926     const_iterator begin () const { return rep().begin(); }
00927 
00929     const_iterator end () const { return rep().end(); }
00930 
00931     // @}
00932 
00933 
00934     // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00936 
00945     // @{
00946 
00947     // To developers. Be careful! Iterators passed to the functions may become
00948     // invalid after call function unique().
00949     
00951     template <typename Val>
00952     iterator insert_fromval (iterator pos, const Val& val)
00953     {
00954         // TODO: Make it faster.
00955         size_type ipos = pos - rep().begin();
00956         insert_fromval(ipos, val);
00957         return rep().begin() + ipos;
00958     }
00959     
00961     template <typename Val>
00962     void insert_fromval (size_type pos, const Val& val)
00963     {
00964         unique();
00965         rep().insert(rep().begin() + pos, val);
00966     }
00967 
00968     template <typename Vec>
00969     iterator insert_fromvec (iterator pos, const Vec& vec)
00970     {
00971         // TODO: Make it faster.
00972         size_type ipos = pos - rep().begin();
00973         insert_fromvec(ipos, vec);
00974         return rep().begin() + ipos;
00975     }
00976     
00977     template <typename Vec>
00978     void insert_fromvec (size_type pos, const Vec& vec)
00979     {
00980         // TODO: Make it faster.
00981         unique();
00982         rep().insert(rep().begin() + pos, vec.begin(), vec.end());
00983     }
00984 
00985     template <typename Str>
00986     iterator insert_fromstr (iterator pos, const Str& str)
00987     {
00988         // TODO: Make it faster.
00989         return insert_fromvec(pos, vector(str, fromstr));
00990     }
00991     
00992     template <typename Str>
00993     void insert_fromstr (size_type pos, const Str& str)
00994     {
00995         // TODO: Make it faster.
00996         insert_fromvec(pos, vector(str, fromstr));
00997     }
00998 
00999     
01000     template <typename X>
01001     iterator insert (iterator pos, const X& x)
01002     {
01003         size_type ipos = pos - rep().begin();
01004         insert(ipos, x);
01005         return rep().begin() + ipos;
01006     }
01007 
01008     template <typename X>
01009     void insert (size_type pos, const X& x)
01010     {
01011         _insert_from_val_str_vec
01012         (
01013             pos, x, type_traits<X>::category_value,
01014             bool_type<type_pair_traits<X, T>::is_assignable>::value
01015         );
01016     }
01017 
01018 private:
01019 
01020     template <typename Val>
01021     void _insert_from_val_str_vec
01022     (size_type pos, const Val& val, const type_category::type&, const true_type&)
01023     { insert_fromval(pos, val); }
01024 
01025     template <typename Str>
01026     void _insert_from_val_str_vec
01027     (size_type pos, const Str& str, const type_category::string&, const false_type&)
01028     { insert_fromstr(pos, str); }
01029 
01030     template <typename Vec>
01031     void _insert_from_val_str_vec
01032     (size_type pos, const Vec& vec, const type_category::vector&, const false_type&)
01033     { insert_fromvec(pos, vec); }
01034 
01035 public:
01036 
01037     template <typename Val>
01038     iterator insert_fromval (iterator pos, size_type size_a, const Val& val)
01039     {
01040         // TODO: Make it faster.
01041         return insert_fromvec(pos, vector(size_a, val, fromval));
01042     }
01043     
01044     template <typename Val>
01045     void insert_fromval (size_type pos, size_type size_a, const Val& val)
01046     {
01047         // TODO: Make it faster.
01048         insert_fromvec(pos, vector(size_a, val, fromval));
01049     }
01050 
01051     template <typename Seq>
01052     iterator insert_fromseq (iterator pos, size_type size_a, const Seq& seq)
01053     {
01054         // TODO: Make it faster.
01055         return insert_fromvec(pos, vector(size_a, seq, fromseq));
01056     }
01057     
01058     template <typename Seq>
01059     void insert_fromseq (size_type pos, size_type size_a, const Seq& seq)
01060     {
01061         // TODO: Make it faster.
01062         insert_fromvec(pos, vector(size_a, seq, fromseq));
01063     }
01064 
01065 
01066     template <typename X>
01067     void insert (size_type pos, size_type size_a, const X& x)
01068     {
01069         _insert_from_val_seq
01070         (
01071             pos, size_a, x,
01072             bool_type<type_pair_traits<X, T>::is_convertible>::value
01073         );
01074     }
01075 
01076 private:
01077 
01078     template <typename Val>
01079     void _insert_from_val_seq
01080     (size_type pos, size_type size_a, const Val& val, const true_type&)
01081     { insert_fromval(pos, size_a, val); }
01082 
01083     template <typename Seq>
01084     void _insert_from_val_seq
01085     (size_type pos, size_type size_a, const Seq& seq, const false_type&)
01086     { insert_fromseq(pos, size_a, seq); }
01087 
01088 public:
01089 
01091     //  before item 'pos' (it's iterator).
01092     //  All elements on and after 'pos' are shifting to back. */
01093     //template <typename In>
01094     //void insert (iterator pos, In first, In last)
01095     //{ unique(); return rep().insert(pos, first, last); }
01096 
01098     //  before item 'pos' (it's index).
01099     //  All elements on and after 'pos' are shifting to back. */
01100     //template <typename In>
01101     //void insert (size_type pos, In first, In last)
01102     //{ return insert(begin() + pos, first, last); }
01103 
01105     //  All elements on and after 'pos' are shifting to back. */
01106     //void insert (iterator pos, size_type n, const T& val)
01107     //{ unique(); rep().insert(pos, n, val); }
01108 
01110     //  All elements on and after 'pos' are shifting to back. */
01111     //void insert (size_type pos, size_type n, const T& val)
01112     //{ insert(begin() + pos, n, val); }
01113 
01115     iterator erase (iterator pos)
01116     {
01117         ARAGELI_ASSERT_0(pos != end());
01118         unique();
01119         return rep().erase(pos);
01120     }
01121     
01123     void erase (size_type pos) { erase(begin() + pos); }
01124     
01126     void erase (iterator first, iterator last)
01127     {
01128         ARAGELI_ASSERT_0(first <= last);
01129         ARAGELI_ASSERT_0(first != end() || last == end());
01130         unique(); rep().erase(first, last);
01131     }
01132     
01134     void erase (size_type pos, size_type n)
01135     { erase(begin() + pos, begin() + pos + n); }
01136 
01138     void push_back (const T& val) { unique(); rep().push_back(val); }
01139     
01141     void push_front (const T& val) { insert(begin(), val); }
01142 
01143     void pop_back ()
01144     {
01145         ARAGELI_ASSERT_0(!is_empty());
01146         unique();
01147         rep().pop_back();
01148     }
01149     
01150     void pop_front ()
01151     {
01152         ARAGELI_ASSERT_0(!is_empty());
01153         //unique();
01154         erase(size_type(0));
01155     }
01156 
01158     template <typename T2>
01159     void remove (const T2& v)
01160     { erase(std::remove(begin(), end(), v), end()); }
01161 
01163     template <typename Fu>
01164     void remove_if (Fu f)
01165     { erase(std::remove_if(begin(), end(), f), end()); }
01166 
01167     // @}
01168 
01169 
01170     // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
01172 
01173 
01174     // @{
01175 
01177     void swap_els (iterator x, iterator y)
01178     { if(x != y){ unique(); std::iter_swap(x, y); } }
01179 
01181     void swap_els (size_type xpos, size_type ypos)
01182     { if(xpos != ypos){ unique(); std::swap(el(xpos), el(ypos)); } }
01183 
01185     template <typename T1, bool REFCNT1>
01186     void swap (vector<T1, REFCNT1>& x)
01187     {
01188         _Internal::swap_help_1
01189             (*this, x, store, x.store, equal_types<T, T1>::value);
01190     }
01191 
01192     // @}
01193 
01194 
01195 private:
01196 
01197     Rep& rep () { return store.value(); }
01198     const Rep& rep () const { return store.value(); }
01199 
01200     reference rep (size_type i) { return rep()[i]; }
01201     const_reference rep (size_type i) const { return rep()[i]; }
01202 
01203     bool do_pack ();
01204 
01205     refcntr_proxy<Rep, REFCNT> store;
01206 };
01207 
01209 
01210 template <typename T, bool REFCNT>
01211 struct type_traits<vector<T, REFCNT> >
01212     : public type_traits_default<vector<T, REFCNT> >
01213 {
01214     static const bool is_specialized = type_traits<T>::is_specialized;
01215 
01216     static const bool is_number = false;
01217     static const bool is_integer_number = false;
01218     static const bool is_polynom = false;
01219     static const bool is_real_number = false;
01220     static const bool is_rational_number = false;
01221     static const bool is_complex_number = false;
01222     static const bool is_ring = type_traits<T>::is_ring;    // +, -, *, null, unit
01223     static const bool is_field = false;
01224     static const bool is_finite = type_traits<T>::is_finite;
01225     static const bool is_additive_group = type_traits<T>::is_additive_group;    // +, -, null
01226     static const bool is_multiplicative_group = false;
01227     static const bool has_zero_divisor = type_traits<T>::has_zero_divisor;
01228     static const bool is_integer_modulo_ring = false;
01229     static const bool is_matrix = false;
01230     static const bool is_vector = true;
01231     
01232     static const bool has_commutative_multiplication =
01233                         type_traits<T>::has_commutative_multiplication;
01234     
01235     static const bool has_commutative_addition =
01236                         type_traits<T>::has_commutative_addition;
01237 
01238     static const bool has_null = type_traits<T>::has_null;
01239     static const bool has_unit = type_traits<T>::has_unit;
01240     static const bool has_opposite_unit = type_traits<T>::has_opposite_unit;
01241     static const bool is_aggregate = true;
01242     typedef T element_type;
01243     typedef type_category::dense_vector category_type;
01244     static const category_type category_value;
01245 
01246     template <typename T1, bool REFCNT2>
01247     struct other_element_type_refcnt { typedef vector<T1, REFCNT2> type; };
01248 
01249 };
01250 
01251 
01252 template <typename T, bool REFCNT>
01253 const type_category::dense_vector
01254     type_traits<vector<T, REFCNT> >::category_value =
01255     type_category::dense_vector();
01256 
01257 
01258 
01259 #define _ARAGELI_VECTOR_RIGHT_OPER(MNEM)                \
01260     template <typename T1, typename T2, bool REFCNT2>   \
01261     inline vector<T2, REFCNT2>& left_assign_##MNEM      \
01262     (const T1& x, vector<T2, REFCNT2>& y)               \
01263     { return y.left_assign_##MNEM(x); }
01264 
01265 _ARAGELI_VECTOR_RIGHT_OPER(plus);
01266 _ARAGELI_VECTOR_RIGHT_OPER(minus);
01267 _ARAGELI_VECTOR_RIGHT_OPER(multiplies);
01268 _ARAGELI_VECTOR_RIGHT_OPER(divides);
01269 _ARAGELI_VECTOR_RIGHT_OPER(modulus);
01270 _ARAGELI_VECTOR_RIGHT_OPER(bitwise_or);
01271 _ARAGELI_VECTOR_RIGHT_OPER(bitwise_and);
01272 _ARAGELI_VECTOR_RIGHT_OPER(bitwise_xor);
01273 _ARAGELI_VECTOR_RIGHT_OPER(shift_left);
01274 _ARAGELI_VECTOR_RIGHT_OPER(shift_right);
01275 
01276 
01277 #undef _ARAGELI_GENERIC_VECTOR_OPERATORS
01278 
01279 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
01280 
01281 template <typename Tag, typename T, bool REFCNT>
01282 struct unary_function_traits<Tag, vector<T, REFCNT> > :
01283     public unary_function_traits_base
01284     <
01285         Tag, vector<T, REFCNT>,
01286         vector<typename unary_function_traits<Tag, T>::result_type, REFCNT>,
01287         unary_function_traits<Tag, T>::alternates_argument,
01288         unary_function_traits<Tag, T>::has_side_effect
01289     >
01290 {};
01291 
01292 
01293 
01294 namespace _Internal
01295 {
01296 
01297 template <typename T1, typename T2> struct select_non_vector;
01298 
01299 template <typename T1, bool REFCNT1, typename T2>
01300 struct select_non_vector<vector<T1, REFCNT1>, T2>
01301 { typedef T2 type; };
01302 
01303 template <typename T1, typename T2, bool REFCNT2>
01304 struct select_non_vector<T1, vector<T2, REFCNT2> >
01305 { typedef T1 type; };
01306 
01307 }
01308 
01309 
01310 template                                                                
01311 <                                                                       
01312     typename Tag, typename V1, typename V2,                                         
01313     bool IS_CONVERT_12, bool IS_CONVERT_21,
01314     typename Tag_class
01315 >                                                                       
01316 struct bfgs_vector_helper_1
01317 {                                                                       
01318     typedef typename _Internal::select_non_vector<V1, V2>::type NV;
01319     
01320     typedef                                                             
01321         typename binary_function_gate_slot<Tag, NV, V1, V2>::function_traits
01322             function_traits;                                            
01323                                                                         
01324     static typename function_traits::result_type                        
01325     function (const V1& a, const V2& b)
01326     { return binary_function_gate_slot<Tag, NV, V1, V2>::function(a, b); }  
01327 };                                                                      
01328 
01329 // For operations that is not a compare operations.
01330 
01331 template <typename Tag, typename V1, typename V2, typename Tag_class>
01332 struct bfgs_vector_helper_1<Tag, V1, V2, false, false, Tag_class>
01333 {                                                                       
01334 private:                                                                
01335                                                                         
01336     typedef binary_function_traits
01337     <                                                                   
01338         Tag,
01339         typename type_traits<V1>::element_type,                         
01340         typename type_traits<V2>::element_type                          
01341     > Fte;                                                              
01342                                                                         
01343 public:                                                                 
01344                                                                         
01345     struct function_traits :                                            
01346         public binary_function_traits_base                              
01347         <                                                               
01348             Tag, V1, V2, V1,
01349             Fte::alternates_first_argument,                             
01350             Fte::alternates_second_argument,                            
01351             Fte::has_side_effect                                        
01352         >                                                               
01353     {};                                                                 
01354                                                                         
01355     static V1 function (const V1& a, const V2& b)                       
01356     { return apply2_vec_by_vec(a, b, gfunc::by_tag<Tag>()); }
01357 };                                                                      
01358                                                                         
01359                                                                         
01360 template <typename Tag, typename V1, typename V2, typename Tag_class>
01361 struct bfgs_vector_helper_1<Tag, V1, V2, false, true, Tag_class>    
01362 {                                                                       
01363 private:                                                                
01364                                                                         
01365     typedef binary_function_traits
01366     <
01367         Tag,
01368         typename type_traits<V1>::element_type,
01369         V2
01370     > Fte;              
01371                                                                         
01372 public:                                                                 
01373                                                                         
01374     struct function_traits :                                            
01375         public binary_function_traits_base                              
01376         <                                                               
01377             Tag, V1, V2, V1,                                                            
01378             Fte::alternates_first_argument,                             
01379             Fte::alternates_second_argument,                            
01380             Fte::has_side_effect                                        
01381         >                                                               
01382     {};                                                                 
01383                                                                         
01384     static V1 function (const V1& a, const V2& b)                       
01385     { return apply2_vec_by_val(a, b, gfunc::by_tag<Tag>()); }
01386 };
01387                                                                         
01388                                                                         
01389 template <typename Tag, typename V1, typename V2, typename Tag_class>               
01390 struct bfgs_vector_helper_1<Tag, V1, V2, true, false, Tag_class>
01391 {                                                                       
01392 private:                                                                
01393                                                                         
01394     typedef binary_function_traits
01395     <
01396         Tag, V1,
01397         typename type_traits<V2>::element_type
01398     > Fte;
01399                                                                         
01400 public:                                                                 
01401                                                                         
01402     struct function_traits :                                            
01403         public binary_function_traits_base                              
01404         <                                                               
01405             Tag, V1, V2, V2,
01406             Fte::alternates_first_argument,                             
01407             Fte::alternates_second_argument,                            
01408             Fte::has_side_effect                                        
01409         >                                                               
01410     {};                                                                 
01411                                                                         
01412     static V2 function (const V1& a, const V2& b)                       
01413     { return apply2_val_by_vec(a, b, gfunc::by_tag<Tag>()); }
01414 };                                                                      
01415 
01416 // For cmp function.
01417 
01418 template <typename V1, typename V2, typename Tag_class>
01419 struct bfgs_vector_helper_1<function_tag::cmp, V1, V2, false, false, Tag_class>
01420 {                                                                       
01421 private:                                                                
01422                                                                         
01423     typedef binary_function_traits
01424     <                                                                   
01425         function_tag::cmp,
01426         typename type_traits<V1>::element_type,                         
01427         typename type_traits<V2>::element_type                          
01428     > Fte;
01429                                                                         
01430 public:                                                                 
01431                                                                         
01432     struct function_traits :                                            
01433         public binary_function_traits_base                              
01434         <                                                               
01435             function_tag::cmp, V1, V2, int,
01436             Fte::alternates_first_argument,                             
01437             Fte::alternates_second_argument,                            
01438             Fte::has_side_effect
01439         >                                                               
01440     {};                                                                 
01441                                                                         
01442     static int function (const V1& a, const V2& b)                      
01443     { return cmpdef_vec_by_vec(a, b); }
01444 };                                                                      
01445                                                                         
01446                                                                         
01447 template <typename V1, typename V2, typename Tag_class>
01448 struct bfgs_vector_helper_1<function_tag::cmp, V1, V2, false, true, Tag_class>  
01449 {                                                                       
01450 private:                                                                
01451                                                                         
01452     typedef binary_function_traits
01453     <
01454         function_tag::cmp,
01455         typename type_traits<V1>::element_type,
01456         V2
01457     > Fte;              
01458                                                                         
01459 public:                                                                 
01460                                                                         
01461     struct function_traits :                                            
01462         public binary_function_traits_base                              
01463         <                                                               
01464             function_tag::cmp, V1, V2, int,                                             
01465             Fte::alternates_first_argument,                             
01466             Fte::alternates_second_argument,                            
01467             Fte::has_side_effect                                        
01468         >                                                               
01469     {};                                                                 
01470                                                                         
01471     static int function (const V1& a, const V2& b)                      
01472     { return cmpdef_vec_by_val(a, b); }
01473 };
01474                                                                         
01475                                                                         
01476 template <typename V1, typename V2, typename Tag_class>             
01477 struct bfgs_vector_helper_1<function_tag::cmp, V1, V2, true, false, Tag_class>
01478 {                                                                       
01479 private:                                                                
01480                                                                         
01481     typedef binary_function_traits
01482     <
01483         function_tag::cmp, V1,
01484         typename type_traits<V2>::element_type
01485     > Fte;
01486                                                                         
01487 public:                                                                 
01488                                                                         
01489     struct function_traits :                                            
01490         public binary_function_traits_base                              
01491         <                                                               
01492             function_tag::cmp, V1, V2, int,
01493             Fte::alternates_first_argument,                             
01494             Fte::alternates_second_argument,                            
01495             Fte::has_side_effect                                        
01496         >                                                               
01497     {};                                                                 
01498                                                                         
01499     static int function (const V1& a, const V2& b)                      
01500     { return cmpdef_val_by_vec(a, b); }
01501 };                                                                      
01502 
01503 // For each_cmp function.
01504 
01505 template <typename V1, typename V2, typename Tag_class>
01506 struct bfgs_vector_helper_1<function_tag::each_cmp, V1, V2, false, false, Tag_class>
01507 {                                                                       
01508 private:                                                                
01509                                                                         
01510     typedef binary_function_traits
01511     <                                                                   
01512         function_tag::each_cmp,
01513         typename type_traits<V1>::element_type,                         
01514         typename type_traits<V2>::element_type                          
01515     > Fte;
01516                                                                         
01517 public:                                                                 
01518                                                                         
01519     struct function_traits :                                            
01520         public binary_function_traits_base                              
01521         <                                                               
01522             function_tag::each_cmp, V1, V2, vector<int, true>,
01523             Fte::alternates_first_argument,                             
01524             Fte::alternates_second_argument,                            
01525             Fte::has_side_effect
01526         >                                                               
01527     {};                                                                 
01528                                                                         
01529     static vector<int, true> function (const V1& a, const V2& b)                        
01530     { return elwisecmp_vec_by_vec(a, b, gfunc::cmp()); }
01531 };                                                                      
01532                                                                         
01533                                                                         
01534 template <typename V1, typename V2, typename Tag_class>
01535 struct bfgs_vector_helper_1<function_tag::each_cmp, V1, V2, false, true, Tag_class> 
01536 {                                                                       
01537 private:                                                                
01538                                                                         
01539     typedef binary_function_traits
01540     <
01541         function_tag::each_cmp,
01542         typename type_traits<V1>::element_type,
01543         V2
01544     > Fte;              
01545                                                                         
01546 public:                                                                 
01547                                                                         
01548     struct function_traits :                                            
01549         public binary_function_traits_base                              
01550         <                                                               
01551             function_tag::each_cmp, V1, V2, vector<int, true>,              
01552             Fte::alternates_first_argument,                             
01553             Fte::alternates_second_argument,                            
01554             Fte::has_side_effect                                        
01555         >                                                               
01556     {};                                                                 
01557                                                                         
01558     static vector<int, true> function (const V1& a, const V2& b)                        
01559     { return elwisecmp_vec_by_val(a, b, gfunc::cmp()); }
01560 };
01561                                                                         
01562                                                                         
01563 template <typename V1, typename V2, typename Tag_class>             
01564 struct bfgs_vector_helper_1<function_tag::each_cmp, V1, V2, true, false, Tag_class>
01565 {                                                                       
01566 private:                                                                
01567                                                                         
01568     typedef binary_function_traits
01569     <
01570         function_tag::each_cmp, V1,
01571         typename type_traits<V2>::element_type
01572     > Fte;
01573                                                                         
01574 public:                                                                 
01575                                                                         
01576     struct function_traits :                                            
01577         public binary_function_traits_base                              
01578         <                                                               
01579             function_tag::each_cmp, V1, V2, vector<int, true>,
01580             Fte::alternates_first_argument,                             
01581             Fte::alternates_second_argument,                            
01582             Fte::has_side_effect                                        
01583         >                                                               
01584     {};                                                                 
01585                                                                         
01586     static vector<int, true> function (const V1& a, const V2& b)                        
01587     { return elwisecmp_val_by_vec(a, b); }
01588 };                                                                      
01589 
01590 // For each* functions.
01591 
01592 template <typename Tag, typename V1, typename V2>
01593 struct bfgs_vector_helper_1<Tag, V1, V2, false, false, function_tag::each_compare>
01594 {                                                                       
01595 private:                                                                
01596                                                                         
01597     typedef binary_function_traits
01598     <                                                                   
01599         Tag,
01600         typename type_traits<V1>::element_type,                         
01601         typename type_traits<V2>::element_type                          
01602     > Fte;
01603                                                                         
01604 public:                                                                 
01605                                                                         
01606     struct function_traits :                                            
01607         public binary_function_traits_base                              
01608         <                                                               
01609             Tag, V1, V2, vector<bool, true>,
01610             Fte::alternates_first_argument,                             
01611             Fte::alternates_second_argument,                            
01612             Fte::has_side_effect
01613         >                                                               
01614     {};                                                                 
01615                                                                         
01616     static vector<bool, true> function (const V1& a, const V2& b)                       
01617     {
01618         return eachcmp_vec_by_vec
01619         (
01620             a, b,
01621             gfunc::by_tag<typename function_tag::omit_each<Tag>::type>()
01622         );
01623     }
01624 };                                                                      
01625                                                                         
01626                                                                         
01627 template <typename Tag, typename V1, typename V2>
01628 struct bfgs_vector_helper_1<Tag, V1, V2, false, true, function_tag::each_compare>
01629 {                                                                       
01630 private:                                                                
01631                                                                         
01632     typedef binary_function_traits
01633     <
01634         Tag,
01635         typename type_traits<V1>::element_type,
01636         V2
01637     > Fte;              
01638                                                                         
01639 public:                                                                 
01640                                                                         
01641     struct function_traits :                                            
01642         public binary_function_traits_base                              
01643         <                                                               
01644             Tag, V1, V2, vector<bool, true>,                                    
01645             Fte::alternates_first_argument,                             
01646             Fte::alternates_second_argument,                            
01647             Fte::has_side_effect                                        
01648         >                                                               
01649     {};                                                                 
01650                                                                         
01651     static vector<bool, true> function (const V1& a, const V2& b)                       
01652     {
01653         return eachcmp_vec_by_val
01654         (
01655             a, b,
01656             gfunc::by_tag<typename function_tag::omit_each<Tag>::type>()
01657         );
01658     }
01659 };
01660                                                                         
01661                                                                         
01662 template <typename Tag, typename V1, typename V2>               
01663 struct bfgs_vector_helper_1<Tag, V1, V2, true, false, function_tag::each_compare>
01664 {                                                                       
01665 private:                                                                
01666                                                                         
01667     typedef binary_function_traits
01668     <
01669         Tag, V1,
01670         typename type_traits<V2>::element_type
01671     > Fte;
01672                                                                         
01673 public:                                                                 
01674                                                                         
01675     struct function_traits :                                            
01676         public binary_function_traits_base                              
01677         <                                                               
01678             Tag, V1, V2, vector<bool, true>,
01679             Fte::alternates_first_argument,                             
01680             Fte::alternates_second_argument,                            
01681             Fte::has_side_effect                                        
01682         >                                                               
01683     {};                                                                 
01684                                                                         
01685     static vector<bool, true> function (const V1& a, const V2& b)                       
01686     {
01687         return eachcmp_val_by_vec
01688         (
01689             a, b,
01690             gfunc::by_tag<typename function_tag::omit_each<Tag>::type>()
01691         );
01692     }
01693 };                                                                      
01694 
01695 
01696 // For all* functions.
01697 
01698 template <typename Tag, typename V1, typename V2>
01699 struct bfgs_vector_helper_1<Tag, V1, V2, false, false, function_tag::all_compare>
01700 {                                                                       
01701 private:                                                                
01702                                                                         
01703     typedef binary_function_traits
01704     <                                                                   
01705         Tag,
01706         typename type_traits<V1>::element_type,                         
01707         typename type_traits<V2>::element_type                          
01708     > Fte;
01709                                                                         
01710 public:                                                                 
01711                                                                         
01712     struct function_traits :                                            
01713         public binary_function_traits_base                              
01714         <                                                               
01715             Tag, V1, V2, bool,
01716             Fte::alternates_first_argument,                             
01717             Fte::alternates_second_argument,                            
01718             Fte::has_side_effect
01719         >                                                               
01720     {};                                                                 
01721                                                                         
01722     static bool function (const V1& a, const V2& b)                     
01723     {
01724         return allcmp_vec_by_vec
01725         (
01726             a, b,
01727             gfunc::by_tag<typename function_tag::omit_each<Tag>::type>()
01728         );
01729     }
01730 };                                                                      
01731                                                                         
01732                                                                         
01733 template <typename Tag, typename V1, typename V2>
01734 struct bfgs_vector_helper_1<Tag, V1, V2, false, true, function_tag::all_compare>
01735 {                                                                       
01736 private:                                                                
01737                                                                         
01738     typedef binary_function_traits
01739     <
01740         Tag,
01741         typename type_traits<V1>::element_type,
01742         V2
01743     > Fte;              
01744                                                                         
01745 public:                                                                 
01746                                                                         
01747     struct function_traits :                                            
01748         public binary_function_traits_base                              
01749         <                                                               
01750             Tag, V1, V2, bool,                                  
01751             Fte::alternates_first_argument,                             
01752             Fte::alternates_second_argument,                            
01753             Fte::has_side_effect                                        
01754         >                                                               
01755     {};                                                                 
01756                                                                         
01757     static bool function (const V1& a, const V2& b)                     
01758     {
01759         return allcmp_vec_by_val
01760         (
01761             a, b,
01762             gfunc::by_tag<typename function_tag::omit_each<Tag>::type>()
01763         );
01764     }
01765 };
01766                                                                         
01767                                                                         
01768 template <typename Tag, typename V1, typename V2>               
01769 struct bfgs_vector_helper_1<Tag, V1, V2, true, false, function_tag::all_compare>
01770 {                                                                       
01771 private:                                                                
01772                                                                         
01773     typedef binary_function_traits
01774     <
01775         Tag, V1,
01776         typename type_traits<V2>::element_type
01777     > Fte;
01778                                                                         
01779 public:                                                                 
01780                                                                         
01781     struct function_traits :                                            
01782         public binary_function_traits_base                              
01783         <                                                               
01784             Tag, V1, V2, bool,
01785             Fte::alternates_first_argument,                             
01786             Fte::alternates_second_argument,                            
01787             Fte::has_side_effect                                        
01788         >                                                               
01789     {};                                                                 
01790                                                                         
01791     static bool function (const V1& a, const V2& b)                     
01792     {
01793         return allcmp_val_by_vec
01794         (
01795             a, b,
01796             gfunc::by_tag<typename function_tag::omit_each<Tag>::type>()
01797         );
01798     }
01799 };                                                                      
01800 
01801 // -------------------------------------------------------
01802 
01803 template <typename Tag, typename T1, typename T2>
01804 struct bfgs_vector_helper_2:
01805     public bfgs_vector_helper_1
01806     <
01807         Tag, T1, T2,
01808         type_traits<T2>::is_vector &&
01809             type_pair_traits
01810             <
01811                 T1,
01812                 typename type_traits<T2>::element_type
01813             >::is_convertible,
01814         type_traits<T1>::is_vector &&
01815             type_pair_traits
01816             <
01817                 T2,
01818                 typename type_traits<T1>::element_type
01819             >::is_convertible,
01820         typename function_tag::compare_category<Tag>::type
01821     >
01822 {};
01823 
01824 
01825 template <typename Tag, typename T1, typename T2>
01826 struct bfgs_vector_helper_3:
01827     public bfgs_vector_helper_2
01828     <
01829         Tag,
01830         typename omit_const_ref<T1>::type,
01831         typename omit_const_ref<T2>::type
01832     >
01833 {};
01834 
01835 
01836 template <typename Tag, typename T, bool REFCNT, typename T1, typename T2>
01837 struct binary_function_gate_slot<Tag, vector<T, REFCNT>, T1, T2>:
01838     public bfgs_vector_helper_3<Tag, T1, T2>
01839 {};
01840 
01841 template <typename Tag, typename T, bool REFCNT, typename T1, typename T2>
01842 struct binary_function_gate_slot<Tag, const vector<T, REFCNT>, T1, T2>:
01843     public bfgs_vector_helper_3<Tag, T1, T2>
01844 {};
01845 
01846 template <typename Tag, typename T, bool REFCNT, typename T1, typename T2>
01847 struct binary_function_gate_slot<Tag, vector<T, REFCNT>&, T1, T2>:
01848     public bfgs_vector_helper_3<Tag, T1, T2>
01849 {};
01850 
01851 template <typename Tag, typename T, bool REFCNT, typename T1, typename T2>
01852 struct binary_function_gate_slot<Tag, const vector<T, REFCNT>&, T1, T2>:
01853     public bfgs_vector_helper_3<Tag, T1, T2>
01854 {};
01855 
01856 
01857 // WARNING! Doxygen fails on the following fragment. We turn-off it from doxygen processing.
01858 #ifndef DOXYGEN_SHOULD_SKIP_THIS
01859 
01860 
01861 #define ARAGELI_BINARY_FUNCTION_MIXGATE_OWNER_1_PARAMS  typename T1, bool REFCNT1
01862 #define ARAGELI_BINARY_FUNCTION_MIXGATE_OWNER_1_TYPE    const vector<T1, REFCNT1>&
01863 #define ARAGELI_BINARY_FUNCTION_MIXGATE_OWNER_2_PARAMS  typename T2, bool REFCNT2
01864 #define ARAGELI_BINARY_FUNCTION_MIXGATE_OWNER_2_TYPE    const vector<T2, REFCNT2>&
01865 
01866 
01867 #define ARAGELI_BINARY_FUNCTION_MIXGATE_OTHER_PARAMS    typename T3
01868 #define ARAGELI_BINARY_FUNCTION_MIXGATE_OTHER_TYPE      const T3&
01869 #define ARAGELI_BINARY_FUNCTION_MIXGATE_OWNER_OTHER_COMMA   ,   
01870 
01871 ARAGELI_ALL_BINARY_ARITHM_FUNCTIONS_MIXGATE
01872 ARAGELI_ALL_BINARY_LOGIC_FUNCTIONS_MIXGATE
01873 ARAGELI_ALL_BINARY_CMP_MIXGATE
01874 ARAGELI_ALL_EACH_ALL_CMP_FUNCTIONS_MIXGATE
01875 
01876 #undef ARAGELI_BINARY_FUNCTION_MIXGATE_OTHER_PARAMS
01877 #undef ARAGELI_BINARY_FUNCTION_MIXGATE_OTHER_TYPE
01878 #undef ARAGELI_BINARY_FUNCTION_MIXGATE_OWNER_OTHER_COMMA
01879 
01880 
01881 #define ARAGELI_BINARY_FUNCTION_MIXGATE_OWNER_OWNER_COMMA   ,
01882 
01883 ARAGELI_ALL_BINARY_ARITHM_FUNCTIONS_SELF_MIXGATE
01884 ARAGELI_ALL_BINARY_LOGIC_FUNCTIONS_SELF_MIXGATE
01885 ARAGELI_ALL_BINARY_CMP_SELF_MIXGATE
01886 ARAGELI_ALL_EACH_ALL_CMP_FUNCTIONS_SELF_MIXGATE
01887 
01888 #undef ARAGELI_BINARY_FUNCTION_MIXGATE_OWNER_OWNER_COMMA
01889 
01890 
01891 #define ARAGELI_BINARY_FUNCTION_MIXGATE_OTHER_PARAMS
01892 #define ARAGELI_BINARY_FUNCTION_MIXGATE_OTHER_TYPE      const big_int&
01893 #define ARAGELI_BINARY_FUNCTION_MIXGATE_OWNER_OTHER_COMMA   
01894 
01895 ARAGELI_ALL_BINARY_ARITHM_FUNCTIONS_MIXGATE
01896 ARAGELI_ALL_BINARY_LOGIC_FUNCTIONS_MIXGATE
01897 ARAGELI_ALL_BINARY_CMP_MIXGATE
01898 ARAGELI_ALL_EACH_ALL_CMP_FUNCTIONS_MIXGATE
01899 
01900 #undef ARAGELI_BINARY_FUNCTION_MIXGATE_OTHER_PARAMS
01901 #undef ARAGELI_BINARY_FUNCTION_MIXGATE_OTHER_TYPE
01902 #undef ARAGELI_BINARY_FUNCTION_MIXGATE_OWNER_OTHER_COMMA
01903 
01904 
01905 #define ARAGELI_BINARY_FUNCTION_MIXGATE_OTHER_PARAMS    typename T3, typename I3, bool REFCNT3
01906 #define ARAGELI_BINARY_FUNCTION_MIXGATE_OTHER_TYPE      const sparse_polynom<T3, I3, REFCNT3>
01907 #define ARAGELI_BINARY_FUNCTION_MIXGATE_OWNER_OTHER_COMMA   ,
01908 
01909 ARAGELI_ALL_BINARY_ARITHM_FUNCTIONS_MIXGATE
01910 ARAGELI_ALL_BINARY_LOGIC_FUNCTIONS_MIXGATE
01911 ARAGELI_ALL_BINARY_CMP_MIXGATE
01912 ARAGELI_ALL_EACH_ALL_CMP_FUNCTIONS_MIXGATE
01913 
01914 #undef ARAGELI_BINARY_FUNCTION_MIXGATE_OTHER_PARAMS
01915 #undef ARAGELI_BINARY_FUNCTION_MIXGATE_OTHER_TYPE
01916 #undef ARAGELI_BINARY_FUNCTION_MIXGATE_OWNER_OTHER_COMMA
01917 
01918 
01919 #define ARAGELI_BINARY_FUNCTION_MIXGATE_OTHER_PARAMS    typename T
01920 #define ARAGELI_BINARY_FUNCTION_MIXGATE_OTHER_TYPE      const rational<T>&
01921 #define ARAGELI_BINARY_FUNCTION_MIXGATE_OWNER_OTHER_COMMA   ,
01922 
01923 ARAGELI_ALL_BINARY_ARITHM_FUNCTIONS_MIXGATE
01924 ARAGELI_ALL_BINARY_LOGIC_FUNCTIONS_MIXGATE
01925 ARAGELI_ALL_BINARY_CMP_MIXGATE
01926 ARAGELI_ALL_EACH_ALL_CMP_FUNCTIONS_MIXGATE
01927 
01928 #undef ARAGELI_BINARY_FUNCTION_MIXGATE_OWNER_2_PARAMS
01929 #undef ARAGELI_BINARY_FUNCTION_MIXGATE_OWNER_2_TYPE
01930 #undef ARAGELI_BINARY_FUNCTION_MIXGATE_OTHER_PARAMS
01931 #undef ARAGELI_BINARY_FUNCTION_MIXGATE_OTHER_TYPE
01932 #undef ARAGELI_BINARY_FUNCTION_MIXGATE_OWNER_OTHER_COMMA
01933 
01934 
01935 #undef ARAGELI_BINARY_FUNCTION_MIXGATE_OWNER_1_PARAMS
01936 #undef ARAGELI_BINARY_FUNCTION_MIXGATE_OWNER_1_TYPE
01937 
01938 
01939 
01940 #endif  // #ifndef DOXYGEN_SHOULD_SKIP_THIS
01941 
01942 
01943 
01945 template
01946 <
01947     typename T1, bool REFCNT1,
01948     typename T2, bool REFCNT2,
01949     typename T1_factory
01950 >
01951 T1 dotprod
01952 (
01953     const vector<T1, REFCNT1>& a,
01954     const vector<T2, REFCNT2>& b,
01955     const T1_factory& t1fctr
01956 );
01957 
01958 
01960 template
01961 <
01962     typename T1, bool REFCNT1,
01963     typename T2, bool REFCNT2
01964 >
01965 inline T1 dotprod
01966 (
01967     const vector<T1, REFCNT1>& a,
01968     const vector<T2, REFCNT2>& b
01969 )
01970 { return dotprod(a, b, factory<T1>()); }
01971 
01972 
01974 
01976 template <typename T, bool REFCNT, typename T2, typename T2_factory>
01977 T2& product (const vector<T, REFCNT>& x, T2& res, const T2_factory& t2fctr);
01978 
01980 
01982 template <typename T, bool REFCNT, typename T2, typename T2_factory>
01983 T2& sum (const vector<T, REFCNT>& x, T2& res, const T2_factory& t2fctr);
01984 
01986 
01988 template <typename T, bool REFCNT, typename T2>
01989 inline T2& product (const vector<T, REFCNT>& x, T2& res)
01990 { return product(x, res, factory<T2>()); }
01991 
01993 
01995 template <typename T, bool REFCNT, typename T2>
01996 inline T2& sum (const vector<T, REFCNT>& x, T2& res)
01997 { return sum(x, res, factory<T2>()); }
01998 
02000 //template <typename T, bool REFCNT, typename T_factory>
02001 //inline T product (const vector<T, REFCNT>& x, const T_factory& tfctr)
02002 //{
02003 //  T res;
02004 //  return product(x, res, tfctr);
02005 //}
02006 //
02008 //template <typename T, bool REFCNT, typename T_factory>
02009 //inline T sum (const vector<T, REFCNT>& x, const T_factory& tfctr)
02010 //{
02011 //  T res;
02012 //  return sum(x, res, tfctr);
02013 //}
02014 
02015 
02017 template <typename T, bool REFCNT>
02018 inline T product (const vector<T, REFCNT>& x)
02019 {
02020     T res;
02021     return product(x, res, factory<T>());
02022 }
02023 
02025 template <typename T, bool REFCNT>
02026 inline T sum (const vector<T, REFCNT>& x)
02027 {
02028     T res;
02029     return sum(x, res, factory<T>());
02030 }
02031 
02032 
02033 // TODO: Migrate all input/output function to vecalg equivalents (begins with vec_).
02034 // By the way, implement them! :)
02035 
02037 template <typename Out, typename T, bool REFCNT>
02038 inline Out& output_list
02039 (
02040     Out& out,
02041     const vector<T, REFCNT>& x,
02042     const char* first_bracket = vector_output_list_first_bracket_default,
02043     const char* second_bracket = vector_output_list_second_bracket_default,
02044     const char* separator = vector_output_list_separator_default
02045 )
02046 { return vec_output_list(out, x, first_bracket, second_bracket, separator); }
02047 
02048 
02050 template <typename In, typename T, bool REFCNT>
02051 In& input_list
02052 (
02053     In& in,
02054     vector<T, REFCNT>& x,
02055     const char* first_bracket = vector_input_list_first_bracket_default,
02056     const char* second_bracket = vector_input_list_second_bracket_default,
02057     const char* separator = vector_input_list_separator_default,
02058     const char* range = vector_input_list_range_default
02059 );
02060 
02061 
02063 template <typename T, bool REFCNT>
02064 std::ostream& output_aligned
02065 (
02066     std::ostream& out,
02067     const vector<T, REFCNT>& x,
02068     const char* left_col = vector_output_aligned_left_col_default,
02069     const char* right_col = vector_output_aligned_right_col_default
02070 );
02071 
02072 
02074 template <typename T, bool REFCNT>
02075 inline std::ostream& vector_output_row
02076 (
02077     std::ostream& out,
02078     const vector<T, REFCNT>& x
02079 )
02080 { return output_list(out, x, "", "", " "); }
02081 
02082 
02084 template <typename T, bool REFCNT>
02085 inline std::ostream& vector_output_col
02086 (
02087     std::ostream& out,
02088     const vector<T, REFCNT>& x
02089 )
02090 { return output_list(out, x, "", "", "\n"); }
02091 
02092 
02094 template <typename T, bool REFCNT>
02095 inline std::ostream& operator<< (std::ostream& out, const vector<T, REFCNT>& x)
02096 { return output_list(out, x); }
02097 
02098 
02100 template <typename T, bool REFCNT>
02101 inline std::istream& operator>> (std::istream& in, vector<T, REFCNT>& x)
02102 { return input_list(in, x); }
02103 
02104 
02106 template <typename T, bool REFCNT>
02107 inline std::ofstream& operator<< (std::ofstream& out, const vector<T, REFCNT>& x)
02108 { return static_cast<std::ofstream&>(output_list(out, x)); }
02109 
02110 
02112 template <typename T, bool REFCNT>
02113 inline std::ifstream& operator>> (std::ifstream& in, vector<T, REFCNT>& x)
02114 { return static_cast<std::ifstream&>(input_list(in, x)); }
02115 
02116 
02118 template <typename T, bool REFCNT>
02119 inline std::ostringstream& operator<< (std::ostringstream& out, const vector<T, REFCNT>& x)
02120 { return static_cast<std::ostringstream&>(output_list(out, x)); }
02121 
02122 
02124 template <typename T, bool REFCNT>
02125 inline std::istringstream& operator>> (std::istringstream& in, vector<T, REFCNT>& x)
02126 { return static_cast<std::istringstream&>(input_list(in, x)); }
02127 
02128 
02130 template <typename T, bool REFCNT>
02131 struct factory<vector<T, REFCNT> >
02132 {
02133 private:
02134 
02135     typedef vector<T, REFCNT> TTT;
02136 
02137 public:
02138 
02139     static const bool is_specialized = true;
02140     
02141     static const TTT& unit ()
02142     {
02143         static const TTT unit_s(1, Arageli::unit<T>());
02144         return unit_s;
02145     }
02146     
02147     static TTT unit (const TTT& pat)
02148     {
02149         if(pat.is_empty())return unit();
02150         else return TTT(pat.size(), Arageli::unit<T>(pat.front()));
02151     }
02152     
02153     static const TTT& opposite_unit ()
02154     {
02155         static const TTT opposite_unit_s(1, Arageli::opposite_unit<T>());
02156         return opposite_unit_s;
02157     }
02158     
02159     static TTT opposite_unit (const TTT& pat)
02160     {
02161         if(pat.is_empty())return opposite_unit();
02162         else return TTT(pat.size(), Arageli::opposite_unit<T>(pat.front()));
02163     }
02164     
02165     static const TTT& null ()
02166     {
02167         static const TTT null_s(1, Arageli::null<T>());
02168         return null_s;
02169     }
02170     
02171     static TTT null (const TTT& pat)
02172     {
02173         if(pat.is_empty())return null();
02174         else return TTT(pat.size(), Arageli::null<T>(pat.front()));
02175     }
02176 
02177 };
02178 
02179 
02180 template <typename T, bool REFCNT>
02181 inline vector<T, REFCNT> opposite
02182 (const vector<T, REFCNT>& x)
02183 { return -x; }
02184 
02185 template <typename T, bool REFCNT>
02186 inline vector<T, REFCNT>& opposite
02187 (const vector<T, REFCNT>& x, vector<T, REFCNT>* y)
02188 { return (*y = x).opposite(); }
02189 
02190 template <typename T, bool REFCNT>
02191 inline vector<T, REFCNT>& opposite
02192 (vector<T, REFCNT>* x)
02193 { return x->opposite(); }
02194 
02195 template <typename T, bool REFCNT>
02196 inline vector<T, REFCNT> inverse
02197 (const vector<T, REFCNT>& x)
02198 {
02199     vector<T, REFCNT> t(x);
02200     return x.inverse();
02201 }
02202 
02203 template <typename T, bool REFCNT>
02204 inline vector<T, REFCNT>& inverse
02205 (const vector<T, REFCNT>& x, vector<T, REFCNT>* y)
02206 { return (*y = x).inverse(); }
02207 
02208 template <typename T, bool REFCNT>
02209 inline vector<T, REFCNT>& inverse
02210 (vector<T, REFCNT>* x)
02211 { return x->inverse(); }
02212 
02213 
02214 template <typename T, bool REFCNT>
02215 inline bool is_unit (const vector<T, REFCNT>& x)
02216 { return x.is_unit(); }
02217 
02218 template <typename T, bool REFCNT>
02219 inline bool is_opposite_unit (const vector<T, REFCNT>& x)
02220 { return x.is_opposite_unit(); }
02221 
02222 template <typename T, bool REFCNT>
02223 inline bool is_null (const vector<T, REFCNT>& x)
02224 { return x.is_null(); }
02225 
02226 template <typename T, bool REFCNT>
02227 inline std::ostream& output_polynom_first
02228 (std::ostream& out, const vector<T, REFCNT>& x)
02229 { return output_list(out, x); }
02230 
02231 template <typename T, bool REFCNT>
02232 inline std::ostream& output_polynom_internal
02233 (std::ostream& out, const vector<T, REFCNT>& x)
02234 { return output_list(out << "+", x); }
02235 
02236 template <typename T, bool REFCNT>
02237 inline std::ostream& output_pow
02238 (std::ostream& out, const vector<T, REFCNT>& x)
02239 { return output_list(out, x); }
02240 
02241 template <typename T, bool REFCNT>
02242 inline std::istream& input_polynom_first
02243 (std::istream& in, vector<T, REFCNT>& x)
02244 { return input_list(in, x); }
02245 
02246 template <typename T, bool REFCNT>
02247 std::istream& input_polynom_internal
02248 (std::istream& in, vector<T, REFCNT>& x);
02249 
02250 template <typename T, bool REFCNT>
02251 inline std::istream& input_pow
02252 (std::istream& in, vector<T, REFCNT>& x)
02253 { return input_polynom_first(in, x); }
02254 
02255 
02256 
02257 
02259 template
02260 <
02261     typename T1, bool REFCNT1,
02262     typename T2, bool REFCNT2,
02263     typename T3, bool REFCNT3
02264 >
02265 void fill_subvector
02266 (
02267     const vector<T1, REFCNT1>& orig,
02268     const vector<T2, REFCNT2>& indexes,
02269     vector<T3, REFCNT3>& res
02270 )
02271 {
02272     res.resize(indexes.size());
02273 
02274     for(typename vector<T2, REFCNT2>::size_type i = 0; i < indexes.size(); ++i)
02275     {
02276         ARAGELI_ASSERT_0(indexes[i] >= 0);
02277         ARAGELI_ASSERT_0(indexes[i] < orig.size());
02278 
02279         res[i] = orig[indexes[i]];
02280     }
02281 }
02282 
02283 
02284 //template <typename T, bool REFCNT>
02285 //const vector<T, REFCNT>
02286 //type_traits<vector<T, REFCNT> >::unit_s =
02287 //  TTT(1::unit());
02288 //
02289 //template <typename T, bool REFCNT>
02290 //const vector<T, REFCNT>
02291 //type_traits<vector<T, REFCNT> >::null_s =
02292 //  TTT(1::null());
02293 //
02294 //template <typename T, bool REFCNT>
02295 //const vector<T, REFCNT>
02296 //type_traits<vector<T, REFCNT> >::opposite_unit_s =
02297 //  TTT(1::opposite_unit());
02298 
02299 
02300 
02301 #define ARAGELI_VECTOR_MATH_FUNCS1_DECL(NAME)       \
02302     template <typename T, bool REFCNT>                  \
02303     vector<T, true> NAME (const vector<T, REFCNT>& x);
02304 
02306 
02309 // @{
02310     
02311 ARAGELI_VECTOR_MATH_FUNCS1_DECL(sin)
02312 ARAGELI_VECTOR_MATH_FUNCS1_DECL(cos)
02313 ARAGELI_VECTOR_MATH_FUNCS1_DECL(tan)
02314 ARAGELI_VECTOR_MATH_FUNCS1_DECL(sinh)
02315 ARAGELI_VECTOR_MATH_FUNCS1_DECL(cosh)
02316 ARAGELI_VECTOR_MATH_FUNCS1_DECL(tanh)
02317 ARAGELI_VECTOR_MATH_FUNCS1_DECL(asin)
02318 ARAGELI_VECTOR_MATH_FUNCS1_DECL(acos)
02319 ARAGELI_VECTOR_MATH_FUNCS1_DECL(atan)
02320 ARAGELI_VECTOR_MATH_FUNCS1_DECL(abs)
02321 ARAGELI_VECTOR_MATH_FUNCS1_DECL(exp)
02322 ARAGELI_VECTOR_MATH_FUNCS1_DECL(floor)
02323 ARAGELI_VECTOR_MATH_FUNCS1_DECL(ceil)
02324 ARAGELI_VECTOR_MATH_FUNCS1_DECL(log)
02325 ARAGELI_VECTOR_MATH_FUNCS1_DECL(log10)
02326 ARAGELI_VECTOR_MATH_FUNCS1_DECL(sqrt)
02327 
02328 template
02329 <
02330     typename T1, bool REFCNT1,
02331     typename T2, bool REFCNT2
02332 >
02333 vector<T1, REFCNT1> pow
02334 (
02335     const vector<T1, REFCNT1>& a,
02336     const vector<T2, REFCNT2>& b
02337 );
02338 
02339 template
02340 <
02341     typename T1, bool REFCNT1,
02342     typename P
02343 >
02344 inline vector<T1, REFCNT1> pow
02345 (const vector<T1, REFCNT1>& a, const P& b);
02346 
02347 
02348 // @}
02349 
02350 #undef ARAGELI_VECTOR_MATH_FUNCS1_DECL
02351 
02352 } // namespace Arageli
02353 
02354 
02355 namespace std
02356 {
02357 
02358 #define ARAGELI_VECTOR_STD_MATH_FUNCS1(NAME)    \
02359     template <typename T, bool REFCNT>          \
02360     inline Arageli::vector<T, true> NAME        \
02361     (const Arageli::vector<T, REFCNT>& x)       \
02362     { return Arageli::NAME(x); }
02363 
02365 
02368 // @{
02369     
02370 ARAGELI_VECTOR_STD_MATH_FUNCS1(sin)
02371 ARAGELI_VECTOR_STD_MATH_FUNCS1(cos)
02372 ARAGELI_VECTOR_STD_MATH_FUNCS1(tan)
02373 ARAGELI_VECTOR_STD_MATH_FUNCS1(sinh)
02374 ARAGELI_VECTOR_STD_MATH_FUNCS1(cosh)
02375 ARAGELI_VECTOR_STD_MATH_FUNCS1(tanh)
02376 ARAGELI_VECTOR_STD_MATH_FUNCS1(asin)
02377 ARAGELI_VECTOR_STD_MATH_FUNCS1(acos)
02378 ARAGELI_VECTOR_STD_MATH_FUNCS1(atan)
02379 ARAGELI_VECTOR_STD_MATH_FUNCS1(abs)
02380 ARAGELI_VECTOR_STD_MATH_FUNCS1(exp)
02381 ARAGELI_VECTOR_STD_MATH_FUNCS1(floor)
02382 ARAGELI_VECTOR_STD_MATH_FUNCS1(ceil)
02383 ARAGELI_VECTOR_STD_MATH_FUNCS1(log)
02384 ARAGELI_VECTOR_STD_MATH_FUNCS1(log10)
02385 ARAGELI_VECTOR_STD_MATH_FUNCS1(sqrt)
02386 
02387 template
02388 <
02389     typename T1, bool REFCNT1,
02390     typename T2, bool REFCNT2
02391 >
02392 inline Arageli::vector<T1, REFCNT1> pow
02393 (
02394     const Arageli::vector<T1, REFCNT1>& a,
02395     const Arageli::vector<T2, REFCNT2>& b
02396 )
02397 { return Arageli::pow(a, b); }
02398 
02399 template
02400 <
02401     typename T1, bool REFCNT1,
02402     typename P
02403 >
02404 inline Arageli::vector<T1, REFCNT1> pow
02405 (
02406     const Arageli::vector<T1, REFCNT1>& a,
02407     const P& b
02408 )
02409 { return Arageli::pow(a, b); }
02410 
02411 // @}
02412 
02413 #undef ARAGELI_VECTOR_STD_MATH_FUNCS1
02414 
02415 
02417 template
02418 <
02419     typename T1, bool REFCNT1,
02420     typename T2, bool REFCNT2
02421 >
02422 inline void swap
02423 (
02424     Arageli::vector<T1, REFCNT1>& a,
02425     Arageli::vector<T2, REFCNT2>& b
02426 )
02427 { a.swap(b); }
02428 
02429 
02431 template <typename T1, bool REFCNT1>
02432 inline void swap
02433 (
02434     Arageli::vector<T1, REFCNT1>& a,
02435     Arageli::vector<T1, REFCNT1>& b
02436 )
02437 { a.swap(b); }
02438 
02439 
02440 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
02442 
02446 
02447 // for_each
02448 
02449 template <typename T, bool REFCNT, typename Fu>
02450 inline Fu for_each (Arageli::vector<T, REFCNT>& x, Fu f)
02451 { return for_each(x.begin(), x.end(), f); }
02452 
02453 template <typename T, bool REFCNT, typename Fu>
02454 inline Fu for_each (const Arageli::vector<T, REFCNT>& x, Fu f)
02455 { return for_each(x.begin(), x.end(), f); }
02456 
02457 // find
02458 
02459 template <typename T, bool REFCNT, typename T1>
02460 inline typename Arageli::vector<T, REFCNT>::iterator
02461 find (Arageli::vector<T, REFCNT>& x, const T1& val)
02462 { return find(x.begin(), x.end(), val); }
02463 
02464 template <typename T, bool REFCNT, typename T1>
02465 inline typename Arageli::vector<T, REFCNT>::const_iterator
02466 find (const Arageli::vector<T, REFCNT>& x, const T1& val)
02467 { return find(x.begin(), x.end(), val); }
02468 
02469 // find_if
02470 
02471 template <typename T, bool REFCNT, typename Fu>
02472 inline typename Arageli::vector<T, REFCNT>::iterator
02473 find_if (Arageli::vector<T, REFCNT>& x, Fu f)
02474 { return find_if(x.begin(), x.end(), f); }
02475 
02476 template <typename T, bool REFCNT, typename Fu>
02477 inline typename Arageli::vector<T, REFCNT>::const_iterator
02478 find_if (const Arageli::vector<T, REFCNT>& x, Fu f)
02479 { return find_if(x.begin(), x.end(), f); }
02480 
02481 // find_end
02482 
02483 template
02484 <
02485     typename T1, bool REFCNT1,
02486     typename T2, bool REFCNT2
02487 >
02488 inline typename Arageli::vector<T1, REFCNT1>::iterator
02489 find_end
02490 (
02491     Arageli::vector<T1, REFCNT1>& a,
02492     const Arageli::vector<T2, REFCNT2>& b
02493 )
02494 { return find_end(a.begin(), a.end(), b.begin(), b.end()); }
02495 
02496 
02497 template
02498 <
02499     typename T1, bool REFCNT1,
02500     typename T2, bool REFCNT2
02501 >
02502 inline typename Arageli::vector<T1, REFCNT1>::const_iterator
02503 find_end
02504 (
02505     const Arageli::vector<T1, REFCNT1>& a,
02506     const Arageli::vector<T2, REFCNT2>& b
02507 )
02508 { return find_end(a.begin(), a.end(), b.begin(), b.end()); }
02509 
02510 
02511 template
02512 <
02513     typename T1, bool REFCNT1,
02514     typename T2, bool REFCNT2,
02515     typename Fb
02516 >
02517 inline typename Arageli::vector<T1, REFCNT1>::iterator
02518 find_end
02519 (
02520     Arageli::vector<T1, REFCNT1>& a,
02521     const Arageli::vector<T2, REFCNT2>& b,
02522     Fb f
02523 )
02524 { return find_end(a.begin(), a.end(), b.begin(), b.end(), f); }
02525 
02526 
02527 template
02528 <
02529     typename T1, bool REFCNT1,
02530     typename T2, bool REFCNT2,
02531     typename Fb
02532 >
02533 inline typename Arageli::vector<T1, REFCNT1>::const_iterator
02534 find_end
02535 (
02536     const Arageli::vector<T1, REFCNT1>& a,
02537     const Arageli::vector<T2, REFCNT2>& b,
02538     Fb f
02539 )
02540 { return find_end(a.begin(), a.end(), b.begin(), b.end(), f); }
02541 
02542 // find_first_of
02543 
02544 template
02545 <
02546     typename T1, bool REFCNT1,
02547     typename T2, bool REFCNT2
02548 >
02549 inline typename Arageli::vector<T1, REFCNT1>::iterator
02550 find_first_of
02551 (
02552     Arageli::vector<T1, REFCNT1>& a,
02553     const Arageli::vector<T2, REFCNT2>& b
02554 )
02555 { return find_first_of(a.begin(), a.end(), b.begin(), b.end()); }
02556 
02557 
02558 template
02559 <
02560     typename T1, bool REFCNT1,
02561     typename T2, bool REFCNT2
02562 >
02563 inline typename Arageli::vector<T1, REFCNT1>::const_iterator
02564 find_first_of
02565 (
02566     const Arageli::vector<T1, REFCNT1>& a,
02567     const Arageli::vector<T2, REFCNT2>& b
02568 )
02569 { return find_first_of(a.begin(), a.end(), b.begin(), b.end()); }
02570 
02571 
02572 template
02573 <
02574     typename T1, bool REFCNT1,
02575     typename T2, bool REFCNT2,
02576     typename Fb
02577 >
02578 inline typename Arageli::vector<T1, REFCNT1>::iterator
02579 find_first_of
02580 (
02581     Arageli::vector<T1, REFCNT1>& a,
02582     const Arageli::vector<T2, REFCNT2>& b,
02583     Fb f
02584 )
02585 { return find_first_of(a.begin(), a.end(), b.begin(), b.end(), f); }
02586 
02587 
02588 template
02589 <
02590     typename T1, bool REFCNT1,
02591     typename T2, bool REFCNT2,
02592     typename Fb
02593 >
02594 inline typename Arageli::vector<T1, REFCNT1>::const_iterator
02595 find_first_of
02596 (
02597     const Arageli::vector<T1, REFCNT1>& a,
02598     const Arageli::vector<T2, REFCNT2>& b,
02599     Fb f
02600 )
02601 { return find_first_of(a.begin(), a.end(), b.begin(), b.end(), f); }
02602 
02603 // adjacent_find
02604 
02605 template <typename T, bool REFCNT>
02606 inline typename Arageli::vector<T, REFCNT>::iterator
02607 adjacent_find (Arageli::vector<T, REFCNT>& x)
02608 { return adjacent_find(x.begin(), x.end()); }
02609 
02610 template <typename T, bool REFCNT>
02611 inline typename Arageli::vector<T, REFCNT>::const_iterator
02612 adjacent_find (const Arageli::vector<T, REFCNT>& x)
02613 { return adjacent_find(x.begin(), x.end()); }
02614 
02615 template <typename T, bool REFCNT, typename Fb>
02616 inline typename Arageli::vector<T, REFCNT>::iterator
02617 adjacent_find (Arageli::vector<T, REFCNT>& x, Fb f)
02618 { return adjacent_find(x.begin(), x.end(), f); }
02619 
02620 template <typename T, bool REFCNT, typename Fb>
02621 inline typename Arageli::vector<T, REFCNT>::const_iterator
02622 adjacent_find (const Arageli::vector<T, REFCNT>& x, Fb f)
02623 { return adjacent_find(x.begin(), x.end(), f); }
02624 
02625 // count
02626 
02627 template <typename T, bool REFCNT, typename T1>
02628 inline typename Arageli::vector<T, REFCNT>::difference_type
02629 count (const Arageli::vector<T, REFCNT>& x, const T1& val)
02630 { return count(x.begin(), x.end(), val); }
02631 
02632 // count_if
02633 
02634 template <typename T, bool REFCNT, typename Fu>
02635 inline typename Arageli::vector<T, REFCNT>::difference_type
02636 count_if (const Arageli::vector<T, REFCNT>& x, Fu f)
02637 { return count_if(x.begin(), x.end(), f); }
02638 
02639 // mismatch
02640 
02641 template
02642 <
02643     typename T1, bool REFCNT1,
02644     typename T2, bool REFCNT2
02645 >
02646 inline
02647     pair
02648     <
02649         typename Arageli::vector<T1, REFCNT1>::const_iterator,
02650         typename Arageli::vector<T2, REFCNT2>::const_iterator
02651     >
02652 mismatch
02653 (
02654     const Arageli::vector<T1, REFCNT1>& a,
02655     const Arageli::vector<T2, REFCNT2>& b
02656 )
02657 {
02658     return mismatch
02659     (
02660         a.begin(), a.begin() + min(a.size(), b.size()),
02661         b.begin()
02662     );
02663 }
02664 
02665 
02666 template
02667 <
02668     typename T1, bool REFCNT1,
02669     typename T2, bool REFCNT2,
02670     typename Fb
02671 >
02672 inline
02673     pair
02674     <
02675         typename Arageli::vector<T1, REFCNT1>::const_iterator,
02676         typename Arageli::vector<T2, REFCNT2>::const_iterator
02677     >
02678 mismatch
02679 (
02680     const Arageli::vector<T1, REFCNT1>& a,
02681     const Arageli::vector<T2, REFCNT2>& b,
02682     Fb f
02683 )
02684 {
02685     return mismatch
02686     (
02687         a.begin(), a.begin() + min(a.size(), b.size()),
02688         b.begin(), f
02689     );
02690 }
02691 
02692 
02693 template
02694 <
02695     typename T1, bool REFCNT1,
02696     typename T2, bool REFCNT2
02697 >
02698 inline
02699     pair
02700     <
02701         typename Arageli::vector<T1, REFCNT1>::const_iterator,
02702         typename Arageli::vector<T2, REFCNT2>::iterator
02703     >
02704 mismatch
02705 (
02706     const Arageli::vector<T1, REFCNT1>& a,
02707     Arageli::vector<T2, REFCNT2>& b
02708 )
02709 {
02710     return mismatch
02711     (
02712         a.begin(), a.begin() + min(a.size(), b.size()),
02713         b.begin()
02714     );
02715 }
02716 
02717 
02718 template
02719 <
02720     typename T1, bool REFCNT1,
02721     typename T2, bool REFCNT2,
02722     typename Fb
02723 >
02724 inline
02725     pair
02726     <
02727         typename Arageli::vector<T1, REFCNT1>::const_iterator,
02728         typename Arageli::vector<T2, REFCNT2>::iterator
02729     >
02730 mismatch
02731 (
02732     const Arageli::vector<T1, REFCNT1>& a,
02733     Arageli::vector<T2, REFCNT2>& b,
02734     Fb f
02735 )
02736 {
02737     return mismatch
02738     (
02739         a.begin(), a.begin() + min(a.size(), b.size()),
02740         b.begin(), f
02741     );
02742 }
02743 
02744 
02745 template
02746 <
02747     typename T1, bool REFCNT1,
02748     typename T2, bool REFCNT2
02749 >
02750 inline
02751     pair
02752     <
02753         typename Arageli::vector<T1, REFCNT1>::iterator,
02754         typename Arageli::vector<T2, REFCNT2>::const_iterator
02755     >
02756 mismatch
02757 (
02758     Arageli::vector<T1, REFCNT1>& a,
02759     const Arageli::vector<T2, REFCNT2>& b
02760 )
02761 {
02762     return mismatch
02763     (
02764         a.begin(), a.begin() + min(a.size(), b.size()),
02765         b.begin()
02766     );
02767 }
02768 
02769 
02770 template
02771 <
02772     typename T1, bool REFCNT1,
02773     typename T2, bool REFCNT2,
02774     typename Fb
02775 >
02776 inline
02777     pair
02778     <
02779         typename Arageli::vector<T1, REFCNT1>::iterator,
02780         typename Arageli::vector<T2, REFCNT2>::const_iterator
02781     >
02782 mismatch
02783 (
02784     Arageli::vector<T1, REFCNT1>& a,
02785     const Arageli::vector<T2, REFCNT2>& b,
02786     Fb f
02787 )
02788 {
02789     return mismatch
02790     (
02791         a.begin(), a.begin() + min(a.size(), b.size()),
02792         b.begin(), f
02793     );
02794 }
02795 
02796 // equal
02797 
02798 template
02799 <
02800     typename T1, bool REFCNT1,
02801     typename T2, bool REFCNT2
02802 >
02803 inline bool equal
02804 (
02805     const Arageli::vector<T1, REFCNT1>& a,
02806     const Arageli::vector<T2, REFCNT2>& b
02807 )
02808 { return a == b; }
02809 
02810 
02811 template
02812 <
02813     typename T1, bool REFCNT1,
02814     typename T2, bool REFCNT2,
02815     typename Fb
02816 >
02817 inline bool equal
02818 (
02819     const Arageli::vector<T1, REFCNT1>& a,
02820     const Arageli::vector<T2, REFCNT2>& b,
02821     Fb f
02822 )
02823 {
02824     if(a.size() != b.size())return false;
02825     return equal(a.begin(), a.end(), b.begin(), f);
02826 }
02827 
02828 // search
02829 
02830 template
02831 <
02832     typename T1, bool REFCNT1,
02833     typename T2, bool REFCNT2
02834 >
02835 inline typename Arageli::vector<T1, REFCNT1>::const_iterator
02836 search
02837 (
02838     const Arageli::vector<T1, REFCNT1>& a,
02839     const Arageli::vector<T2, REFCNT2>& b
02840 )
02841 { return search(a.begin(), a.end(), b.begin(), b.end()); }
02842 
02843 
02844 template
02845 <
02846     typename T1, bool REFCNT1,
02847     typename T2, bool REFCNT2,
02848     typename Fb
02849 >
02850 inline typename Arageli::vector<T1, REFCNT1>::const_iterator
02851 search
02852 (
02853     const Arageli::vector<T1, REFCNT1>& a,
02854     const Arageli::vector<T2, REFCNT2>& b,
02855     Fb f
02856 )
02857 { return search(a.begin(), a.end(), b.begin(), b.end(), f); }
02858 
02859 
02860 template
02861 <
02862     typename T1, bool REFCNT1,
02863     typename T2, bool REFCNT2
02864 >
02865 inline typename Arageli::vector<T1, REFCNT1>::iterator
02866 search
02867 (
02868     Arageli::vector<T1, REFCNT1>& a,
02869     const Arageli::vector<T2, REFCNT2>& b
02870 )
02871 { return search(a.begin(), a.end(), b.begin(), b.end()); }
02872 
02873 
02874 template
02875 <
02876     typename T1, bool REFCNT1,
02877     typename T2, bool REFCNT2,
02878     typename Fb
02879 >
02880 inline typename Arageli::vector<T1, REFCNT1>::iterator
02881 search
02882 (
02883     Arageli::vector<T1, REFCNT1>& a,
02884     const Arageli::vector<T2, REFCNT2>& b,
02885     Fb f
02886 )
02887 { return search(a.begin(), a.end(), b.begin(), b.end(), f); }
02888 
02889 // search_n
02890 
02891 template
02892 <
02893     typename T1, bool REFCNT1,
02894     typename Size, typename T
02895 >
02896 inline typename Arageli::vector<T1, REFCNT1>::const_iterator
02897 search
02898 (
02899     const Arageli::vector<T1, REFCNT1>& a,
02900     Size count, const T& value
02901 )
02902 { return search_n(a.begin(), a.end(), count, value); }
02903 
02904 
02905 template
02906 <
02907     typename T1, bool REFCNT1,
02908     typename Size, typename T, typename Fb
02909 >
02910 inline typename Arageli::vector<T1, REFCNT1>::const_iterator
02911 search
02912 (
02913     const Arageli::vector<T1, REFCNT1>& a,
02914     Size count, const T& value, Fb f
02915 )
02916 { return search_n(a.begin(), a.end(), count, value, f); }
02917 
02918 
02919 template
02920 <
02921     typename T1, bool REFCNT1,
02922     typename Size, typename T
02923 >
02924 inline typename Arageli::vector<T1, REFCNT1>::iterator
02925 search
02926 (
02927     Arageli::vector<T1, REFCNT1>& a,
02928     Size count, const T& value
02929 )
02930 { return search_n(a.begin(), a.end(), count, value); }
02931 
02932 
02933 template
02934 <
02935     typename T1, bool REFCNT1,
02936     typename Size, typename T, typename Fb
02937 >
02938 inline typename Arageli::vector<T1, REFCNT1>::iterator
02939 search
02940 (
02941     Arageli::vector<T1, REFCNT1>& a,
02942     Size count, const T& value, Fb f
02943 )
02944 { return search_n(a.begin(), a.end(), count, value, f); }
02945 
02946 // copy
02947 
02948 template
02949 <
02950     typename T1, bool REFCNT1,
02951     typename Out
02952 >
02953 inline Out copy
02954 (
02955     const Arageli::vector<T1, REFCNT1>& a,
02956     Out out
02957 )
02958 { return copy(a.begin(), a.end(), out); }
02959 
02960 // copy_backward
02961 
02962 template
02963 <
02964     typename T1, bool REFCNT1,
02965     typename Out
02966 >
02967 inline Out copy_backward
02968 (
02969     const Arageli::vector<T1, REFCNT1>& a,
02970     Out out
02971 )
02972 { return copy_backward(a.begin(), a.end(), out); }
02973 
02974 // transform
02975 
02977 template <typename T1, bool REFCNT1, typename Fu>
02978 inline void transform (Arageli::vector<T1, REFCNT1>& a, Fu f)
02979 { return transform(a.begin(), a.end(), a.begin(), f); }
02980 
02981 
02983 
02984 template
02985 <
02986     typename T1, bool REFCNT1,
02987     typename T2, bool REFCNT2,
02988     typename Fu
02989 >
02990 inline void transform
02991 (
02992     const Arageli::vector<T1, REFCNT1>& a,
02993     Arageli::vector<T2, REFCNT2>& b,
02994     Fu f
02995 )
02996 {
02997     ARAGELI_ASSERT_0(a.size() <= b.size());
02998     return transform(a.begin(), a.end(), b.begin(), f);
02999 }
03000 
03001 
03002 template
03003 <
03004     typename T1, bool REFCNT1,
03005     typename T2, bool REFCNT2,
03006     typename T3, bool REFCNT3,
03007     typename Fb
03008 >
03009 inline void transform
03010 (
03011     const Arageli::vector<T1, REFCNT1>& a,
03012     const Arageli::vector<T2, REFCNT2>& b,
03013     Arageli::vector<T3, REFCNT3>& c,
03014     Fb f
03015 )
03016 {
03017     ARAGELI_ASSERT_0(a.size() <= b.size() && a.size() <= c.size());
03018     return transform(a.begin(), a.end(), b.begin(), c.begin(), f);
03019 }
03020 
03021 // replace
03022 
03023 template
03024 <
03025     typename T1, bool REFCNT1,
03026     typename T2
03027 >
03028 inline void replace
03029 (
03030     Arageli::vector<T1, REFCNT1>& a,
03031     const T2& oldv, const T2& newv  // WARNING! Type of oldv must not be
03032                                     // equal to type of newv.
03033 )
03034 { replace(a.begin(), a.end(), oldv, newv); }
03035 
03036 // replace_if
03037 
03038 template
03039 <
03040     typename T1, bool REFCNT1,
03041     typename Fu, typename T2
03042 >
03043 inline void replace_if
03044 (
03045     Arageli::vector<T1, REFCNT1>& a,
03046     Fu f, const T2& newv
03047 )
03048 { replace_if(a.begin(), a.end(), f, newv); }
03049 
03050 // replace_copy
03051 
03052 template
03053 <
03054     typename T1, bool REFCNT1,
03055     typename Out, typename T2
03056 >
03057 inline Out replace_copy
03058 (
03059     Arageli::vector<T1, REFCNT1>& a,
03060     Out out,
03061     const T2& oldv, const T2& newv  // WARNING! Type of oldv must not be
03062                                     // equal to type of newv.
03063 )
03064 { return replace_copy(a.begin(), a.end(), out, oldv, newv); }
03065 
03066 
03067 template
03068 <
03069     typename T1, bool REFCNT1,
03070     typename T2, bool REFCNT2,
03071     typename T3
03072 >
03073 inline void replace_copy
03074 (
03075     Arageli::vector<T1, REFCNT1>& a,
03076     Arageli::vector<T2, REFCNT2>& b,
03077     const T3& oldv, const T3& newv  // WARNING! Type of oldv must not be
03078                                     // equal to type of newv.
03079 )
03080 {
03081     ARAGELI_ASSERT_0(a.size() <= b.size());
03082     replace_copy(a.begin(), a.end(), b.begin(), oldv, newv);
03083 }
03084 
03085 // replace_copy_if
03086 
03087 template
03088 <
03089     typename T1, bool REFCNT1,
03090     typename Out, typename Fu, typename T2
03091 >
03092 inline Out replace_copy_if
03093 (
03094     Arageli::vector<T1, REFCNT1>& a,
03095     Out out,
03096     Fu f, const T2& newv
03097 )
03098 { return replace_copy_if(a.begin(), a.end(), out, f, newv); }
03099 
03100 
03101 template
03102 <
03103     typename T1, bool REFCNT1,
03104     typename T2, bool REFCNT2,
03105     typename Fu, typename T3
03106 >
03107 inline void replace_copy_if
03108 (
03109     Arageli::vector<T1, REFCNT1>& a,
03110     Arageli::vector<T2, REFCNT2>& b,
03111     Fu f, const T3& newv
03112 )
03113 {
03114     ARAGELI_ASSERT_0(a.size() <= b.size());
03115     replace_copy_if(a.begin(), a.end(), b.begin(), f, newv);
03116 }
03117 
03118 // fill
03119 
03120 template
03121 <
03122     typename T1, bool REFCNT1,
03123     typename T2
03124 >
03125 inline void fill
03126 (
03127     Arageli::vector<T1, REFCNT1>& a,
03128     const T2& v
03129 )
03130 { fill(a.begin(), a.end(), v); }
03131 
03132 // generate
03133 
03134 template
03135 <
03136     typename T1, bool REFCNT1,
03137     typename Fn
03138 >
03139 inline void generate
03140 (
03141     Arageli::vector<T1, REFCNT1>& a,
03142     Fn f
03143 )
03144 { generate(a.begin(), a.end(), f); }
03145 
03146 // remove
03147 
03148 template
03149 <
03150     typename T1, bool REFCNT1,
03151     typename T2
03152 >
03153 inline typename Arageli::vector<T1, REFCNT1>::iterator
03154 remove
03155 (
03156     Arageli::vector<T1, REFCNT1>& a,
03157     const T2& v
03158 )
03159 { return remove(a.begin(), a.end(), v); }
03160 
03161 // remove_if
03162 
03163 template
03164 <
03165     typename T1, bool REFCNT1,
03166     typename Fu
03167 >
03168 inline typename Arageli::vector<T1, REFCNT1>::iterator
03169 remove_if
03170 (
03171     Arageli::vector<T1, REFCNT1>& a,
03172     Fu f
03173 )
03174 { return remove_if(a.begin(), a.end(), f); }
03175 
03176 // remove_copy
03177 
03178 template
03179 <
03180     typename T1, bool REFCNT1,
03181     typename T2, typename Out
03182 >
03183 inline Out remove_copy
03184 (
03185     const Arageli::vector<T1, REFCNT1>& a,
03186     Out out, const T2& v
03187 )
03188 { return remove_copy(a.begin(), a.end(), out, v); }
03189 
03190 
03191 // remove_copy_if
03192 
03193 template
03194 <
03195     typename T1, bool REFCNT1,
03196     typename Fu, typename Out
03197 >
03198 inline Out remove_copy
03199 (
03200     const Arageli::vector<T1, REFCNT1>& a,
03201     Out out, Fu f
03202 )
03203 { return remove_copy_if(a.begin(), a.end(), out, f); }
03204 
03205 // unique
03206 
03207 template <typename T1, bool REFCNT1>
03208 inline typename Arageli::vector<T1, REFCNT1>::iterator
03209 unique (Arageli::vector<T1, REFCNT1>& a)
03210 { return unique(a.begin(), a.end()); }
03211 
03212 template <typename T1, bool REFCNT1, typename Fb>
03213 inline typename Arageli::vector<T1, REFCNT1>::iterator
03214 unique (Arageli::vector<T1, REFCNT1>& a, Fb f)
03215 { return unique(a.begin(), a.end(), f); }
03216 
03217 // unique_copy
03218 
03219 template
03220 <
03221     typename T1, bool REFCNT1,
03222     typename Out
03223 >
03224 inline Out unique_copy
03225 (const Arageli::vector<T1, REFCNT1>& a, Out out)
03226 { return unique_copy(a.begin(), a.end(), out); }
03227 
03228 
03229 template
03230 <
03231     typename T1, bool REFCNT1,
03232     typename Out, typename Fu
03233 >
03234 inline Out unique_copy
03235 (const Arageli::vector<T1, REFCNT1>& a, Out out, Fu f)
03236 { return unique_copy(a.begin(), a.end(), out, f); }
03237 
03238 // reverse
03239 
03240 template <typename T1, bool REFCNT1>
03241 inline void reverse (Arageli::vector<T1, REFCNT1>& a)
03242 { reverse(a.begin(), a.end()); }
03243 
03244 // reverse_copy
03245 
03246 template <typename T1, bool REFCNT1, typename Out>
03247 inline Out reverse_copy (const Arageli::vector<T1, REFCNT1>& a, Out out)
03248 { return reverse_copy(a.begin(), a.end(), out); }
03249 
03250 // rotate
03251 
03252 template <typename T1, bool REFCNT1>
03253 inline void rotate
03254 (
03255     Arageli::vector<T1, REFCNT1>& a,
03256     typename Arageli::vector<T1, REFCNT1>::iterator middle
03257 )
03258 { rotate(a.begin(), middle, a.end()); }
03259 
03260 template <typename T1, bool REFCNT1>
03261 inline void rotate
03262 (
03263     Arageli::vector<T1, REFCNT1>& a,
03264     typename Arageli::vector<T1, REFCNT1>::difference_type middle
03265 )
03266 { rotate(a.begin(), a.begin() + middle, a.end()); }
03267 
03268 // rotate_copy
03269 
03270 template <typename T1, bool REFCNT1, typename Out>
03271 inline Out rotate
03272 (
03273     Arageli::vector<T1, REFCNT1>& a,
03274     typename Arageli::vector<T1, REFCNT1>::iterator middle,
03275     Out out
03276 )
03277 { return rotate_copy(a.begin(), middle, a.end(), out); }
03278 
03279 template <typename T1, bool REFCNT1, typename Out>
03280 inline Out rotate
03281 (
03282     Arageli::vector<T1, REFCNT1>& a,
03283     typename Arageli::vector<T1, REFCNT1>::difference_type middle,
03284     Out out
03285 )
03286 { rotate_copy(a.begin(), a.begin() + middle, a.end(), out); }
03287 
03288 // random_shuffle
03289 
03290 template <typename T1, bool REFCNT1>
03291 inline void random_shuffle (Arageli::vector<T1, REFCNT1>& a)
03292 { random_shuffle(a.begin(), a.end()); }
03293 
03294 template <typename T1, bool REFCNT1, typename Rand>
03295 inline void random_shuffle
03296 (Arageli::vector<T1, REFCNT1>& a, Rand r)
03297 { random_shuffle(a.begin(), a.end(), r); }
03298 
03299 // partition
03300 
03301 template <typename T1, bool REFCNT1, typename Fu>
03302 inline typename Arageli::vector<T1, REFCNT1>::iterator
03303 partition (Arageli::vector<T1, REFCNT1>& a, Fu f)
03304 { return partition(a.begin(), a.end(), f); }
03305 
03306 // stable_partition
03307 
03308 template <typename T1, bool REFCNT1, typename Fu>
03309 inline typename Arageli::vector<T1, REFCNT1>::iterator
03310 stable_partition (Arageli::vector<T1, REFCNT1>& a, Fu f)
03311 { return stable_partition(a.begin(), a.end(), f); }
03312 
03313 // sort
03314 
03315 template <typename T1, bool REFCNT1>
03316 inline void sort (Arageli::vector<T1, REFCNT1>& a)
03317 { sort(a.begin(), a.end()); }
03318 
03319 template <typename T1, bool REFCNT1, typename Cmp>
03320 inline void sort (Arageli::vector<T1, REFCNT1>& a, Cmp cmp)
03321 { sort(a.begin(), a.end(), cmp); }
03322 
03323 // stable_sort
03324 
03325 template <typename T1, bool REFCNT1>
03326 inline void stable_sort (Arageli::vector<T1, REFCNT1>& a)
03327 { stable_sort(a.begin(), a.end()); }
03328 
03329 template <typename T1, bool REFCNT1, typename Cmp>
03330 inline void stable_sort (Arageli::vector<T1, REFCNT1>& a, Cmp cmp)
03331 { stable_sort(a.begin(), a.end(), cmp); }
03332 
03333 // partial_sort
03334 
03335 template <typename T1, bool REFCNT1>
03336 inline void partial_sort
03337 (
03338     Arageli::vector<T1, REFCNT1>& a,
03339     typename Arageli::vector<T1, REFCNT1>::iterator middle
03340 )
03341 { partial_sort(a.begin(), middle, a.end()); }
03342 
03343 template <typename T1, bool REFCNT1>
03344 inline void partial_sort
03345 (
03346     Arageli::vector<T1, REFCNT1>& a,
03347     typename Arageli::vector<T1, REFCNT1>::difference_type middle
03348 )
03349 { partial_sort(a.begin(), a.begin() + middle, a.end()); }
03350 
03351 template <typename T1, bool REFCNT1, typename Cmp>
03352 inline void partial_sort
03353 (
03354     Arageli::vector<T1, REFCNT1>& a,
03355     typename Arageli::vector<T1, REFCNT1>::iterator middle,
03356     Cmp cmp
03357 )
03358 { partial_sort(a.begin(), middle, a.end(), cmp); }
03359 
03360 template <typename T1, bool REFCNT1, typename Cmp>
03361 inline void partial_sort
03362 (
03363     Arageli::vector<T1, REFCNT1>& a,
03364     typename Arageli::vector<T1, REFCNT1>::difference_type middle,
03365     Cmp cmp
03366 )
03367 { partial_sort(a.begin(), a.begin() + middle, a.end(), cmp); }
03368 
03369 // partial_sort_copy
03370 
03371 template
03372 <
03373     typename T1, bool REFCNT1,
03374     typename T2, bool REFCNT2
03375 >
03376 inline typename Arageli::vector<T2, REFCNT2>::iterator
03377 partial_sort_copy
03378 (
03379     const Arageli::vector<T1, REFCNT1>& a,
03380     Arageli::vector<T2, REFCNT2>& b
03381 )
03382 { partial_sort_copy(a.begin(), a.end(), b.begin(), b.end()); }
03383 
03384 template
03385 <
03386     typename T1, bool REFCNT1,
03387     typename T2, bool REFCNT2,
03388     typename Cmp
03389 >
03390 inline typename Arageli::vector<T2, REFCNT2>::iterator
03391 partial_sort_copy
03392 (
03393     const Arageli::vector<T1, REFCNT1>& a,
03394     Arageli::vector<T2, REFCNT2>& b,
03395     Cmp cmp
03396 )
03397 { partial_sort_copy(a.begin(), a.end(), b.begin(), b.end(), cmp); }
03398 
03399 // nth_element
03400 
03401 template <typename T1, bool REFCNT1>
03402 inline void nth_element
03403 (
03404     Arageli::vector<T1, REFCNT1>& a,
03405     typename Arageli::vector<T1, REFCNT1>::iterator nth
03406 )
03407 { nth_element(a.begin(), nth, a.end()); }
03408 
03409 template <typename T1, bool REFCNT1, typename Cmp>
03410 inline void nth_element
03411 (
03412     Arageli::vector<T1, REFCNT1>& a,
03413     typename Arageli::vector<T1, REFCNT1>::iterator nth,
03414     Cmp cmp
03415 )
03416 { nth_element(a.begin(), nth, a.end(), cmp); }
03417 
03418 template <typename T1, bool REFCNT1>
03419 inline void nth_element
03420 (
03421     Arageli::vector<T1, REFCNT1>& a,
03422     typename Arageli::vector<T1, REFCNT1>::difference_type nth
03423 )
03424 { nth_element(a.begin(), a.begin() + nth, a.end()); }
03425 
03426 template <typename T1, bool REFCNT1, typename Cmp>
03427 inline void nth_element
03428 (
03429     Arageli::vector<T1, REFCNT1>& a,
03430     typename Arageli::vector<T1, REFCNT1>::difference_type nth,
03431     Cmp cmp
03432 )
03433 { nth_element(a.begin(), a.begin() + nth, a.end(), cmp); }
03434 
03435 // lower_bound
03436 
03437 template <typename T1, bool REFCNT1, typename T2>
03438 inline typename Arageli::vector<T1, REFCNT1>::iterator
03439 lower_bound
03440 (
03441     Arageli::vector<T1, REFCNT1>& a,
03442     const T2& v
03443 )
03444 { lower_bound(a.begin(), a.begin(), v); }
03445 
03446 template
03447 <
03448     typename T1, bool REFCNT1,
03449     typename T2, typename Cmp
03450 >
03451 inline typename Arageli::vector<T1, REFCNT1>::iterator
03452 lower_bound
03453 (
03454     Arageli::vector<T1, REFCNT1>& a,
03455     const T2& v, Cmp cmp
03456 )
03457 { lower_bound(a.begin(), a.begin(), v, cmp); }
03458 
03459 template <typename T1, bool REFCNT1, typename T2>
03460 inline typename Arageli::vector<T1, REFCNT1>::const_iterator
03461 lower_bound
03462 (
03463     const Arageli::vector<T1, REFCNT1>& a,
03464     const T2& v
03465 )
03466 { lower_bound(a.begin(), a.begin(), v); }
03467 
03468 template
03469 <
03470     typename T1, bool REFCNT1,
03471     typename T2, typename Cmp
03472 >
03473 inline typename Arageli::vector<T1, REFCNT1>::const_iterator
03474 lower_bound
03475 (
03476     const Arageli::vector<T1, REFCNT1>& a,
03477     const T2& v, Cmp cmp
03478 )
03479 { lower_bound(a.begin(), a.begin(), v, cmp); }
03480 
03481 // upper_bound
03482 
03483 template <typename T1, bool REFCNT1, typename T2>
03484 inline typename Arageli::vector<T1, REFCNT1>::iterator
03485 upper_bound
03486 (
03487     Arageli::vector<T1, REFCNT1>& a,
03488     const T2& v
03489 )
03490 { upper_bound(a.begin(), a.begin(), v); }
03491 
03492 template
03493 <
03494     typename T1, bool REFCNT1,
03495     typename T2, typename Cmp
03496 >
03497 inline typename Arageli::vector<T1, REFCNT1>::iterator
03498 upper_bound
03499 (
03500     Arageli::vector<T1, REFCNT1>& a,
03501     const T2& v, Cmp cmp
03502 )
03503 { upper_bound(a.begin(), a.begin(), v, cmp); }
03504 
03505 template <typename T1, bool REFCNT1, typename T2>
03506 inline typename Arageli::vector<T1, REFCNT1>::const_iterator
03507 upper_bound
03508 (
03509     const Arageli::vector<T1, REFCNT1>& a,
03510     const T2& v
03511 )
03512 { upper_bound(a.begin(), a.begin(), v); }
03513 
03514 template
03515 <
03516     typename T1, bool REFCNT1,
03517     typename T2, typename Cmp
03518 >
03519 inline typename Arageli::vector<T1, REFCNT1>::const_iterator
03520 upper_bound
03521 (
03522     const Arageli::vector<T1, REFCNT1>& a,
03523     const T2& v, Cmp cmp
03524 )
03525 { upper_bound(a.begin(), a.begin(), v, cmp); }
03526 
03527 // equal_range
03528 
03529 template <typename T1, bool REFCNT1, typename T2>
03530 inline
03531 pair
03532 <
03533     typename Arageli::vector<T1, REFCNT1>::iterator,
03534     typename Arageli::vector<T1, REFCNT1>::iterator
03535 >
03536 equal_range
03537 (
03538     Arageli::vector<T1, REFCNT1>& a,
03539     const T2& v
03540 )
03541 { equal_range(a.begin(), a.begin(), v); }
03542 
03543 template
03544 <
03545     typename T1, bool REFCNT1,
03546     typename T2, typename Cmp
03547 >
03548 inline
03549 pair
03550 <
03551     typename Arageli::vector<T1, REFCNT1>::iterator,
03552     typename Arageli::vector<T1, REFCNT1>::iterator
03553 >
03554 equal_range
03555 (
03556     Arageli::vector<T1, REFCNT1>& a,
03557     const T2& v, Cmp cmp
03558 )
03559 { equal_range(a.begin(), a.begin(), v, cmp); }
03560 
03561 template <typename T1, bool REFCNT1, typename T2>
03562 inline
03563 pair
03564 <
03565     typename Arageli::vector<T1, REFCNT1>::const_iterator,
03566     typename Arageli::vector<T1, REFCNT1>::const_iterator
03567 >
03568 equal_range
03569 (
03570     const Arageli::vector<T1, REFCNT1>& a,
03571     const T2& v
03572 )
03573 { equal_range(a.begin(), a.begin(), v); }
03574 
03575 template
03576 <
03577     typename T1, bool REFCNT1,
03578     typename T2, typename Cmp
03579 >
03580 inline
03581 pair
03582 <
03583     typename Arageli::vector<T1, REFCNT1>::const_iterator,
03584     typename Arageli::vector<T1, REFCNT1>::const_iterator
03585 >
03586 equal_range
03587 (
03588     const Arageli::vector<T1, REFCNT1>& a,
03589     const T2& v, Cmp cmp
03590 )
03591 { equal_range(a.begin(), a.begin(), v, cmp); }
03592 
03593 // binary_search
03594 
03595 template <typename T, bool REFCNT, typename T1>
03596 inline bool binary_search
03597 (const Arageli::vector<T, REFCNT>& x, const T1& val)
03598 { return binary_search(x.begin(), x.end(), val); }
03599 
03600 template
03601 <
03602     typename T, bool REFCNT,
03603     typename T1, typename Cmp
03604 >
03605 inline bool binary_search
03606 (const Arageli::vector<T, REFCNT>& x, const T1& val, Cmp cmp)
03607 { return binary_search(x.begin(), x.end(), val, cmp); }
03608 
03609 // merge
03610 
03611 template
03612 <
03613     typename T1, bool REFCNT1,
03614     typename T2, bool REFCNT2,
03615     typename Out
03616 >
03617 inline Out merge
03618 (
03619     const Arageli::vector<T1, REFCNT1>& a,
03620     const Arageli::vector<T2, REFCNT2>& b,
03621     Out out
03622 )
03623 { merge(a.begin(), a.end(), b.begin(), b.end(), out); }
03624 
03625 template
03626 <
03627     typename T1, bool REFCNT1,
03628     typename T2, bool REFCNT2,
03629     typename Out, typename Cmp
03630 >
03631 inline Out merge
03632 (
03633     const Arageli::vector<T1, REFCNT1>& a,
03634     const Arageli::vector<T2, REFCNT2>& b,
03635     Out out, Cmp cmp
03636 )
03637 { merge(a.begin(), a.end(), b.begin(), b.end(), out, cmp); }
03638 
03639 // inplace_merge
03640 
03641 template <typename T1, bool REFCNT1, typename Out>
03642 inline Out inplace_merge
03643 (
03644     Arageli::vector<T1, REFCNT1>& a,
03645     typename Arageli::vector<T1, REFCNT1>::iterator middle
03646 )
03647 { inplace_merge(a.begin(), middle, a.end()); }
03648 
03649 template
03650 <
03651     typename T1, bool REFCNT1,
03652     typename Out, typename Cmp
03653 >
03654 inline Out inplace_merge
03655 (
03656     Arageli::vector<T1, REFCNT1>& a,
03657     typename Arageli::vector<T1, REFCNT1>::iterator middle,
03658     Cmp cmp
03659 )
03660 { inplace_merge(a.begin(), middle, a.end(), cmp); }
03661 
03662 template <typename T1, bool REFCNT1, typename Out>
03663 inline Out inplace_merge
03664 (
03665     Arageli::vector<T1, REFCNT1>& a,
03666     typename Arageli::vector<T1, REFCNT1>::difference_type middle
03667 )
03668 { inplace_merge(a.begin(), a.begin() + middle, a.end()); }
03669 
03670 template
03671 <
03672     typename T1, bool REFCNT1,
03673     typename Out, typename Cmp
03674 >
03675 inline Out inplace_merge
03676 (
03677     Arageli::vector<T1, REFCNT1>& a,
03678     typename Arageli::vector<T1, REFCNT1>::difference_type middle,
03679     Cmp cmp
03680 )
03681 { inplace_merge(a.begin(), a.begin() + middle, a.end(), cmp); }
03682 
03683 
03684 // WARNING. Implementation of all other standard algorithm for vector
03685 // must be here. Those are 25.3.5--25.3.9.
03686 
03688 
03689 
03690 }
03691 
03692 
03693 #ifdef ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE
03694     #define ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE_VECTOR
03695     #include "vector.cpp"
03696     #undef  ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE_VECTOR
03697 #endif
03698 
03699 
03700 #endif  //  #ifndef _ARAGELI_vector_hpp_
03701 

Generated on Thu Aug 31 17:38:16 2006 for Arageli by  doxygen 1.4.7