ccgsl 2.7.2
C++wrappersforGnuScientificLibrary
block.hpp
Go to the documentation of this file.
1/*
2 * $Id: block.hpp 313 2014-02-22 14:29:57Z jdl3 $
3 * Copyright (C) 2010, 2011, 2012, 2014, 2024 John D Lamb
4 * Enum copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#ifndef CCGSL_BLOCK_HPP
22#define CCGSL_BLOCK_HPP
23
24#include<gsl/gsl_block.h>
25#include<new>
26#include<iterator>
27#include<cstring>
28#include<cstddef>
29#ifdef __GXX_EXPERIMENTAL_CXX0X__
30#include<initializer_list>
31#endif
32
33#include"exception.hpp"
34
35// This file is used as a template
36
37namespace gsl {
42 class block {
43 public:
48 ccgsl_pointer = 0;
49 count = 0; // initially nullptr will do
50 }
51 // Refines random access container
52 // Refines assignable
57 explicit block( size_t const n ){
58 if( n > 0 )
59 ccgsl_pointer = gsl_block_alloc( n );
60 else {
61 ccgsl_pointer = new gsl_block;
62 ccgsl_pointer->size = 0;
63 ccgsl_pointer->data = 0;
64 }
65 // just plausibly we could allocate block but not count
66 try { count = new size_t; } catch( std::bad_alloc& e ){
67 // try to tidy up before rethrowing
68 if( n > 0 ) gsl_block_free( ccgsl_pointer );
69 else delete ccgsl_pointer;
70 throw e;
71 }
72 *count = 1; // initially there is just one reference to ccgsl_pointer
73 }
79 explicit block( gsl_block* v ){
80 ccgsl_pointer = v;
81 // just plausibly we could fail to allocate count: no further action needed.
82 count = new size_t;
83 *count = 1; // initially there is just one reference to ccgsl_pointer
84 }
85#ifdef __GXX_EXPERIMENTAL_CXX0X__
90 block( std::initializer_list<double> initializer_list ){
91 size_t const n = initializer_list.size();
92 ccgsl_pointer = gsl_block_alloc( n );
93 // just plausibly we could allocate vector but not count
94 try { count = new size_t; } catch( std::bad_alloc& e ){
95 // try to tidy up before rethrowing
96 if( n > 0 ) gsl_block_free( ccgsl_pointer );
97 else delete ccgsl_pointer;
98 throw e;
99 }
100 *count = 1; // initially there is just one reference to ccgsl_pointer
101 // now copy
102 auto p = begin();
103 for( auto x : initializer_list ){ *p = x; ++p; }
104 }
105#endif
106 // copy constructor
112 if( count != 0 ) ++*count; // block is now shared.
113 }
114 // assignment operator
119 block& operator=( block const& v ){
120 // first, possibly delete anything pointed to by this
121 if( count == 0 or --*count == 0 ){
122 if( ccgsl_pointer != 0 ){
123 if( ccgsl_pointer->size > 0 ) gsl_block_free( ccgsl_pointer );
124 else delete ccgsl_pointer; }
125 delete count;
126 }
127 // Then copy
129 count = v.count;
130 if( count != 0 ) ++*count; // block is now shared.
131 return *this;
132 }
133 // clone()
139 block clone() const {
140 block copy( ccgsl_pointer->size );
141 // Now copy
142 memcpy( copy.ccgsl_pointer->data, ccgsl_pointer->data, ccgsl_pointer->size * sizeof( double ) );
143 // return new object
144 return copy;
145 }
146 // destructor
151 if( count == 0 or --*count == 0 ){
152 // could have allocated null pointer
153 if( ccgsl_pointer != 0 ){
154 if( ccgsl_pointer->size > 0 ) gsl_block_free( ccgsl_pointer );
155 else delete ccgsl_pointer; }
156 delete count;
157 }
158 }
162 void reset(){ block().swap( *this ); }
163#ifdef __GXX_EXPERIMENTAL_CXX0X__
168 block( block&& v ) : ccgsl_pointer( v.ccgsl_pointer ), count( nullptr ){
169 std::swap( count, v.count );
170 v.ccgsl_pointer = nullptr;
171 }
178 block( std::move( v ) ).swap( *this );
179 return *this;
180 }
181#endif
182 // Refines equality comparable
183 // == operator
190 bool operator==( block const& v ) const {
191 // trivially equal if gsl_block*s are identical
192 if( ccgsl_pointer == v.ccgsl_pointer ) return true;
193 // trivially not equal if one is zero: != should be same as xor here
194 if( (ccgsl_pointer == 0) != (v.ccgsl_pointer == 0 ) ) return false;
195 // trivially not equal if sizes are different
196 if( ccgsl_pointer->size != v.ccgsl_pointer->size ) return false;
197 // check elementwise for equality
198 for( size_t i = 0; i < ccgsl_pointer->size; ++i )
199 if( ccgsl_pointer->data[i] != v.ccgsl_pointer->data[i] ) return false;
200 return true;
201 }
202 // != operator
209 bool operator!=( block const& v ) const { return not operator==( v ); }
210 // Refines forward container
211 // Refines less than comparable
212 // operator<
221 bool operator<( block const& v ) const {
222 // null block comes first
223 if( ccgsl_pointer == 0 ) return v.ccgsl_pointer != 0;
224 // if v is null then this > v
225 if( v.ccgsl_pointer == 0 ) return false;
226 // Now compare elementwise
227 size_t const size = ccgsl_pointer->size;
228 size_t const v_size = v.ccgsl_pointer->size;
229 size_t const min = size > v_size ? size : v_size;
230 for( size_t i = 0; i < min; ++i ){
231 double const t = ccgsl_pointer->data[i];
232 double const u =v.ccgsl_pointer->data[i];
233 if( t < u ) return true;
234 if( u < t ) return false;
235 }
236 // elements match.
237 return size < v_size;
238 }
239 // operator>
248 bool operator>( block const& v ) const {
249 // null block comes first
250 if( ccgsl_pointer == 0 ) return false;
251 // if v is null then this > v
252 if( v.ccgsl_pointer == 0 ) return true;
253 // Now compare elementwise
254 size_t const size = ccgsl_pointer->size;
255 size_t const v_size = v.ccgsl_pointer->size;
256 size_t const min = size > v_size ? size : v_size;
257 for( size_t i = 0; i < min; ++i ){
258 double const t = ccgsl_pointer->data[i];
259 double const u =v.ccgsl_pointer->data[i];
260 if( t > u ) return true;
261 if( u > t ) return false;
262 }
263 // elements match.
264 return size > v_size;
265 }
266 // operator<=
275 bool operator<=( block const& v ) const {
276 return operator<( v ) or operator==( v );
277 }
278 // operator>=
287 bool operator>=( block const& v ) const {
288 return operator>( v ) or operator==( v );
289 }
290 // Refines container
291 // type value_type
295 typedef double value_type;
296 // type reference
301 // type const_reference
306 // type pointer
311 // type const_pointer
315 typedef value_type const* const_pointer;
316 // type iterator
317 private:
322 template<typename container, typename content, bool reverse> class iterator_base {
323 friend class block;
324 public:
328 typedef std::random_access_iterator_tag iterator_category;
332 typedef double value_type;
341 // // type iterator_traits<block>::difference_type
345 typedef ptrdiff_t difference_type;
346 public:
347 // // operator*
353 // Always try to return something
354 static content something = 0;
355 // First check that iterator is initialised.
356 if( v == 0 ){
357 gsl_error( "iterator not initialised", __FILE__, __LINE__, exception::GSL_EFAULT );
358 return something;
359 } else if( v->ccgsl_pointer == 0 ){
360 gsl_error( "block not initialised", __FILE__, __LINE__, exception::GSL_EFAULT );
361 return something;
362 }
363 // Check that position make sense
364 if( position >= static_cast<difference_type>( v->size() ) ){
365 gsl_error( "trying to dereference beyond rbegin()", __FILE__, __LINE__, exception::GSL_EFAILED );
366 return something;
367 }
368 if( position <= -1 ){
369 gsl_error( "trying to dereference beyond begin()", __FILE__, __LINE__, exception::GSL_EFAILED );
370 return something;
371 }
372 // position and v are valid: return data
373 return *(v->ccgsl_pointer->data + position);
374 }
375 // // operator->
381 // First check that iterator is initialised.
382 if( v == 0 ){
383 gsl_error( "iterator not initialised", __FILE__, __LINE__, exception::GSL_EFAILED );
384 return 0;
385 } else if( v->ccgsl_pointer == 0 ){
386 gsl_error( "block not initialised", __FILE__, __LINE__, exception::GSL_EFAILED );
387 return 0;
388 }
389 // Check that position make sense
390 if( position >= static_cast<difference_type>( v->size() ) ){
391 gsl_error( "trying to dereference end()", __FILE__, __LINE__, exception::GSL_EFAILED );
392 return 0;
393 }
394 if( position <= -1 ){
395 gsl_error( "trying to dereference rend()", __FILE__, __LINE__, exception::GSL_EFAILED );
396 return 0;
397 }
398 // position and v are valid: return data
399 return v->ccgsl_pointer->data + position;
400 }
401 // // operator[]
408 // Always try to return something
409 static content something = 0;
410 // First check that iterator is initialised.
411 if( v == 0 ){
412 gsl_error( "iterator not initialised", __FILE__, __LINE__, exception::GSL_EFAILED );
413 return something;
414 } else if( v->ccgsl_pointer == 0 ){
415 gsl_error( "block not initialised", __FILE__, __LINE__, exception::GSL_EFAILED );
416 return something;
417 }
418 // Check that position make sense
419 difference_type const p = reverse ? position - n : position + n;
420 if( p >= static_cast<difference_type>( v->size() ) ){
421 gsl_error( "trying to dereference beyond rbegin()", __FILE__, __LINE__, exception::GSL_EFAILED );
422 return something;
423 }
424 if( p <= -1 ){
425 gsl_error( "trying to dereference beyond begin()", __FILE__, __LINE__, exception::GSL_EFAILED );
426 return something;
427 }
428 // p is a valid position
429 return *(v->ccgsl_pointer->data + p);
430 }
431 // // operator-: find distance between two iterators
438 // Warn if either iterator undefined
439 if( v == 0 or i.v == 0 ){
440 gsl_error( "iterator not initialised", __FILE__, __LINE__, exception::GSL_EFAILED );
441 return 0;
442 } else if( v->ccgsl_pointer == 0 or i.v->ccgsl_pointer == 0 ){
443 gsl_error( "block not initialised", __FILE__, __LINE__, exception::GSL_EFAILED );
444 return 0;
445 }
446 // Warn if iterators do not point to same block
447 if( v->ccgsl_pointer != i.v->ccgsl_pointer ){
448 gsl_error( "trying to take difference of iterators for different blocks", __FILE__, __LINE__,
450 return 0;
451 }
452 return reverse ? i.position - position : position - i.position;
453 }
454 // // operator!=
455 // // operator<
462 return this->v == i.v and this->position == i.position;
463 }
470 return not this->operator==( i );
471 }
480 // Warn if either iterator undefined
481 if( v == 0 or i.v == 0 ){
482 gsl_error( "iterator not initialised", __FILE__, __LINE__, exception::GSL_EFAILED );
483 return false;
484 }
485 // Warn if iterators do not point to same block
486 if( v->ccgsl_pointer != i.v->ccgsl_pointer ){
487 gsl_error( "trying to take difference of iterators for different blocks", __FILE__, __LINE__,
489 return false;
490 }
491 return reverse ? i.position < position : position < i.position;
492 }
493 protected:
498 void increment(){
499 // Only makes sense if v points to a block
500 if( v == 0 ){
501 gsl_error( "iterator not initialised", __FILE__, __LINE__, exception::GSL_EFAILED );
502 return;
503 } else if( v->ccgsl_pointer == 0 ){
504 gsl_error( "block not initialised", __FILE__, __LINE__, exception::GSL_EFAILED );
505 return;
506 }
507 // increment position and check against size
508 if( reverse ){ if( position >= 0 ) --position; }
509 else { if( position < static_cast<difference_type>( v->size() ) ) ++position; }
510 }
515 void decrement(){
516 // Only makes sense if v points to a block
517 if( v == 0 ){
518 gsl_error( "iterator not initialised", __FILE__, __LINE__, exception::GSL_EFAILED );
519 return;
520 } else if( v->ccgsl_pointer == 0 ){
521 gsl_error( "block not initialised", __FILE__, __LINE__, exception::GSL_EFAILED );
522 return;
523 }
524 // decrement position and check against size
525 if( reverse ){ if( position < static_cast<difference_type>( v->size() ) ) ++position; }
526 else { if( position >= 0 ) --position; }
527 }
532 void shift( difference_type const n ){
533 // Warn if iterator undefined
534 if( v == 0 ){
535 gsl_error( "iterator not initialised", __FILE__, __LINE__, exception::GSL_EFAILED );
536 return;
537 } else if( v->ccgsl_pointer == 0 ){
538 gsl_error( "block not initialised", __FILE__, __LINE__, exception::GSL_EFAILED );
539 return;
540 }
541 position += reverse ? -n : n;
542 }
546 iterator_base(){ v = 0; }
553 : v( v ), position( position ){}
557 container* v;
562 };
563 // Need to know about const_iterator_t
564 template<bool reverse> class const_iterator_t;
568 template<bool reverse> class iterator_t : public iterator_base<block,double,reverse>{
569 public:
570 // // Refines output iterator
571 // // operator=
579 return *this;
580 }
581 // // Refines forward iterator
582 // // operator++ (both)
589 return *this;
590 }
596 // return value
599 return result;
600 }
601 // // Refines bidirectional iterator
602 // // operator-- (both)
609 return *this;
610 }
616 // return value
619 return result;
620 }
626 // // operator+=
633 this->shift( n );
634 return *this;
635 }
636 // // operator-=
643 this->shift( -n );
644 return *this;
645 }
646 // // operator+ (n+i)(i+n)
655 result.shift( n );
656 return result;
657 }
658 // // operator- (n-i)(i-n)(i-j)
667 result.shift( -n );
668 return result;
669 }
677 }
684 // Warn if either iterator undefined
685 if( this->v == 0 or i.v == 0 ){
686 gsl_error( "iterator not initialised", __FILE__, __LINE__, exception::GSL_EFAILED );
687 return 0;
688 } else if( this->v->ccgsl_pointer == 0 or i.v->ccgsl_pointer == 0 ){
689 gsl_error( "block not initialised", __FILE__, __LINE__, exception::GSL_EFAILED );
690 return 0;
691 }
692 // Warn if iterators do not point to same block
693 if( this->v->ccgsl_pointer != i.v->ccgsl_pointer ){
694 gsl_error( "trying to take difference of iterators for different blocks", __FILE__, __LINE__,
696 return 0;
697 }
698 return reverse ? i.position - this->position : this->position - i.position;
699 }
705 bool operator==( const_iterator_t<reverse> const& i ) const {
706 return this->v == i.v and this->position == i.position;
707 }
713 bool operator!=( const_iterator_t<reverse> const& i ) const {
714 return not this->operator==( i );
715 }
721 bool operator<( const_iterator_t<reverse> const& i ) const {
722 // Warn if either iterator undefined
723 if( this->v == 0 or i.v == 0 ){
724 gsl_error( "iterator not initialised", __FILE__, __LINE__, exception::GSL_EFAILED );
725 return false;
726 }
727 // Warn if iterators do not point to same block
728 if( this->v->ccgsl_pointer != i.v->ccgsl_pointer ){
729 gsl_error( "trying to take difference of iterators for different blocks", __FILE__, __LINE__,
731 return false;
732 }
733 return reverse ? i.position < this->position : this->position < i.position;
734 }
738 iterator_t() : iterator_base<block,double,reverse>(){}
739 protected:
740 friend class block;
741 // We need a constructor for block
748 : iterator_base<block,double,reverse>( v, position ){}
749 };
753 template<bool reverse> class const_iterator_t
754 : public iterator_base<block const,double,reverse>{
755 public:
756 // // Refines output iterator
757 // // operator=
765 return *this;
766 }
767 // // Refines forward iterator
768 // // operator++ (both)
775 return *this;
776 }
782 // return value
785 return result;
786 }
787 // // Refines bidirectional iterator
788 // // operator-- (both)
795 return *this;
796 }
802 // return value
805 return result;
806 }
812 // // operator+=
819 this->shift( n );
820 return *this;
821 }
822 // // operator-=
829 this->shift( -n );
830 return *this;
831 }
832 // // operator+ (n+i)(i+n)
841 result += n;
842 return result;
843 }
844 // // operator- (n-i)(i-n)(i-j)
853 result -= n;
854 return result;
855 }
863 }
870 // Warn if either iterator undefined
871 if( this->v == 0 or i.v == 0 ){
872 gsl_error( "iterator not initialised", __FILE__, __LINE__, exception::GSL_EFAILED );
873 return 0;
874 } else if( this->v->ccgsl_pointer == 0 or i.v->ccgsl_pointer == 0 ){
875 gsl_error( "block not initialised", __FILE__, __LINE__, exception::GSL_EFAILED );
876 return 0;
877 }
878 // Warn if iterators do not point to same block
879 if( this->v->ccgsl_pointer != i.v->ccgsl_pointer ){
880 gsl_error( "trying to take difference of iterators for different blocks", __FILE__, __LINE__,
882 return 0;
883 }
884 return reverse ? i.position - this->position : this->position - i.position;
885 }
889 const_iterator_t() : iterator_base<block,double,reverse>(){}
897 }
903 bool operator==( iterator_t<reverse> const& i ) const {
904 return this->v == i.v and this->position == i.position;
905 }
911 bool operator!=( iterator_t<reverse> const& i ) const {
912 return not this->operator==( i );
913 }
919 bool operator<( iterator_t<reverse> const& i ) const {
920 // Warn if either iterator undefined
921 if( this->v == 0 or i.v == 0 ){
922 gsl_error( "iterator not initialised", __FILE__, __LINE__, exception::GSL_EFAILED );
923 return false;
924 }
925 // Warn if iterators do not point to same block
926 if( this->v->ccgsl_pointer != i.v->ccgsl_pointer ){
927 gsl_error( "trying to take difference of iterators for different blocks", __FILE__, __LINE__,
929 return false;
930 }
931 return reverse ? i.position < this->position : this->position < i.position;
932 }
938 bool operator==( const_iterator_t<reverse> const& i ) const {
939 return this->v == i.v and this->position == i.position;
940 }
946 bool operator!=( const_iterator_t<reverse> const& i ) const {
947 return not this->operator==( i );
948 }
954 bool operator<( const_iterator_t<reverse> const& i ) const {
955 // Warn if either iterator undefined
956 if( this->v == 0 or i.v == 0 ){
957 gsl_error( "iterator not initialised", __FILE__, __LINE__, exception::GSL_EFAILED );
958 return false;
959 }
960 // Warn if iterators do not point to same block
961 if( this->v->ccgsl_pointer != i.v->ccgsl_pointer ){
962 gsl_error( "trying to take difference of iterators for different blocks", __FILE__, __LINE__,
964 return false;
965 }
966 return reverse ? i.position < this->position : this->position < i.position;
967 }
968 protected:
969 // We need a constructor for block
970 friend class block;
977 : iterator_base<block const,double,reverse>( v, position ){}
978 };
979 public:
996 // type difference_type
1001 // type size_type
1005 typedef size_t size_type;
1006 // begin()
1012 return iterator( this, 0 );
1013 }
1019 return const_iterator( this, 0 );
1020 }
1021 // end()
1027 if( ccgsl_pointer == 0 ) return iterator( this, 0 );
1028 return iterator( this, size() );
1029 }
1035 if( ccgsl_pointer == 0 ) return const_iterator( this, 0 );
1036 return const_iterator( this, size() );
1037 }
1038 // size()
1043 size_type size() const { return ccgsl_pointer->size; }
1049 double* data() {
1050 if( ccgsl_pointer == 0 ) gsl_error( "null block", __FILE__, __LINE__, GSL_EFAULT );
1051 return ccgsl_pointer->data; }
1057 double const* data() const {
1058 if( ccgsl_pointer == 0 ) gsl_error( "null block", __FILE__, __LINE__, GSL_EFAULT );
1059 return ccgsl_pointer->data; }
1060 // max_size()
1066 size_type max_size() const { return ccgsl_pointer->size; }
1067 // empty()
1072 bool empty() const { return ccgsl_pointer == 0 or ccgsl_pointer->size == 0; }
1073 // swap() --- should work even if sizes don't match
1079 void swap( block& v ){
1080 std::swap( ccgsl_pointer, v.ccgsl_pointer );
1081 std::swap( count, v.count );
1082 }
1083 // Refines reversible container
1084 // rbegin()
1090 if( ccgsl_pointer ==0 ) return reverse_iterator( this, 0 );
1091 return reverse_iterator( this, size() - 1 );
1092 }
1098 if( ccgsl_pointer ==0 ) return const_reverse_iterator( this, 0 );
1099 return const_reverse_iterator( this, size() - 1 );
1100 }
1101 // rend()
1107 return reverse_iterator( this, -1 );
1108 }
1114 return const_reverse_iterator( this, -1 );
1115 }
1116 // operator[]
1122 double& operator[]( size_t const n ){
1123 // Always try to return something
1124 static double something = 0;
1125 // First check that iterator is initialised.
1126 if( ccgsl_pointer == 0 ){
1127 gsl_error( "block is null", __FILE__, __LINE__, exception::GSL_EFAULT );
1128 return something;
1129 }
1130#ifndef GSL_RANGE_CHECK_OFF
1131 // Check that position make sense
1132 if( n >= size() ){
1133 gsl_error( "trying to read beyond end of block", __FILE__, __LINE__, exception::GSL_EINVAL );
1134 return something;
1135 }
1136 // n is a valid position
1137#endif
1138 return *(ccgsl_pointer->data + n);
1139 }
1145 double const& operator[]( size_t const n ) const {
1146 // Always try to return something
1147 static double something = 0;
1148 // First check that iterator is initialised.
1149 if( ccgsl_pointer == 0 ){
1150 gsl_error( "block is null", __FILE__, __LINE__, exception::GSL_EFAULT );
1151 return something;
1152 }
1153#ifndef GSL_RANGE_CHECK_OFF
1154 // Check that position make sense
1155 if( n >= size() ){
1156 gsl_error( "trying to read beyond end of block", __FILE__, __LINE__, exception::GSL_EINVAL );
1157 return something;
1158 }
1159 // n is a valid position
1160#endif
1161 return *(ccgsl_pointer->data + n);
1162 }
1163 private:
1167 gsl_block* ccgsl_pointer;
1171 size_t* count;
1172 public:
1173 // shared reference functions
1178 gsl_block* get() const { return ccgsl_pointer; }
1184 bool unique() const { return count != 0 and *count == 1; }
1189 size_t use_count() const { return count == 0 ? 0 : *count; }
1195#ifdef __GXX_EXPERIMENTAL_CXX0X__
1196 explicit
1197#endif
1198 operator bool() const { return ccgsl_pointer != 0; }
1199 };
1200
1201 // gsl functions
1202
1209 inline block::iterator operator+
1211 block::iterator const& i ){
1212 return i + n;
1213 }
1214
1221 inline block::const_iterator operator+
1223 block::const_iterator const& i ){
1224 return i + n;
1225 }
1226
1235 block::reverse_iterator const& i ){
1236 return i + n;
1237 }
1238
1248 return i + n;
1249 }
1250
1251}
1252
1253#endif
A class template for the const iterators.
Definition: block.hpp:754
const_iterator_t< reverse > operator--(int)
The postfix – operator.
Definition: block.hpp:801
const_iterator_t< reverse > operator+(difference_type const n) const
The + operator.
Definition: block.hpp:839
iterator_base< blockconst, double, reverse >::difference_type difference_type
Difference type.
Definition: block.hpp:811
bool operator!=(iterator_t< reverse > const &i) const
Comparison with non-const iterator.
Definition: block.hpp:911
const_iterator_t & operator=(const_iterator_t< reverse > const &i)
We can assign one output iterator from another.
Definition: block.hpp:762
bool operator==(iterator_t< reverse > const &i) const
Comparison with non-const iterator.
Definition: block.hpp:903
const_iterator_t()
The default constructor.
Definition: block.hpp:889
bool operator<(iterator_t< reverse > const &i) const
Comparison with non-const iterator.
Definition: block.hpp:919
bool operator<(const_iterator_t< reverse > const &i) const
Comparison with const iterator.
Definition: block.hpp:954
const_iterator_t< reverse > & operator-=(difference_type const n)
The -= operator.
Definition: block.hpp:828
bool operator!=(const_iterator_t< reverse > const &i) const
Comparison with const iterator.
Definition: block.hpp:946
difference_type operator-(const_iterator_t< reverse > const &i) const
The - operator: find distance between two iterators.
Definition: block.hpp:861
const_iterator_t(iterator_t< reverse > const &i)
A copy constructor.
Definition: block.hpp:894
const_iterator_t< reverse > & operator+=(difference_type const n)
The += operator.
Definition: block.hpp:818
difference_type operator-(iterator_t< reverse > const &i) const
The - operator: find distance between two iterators.
Definition: block.hpp:869
const_iterator_t< reverse > operator-(difference_type const n) const
The - operator: subtract distance from iterator.
Definition: block.hpp:851
const_iterator_t< reverse > operator++(int)
The postfix ++ operator.
Definition: block.hpp:781
const_iterator_t(block const *v, difference_type position)
This constructor allows block to create non-default iterators.
Definition: block.hpp:976
bool operator==(const_iterator_t< reverse > const &i) const
Comparison with const iterator.
Definition: block.hpp:938
const_iterator_t< reverse > & operator++()
The prefix ++ operator.
Definition: block.hpp:773
const_iterator_t< reverse > & operator--()
The prefix – operator.
Definition: block.hpp:793
The container must have iterator types.
Definition: block.hpp:322
reference operator*() const
Dereference the pointer.
Definition: block.hpp:352
value_type & reference
An iterator must have a reference type.
Definition: block.hpp:340
void decrement()
Decrement the iterator.
Definition: block.hpp:515
bool operator<(iterator_base< container, content, reverse > const &i) const
The < operator is used to compare iterators.
Definition: block.hpp:479
reference operator[](difference_type const n) const
Get element at i + n by reference ([] operator).
Definition: block.hpp:407
value_type * pointer
An iterator must have a pointer typea.
Definition: block.hpp:336
std::random_access_iterator_tag iterator_category
An iterator must have an iterator category.
Definition: block.hpp:328
void shift(difference_type const n)
Shift iterator n places.
Definition: block.hpp:532
bool operator==(iterator_base< container, content, reverse > const &i) const
The == operator.
Definition: block.hpp:461
double value_type
An iterator must have a value type.
Definition: block.hpp:332
void increment()
Increment the iterator.
Definition: block.hpp:498
difference_type position
Mark position of iterator within block.
Definition: block.hpp:561
bool operator!=(iterator_base< container, content, reverse > const &i) const
The != operator.
Definition: block.hpp:469
difference_type operator-(iterator_base< container, content, reverse > const &i) const
The - operator: find distance between two iterators.
Definition: block.hpp:437
ptrdiff_t difference_type
An iterator must have a difference_type.
Definition: block.hpp:345
container * v
Store a pointer to a block we can iterate over: 0 if no block.
Definition: block.hpp:557
iterator_base()
The iterator is default constructible.
Definition: block.hpp:546
pointer operator->() const
Dereference the pointer.
Definition: block.hpp:380
iterator_base(container *v, difference_type position)
This constructor allows block to create non-default iterators.
Definition: block.hpp:552
A class template for the two non-const iterators.
Definition: block.hpp:568
difference_type operator-(const_iterator_t< reverse > const &i) const
The - operator: find distance between two iterators.
Definition: block.hpp:683
iterator_t< reverse > & operator+=(difference_type const n)
The += operator.
Definition: block.hpp:632
iterator_t< reverse > operator++(int)
The postfix ++ operator.
Definition: block.hpp:595
difference_type operator-(iterator_t< reverse > const &i) const
The - operator: find distance between two iterators.
Definition: block.hpp:675
bool operator==(const_iterator_t< reverse > const &i) const
Comparison with const iterator.
Definition: block.hpp:705
iterator_t< reverse > & operator--()
The prefix – operator.
Definition: block.hpp:607
iterator_t(block *v, difference_type position)
This constructor allows block to create non-default iterators.
Definition: block.hpp:747
iterator_t< reverse > operator+(difference_type const n) const
The + operator.
Definition: block.hpp:653
iterator_t< reverse > & operator-=(difference_type const n)
The -= operator.
Definition: block.hpp:642
bool operator<(const_iterator_t< reverse > const &i) const
Comparison with const iterator.
Definition: block.hpp:721
iterator_t< reverse > operator--(int)
The postfix – operator.
Definition: block.hpp:615
iterator_t< reverse > & operator++()
The prefix ++ operator.
Definition: block.hpp:587
bool operator!=(const_iterator_t< reverse > const &i) const
Comparison with const iterator.
Definition: block.hpp:713
iterator_base< block, double, reverse >::difference_type difference_type
Difference type.
Definition: block.hpp:625
iterator_t()
The default constructor.
Definition: block.hpp:738
iterator_t< reverse > & operator=(iterator_t< reverse > const &i)
We can assign one output iterator from another.
Definition: block.hpp:576
iterator_t< reverse > operator-(difference_type const n) const
The - operator: subtract distance from iterator.
Definition: block.hpp:665
This class handles vectors as shared handles.
Definition: block.hpp:42
bool operator<=(block const &v) const
A container needs to define an ordering for sorting.
Definition: block.hpp:275
const_reverse_iterator rend() const
Get iterator pointing beyond last block element.
Definition: block.hpp:1113
block(std::initializer_list< double > initializer_list)
Could construct from a std::initializer_list in C++11.
Definition: block.hpp:90
gsl_block * get() const
Get the gsl_block.
Definition: block.hpp:1178
bool unique() const
Find if this is the only object sharing the gsl_block.
Definition: block.hpp:1184
size_t * count
The shared reference count.
Definition: block.hpp:1171
block & operator=(block &&v)
Move operator.
Definition: block.hpp:177
~block()
The destructor only deletes the pointers if count reaches zero.
Definition: block.hpp:150
block clone() const
The clone function.
Definition: block.hpp:139
const_iterator_t< true > const_reverse_iterator
The const_reverse_iterator type.
Definition: block.hpp:991
iterator begin()
Get iterator pointing to first block element.
Definition: block.hpp:1011
double const & operator[](size_t const n) const
Get element at position n by reference ([] operator).
Definition: block.hpp:1145
value_type * pointer
A container must have a pointer type.
Definition: block.hpp:310
bool operator==(block const &v) const
Two block objects are identically equal if their elements are identical.
Definition: block.hpp:190
void swap(block &v)
Swap two block objects.
Definition: block.hpp:1079
value_type & reference
A container must have a reference type.
Definition: block.hpp:300
block()
The default constructor is only really useful for assigning to.
Definition: block.hpp:47
const_reverse_iterator rbegin() const
Get iterator pointing to first block element.
Definition: block.hpp:1097
double const * data() const
Give access to the data block.
Definition: block.hpp:1057
block(block &&v)
Move constructor.
Definition: block.hpp:168
bool operator>=(block const &v) const
A container needs to define an ordering for sorting.
Definition: block.hpp:287
block(size_t const n)
The default constructor creates a new block with n elements.
Definition: block.hpp:57
block(block const &v)
The copy constructor.
Definition: block.hpp:111
size_type max_size() const
The max size (number of elements) of the block.
Definition: block.hpp:1066
const_iterator::difference_type difference_type
A container must have a difference_type.
Definition: block.hpp:1000
value_type const & const_reference
A container must have a constant reference type.
Definition: block.hpp:305
bool empty() const
Find if the block is empty.
Definition: block.hpp:1072
bool operator!=(block const &v) const
Two block objects are different equal if their elements are not identical.
Definition: block.hpp:209
size_t size_type
A container must have a size_type.
Definition: block.hpp:1005
reverse_iterator rend()
Get iterator pointing beyond last block element.
Definition: block.hpp:1106
size_type size() const
The size (number of elements) of the block.
Definition: block.hpp:1043
double & operator[](size_t const n)
Get element at position n by reference ([] operator).
Definition: block.hpp:1122
size_t use_count() const
Find how many block objects share this pointer.
Definition: block.hpp:1189
reverse_iterator rbegin()
Get iterator pointing to first block element.
Definition: block.hpp:1089
double * data()
Give access to the data block.
Definition: block.hpp:1049
const_iterator begin() const
Get iterator pointing to first block element.
Definition: block.hpp:1018
gsl_block * ccgsl_pointer
The shared pointer.
Definition: block.hpp:1167
block(gsl_block *v)
Could construct from a gsl_block.
Definition: block.hpp:79
value_type const * const_pointer
A container must have a constant pointer type.
Definition: block.hpp:315
bool operator>(block const &v) const
A container needs to define an ordering for sorting.
Definition: block.hpp:248
void reset()
Stop sharing ownership of the shared pointer.
Definition: block.hpp:162
iterator_t< false > iterator
The iterator type.
Definition: block.hpp:987
bool operator<(block const &v) const
A container needs to define an ordering for sorting.
Definition: block.hpp:221
iterator end()
Get iterator pointing beyond last block element.
Definition: block.hpp:1026
double value_type
A container must have a value_type.
Definition: block.hpp:295
iterator_t< true > reverse_iterator
The reverse_iterator type.
Definition: block.hpp:995
const_iterator end() const
Get iterator pointing beyond last block element.
Definition: block.hpp:1034
block & operator=(block const &v)
The assignment operator.
Definition: block.hpp:119
const_iterator_t< false > const_iterator
The const_iterator type.
Definition: block.hpp:983
@ GSL_EFAILED
generic failure
Definition: exception.hpp:476
@ GSL_EINVAL
invalid argument supplied by user
Definition: exception.hpp:475
@ GSL_EFAULT
invalid pointer
Definition: exception.hpp:474
int min(movstat::end_t const endtype, vector const &x, vector &y, workspace &w)
C++ version of gsl_movstat_min().
Definition: movstat.hpp:581
size_t n(workspace const &w)
C++ version of gsl_rstat_n().
Definition: rstat.hpp:299
gsl_sf_result result
Typedef for gsl_sf_result.
Definition: sf_result.hpp:30
The gsl package creates an interface to the GNU Scientific Library for C++.
Definition: blas.hpp:34