1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347
|
//
// Copyright (c) 2003
// Gunter Winkler, Joerg Walter
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// The authors gratefully acknowledge the support of
// GeNeSys mbH & Co. KG in producing this work.
//
#ifndef _BOOST_UBLAS_VECTOR_OF_VECTOR_
#define _BOOST_UBLAS_VECTOR_OF_VECTOR_
#include <boost/type_traits.hpp>
#include <boost/numeric/ublas/storage_sparse.hpp>
#include <boost/numeric/ublas/matrix_sparse.hpp>
// Iterators based on ideas of Jeremy Siek
namespace boost { namespace numeric { namespace ublas {
// uBLAS sparse vector based sparse matrix class
// FIXME outer vector can be sparse type but it is completely filled
template<class T, class L, class A>
class generalized_vector_of_vector:
public matrix_container<generalized_vector_of_vector<T, L, A> > {
typedef T &true_reference;
typedef T *pointer;
typedef const T *const_pointer;
typedef L layout_type;
typedef generalized_vector_of_vector<T, L, A> self_type;
public:
#ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
using matrix_container<self_type>::operator ();
#endif
typedef typename A::size_type size_type;
typedef typename A::difference_type difference_type;
typedef T value_type;
typedef const T &const_reference;
#ifndef BOOST_UBLAS_STRICT_VECTOR_SPARSE
typedef T &reference;
#else
typedef sparse_matrix_element<self_type> reference;
#endif
typedef A array_type;
typedef const matrix_reference<const self_type> const_closure_type;
typedef matrix_reference<self_type> closure_type;
typedef typename A::value_type vector_data_value_type;
typedef vector_data_value_type vector_temporary_type;
typedef self_type matrix_temporary_type;
typedef sparse_tag storage_category;
typedef typename L::orientation_category orientation_category;
// Construction and destruction
BOOST_UBLAS_INLINE
generalized_vector_of_vector ():
matrix_container<self_type> (),
size1_ (0), size2_ (0), data_ (1) {
const size_type sizeM = layout_type::size_M (size1_, size2_);
// create size1+1 empty vector elements
data_.insert_element (sizeM, vector_data_value_type ());
storage_invariants ();
}
BOOST_UBLAS_INLINE
generalized_vector_of_vector (size_type size1, size_type size2, size_type non_zeros = 0):
matrix_container<self_type> (),
size1_ (size1), size2_ (size2), data_ (layout_type::size_M (size1_, size2_) + 1) {
const size_type sizeM = layout_type::size_M (size1_, size2_);
const size_type sizem = layout_type::size_m (size1_, size2_);
for (size_type i = 0; i < sizeM; ++ i) // create size1 vector elements
data_.insert_element (i, vector_data_value_type ()) .resize (sizem, false);
data_.insert_element (sizeM, vector_data_value_type ());
storage_invariants ();
}
BOOST_UBLAS_INLINE
generalized_vector_of_vector (const generalized_vector_of_vector &m):
matrix_container<self_type> (),
size1_ (m.size1_), size2_ (m.size2_), data_ (m.data_) {
storage_invariants ();
}
template<class AE>
BOOST_UBLAS_INLINE
generalized_vector_of_vector (const matrix_expression<AE> &ae, size_type non_zeros = 0):
matrix_container<self_type> (),
size1_ (ae ().size1 ()), size2_ (ae ().size2 ()), data_ (layout_type::size_M (size1_, size2_) + 1) {
const size_type sizeM = layout_type::size_M (size1_, size2_);
const size_type sizem = layout_type::size_m (size1_, size2_);
for (size_type i = 0; i < sizeM; ++ i) // create size1 vector elements
data_.insert_element (i, vector_data_value_type ()) .resize (sizem, false);
data_.insert_element (sizeM, vector_data_value_type ());
storage_invariants ();
matrix_assign<scalar_assign> (*this, ae);
}
// Accessors
BOOST_UBLAS_INLINE
size_type size1 () const {
return size1_;
}
BOOST_UBLAS_INLINE
size_type size2 () const {
return size2_;
}
BOOST_UBLAS_INLINE
size_type nnz_capacity () const {
size_type non_zeros = 0;
for (const_vectoriterator_type itv = data_.begin (); itv != data_.end (); ++ itv)
non_zeros += (*itv).nnz_capacity ();
return non_zeros;
}
BOOST_UBLAS_INLINE
size_type nnz () const {
size_type non_zeros = 0;
for (const_vectoriterator_type itv = data_.begin (); itv != data_.end (); ++ itv)
non_zeros += (*itv).nnz ();
return non_zeros;
}
// Storage accessors
BOOST_UBLAS_INLINE
const array_type &data () const {
return data_;
}
BOOST_UBLAS_INLINE
array_type &data () {
return data_;
}
// Resizing
BOOST_UBLAS_INLINE
void resize (size_type size1, size_type size2, bool preserve = true) {
const size_type oldM = layout_type::size_M (size1_, size2_);
size1_ = size1;
size2_ = size2;
const size_type sizeM = layout_type::size_M (size1_, size2_);
const size_type sizem = layout_type::size_m (size1_, size2_);
data ().resize (sizeM + 1, preserve);
if (preserve) {
for (size_type i = 0; (i <= oldM) && (i < sizeM); ++ i)
ref (data () [i]).resize (sizem, preserve);
for (size_type i = oldM+1; i < sizeM; ++ i) // create new vector elements
data_.insert_element (i, vector_data_value_type ()) .resize (sizem, false);
if (sizeM > oldM) {
data_.insert_element (sizeM, vector_data_value_type ());
} else {
ref (data () [sizeM]).resize (0, false);
}
} else {
for (size_type i = 0; i < sizeM; ++ i)
data_.insert_element (i, vector_data_value_type ()) .resize (sizem, false);
data_.insert_element (sizeM, vector_data_value_type ());
}
storage_invariants ();
}
// Element support
BOOST_UBLAS_INLINE
pointer find_element (size_type i, size_type j) {
return const_cast<pointer> (const_cast<const self_type&>(*this).find_element (i, j));
}
BOOST_UBLAS_INLINE
const_pointer find_element (size_type i, size_type j) const {
const size_type elementM = layout_type::index_M (i, j);
const size_type elementm = layout_type::index_m (i, j);
// optimise: check the storage_type and index directly if element always exists
if (boost::is_convertible<typename array_type::storage_category, packed_tag>::value) {
return & (data () [elementM] [elementm]);
}
else {
const typename array_type::value_type *pv = data ().find_element (elementM);
if (!pv)
return 0;
return pv->find_element (elementm);
}
}
// Element access
BOOST_UBLAS_INLINE
const_reference operator () (size_type i, size_type j) const {
const_pointer p = find_element (i, j);
// optimise: check the storage_type and index directly if element always exists
if (boost::is_convertible<typename array_type::storage_category, packed_tag>::value) {
BOOST_UBLAS_CHECK (p, internal_logic () );
return *p;
}
else {
if (p)
return *p;
else
return zero_;
}
}
BOOST_UBLAS_INLINE
reference operator () (size_type i, size_type j) {
#ifndef BOOST_UBLAS_STRICT_MATRIX_SPARSE
return at_element (i, j);
#else
return reference (*this, i, j);
#endif
}
// Assignment
BOOST_UBLAS_INLINE
generalized_vector_of_vector &operator = (const generalized_vector_of_vector &m) {
if (this != &m) {
size1_ = m.size1_;
size2_ = m.size2_;
data () = m.data ();
}
storage_invariants ();
return *this;
}
BOOST_UBLAS_INLINE
generalized_vector_of_vector &assign_temporary (generalized_vector_of_vector &m) {
swap (m);
return *this;
}
template<class AE>
BOOST_UBLAS_INLINE
generalized_vector_of_vector &operator = (const matrix_expression<AE> &ae) {
self_type temporary (ae);
return assign_temporary (temporary);
}
template<class AE>
BOOST_UBLAS_INLINE
generalized_vector_of_vector &assign (const matrix_expression<AE> &ae) {
matrix_assign<scalar_assign> (*this, ae);
return *this;
}
template<class AE>
BOOST_UBLAS_INLINE
generalized_vector_of_vector& operator += (const matrix_expression<AE> &ae) {
self_type temporary (*this + ae);
return assign_temporary (temporary);
}
template<class AE>
BOOST_UBLAS_INLINE
generalized_vector_of_vector &plus_assign (const matrix_expression<AE> &ae) {
matrix_assign<scalar_plus_assign> (*this, ae);
return *this;
}
template<class AE>
BOOST_UBLAS_INLINE
generalized_vector_of_vector& operator -= (const matrix_expression<AE> &ae) {
self_type temporary (*this - ae);
return assign_temporary (temporary);
}
template<class AE>
BOOST_UBLAS_INLINE
generalized_vector_of_vector &minus_assign (const matrix_expression<AE> &ae) {
matrix_assign<scalar_minus_assign> (*this, ae);
return *this;
}
template<class AT>
BOOST_UBLAS_INLINE
generalized_vector_of_vector& operator *= (const AT &at) {
matrix_assign_scalar<scalar_multiplies_assign> (*this, at);
return *this;
}
template<class AT>
BOOST_UBLAS_INLINE
generalized_vector_of_vector& operator /= (const AT &at) {
matrix_assign_scalar<scalar_divides_assign> (*this, at);
return *this;
}
// Swapping
BOOST_UBLAS_INLINE
void swap (generalized_vector_of_vector &m) {
if (this != &m) {
std::swap (size1_, m.size1_);
std::swap (size2_, m.size2_);
data ().swap (m.data ());
}
storage_invariants ();
}
BOOST_UBLAS_INLINE
friend void swap (generalized_vector_of_vector &m1, generalized_vector_of_vector &m2) {
m1.swap (m2);
}
// Sorting
void sort () {
vectoriterator_type itv (data ().begin ());
vectoriterator_type itv_end (data ().end ());
while (itv != itv_end) {
(*itv).sort ();
++ itv;
}
}
// Element insertion and erasure
BOOST_UBLAS_INLINE
true_reference insert_element (size_type i, size_type j, const_reference t) {
const size_type elementM = layout_type::index_M (i, j);
const size_type elementm = layout_type::index_m (i, j);
vector_data_value_type& vd (ref (data () [elementM]));
storage_invariants ();
return vd.insert_element (elementm, t);
}
BOOST_UBLAS_INLINE
void append_element (size_type i, size_type j, const_reference t) {
const size_type elementM = layout_type::index_M (i, j);
const size_type elementm = layout_type::index_m (i, j);
vector_data_value_type& vd (ref (data () [elementM]));
storage_invariants ();
return vd.append_element (elementm, t);
}
BOOST_UBLAS_INLINE
void erase_element (size_type i, size_type j) {
vectoriterator_type itv (data ().find (layout_type::index_M (i, j)));
if (itv == data ().end ())
return;
(*itv).erase_element (layout_type::index_m (i, j));
storage_invariants ();
}
BOOST_UBLAS_INLINE
void clear () {
const size_type sizeM = layout_type::size_M (size1_, size2_);
// FIXME should clear data () if this is done via value_type/*zero*/() then it is not size preserving
for (size_type i = 0; i < sizeM; ++ i)
ref (data () [i]).clear ();
storage_invariants ();
}
// Iterator types
private:
// Use vector iterator
typedef typename A::const_iterator const_vectoriterator_type;
typedef typename A::iterator vectoriterator_type;
typedef typename A::value_type::const_iterator const_subiterator_type;
typedef typename A::value_type::iterator subiterator_type;
BOOST_UBLAS_INLINE
true_reference at_element (size_type i, size_type j) {
return ref (ref (data () [layout_type::index_M (i, j)]) [layout_type::index_m (i, j)]);
}
public:
class const_iterator1;
class iterator1;
class const_iterator2;
class iterator2;
typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
typedef reverse_iterator_base1<iterator1> reverse_iterator1;
typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
typedef reverse_iterator_base2<iterator2> reverse_iterator2;
// Element lookup
// BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.
const_iterator1 find1 (int rank, size_type i, size_type j, int direction = 1) const {
for (;;) {
const_vectoriterator_type itv (data ().find (layout_type::index_M (i, j)));
const_vectoriterator_type itv_end (data ().end ());
if (itv == itv_end)
return const_iterator1 (*this, rank, i, j, itv_end, (*(-- itv)).end ());
const_subiterator_type it ((*itv).find (layout_type::index_m (i, j)));
const_subiterator_type it_end ((*itv).end ());
if (rank == 0)
return const_iterator1 (*this, rank, i, j, itv, it);
if (it != it_end && it.index () == layout_type::index_m (i, j))
return const_iterator1 (*this, rank, i, j, itv, it);
if (direction > 0) {
if (layout_type::fast_i ()) {
if (it == it_end)
return const_iterator1 (*this, rank, i, j, itv, it);
i = it.index ();
} else {
if (i >= size1_)
return const_iterator1 (*this, rank, i, j, itv, it);
++ i;
}
} else /* if (direction < 0) */ {
if (layout_type::fast_i ()) {
if (it == (*itv).begin ())
return const_iterator1 (*this, rank, i, j, itv, it);
--it;
i = it.index ();
} else {
if (i == 0)
return const_iterator1 (*this, rank, i, j, itv, it);
-- i;
}
}
}
}
// BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.
iterator1 find1 (int rank, size_type i, size_type j, int direction = 1) {
for (;;) {
vectoriterator_type itv (data ().find (layout_type::index_M (i, j)));
vectoriterator_type itv_end (data ().end ());
if (itv == itv_end)
return iterator1 (*this, rank, i, j, itv_end, (*(-- itv)).end ());
subiterator_type it ((*itv).find (layout_type::index_m (i, j)));
subiterator_type it_end ((*itv).end ());
if (rank == 0)
return iterator1 (*this, rank, i, j, itv, it);
if (it != it_end && it.index () == layout_type::index_m (i, j))
return iterator1 (*this, rank, i, j, itv, it);
if (direction > 0) {
if (layout_type::fast_i ()) {
if (it == it_end)
return iterator1 (*this, rank, i, j, itv, it);
i = it.index ();
} else {
if (i >= size1_)
return iterator1 (*this, rank, i, j, itv, it);
++ i;
}
} else /* if (direction < 0) */ {
if (layout_type::fast_i ()) {
if (it == (*itv).begin ())
return iterator1 (*this, rank, i, j, itv, it);
--it;
i = it.index ();
} else {
if (i == 0)
return iterator1 (*this, rank, i, j, itv, it);
-- i;
}
}
}
}
// BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.
const_iterator2 find2 (int rank, size_type i, size_type j, int direction = 1) const {
for (;;) {
const_vectoriterator_type itv (data ().find (layout_type::index_M (i, j)));
const_vectoriterator_type itv_end (data ().end ());
if (itv == itv_end)
return const_iterator2 (*this, rank, i, j, itv_end, (*(-- itv)).end ());
const_subiterator_type it ((*itv).find (layout_type::index_m (i, j)));
const_subiterator_type it_end ((*itv).end ());
if (rank == 0)
return const_iterator2 (*this, rank, i, j, itv, it);
if (it != it_end && it.index () == layout_type::index_m (i, j))
return const_iterator2 (*this, rank, i, j, itv, it);
if (direction > 0) {
if (layout_type::fast_j ()) {
if (it == it_end)
return const_iterator2 (*this, rank, i, j, itv, it);
j = it.index ();
} else {
if (j >= size2_)
return const_iterator2 (*this, rank, i, j, itv, it);
++ j;
}
} else /* if (direction < 0) */ {
if (layout_type::fast_j ()) {
if (it == (*itv).begin ())
return const_iterator2 (*this, rank, i, j, itv, it);
--it;
j = it.index ();
} else {
if (j == 0)
return const_iterator2 (*this, rank, i, j, itv, it);
-- j;
}
}
}
}
// BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.
iterator2 find2 (int rank, size_type i, size_type j, int direction = 1) {
for (;;) {
vectoriterator_type itv (data ().find (layout_type::index_M (i, j)));
vectoriterator_type itv_end (data ().end ());
if (itv == itv_end)
return iterator2 (*this, rank, i, j, itv_end, (*(-- itv)).end ());
subiterator_type it ((*itv).find (layout_type::index_m (i, j)));
subiterator_type it_end ((*itv).end ());
if (rank == 0)
return iterator2 (*this, rank, i, j, itv, it);
if (it != it_end && it.index () == layout_type::index_m (i, j))
return iterator2 (*this, rank, i, j, itv, it);
if (direction > 0) {
if (layout_type::fast_j ()) {
if (it == it_end)
return iterator2 (*this, rank, i, j, itv, it);
j = it.index ();
} else {
if (j >= size2_)
return iterator2 (*this, rank, i, j, itv, it);
++ j;
}
} else /* if (direction < 0) */ {
if (layout_type::fast_j ()) {
if (it == (*itv).begin ())
return iterator2 (*this, rank, i, j, itv, it);
--it;
j = it.index ();
} else {
if (j == 0)
return iterator2 (*this, rank, i, j, itv, it);
-- j;
}
}
}
}
class const_iterator1:
public container_const_reference<generalized_vector_of_vector>,
public bidirectional_iterator_base<sparse_bidirectional_iterator_tag,
const_iterator1, value_type> {
public:
typedef typename generalized_vector_of_vector::difference_type difference_type;
typedef typename generalized_vector_of_vector::value_type value_type;
typedef typename generalized_vector_of_vector::const_reference reference;
typedef const typename generalized_vector_of_vector::pointer pointer;
typedef const_iterator2 dual_iterator_type;
typedef const_reverse_iterator2 dual_reverse_iterator_type;
// Construction and destruction
BOOST_UBLAS_INLINE
const_iterator1 ():
container_const_reference<self_type> (), rank_ (), i_ (), j_ (), itv_ (), it_ () {}
BOOST_UBLAS_INLINE
const_iterator1 (const self_type &m, int rank, size_type i, size_type j, const const_vectoriterator_type &itv, const const_subiterator_type &it):
container_const_reference<self_type> (m), rank_ (rank), i_ (i), j_ (j), itv_ (itv), it_ (it) {}
BOOST_UBLAS_INLINE
const_iterator1 (const iterator1 &it):
container_const_reference<self_type> (it ()), rank_ (it.rank_), i_ (it.i_), j_ (it.j_), itv_ (it.itv_), it_ (it.it_) {}
// Arithmetic
BOOST_UBLAS_INLINE
const_iterator1 &operator ++ () {
if (rank_ == 1 && layout_type::fast_i ())
++ it_;
else {
const self_type &m = (*this) ();
i_ = index1 () + 1;
if (rank_ == 1 && ++ itv_ == m.end1 ().itv_)
*this = m.find1 (rank_, i_, j_, 1);
else if (rank_ == 1) {
it_ = (*itv_).begin ();
if (it_ == (*itv_).end () || index2 () != j_)
*this = m.find1 (rank_, i_, j_, 1);
}
}
return *this;
}
BOOST_UBLAS_INLINE
const_iterator1 &operator -- () {
if (rank_ == 1 && layout_type::fast_i ())
-- it_;
else {
const self_type &m = (*this) ();
i_ = index1 () - 1;
if (rank_ == 1 && -- itv_ == m.end1 ().itv_)
*this = m.find1 (rank_, i_, j_, -1);
else if (rank_ == 1) {
it_ = (*itv_).begin ();
if (it_ == (*itv_).end () || index2 () != j_)
*this = m.find1 (rank_, i_, j_, -1);
}
}
return *this;
}
// Dereference
BOOST_UBLAS_INLINE
const_reference operator * () const {
BOOST_UBLAS_CHECK (index1 () < (*this) ().size1 (), bad_index ());
BOOST_UBLAS_CHECK (index2 () < (*this) ().size2 (), bad_index ());
if (rank_ == 1) {
return *it_;
} else {
return (*this) () (i_, j_);
}
}
#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
const_iterator2 begin () const {
const self_type &m = (*this) ();
return m.find2 (1, index1 (), 0);
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
const_iterator2 cbegin () const {
return begin ();
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
const_iterator2 end () const {
const self_type &m = (*this) ();
return m.find2 (1, index1 (), m.size2 ());
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
const_iterator2 cend () const {
return end ();
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
const_reverse_iterator2 rbegin () const {
return const_reverse_iterator2 (end ());
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
const_reverse_iterator2 crbegin () const {
return rbegin ();
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
const_reverse_iterator2 rend () const {
return const_reverse_iterator2 (begin ());
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
const_reverse_iterator2 crend () const {
return rend ();
}
#endif
// Indices
BOOST_UBLAS_INLINE
size_type index1 () const {
BOOST_UBLAS_CHECK (*this != (*this) ().find1 (0, (*this) ().size1 (), j_), bad_index ());
if (rank_ == 1) {
BOOST_UBLAS_CHECK (layout_type::index_M (itv_.index (), it_.index ()) < (*this) ().size1 (), bad_index ());
return layout_type::index_M (itv_.index (), it_.index ());
} else {
return i_;
}
}
BOOST_UBLAS_INLINE
size_type index2 () const {
BOOST_UBLAS_CHECK (*this != (*this) ().find1 (0, (*this) ().size1 (), j_), bad_index ());
if (rank_ == 1) {
BOOST_UBLAS_CHECK (layout_type::index_m (itv_.index (), it_.index ()) < (*this) ().size2 (), bad_index ());
return layout_type::index_m (itv_.index (), it_.index ());
} else {
return j_;
}
}
// Assignment
BOOST_UBLAS_INLINE
const_iterator1 &operator = (const const_iterator1 &it) {
container_const_reference<self_type>::assign (&it ());
rank_ = it.rank_;
i_ = it.i_;
j_ = it.j_;
itv_ = it.itv_;
it_ = it.it_;
return *this;
}
// Comparison
BOOST_UBLAS_INLINE
bool operator == (const const_iterator1 &it) const {
BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
// BOOST_UBLAS_CHECK (rank_ == it.rank_, internal_logic ());
if (rank_ == 1 || it.rank_ == 1) {
return it_ == it.it_;
} else {
return i_ == it.i_ && j_ == it.j_;
}
}
private:
int rank_;
size_type i_;
size_type j_;
const_vectoriterator_type itv_;
const_subiterator_type it_;
};
BOOST_UBLAS_INLINE
const_iterator1 begin1 () const {
return find1 (0, 0, 0);
}
BOOST_UBLAS_INLINE
const_iterator1 cbegin1 () const {
return begin1 ();
}
BOOST_UBLAS_INLINE
const_iterator1 end1 () const {
return find1 (0, size1_, 0);
}
BOOST_UBLAS_INLINE
const_iterator1 cend1 () const {
return end1 ();
}
class iterator1:
public container_reference<generalized_vector_of_vector>,
public bidirectional_iterator_base<sparse_bidirectional_iterator_tag,
iterator1, value_type> {
public:
typedef typename generalized_vector_of_vector::difference_type difference_type;
typedef typename generalized_vector_of_vector::value_type value_type;
typedef typename generalized_vector_of_vector::true_reference reference;
typedef typename generalized_vector_of_vector::pointer pointer;
typedef iterator2 dual_iterator_type;
typedef reverse_iterator2 dual_reverse_iterator_type;
// Construction and destruction
BOOST_UBLAS_INLINE
iterator1 ():
container_reference<self_type> (), rank_ (), i_ (), j_ (), itv_ (), it_ () {}
BOOST_UBLAS_INLINE
iterator1 (self_type &m, int rank, size_type i, size_type j, const vectoriterator_type &itv, const subiterator_type &it):
container_reference<self_type> (m), rank_ (rank), i_ (i), j_ (j), itv_ (itv), it_ (it) {}
// Arithmetic
BOOST_UBLAS_INLINE
iterator1 &operator ++ () {
if (rank_ == 1 && layout_type::fast_i ())
++ it_;
else {
self_type &m = (*this) ();
i_ = index1 () + 1;
if (rank_ == 1 && ++ itv_ == m.end1 ().itv_)
*this = m.find1 (rank_, i_, j_, 1);
else if (rank_ == 1) {
it_ = (*itv_).begin ();
if (it_ == (*itv_).end () || index2 () != j_)
*this = m.find1 (rank_, i_, j_, 1);
}
}
return *this;
}
BOOST_UBLAS_INLINE
iterator1 &operator -- () {
if (rank_ == 1 && layout_type::fast_i ())
-- it_;
else {
self_type &m = (*this) ();
i_ = index1 () - 1;
if (rank_ == 1 && -- itv_ == m.end1 ().itv_)
*this = m.find1 (rank_, i_, j_, -1);
else if (rank_ == 1) {
it_ = (*itv_).begin ();
if (it_ == (*itv_).end () || index2 () != j_)
*this = m.find1 (rank_, i_, j_, -1);
}
}
return *this;
}
// Dereference
BOOST_UBLAS_INLINE
true_reference operator * () const {
BOOST_UBLAS_CHECK (index1 () < (*this) ().size1 (), bad_index ());
BOOST_UBLAS_CHECK (index2 () < (*this) ().size2 (), bad_index ());
if (rank_ == 1) {
return *it_;
} else {
return (*this) ().at_element (i_, j_);
}
}
#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
iterator2 begin () const {
self_type &m = (*this) ();
return m.find2 (1, index1 (), 0);
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
iterator2 end () const {
self_type &m = (*this) ();
return m.find2 (1, index1 (), m.size2 ());
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
reverse_iterator2 rbegin () const {
return reverse_iterator2 (end ());
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
reverse_iterator2 rend () const {
return reverse_iterator2 (begin ());
}
#endif
// Indices
BOOST_UBLAS_INLINE
size_type index1 () const {
BOOST_UBLAS_CHECK (*this != (*this) ().find1 (0, (*this) ().size1 (), j_), bad_index ());
if (rank_ == 1) {
BOOST_UBLAS_CHECK (layout_type::index_M (itv_.index (), it_.index ()) < (*this) ().size1 (), bad_index ());
return layout_type::index_M (itv_.index (), it_.index ());
} else {
return i_;
}
}
BOOST_UBLAS_INLINE
size_type index2 () const {
BOOST_UBLAS_CHECK (*this != (*this) ().find1 (0, (*this) ().size1 (), j_), bad_index ());
if (rank_ == 1) {
BOOST_UBLAS_CHECK (layout_type::index_m (itv_.index (), it_.index ()) < (*this) ().size2 (), bad_index ());
return layout_type::index_m (itv_.index (), it_.index ());
} else {
return j_;
}
}
// Assignment
BOOST_UBLAS_INLINE
iterator1 &operator = (const iterator1 &it) {
container_reference<self_type>::assign (&it ());
rank_ = it.rank_;
i_ = it.i_;
j_ = it.j_;
itv_ = it.itv_;
it_ = it.it_;
return *this;
}
// Comparison
BOOST_UBLAS_INLINE
bool operator == (const iterator1 &it) const {
BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
// BOOST_UBLAS_CHECK (rank_ == it.rank_, internal_logic ());
if (rank_ == 1 || it.rank_ == 1) {
return it_ == it.it_;
} else {
return i_ == it.i_ && j_ == it.j_;
}
}
private:
int rank_;
size_type i_;
size_type j_;
vectoriterator_type itv_;
subiterator_type it_;
friend class const_iterator1;
};
BOOST_UBLAS_INLINE
iterator1 begin1 () {
return find1 (0, 0, 0);
}
BOOST_UBLAS_INLINE
iterator1 end1 () {
return find1 (0, size1_, 0);
}
class const_iterator2:
public container_const_reference<generalized_vector_of_vector>,
public bidirectional_iterator_base<sparse_bidirectional_iterator_tag,
const_iterator2, value_type> {
public:
typedef typename generalized_vector_of_vector::difference_type difference_type;
typedef typename generalized_vector_of_vector::value_type value_type;
typedef typename generalized_vector_of_vector::const_reference reference;
typedef const typename generalized_vector_of_vector::pointer pointer;
typedef const_iterator1 dual_iterator_type;
typedef const_reverse_iterator1 dual_reverse_iterator_type;
// Construction and destruction
BOOST_UBLAS_INLINE
const_iterator2 ():
container_const_reference<self_type> (), rank_ (), i_ (), j_ (), itv_ (), it_ () {}
BOOST_UBLAS_INLINE
const_iterator2 (const self_type &m, int rank, size_type i, size_type j, const const_vectoriterator_type &itv, const const_subiterator_type &it):
container_const_reference<self_type> (m), rank_ (rank), i_ (i), j_ (j), itv_ (itv), it_ (it) {}
BOOST_UBLAS_INLINE
const_iterator2 (const iterator2 &it):
container_const_reference<self_type> (it ()), rank_ (it.rank_), i_ (it.i_), j_ (it.j_), itv_ (it.itv_), it_ (it.it_) {}
// Arithmetic
BOOST_UBLAS_INLINE
const_iterator2 &operator ++ () {
if (rank_ == 1 && layout_type::fast_j ())
++ it_;
else {
const self_type &m = (*this) ();
j_ = index2 () + 1;
if (rank_ == 1 && ++ itv_ == m.end2 ().itv_)
*this = m.find2 (rank_, i_, j_, 1);
else if (rank_ == 1) {
it_ = (*itv_).begin ();
if (it_ == (*itv_).end () || index1 () != i_)
*this = m.find2 (rank_, i_, j_, 1);
}
}
return *this;
}
BOOST_UBLAS_INLINE
const_iterator2 &operator -- () {
if (rank_ == 1 && layout_type::fast_j ())
-- it_;
else {
const self_type &m = (*this) ();
j_ = index2 () - 1;
if (rank_ == 1 && -- itv_ == m.end2 ().itv_)
*this = m.find2 (rank_, i_, j_, -1);
else if (rank_ == 1) {
it_ = (*itv_).begin ();
if (it_ == (*itv_).end () || index1 () != i_)
*this = m.find2 (rank_, i_, j_, -1);
}
}
return *this;
}
// Dereference
BOOST_UBLAS_INLINE
const_reference operator * () const {
BOOST_UBLAS_CHECK (index1 () < (*this) ().size1 (), bad_index ());
BOOST_UBLAS_CHECK (index2 () < (*this) ().size2 (), bad_index ());
if (rank_ == 1) {
return *it_;
} else {
return (*this) () (i_, j_);
}
}
#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
const_iterator1 begin () const {
const self_type &m = (*this) ();
return m.find1 (1, 0, index2 ());
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
const_iterator1 cbegin () const {
return begin ();
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
const_iterator1 end () const {
const self_type &m = (*this) ();
return m.find1 (1, m.size1 (), index2 ());
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
const_iterator1 cend () const {
return end ();
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
const_reverse_iterator1 rbegin () const {
return const_reverse_iterator1 (end ());
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
const_reverse_iterator1 crbegin () const {
return rbegin ();
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
const_reverse_iterator1 rend () const {
return const_reverse_iterator1 (begin ());
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
const_reverse_iterator1 crend () const {
return rend ();
}
#endif
// Indices
BOOST_UBLAS_INLINE
size_type index1 () const {
BOOST_UBLAS_CHECK (*this != (*this) ().find2 (0, i_, (*this) ().size2 ()), bad_index ());
if (rank_ == 1) {
BOOST_UBLAS_CHECK (layout_type::index_M (itv_.index (), it_.index ()) < (*this) ().size1 (), bad_index ());
return layout_type::index_M (itv_.index (), it_.index ());
} else {
return i_;
}
}
BOOST_UBLAS_INLINE
size_type index2 () const {
BOOST_UBLAS_CHECK (*this != (*this) ().find2 (0, i_, (*this) ().size2 ()), bad_index ());
if (rank_ == 1) {
BOOST_UBLAS_CHECK (layout_type::index_m (itv_.index (), it_.index ()) < (*this) ().size2 (), bad_index ());
return layout_type::index_m (itv_.index (), it_.index ());
} else {
return j_;
}
}
// Assignment
BOOST_UBLAS_INLINE
const_iterator2 &operator = (const const_iterator2 &it) {
container_const_reference<self_type>::assign (&it ());
rank_ = it.rank_;
i_ = it.i_;
j_ = it.j_;
itv_ = it.itv_;
it_ = it.it_;
return *this;
}
// Comparison
BOOST_UBLAS_INLINE
bool operator == (const const_iterator2 &it) const {
BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
// BOOST_UBLAS_CHECK (rank_ == it.rank_, internal_logic ());
if (rank_ == 1 || it.rank_ == 1) {
return it_ == it.it_;
} else {
return i_ == it.i_ && j_ == it.j_;
}
}
private:
int rank_;
size_type i_;
size_type j_;
const_vectoriterator_type itv_;
const_subiterator_type it_;
};
BOOST_UBLAS_INLINE
const_iterator2 begin2 () const {
return find2 (0, 0, 0);
}
BOOST_UBLAS_INLINE
const_iterator2 cbegin2 () const {
return begin2 ();
}
BOOST_UBLAS_INLINE
const_iterator2 end2 () const {
return find2 (0, 0, size2_);
}
BOOST_UBLAS_INLINE
const_iterator2 cend2 () const {
return end2 ();
}
class iterator2:
public container_reference<generalized_vector_of_vector>,
public bidirectional_iterator_base<sparse_bidirectional_iterator_tag,
iterator2, value_type> {
public:
typedef typename generalized_vector_of_vector::difference_type difference_type;
typedef typename generalized_vector_of_vector::value_type value_type;
typedef typename generalized_vector_of_vector::true_reference reference;
typedef typename generalized_vector_of_vector::pointer pointer;
typedef iterator1 dual_iterator_type;
typedef reverse_iterator1 dual_reverse_iterator_type;
// Construction and destruction
BOOST_UBLAS_INLINE
iterator2 ():
container_reference<self_type> (), rank_ (), i_ (), j_ (), itv_ (), it_ () {}
BOOST_UBLAS_INLINE
iterator2 (self_type &m, int rank, size_type i, size_type j, const vectoriterator_type &itv, const subiterator_type &it):
container_reference<self_type> (m), rank_ (rank), i_ (i), j_ (j), itv_ (itv), it_ (it) {}
// Arithmetic
BOOST_UBLAS_INLINE
iterator2 &operator ++ () {
if (rank_ == 1 && layout_type::fast_j ())
++ it_;
else {
self_type &m = (*this) ();
j_ = index2 () + 1;
if (rank_ == 1 && ++ itv_ == m.end2 ().itv_)
*this = m.find2 (rank_, i_, j_, 1);
else if (rank_ == 1) {
it_ = (*itv_).begin ();
if (it_ == (*itv_).end () || index1 () != i_)
*this = m.find2 (rank_, i_, j_, 1);
}
}
return *this;
}
BOOST_UBLAS_INLINE
iterator2 &operator -- () {
if (rank_ == 1 && layout_type::fast_j ())
-- it_;
else {
self_type &m = (*this) ();
j_ = index2 () - 1;
if (rank_ == 1 && -- itv_ == m.end2 ().itv_)
*this = m.find2 (rank_, i_, j_, -1);
else if (rank_ == 1) {
it_ = (*itv_).begin ();
if (it_ == (*itv_).end () || index1 () != i_)
*this = m.find2 (rank_, i_, j_, -1);
}
}
return *this;
}
// Dereference
BOOST_UBLAS_INLINE
true_reference operator * () const {
BOOST_UBLAS_CHECK (index1 () < (*this) ().size1 (), bad_index ());
BOOST_UBLAS_CHECK (index2 () < (*this) ().size2 (), bad_index ());
if (rank_ == 1) {
return *it_;
} else {
return (*this) ().at_element (i_, j_);
}
}
#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
iterator1 begin () const {
self_type &m = (*this) ();
return m.find1 (1, 0, index2 ());
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
iterator1 end () const {
self_type &m = (*this) ();
return m.find1 (1, m.size1 (), index2 ());
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
reverse_iterator1 rbegin () const {
return reverse_iterator1 (end ());
}
BOOST_UBLAS_INLINE
#ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
typename self_type::
#endif
reverse_iterator1 rend () const {
return reverse_iterator1 (begin ());
}
#endif
// Indices
BOOST_UBLAS_INLINE
size_type index1 () const {
BOOST_UBLAS_CHECK (*this != (*this) ().find2 (0, i_, (*this) ().size2 ()), bad_index ());
if (rank_ == 1) {
BOOST_UBLAS_CHECK (layout_type::index_M (itv_.index (), it_.index ()) < (*this) ().size1 (), bad_index ());
return layout_type::index_M (itv_.index (), it_.index ());
} else {
return i_;
}
}
BOOST_UBLAS_INLINE
size_type index2 () const {
BOOST_UBLAS_CHECK (*this != (*this) ().find2 (0, i_, (*this) ().size2 ()), bad_index ());
if (rank_ == 1) {
BOOST_UBLAS_CHECK (layout_type::index_m (itv_.index (), it_.index ()) < (*this) ().size2 (), bad_index ());
return layout_type::index_m (itv_.index (), it_.index ());
} else {
return j_;
}
}
// Assignment
BOOST_UBLAS_INLINE
iterator2 &operator = (const iterator2 &it) {
container_reference<self_type>::assign (&it ());
rank_ = it.rank_;
i_ = it.i_;
j_ = it.j_;
itv_ = it.itv_;
it_ = it.it_;
return *this;
}
// Comparison
BOOST_UBLAS_INLINE
bool operator == (const iterator2 &it) const {
BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
// BOOST_UBLAS_CHECK (rank_ == it.rank_, internal_logic ());
if (rank_ == 1 || it.rank_ == 1) {
return it_ == it.it_;
} else {
return i_ == it.i_ && j_ == it.j_;
}
}
private:
int rank_;
size_type i_;
size_type j_;
vectoriterator_type itv_;
subiterator_type it_;
friend class const_iterator2;
};
BOOST_UBLAS_INLINE
iterator2 begin2 () {
return find2 (0, 0, 0);
}
BOOST_UBLAS_INLINE
iterator2 end2 () {
return find2 (0, 0, size2_);
}
// Reverse iterators
BOOST_UBLAS_INLINE
const_reverse_iterator1 rbegin1 () const {
return const_reverse_iterator1 (end1 ());
}
BOOST_UBLAS_INLINE
const_reverse_iterator1 crbegin1 () const {
return rbegin1 ();
}
BOOST_UBLAS_INLINE
const_reverse_iterator1 rend1 () const {
return const_reverse_iterator1 (begin1 ());
}
BOOST_UBLAS_INLINE
const_reverse_iterator1 crend1 () const {
return rend1 ();
}
BOOST_UBLAS_INLINE
reverse_iterator1 rbegin1 () {
return reverse_iterator1 (end1 ());
}
BOOST_UBLAS_INLINE
reverse_iterator1 rend1 () {
return reverse_iterator1 (begin1 ());
}
BOOST_UBLAS_INLINE
const_reverse_iterator2 rbegin2 () const {
return const_reverse_iterator2 (end2 ());
}
BOOST_UBLAS_INLINE
const_reverse_iterator2 crbegin2 () const {
return rbegin2 ();
}
BOOST_UBLAS_INLINE
const_reverse_iterator2 rend2 () const {
return const_reverse_iterator2 (begin2 ());
}
BOOST_UBLAS_INLINE
const_reverse_iterator2 crend2 () const {
return rend2 ();
}
BOOST_UBLAS_INLINE
reverse_iterator2 rbegin2 () {
return reverse_iterator2 (end2 ());
}
BOOST_UBLAS_INLINE
reverse_iterator2 rend2 () {
return reverse_iterator2 (begin2 ());
}
// Serialization
template<class Archive>
void serialize(Archive & ar, const unsigned int /* file_version */){
// we need to copy to a collection_size_type to get a portable
// and efficient serialization
serialization::collection_size_type s1 (size1_);
serialization::collection_size_type s2 (size2_);
// serialize the sizes
ar & serialization::make_nvp("size1",s1)
& serialization::make_nvp("size2",s2);
// copy the values back if loading
if (Archive::is_loading::value) {
size1_ = s1;
size2_ = s2;
}
ar & serialization::make_nvp("data", data_);
storage_invariants();
}
private:
void storage_invariants () const
{
BOOST_UBLAS_CHECK (layout_type::size_M (size1_, size2_) + 1 == data_.size (), internal_logic ());
BOOST_UBLAS_CHECK (data ().begin () != data ().end (), internal_logic ());
}
size_type size1_;
size_type size2_;
array_type data_;
static const value_type zero_;
};
template<class T, class L, class A>
const typename generalized_vector_of_vector<T, L, A>::value_type generalized_vector_of_vector<T, L, A>::zero_ = value_type/*zero*/();
}}}
#endif
|