20#ifndef CCGSL_COMBINATION_HPP
21#define CCGSL_COMBINATION_HPP
26#include<gsl/gsl_combination.h>
51 try {
count =
new size_t; }
catch( std::bad_alloc& e ){
104 gsl_combination_memcpy( copy.
get(),
get() );
119#ifdef __GXX_EXPERIMENTAL_CXX0X__
125 std::swap(
count, v.count );
126 v.ccgsl_pointer =
nullptr;
135 std::swap(
count, v.count );
176#ifdef __GXX_EXPERIMENTAL_CXX0X__
209 int fread( FILE* stream ){
return gsl_combination_fread( stream,
get() ); }
215 int fwrite( FILE* stream )
const {
return gsl_combination_fwrite( stream,
get() ); }
221 int fscanf( FILE* stream ){
return gsl_combination_fscanf( stream,
get() ); }
228 int fprintf( FILE* stream,
char const* format )
const {
229 return gsl_combination_fprintf( stream,
get(), format ); }
234 size_t n()
const {
return get()->n; }
239 size_t k()
const {
return get()->k; }
249 int valid() {
return gsl_combination_valid(
get() ); }
254 int next(){
return gsl_combination_next(
get() ); }
259 int prev(){
return gsl_combination_prev(
get() ); }
265 size_t get(
size_t const i )
const {
return gsl_combination_get(
get(), i ); }
271 size_t operator[](
size_t const i )
const {
return gsl_combination_get(
get(), i ); }
277 template<
typename container,
typename content,
bool reverse>
class iterator_base {
309 static content something = 0;
314 }
else if(
v->ccgsl_pointer == 0 ){
328 return *(
v->ccgsl_pointer->data +
position);
340 }
else if(
v->ccgsl_pointer == 0 ){
354 return *(
v->ccgsl_pointer->data +
position);
364 static content something = 0;
369 }
else if(
v->ccgsl_pointer == 0 ){
384 return *(
v->ccgsl_pointer->data + p );
394 if(
v == 0 or i.
v == 0 ){
397 }
else if(
v->ccgsl_pointer == 0 or i.
v->ccgsl_pointer == 0 ){
402 if(
v->ccgsl_pointer != i.
v->ccgsl_pointer ){
403 gsl_error(
"trying to take difference of iterators for different combinations", __FILE__, __LINE__,
436 if(
v == 0 or i.
v == 0 ){
441 if(
v->ccgsl_pointer != i.
v->ccgsl_pointer ){
442 gsl_error(
"trying to take difference of iterators for different combinations", __FILE__, __LINE__,
458 }
else if(
v->ccgsl_pointer == 0 ){
475 }
else if(
v->ccgsl_pointer == 0 ){
492 }
else if(
v->ccgsl_pointer == 0 ){
522 :
public iterator_base<combination const,unsigned long,reverse>{
667 if( this->
v == 0 or i.
v == 0 ){
673 gsl_error(
"trying to take difference of iterators for different combinations", __FILE__, __LINE__,
A class template for the const iterators.
const_iterator_t(const_iterator_t< reverse > const &i)
A copy constructor.
const_iterator_t()
The default constructor.
const_iterator_t< reverse > & operator--()
The prefix – operator.
const_iterator_t< reverse > operator++(int)
The postfix ++ operator.
bool operator<(const_iterator_t< reverse > const &i) const
Comparison with const_iterator.
difference_type operator-(const_iterator_t< reverse > const &i) const
The - operator: find distance between two iterators.
const_iterator_t< reverse > operator-(difference_type const n) const
The - operator: subtract distance from iterator.
const_iterator_t< reverse > & operator=(const_iterator_t< reverse > const &i)
We can assign one output iterator from another.
const_iterator_t< reverse > & operator-=(difference_type const n)
The -= operator.
bool operator!=(const_iterator_t< reverse > const &i) const
Comparison with const_iterator.
const_iterator_t< reverse > & operator++()
The prefix ++ operator.
const_iterator_t< reverse > operator+(difference_type const n) const
The + operator.
const_iterator_t< reverse > & operator+=(difference_type const n)
The += operator.
iterator_base< combinationconst, unsignedlong, reverse >::difference_type difference_type
Difference type.
const_iterator_t< reverse > operator--(int)
The postfix – operator.
const_iterator_t(combination const *v, difference_type position)
This constructor allows combination to create non-default iterators.
bool operator==(const_iterator_t< reverse > const &i) const
Comparison with const_iterator.
The container must have iterator types.
void shift(difference_type const n)
Shift iterator n places.
reference operator[](difference_type const n) const
Get element at i + n by reference ([] operator).
void decrement()
Decrement the iterator.
difference_type position
Mark position of iterator within combination.
container * v
Store a pointer to a combination we can iterate over: 0 if no combination.
bool operator==(iterator_base< container, content, reverse > const &i) const
The == operator.
void increment()
Increment the iterator.
ptrdiff_t difference_type
An iterator must have a difference_type.
bool operator!=(iterator_base< container, content, reverse > const &i) const
The != operator.
reference operator*() const
Dereference the pointer.
value_type * pointer
An iterator must have a pointer typea.
pointer operator->() const
Dereference the pointer.
difference_type operator-(iterator_base< container, content, reverse > const &i) const
The - operator: find distance between two iterators.
iterator_base(container *v, difference_type position)
This constructor allows combination to create non-default iterators.
size_t value_type
An iterator must have a value type.
iterator_base()
The iterator is default constructible.
value_type & reference
An iterator must have a reference type.
std::random_access_iterator_tag iterator_category
An iterator must have an iterator category.
bool operator<(iterator_base< container, content, reverse > const &i) const
The < operator is used to compare iterators.
This class handles GSL combination objects.
const_iterator_t< false > const_iterator
The const_iterator type.
combination(combination const &v)
The copy constructor.
int next()
C++ version of gsl_combination_next().
combination & operator=(combination const &v)
The assignment operator.
int prev()
C++ version of gsl_combination_prev().
size_t get(size_t const i) const
C++ version of gsl_combination_get().
gsl_combination const * get() const
Get the gsl_combination.
~combination()
The destructor only deletes the pointers if count reaches zero.
const_iterator_t< true > const_reverse_iterator
The const_reverse_iterator type.
void init_first()
C++ version of gsl_combination_init_first().
bool unique() const
Find if this is the only object sharing the gsl_combination.
int memcpy(combination const &src)
C++ version of gsl_combination_memcpy().
combination(combination &&v)
Move constructor.
combination(gsl_combination *v)
Could construct from a gsl_combination.
size_t n() const
C++ version of gsl_combination_n(): Size of set.
combination & operator=(combination &&v)
Move operator.
combination()
The default constructor is only really useful for assigning to.
int fprintf(FILE *stream, char const *format) const
C++ version of gsl_combination_fprintf().
int valid()
C++ version of gsl_combination_valid().
const_iterator end() const
Get iterator pointing beyond last combination element.
size_t * count
The shared reference count.
gsl_combination * get()
Get the gsl_combination.
void init_last()
C++ version of gsl_combination_init_last().
combination clone() const
The clone function.
size_t k() const
C++ version of gsl_combination_k(): Number of selections.
size_t size_type
A container must have a size_type.
const_iterator begin() const
Get iterator pointing to first combination element.
int fwrite(FILE *stream) const
C++ version of gsl_combination_fwrite().
const_iterator::difference_type difference_type
A container must have a difference_type.
int fread(FILE *stream)
C++ version of gsl_combination_fread().
static combination calloc(size_t const n, size_t const k)
C++ version of gsl_combination_calloc().
int fscanf(FILE *stream)
C++ version of gsl_combination_fscanf().
size_t use_count() const
Find how many combination objects share this pointer.
size_t * data()
C++ version of gsl_combination_data().
size_t operator[](size_t const i) const
C++ version of gsl_combination_get().
gsl_combination * ccgsl_pointer
The shared pointer.
combination(size_t const n, size_t const k, bool init=false)
This constructor creates a new combination with n elements from which k are chosen.
@ GSL_EFAILED
generic failure
@ GSL_EFAULT
invalid pointer
int init(series &cs, function_scl const &func, double const a, double const b)
C++ version of gsl_cheb_init().
gsl_sf_result result
Typedef for gsl_sf_result.
The gsl package creates an interface to the GNU Scientific Library for C++.