vector.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002     
00003     vector.cpp -- Описание см. в файле vector.hpp.
00004 
00005     Этот файл является частью библиотеки Arageli.
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 #include "config.hpp"
00014 
00015 #if !defined(ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE) || \
00016     defined(ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE_VECTOR)
00017 
00018 #include <sstream>
00019 #include <vector>
00020 #include <string>
00021 #include <sstream>
00022 #include <list>
00023 #include <numeric>
00024 
00025 #include "vector.hpp"
00026 #include "_utility.hpp"
00027 
00028 
00029 namespace Arageli
00030 {
00031 
00032 
00033 template <typename T, bool REFCNT>
00034 void vector<T, REFCNT>::assign_fromstr (const char* s)
00035 {
00036     std::istringstream buf(s);
00037     // WARNING. It is valid if there are no virtual function.
00038     static_cast<std::istream&>(buf) >> *this;
00039     if(!buf && !buf.eof())
00040         throw incorrect_string(s);
00041 }
00042 
00043 
00044 template <typename T, bool REFCNT>
00045 bool vector<T, REFCNT>::is_null () const
00046 {
00047     for(size_type i = 0; i < size(); ++i)
00048         if(!Arageli::is_null(rep(i)))return false;
00049     return true;
00050 }
00051 
00052 
00053 template <typename T, bool REFCNT>
00054 bool vector<T, REFCNT>::is_unit () const
00055 {
00056     if(is_empty())return false;
00057     for(size_type i = 0; i < size(); ++i)
00058         if(!Arageli::is_unit(rep(i)))return false;
00059     return true;
00060 }
00061 
00062 
00063 template <typename T, bool REFCNT>
00064 bool vector<T, REFCNT>::is_opposite_unit () const
00065 {
00066     if(is_empty())return false;
00067     for(size_type i = 0; i < size(); ++i)
00068         if(!Arageli::is_opposite_unit(rep(i)))return false;
00069     return true;
00070 }
00071 
00072 
00073 template <typename T, bool REFCNT>
00074 vector<T, REFCNT>& vector<T, REFCNT>::inverse ()
00075 {
00076     unique();
00077     for(size_type i = 0; i < size(); ++i)
00078         Arageli::inverse(&rep(i));
00079     return *this;
00080 }
00081 
00082 
00083 template <typename T, bool REFCNT>
00084 vector<T, REFCNT>& vector<T, REFCNT>::bitwise_not ()
00085 {
00086     unique();
00087     for(size_type i = 0; i < size(); ++i)
00088         Arageli::assign_bitwise_not(rep(i));
00089     return *this;
00090 }
00091 
00092 template <typename T, bool REFCNT>
00093 vector<T, REFCNT>& vector<T, REFCNT>::logical_not ()
00094 {
00095     unique();
00096     for(size_type i = 0; i < size(); ++i)
00097         Arageli::assign_logical_not(rep(i));
00098     return *this;
00099 }
00100 
00101 //template <typename T, bool REFCNT>
00102 //bool vector<T, REFCNT>::operator! () const
00103 //{
00104 //  vector<bool> res(size());
00105 //
00106 //  for(size_type i = 0; i < size(); ++i)
00107 //      res[i] = blogical_not(rep(i));
00108 //  return *this;
00109 //}
00110 //
00111 
00112 //#define _ARAGELI_VECTOR_OPERATOR_ASSIGN_1(OPER, MNEM)                 \
00113 //  template <typename T1, bool REFCNT1>                                \
00114 //  template <typename T2>                                              \
00115 //  vector<T1, REFCNT1>& vector<T1, REFCNT1>::MNEM##_scalar             \
00116 //  (const T2& x)                                                       \
00117 //  {                                                                   \
00118 //      if(is_empty())return *this;                                     \
00119 //      /*unique();*/                                                   \
00120 //                                                                      \
00121 //      iterator i = begin(), iend = end();                             \
00122 //      for(; i < iend; ++i)                                            \
00123 //          *i OPER x;                                                  \
00124 //                                                                      \
00125 //      return *this;                                                   \
00126 //  }                                                                   \
00127 //                                                                      \
00128 //  template <typename T1, bool REFCNT1>                                \
00129 //  template <typename T2>                                              \
00130 //  vector<T1, REFCNT1>& vector<T1, REFCNT1>::MNEM##_vector             \
00131 //  (const T2& x)                                                       \
00132 //  {                                                                   \
00133 //      ARAGELI_ASSERT_0(x.size() == size());                           \
00134 //      if(is_empty())return *this;                                     \
00135 //      /*unique();*/                                                   \
00136 //                                                                      \
00137 //      iterator i1 = begin(), i1end = end();                           \
00138 //      typename T2::const_iterator i2 = x.begin();                     \
00139 //      for(; i1 < i1end; ++i1, ++i2)                                   \
00140 //          *i1 OPER *i2;                                               \
00141 //                                                                      \
00142 //      return *this;                                                   \
00143 //  }
00144 //
00145 //
00146 //_ARAGELI_VECTOR_OPERATOR_ASSIGN_1(+=, add)
00147 //_ARAGELI_VECTOR_OPERATOR_ASSIGN_1(-=, sub)
00148 //_ARAGELI_VECTOR_OPERATOR_ASSIGN_1(*=, mul)
00149 //_ARAGELI_VECTOR_OPERATOR_ASSIGN_1(/=, div);
00150 //_ARAGELI_VECTOR_OPERATOR_ASSIGN_1(%=, mod);
00151 //_ARAGELI_VECTOR_OPERATOR_ASSIGN_1(&=, bitand)
00152 //_ARAGELI_VECTOR_OPERATOR_ASSIGN_1(|=, bitor)
00153 //_ARAGELI_VECTOR_OPERATOR_ASSIGN_1(^=, bitxor)
00154 //_ARAGELI_VECTOR_OPERATOR_ASSIGN_1(<<=, shl)
00155 //_ARAGELI_VECTOR_OPERATOR_ASSIGN_1(>>=, shr)
00156 
00157 
00158 //#define _ARAGELI_VECTOR_OPERATOR_ASSIGN_2(OPER, MNEM)                 \
00159 //  template <typename T1, bool REFCNT1>                                \
00160 //  template <typename T2>                                              \
00161 //  vector<T1, REFCNT1>& vector<T1, REFCNT1>::MNEM##_scalar             \
00162 //  (const T2& x)                                                       \
00163 //  {                                                                   \
00164 //      ARAGELI_ASSERT_0(!is_null(x));                                  \
00165 //      if(is_empty())return *this;                                     \
00166 //      /*unique();*/                                                   \
00167 //                                                                      \
00168 //      iterator i = begin(), iend = end();                             \
00169 //      for(; i < iend; ++i)                                            \
00170 //          *i OPER x;                                                  \
00171 //                                                                      \
00172 //      return *this;                                                   \
00173 //  }                                                                   \
00174 //                                                                      \
00175 //  template <typename T1, bool REFCNT1>                                \
00176 //  template <typename T2>                                              \
00177 //  vector<T1, REFCNT1>& vector<T1, REFCNT1>::MNEM##_vector             \
00178 //  (const T2& x)                                                       \
00179 //  {                                                                   \
00180 //      ARAGELI_ASSERT_0(x.size() == size());                           \
00181 //      if(is_empty())return *this;                                     \
00182 //      unique();                                                       \
00183 //                                                                      \
00184 //      iterator i1 = begin(), i1end = end();                           \
00185 //      typename T2::const_iterator i2 = x.begin();                     \
00186 //      for(; i1 < i1end; ++i1, ++i2)                                   \
00187 //      {                                                               \
00188 //          ARAGELI_ASSERT_0(!is_null(*i2]));                           \
00189 //          *i1 OPER *i2;                                               \
00190 //      }                                                               \
00191 //                                                                      \
00192 //      return *this;                                                   \
00193 //  }
00194 //
00195 //_ARAGELI_VECTOR_OPERATOR_ASSIGN_2(/=, div);
00196 //_ARAGELI_VECTOR_OPERATOR_ASSIGN_2(%=, mod);
00197 
00198 #undef _ARAGELI_VECTOR_OPERATOR_ASSIGN_1
00199 //#undef _ARAGELI_VECTOR_OPERATOR_ASSIGN_2
00200 
00201 
00202 //template <typename T1, bool REFCNT1>
00203 //template <typename T2>
00204 //vector<T1, REFCNT1>& vector<T1, REFCNT1>::operator+=
00205 //(const T2& x)
00206 //{
00207 //  if(is_empty())return *this;
00208 //  unique();
00209 //
00210 //  Rep& repr = rep();
00211 //  for(size_type i = 0; i < size(); ++i)
00212 //      repr[i] += x;
00213 //
00214 //  return *this;
00215 //}
00216 //
00217 //
00218 //template <typename T1, bool REFCNT1>
00219 //template <typename T2>
00220 //vector<T1, REFCNT1>& vector<T1, REFCNT1>::operator-=
00221 //(const T2& x)
00222 //{
00223 //  if(is_empty())return *this;
00224 //  unique();
00225 //
00226 //  Rep& repr = rep();
00227 //  for(size_type i = 0; i < size(); ++i)
00228 //      repr[i] -= x;
00229 //
00230 //  return *this;
00231 //}
00232 //
00233 //
00234 //template <typename T1, bool REFCNT1>
00235 //template <typename T2>
00236 //vector<T1, REFCNT1>& vector<T1, REFCNT1>::operator*=
00237 //(const T2& x)
00238 //{
00239 //  if(is_empty())return *this;
00240 //  unique();
00241 //
00242 //  Rep& repr = rep();
00243 //  for(size_type i = 0; i < size(); ++i)
00244 //      repr[i] *= x;
00245 //
00246 //  return *this;
00247 //}
00248 
00249 
00250 //template <typename T1, bool REFCNT1>
00251 //template <typename T2>
00252 //vector<T1, REFCNT1>& vector<T1, REFCNT1>::operator/=
00253 //(const T2& x)
00254 //{
00255 //  ARAGELI_ASSERT_0(!type_traits<T2>::is_null(x));
00256 //  if(is_empty())return *this;
00257 //  unique();
00258 //
00259 //  Rep& repr = rep();
00260 //  for(size_type i = 0; i < size(); ++i)
00261 //      repr[i] /= x;
00262 //
00263 //  return *this;
00264 //}
00265 //
00266 //
00267 //template <typename T1, bool REFCNT1>
00268 //template <typename T2>
00269 //vector<T1, REFCNT1>& vector<T1, REFCNT1>::operator%=
00270 //(const T2& x)
00271 //{
00272 //  ARAGELI_ASSERT_0(!type_traits<T2>::is_null(x));
00273 //  if(is_empty())return *this;
00274 //  unique();
00275 //
00276 //  Rep& repr = rep();
00277 //  for(size_type i = 0; i < size(); ++i)
00278 //      repr[i] %= x;
00279 //
00280 //  return *this;
00281 //}
00282 
00283 
00284 //template <typename T1, bool REFCNT1>
00285 //template <typename T2, bool REFCNT2>
00286 //vector<T1, REFCNT1>& vector<T1, REFCNT1>::operator+=
00287 //(const vector<T2, REFCNT2>& x)
00288 //{
00289 //  ARAGELI_ASSERT_0(x.size() == size());
00290 //  if(is_empty())return *this;
00291 //  unique();
00292 //
00293 //  Rep& repr1 = rep();
00294 //  const typename vector<T2, REFCNT2>::Rep& repr2 = x.rep();
00295 //  for(size_type i = 0; i < repr1.size(); ++i)
00296 //      repr1[i] += repr2[i];
00297 //
00298 //  return *this;
00299 //}
00300 //
00301 //
00302 //template <typename T1, bool REFCNT1>
00303 //template <typename T2, bool REFCNT2>
00304 //vector<T1, REFCNT1>& vector<T1, REFCNT1>::operator-=
00305 //(const vector<T2, REFCNT2>& x)
00306 //{
00307 //  ARAGELI_ASSERT_0(x.size() == size());
00308 //  if(is_empty())return *this;
00309 //  unique();
00310 //
00311 //  Rep& repr1 = rep();
00312 //  const typename vector<T2, REFCNT2>::Rep& repr2 = x.rep();
00313 //  for(size_type i = 0; i < repr1.size(); ++i)
00314 //      repr1[i] -= repr2[i];
00315 //
00316 //  return *this;
00317 //}
00318 //
00319 //
00320 //template <typename T1, bool REFCNT1>
00321 //template <typename T2, bool REFCNT2>
00322 //vector<T1, REFCNT1>& vector<T1, REFCNT1>::operator*=
00323 //(const vector<T2, REFCNT2>& x)
00324 //{
00325 //  ARAGELI_ASSERT_0(x.size() == size());
00326 //  if(is_empty())return *this;
00327 //  unique();
00328 //
00329 //  Rep& repr1 = rep();
00330 //  const typename vector<T2, REFCNT2>::Rep& repr2 = x.rep();
00331 //  for(size_type i = 0; i < repr1.size(); ++i)
00332 //      repr1[i] *= repr2[i];
00333 //
00334 //  return *this;
00335 //}
00336 
00337 
00338 //template <typename T1, bool REFCNT1>
00339 //template <typename T2, bool REFCNT2>
00340 //vector<T1, REFCNT1>& vector<T1, REFCNT1>::operator/=
00341 //(const vector<T2, REFCNT2>& x)
00342 //{
00343 //  ARAGELI_ASSERT_0(x.size() == size());
00344 //  if(is_empty())return *this;
00345 //  unique();
00346 //
00347 //  Rep& repr1 = rep();
00348 //  const typename vector<T2, REFCNT2>::Rep& repr2 = x.rep();
00349 //  for(size_type i = 0; i < repr1.size(); ++i)
00350 //  {
00351 //      ARAGELI_ASSERT_0(!TT2::is_null(repr2[i]));
00352 //      repr1[i] /= repr2[i];
00353 //  }
00354 //
00355 //  return *this;
00356 //}
00357 //
00358 //
00359 //template <typename T1, bool REFCNT1>
00360 //template <typename T2, bool REFCNT2>
00361 //vector<T1, REFCNT1>& vector<T1, REFCNT1>::operator%=
00362 //(const vector<T2, REFCNT2>& x)
00363 //{
00364 //  ARAGELI_ASSERT_0(x.size() == size());
00365 //  if(is_empty())return *this;
00366 //  unique();
00367 //
00368 //  Rep& repr1 = rep();
00369 //  const typename vector<T2, REFCNT2>::Rep& repr2 = x.rep();
00370 //  for(size_type i = 0; i < repr1.size(); ++i)
00371 //  {
00372 //      ARAGELI_ASSERT_0(!TT2::is_null(repr2[i]));
00373 //      repr1[i] %= repr2[i];
00374 //  }
00375 //
00376 //  return *this;
00377 //}
00378 
00379 
00380 template <typename T1, bool REFCNT1>
00381 vector<T1, REFCNT1>& vector<T1, REFCNT1>::opposite ()
00382 {
00383     if(is_empty())return *this;
00384     unique();
00385 
00386     Rep& repr1 = rep();
00387     for(size_type i = 0; i < size(); ++i)
00388         Arageli::opposite(&repr1[i]);
00389 
00390     return *this;
00391 }
00392 
00393 
00394 template <typename T, bool REFCNT>
00395 bool vector<T, REFCNT>::do_pack ()
00396 {
00397     ARAGELI_ASSERT_1(size() < capacity());
00398 
00399     unique();
00400     Rep trep = rep();
00401     trep.swap(rep());
00402 }
00403 
00404 
00405 template <typename T, bool REFCNT>
00406 template <typename SV, typename V>
00407 V& vector<T, REFCNT>::copy_subvector (const SV& sv, V& res) const
00408 {
00409     size_type sz = sv.size();
00410     res.resize(sz);
00411     const_iterator thisvec = begin();
00412     typename V::iterator iv = res.begin();
00413 
00414     for
00415     (
00416         typename SV::const_iterator i = sv.begin(), svend = sv.end();
00417         i != svend;
00418         ++i, ++iv
00419     )
00420     {
00421         ARAGELI_ASSERT_0(*i < size());
00422         *iv = thisvec[*i];
00423     }
00424 
00425     return res;
00426 }
00427 
00428 
00429 template <typename T, bool REFCNT>
00430 template <typename SV>
00431 void vector<T, REFCNT>::erase_subvector (const SV& sv)
00432 {
00433     // WARNING! Slow implementation!!!
00434     // O(sv.size() * log(sv.size()) + this->size())
00435 
00436     //std::cout << "\n*** sv = " << sv << " ***\n";
00437 
00438     if(sv.is_empty())return;
00439 
00440     SV svt = sv;    // copy because need sorting and uniquelization
00441     typedef typename SV::iterator SViter;
00442     std::sort(svt.begin(), svt.end());
00443     
00444     SViter
00445         svti = svt.begin(),
00446         svtend = std::unique(svti, svt.end());
00447 
00448     size_type curerased = *svti;
00449 
00450     //if(*(svtend-1) >= size())
00451     //{
00452     //  std::cout << "\nsv = " << sv << ", *(svtend-1) = " << *(svtend-1) << ", size() = " << size();
00453     //}
00454     
00455     ARAGELI_ASSERT_0(*(svtend-1) < size());
00456     ARAGELI_ASSERT_0(curerased < size());
00457     
00458     iterator
00459         thisdst = begin() + curerased,
00460         thissrc = thisdst + 1,
00461         thisend = end();
00462 
00463     for(;;)
00464     {
00465         ++svti;
00466 
00467         if(svti != svtend && *svti == curerased+1)
00468         {
00469             ++curerased;
00470             ++svti;
00471             ARAGELI_ASSERT_0(thissrc != thisend);
00472             ++thissrc;
00473         }
00474 
00475         ARAGELI_ASSERT_1(thissrc != thisend || svti == svtend);
00476 
00477         iterator tend =     // end of current copied part of vector
00478             svti == svtend ?
00479             thisend : thissrc + (*svti - curerased - 1);
00480 
00481         thisdst = std::copy(thissrc, tend, thisdst);
00482 
00483         if(tend == thisend)
00484             break;
00485 
00486         thissrc = tend + 1;
00487         ARAGELI_ASSERT_1(svti != svtend);
00488         curerased = *svti;
00489     }
00490 
00491     ARAGELI_ASSERT_1(svti == svtend);
00492     ARAGELI_ASSERT_1(thisdst + (svtend - svt.begin()) == thisend);
00493     erase(thisdst, thisend);
00494 }
00495 
00496 
00497 
00498 
00499 template
00500 <
00501     typename T1, bool REFCNT1,
00502     typename T2, bool REFCNT2,
00503     typename T1_factory
00504 >
00505 T1 dotprod
00506 (
00507     const vector<T1, REFCNT1>& a,
00508     const vector<T2, REFCNT2>& b,
00509     const T1_factory& t1fctr
00510 )
00511 {
00512     ARAGELI_ASSERT_0(a.size() == b.size());
00513 
00514     T1 res = a.is_empty() ? t1fctr.null() : t1fctr.null(a[0]);
00515     typename vector<T1, REFCNT1>::size_type size = a.size();
00516     
00517     for(std::size_t i = 0; i < size; ++i)
00518         res += a[i]*b[i];
00519 
00520     return res;
00521 }
00522 
00523 
00524 template <typename T, bool REFCNT, typename T2, typename T2_factory>
00525 T2& product (const vector<T, REFCNT>& x, T2& res, const T2_factory& t2fctr)
00526 {
00527     if(x.is_empty())return res = t2fctr.unit();
00528     res = x[0];
00529     for(std::size_t i = 1; i < x.size(); ++i)
00530         res *= x[i];
00531     return res;
00532 }
00533 
00534 
00535 template <typename T, bool REFCNT, typename T2, typename T2_factory>
00536 T2& sum (const vector<T, REFCNT>& x, T2& res, const T2_factory& t2fctr)
00537 {
00538     if(x.is_empty())return res = t2fctr.null();
00539     res = x[0];
00540     for(std::size_t i = 1; i < x.size(); ++i)
00541         res += x[i];
00542     return res;
00543 }
00544 
00545 
00546 template <typename In, typename T, bool REFCNT>
00547 In& input_list
00548 (
00549     In& in,
00550     vector<T, REFCNT>& x,
00551     const char* first_bracket,
00552     const char* second_bracket,
00553     const char* separator,
00554     const char* range
00555 )
00556 {
00557     ARAGELI_ASSERT_0(_Internal::is_not_contains_spaces(first_bracket));
00558     ARAGELI_ASSERT_0(_Internal::is_not_contains_spaces(second_bracket));
00559     ARAGELI_ASSERT_0(_Internal::is_not_contains_spaces(separator));
00560     ARAGELI_ASSERT_0(_Internal::is_not_contains_spaces(range));
00561 
00562     if(_Internal::is_bad_read_literal(in, first_bracket))return in;
00563 
00564     // (second_bracket == "") is special case
00565     // in this case vector must be terminated by the some invalid character
00566 
00567     if(*second_bracket && _Internal::read_literal(in, second_bracket))
00568     { // empty vector
00569         x.resize(0);
00570         return in;
00571     }
00572 
00573     std::list<T> buf;   // a temporary buffer for values
00574 
00575     T t;
00576     
00577     for(;;)
00578     {
00579         in >> t;
00580     
00581         if(_Internal::is_bad_input(in))return in;
00582         else if(_Internal::read_literal(in, separator))
00583         { // "t,"
00584             buf.push_back(t);
00585             continue;
00586         }
00587         else if(_Internal::read_literal(in, range))
00588         { // "t:"
00589             T t1;
00590             in >> t1;
00591             
00592             if(_Internal::is_bad_input(in))return in;
00593             else if(_Internal::read_literal(in, separator))
00594             { // "t:t1,"
00595                 generate_range_helper(t, t1, std::back_inserter(buf));
00596                 continue;
00597             }
00598             else if(_Internal::read_literal(in, range))
00599             { // "t:t1:"
00600                 T t2;
00601                 in >> t2;
00602 
00603                 if(_Internal::is_bad_input(in))return in;
00604                 else if(_Internal::read_literal(in, separator))
00605                 { // "t:t1:t2,"
00606                     generate_range_helper(t, t1, t2, std::back_inserter(buf));
00607                     continue;
00608                 }
00609                 else if
00610                 (
00611                     *second_bracket == 0 ||
00612                     _Internal::read_literal(in, second_bracket)
00613                 )
00614                 { // "t:t1:t2)"
00615                     generate_range_helper(t, t1, t2, std::back_inserter(buf));
00616                     break;
00617                 }
00618             }
00619             else if(*second_bracket == 0 || _Internal::read_literal(in, second_bracket))
00620             { // "t:t1)"
00621                 generate_range_helper(t, t1, std::back_inserter(buf));
00622                 break;
00623             }
00624         }
00625         else if(*second_bracket == 0 || _Internal::read_literal(in, second_bracket))
00626         { // "t)"
00627             buf.push_back(t);
00628             break;
00629         }
00630         
00631         in.clear(std::ios_base::badbit);
00632         return in;
00633     }
00634 
00635     // WARNING! Inefficient!
00636     //std::copy(buf.begin(), buf.end(), std::ostream_iterator<T>(std::cerr, ", "));
00637     x.resize(buf.size());
00638     std::copy(buf.begin(), buf.end(), x.begin());
00639     return in;
00640 }
00641 
00642 
00643 template <typename T, bool REFCNT>
00644 std::ostream& output_aligned
00645 (
00646     std::ostream& out,
00647     const vector<T, REFCNT>& x,
00648     const char* left_col,
00649     const char* right_col
00650 )
00651 {
00652     if(x.is_empty())return out;
00653     
00654     std::vector<std::string> buf(x.size());
00655     std::size_t maxlen = 0;
00656 
00657     for(std::size_t i = 0; i < x.size(); ++i)
00658     {
00659         std::ostringstream strbuf;
00660         strbuf.copyfmt(out);
00661         strbuf << x[i];
00662         buf[i] = strbuf.str();
00663 
00664         if(buf[i].length() > maxlen)
00665             maxlen = buf[i].length();
00666     }
00667 
00668     for(std::size_t i = 0; i < x.size(); ++i)
00669     {
00670         std::size_t numspace = maxlen - buf[i].length();
00671         
00672         out
00673             << left_col << std::string(numspace/2, ' ')
00674             << buf[i] << std::string(numspace - numspace/2, ' ')
00675             << right_col << '\n';
00676     }
00677 
00678     return out;
00679 }
00680 
00681 
00682 template <typename T, bool REFCNT>
00683 std::istream& input_polynom_internal
00684 (std::istream& in, vector<T, REFCNT>& x)
00685 {
00686     char ch = 0;
00687     in >> ch;
00688     if(!in && !in.eof() || ch != '+' && ch != '-')return in;
00689     vector<T, REFCNT> res;
00690     in >> res;
00691     if(!in && !in.eof())return in;
00692     if(ch == '-')res.opposite();
00693     x = res;
00694     return in;
00695 }
00696 
00697 
00698 #define ARAGELI_VECTOR_MATH_FUNCS1_IMPL(NAME)           \
00699     template <typename T, bool REFCNT>                  \
00700     vector<T, true> NAME                                \
00701     (const vector<T, REFCNT>& x)                        \
00702     {                                                   \
00703         std::size_t size = x.size();                            \
00704         vector<T, true> res(size);                      \
00705                                                         \
00706         typename vector<T, REFCNT>::const_iterator      \
00707             xbeg = x.begin();                           \
00708         typename vector<T, true>::iterator              \
00709             resbeg = res.begin();                       \
00710                                                         \
00711         for(std::size_t i = 0; i < size; ++i)               \
00712             resbeg[i] = NAME(xbeg[i]);                  \
00713                                                         \
00714         return res;                                     \
00715     }
00716 
00717 
00718 ARAGELI_VECTOR_MATH_FUNCS1_IMPL(sin)
00719 ARAGELI_VECTOR_MATH_FUNCS1_IMPL(cos)
00720 ARAGELI_VECTOR_MATH_FUNCS1_IMPL(tan)
00721 ARAGELI_VECTOR_MATH_FUNCS1_IMPL(sinh)
00722 ARAGELI_VECTOR_MATH_FUNCS1_IMPL(cosh)
00723 ARAGELI_VECTOR_MATH_FUNCS1_IMPL(tanh)
00724 ARAGELI_VECTOR_MATH_FUNCS1_IMPL(asin)
00725 ARAGELI_VECTOR_MATH_FUNCS1_IMPL(acos)
00726 ARAGELI_VECTOR_MATH_FUNCS1_IMPL(atan)
00727 ARAGELI_VECTOR_MATH_FUNCS1_IMPL(abs)
00728 ARAGELI_VECTOR_MATH_FUNCS1_IMPL(exp)
00729 ARAGELI_VECTOR_MATH_FUNCS1_IMPL(floor)
00730 ARAGELI_VECTOR_MATH_FUNCS1_IMPL(ceil)
00731 ARAGELI_VECTOR_MATH_FUNCS1_IMPL(log)
00732 ARAGELI_VECTOR_MATH_FUNCS1_IMPL(log10)
00733 ARAGELI_VECTOR_MATH_FUNCS1_IMPL(sqrt)
00734 
00735 
00736 #undef ARAGELI_VECTOR_MATH_FUNCS1_IMPL
00737 
00738     
00739 template
00740 <
00741     typename T1, bool REFCNT1,
00742     typename T2, bool REFCNT2
00743 >
00744 vector<T1, REFCNT1> pow
00745 (
00746     const vector<T1, REFCNT1>& a,
00747     const vector<T2, REFCNT2>& b
00748 )
00749 {
00750     ARAGELI_ASSERT_0(a.size() == b.size());
00751     std::size_t size = a.size();
00752     vector<T1, REFCNT1> res(size);
00753     for(std::size_t i = 0; i < size; ++i)
00754         res[i] = pow(a[i], b[i]);
00755 
00756     return res;
00757 }
00758 
00759 
00760 template
00761 <
00762     typename T, bool REFCNT,
00763     typename P
00764 >
00765 vector<T, REFCNT> pow
00766 (const vector<T, REFCNT>& a, const P& b)
00767 {
00768     std::size_t size = a.size();
00769     vector<T, REFCNT> res(size);
00770     for(std::size_t i = 0; i < size; ++i)
00771         res[i] = pow(a[i], b);
00772 }
00773 
00774 } // namespace Arageli
00775 
00776 
00777 namespace std
00778 {
00779 
00780 
00781 
00782 }
00783 
00784 #endif // #ifndef ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE

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