📄 concepts.hpp
字号:
//
// Copyright (c) 2000-2002
// Joerg Walter, Mathias Koch
//
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without fee,
// provided that the above copyright notice appear in all copies and
// that both that copyright notice and this permission notice appear
// in supporting documentation. The authors make no representations
// about the suitability of this software for any purpose.
// It is provided "as is" without express or implied warranty.
//
// The authors gratefully acknowledge the support of
// GeNeSys mbH & Co. KG in producing this work.
//
#ifndef BOOST_UBLAS_CONCEPTS_H
#define BOOST_UBLAS_CONCEPTS_H
#include <boost/concept_check.hpp>
// #define INTERNAL_STORAGE
// #define INTERNAL_STORAGE_SPARSE
// #define INTERNAL_VECTOR
// #define INTERNAL_VECTOR_PROXY
// #define INTERNAL_VECTOR_SPARSE
// #define INTERNAL_MATRIX
// #define INTERNAL_MATRIX_PROXY
// #define INTERNAL_BANDED
// #define INTERNAL_TRIANGULAR
// #define INTERNAL_SYMMETRIC
// #define INTERNAL_HERMITIAN
// #define INTERNAL_MATRIX_SPARSE
// #define INTERNAL_VECTOR_EXPRESSION
// #define INTERNAL_MATRIX_EXPRESSION
// #define EXTERNAL
// Concept checks based on ideas of Jeremy Siek
namespace boost { namespace numeric { namespace ublas {
#ifdef BOOST_UBLAS_DEPRECATED
template<class T>
void ignore_unused_variable_warning (const T &t) {}
#endif
template<class T>
struct AssignableConcept {
typedef T value_type;
static void constraints (value_type t) {
// Copy Constructor
value_type c1 (t);
value_type c2 = t;
// Assignment
value_type a = t;
std::swap (c1, c2);
ignore_unused_variable_warning (a);
}
};
template<class T>
struct EqualityComparableConcept {
typedef T value_type;
static void constraints (const value_type t) {
bool b;
// Equality
b = t == t;
// Inequality
b = t != t;
ignore_unused_variable_warning (b);
}
};
template<class T>
struct LessThanComparableConcept {
typedef T value_type;
static void constraints (const value_type t) {
bool b;
b = t < t;
b = t <= t;
b = t >= t;
b = t > t;
ignore_unused_variable_warning (b);
}
};
template<class T>
struct DefaultConstructibleConcept {
typedef T value_type;
static void constraints () {
// Default Constructor
static value_type c1 = value_type ();
static value_type c2;
ignore_unused_variable_warning (c1);
ignore_unused_variable_warning (c2);
}
};
template<class I, class T = BOOST_UBLAS_TYPENAME I::value_type>
struct BidirectionalIteratorConcept {
typedef I iterator_type;
typedef T value_type;
static void constraints () {
#define BOOST_UBLAS_ITERATOR_IS_ASSIGNABLE
#ifdef BOOST_UBLAS_ITERATOR_IS_ASSIGNABLE
AssignableConcept<iterator_type>::constraints (iterator_type ());
#endif
EqualityComparableConcept<iterator_type>::constraints (iterator_type ());
DefaultConstructibleConcept<iterator_type>::constraints ();
iterator_type it = iterator_type ();
value_type t = value_type ();
// Dereference
t = *it;
// Member access
// it->m;
// Preincrement
++ it;
// Postincrement
it ++;
// Predecrement
-- it;
// Postdecrement
it --;
ignore_unused_variable_warning (t);
}
};
template<class I, class T = BOOST_UBLAS_TYPENAME I::value_type>
struct MutableBidirectionalIteratorConcept {
typedef I iterator_type;
typedef T value_type;
static void constraints () {
BidirectionalIteratorConcept<iterator_type, value_type>::constraints ();
iterator_type it = iterator_type ();
value_type t = value_type ();
#ifdef BOOST_UBLAS_NON_STD
// Dereference assignment
*it = t;
#else
ignore_unused_variable_warning (it);
#endif
ignore_unused_variable_warning (t);
}
};
template<class I, class D = BOOST_UBLAS_TYPENAME I::difference_type, class T = BOOST_UBLAS_TYPENAME I::value_type>
struct RandomAccessIteratorConcept {
typedef I iterator_type;
typedef D difference_type;
typedef T value_type;
static void constraints () {
LessThanComparableConcept<iterator_type>::constraints (iterator_type ());
BidirectionalIteratorConcept<iterator_type, value_type>::constraints ();
iterator_type it = iterator_type (), it1 = iterator_type (), it2 = iterator_type ();
difference_type n (0);
value_type t = value_type ();
// Forward motion
it += n;
// Iterator addition
#ifdef BOOST_UBLAS_ITERATOR_IS_ASSIGNABLE
it = it + n;
#else
iterator_type itp (it + n);
#endif
// Backward motion
it -= n;
// Iterator subtraction
#ifdef BOOST_UBLAS_ITERATOR_IS_ASSIGNABLE
it = it - n;
#else
iterator_type itm (it - n);
#endif
// Difference
n = it1 - it2;
// Element operator
#ifdef BOOST_UBLAS_ITERATOR_IS_INDEXABLE
t = it [n];
#else
t = *(it + n);
#endif
ignore_unused_variable_warning (t);
}
};
template<class I, class D = BOOST_UBLAS_TYPENAME I::difference_type, class T = BOOST_UBLAS_TYPENAME I::value_type>
struct MutableRandomAccessIteratorConcept {
typedef I iterator_type;
typedef D difference_type;
typedef T value_type;
static void constraints () {
MutableBidirectionalIteratorConcept<iterator_type, value_type>::constraints ();
RandomAccessIteratorConcept<iterator_type, difference_type, value_type>::constraints ();
iterator_type it = iterator_type ();
difference_type n (0);
value_type t = value_type ();
// Element assignment
#ifdef BOOST_UBLAS_ITERATOR_IS_INDEXABLE
it [n] = t;
#else
*(it + n) = t;
#endif
}
};
template<class I>
struct Indexed1DIteratorConcept {
typedef I iterator_type;
static void constraints () {
iterator_type it = iterator_type ();
// Function call
it ();
// Index
it.index ();
}
};
template<class I>
struct IndexedBidirectional1DIteratorConcept {
typedef I iterator_type;
static void constraints () {
BidirectionalIteratorConcept<iterator_type>::constraints ();
Indexed1DIteratorConcept<iterator_type>::constraints ();
}
};
template<class I>
struct MutableIndexedBidirectional1DIteratorConcept {
typedef I iterator_type;
static void constraints () {
MutableBidirectionalIteratorConcept<iterator_type>::constraints ();
Indexed1DIteratorConcept<iterator_type>::constraints ();
}
};
template<class I>
struct IndexedRandomAccess1DIteratorConcept {
typedef I iterator_type;
static void constraints () {
RandomAccessIteratorConcept<iterator_type>::constraints ();
Indexed1DIteratorConcept<iterator_type>::constraints ();
}
};
template<class I>
struct MutableIndexedRandomAccess1DIteratorConcept {
typedef I iterator_type;
static void constraints () {
MutableRandomAccessIteratorConcept<iterator_type>::constraints ();
Indexed1DIteratorConcept<iterator_type>::constraints ();
}
};
template<class I>
struct Indexed2DIteratorConcept {
typedef I iterator_type;
typedef typename I::dual_iterator_type dual_iterator_type;
typedef typename I::dual_reverse_iterator_type dual_reverse_iterator_type;
static void constraints () {
iterator_type it = iterator_type ();
// Function call
it ();
// Indices
it.index1 ();
it.index2 ();
// Iterator begin/end
dual_iterator_type it_begin (it.begin ());
dual_iterator_type it_end (it.end ());
// Reverse iterator begin/end
dual_reverse_iterator_type it_rbegin (it.rbegin ());
dual_reverse_iterator_type it_rend (it.rend ());
ignore_unused_variable_warning (it_begin);
ignore_unused_variable_warning (it_end);
ignore_unused_variable_warning (it_rbegin);
ignore_unused_variable_warning (it_rend);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -