vector.hpp 3.47 KB
Newer Older
1
// Software License for MTL
2
//
3
4
5
6
7
// Copyright (c) 2007 The Trustees of Indiana University.
//               2008 Dresden University of Technology and the Trustees of Indiana University.
//               2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
8
//
9
// This file is part of the Matrix Template Library
10
//
11
12
13
14
15
16
17
18
19
20
// See also license.mtl.txt in the distribution.

#ifndef MTL_VECTOR_CONCEPTS_INCLUDE
#define MTL_VECTOR_CONCEPTS_INCLUDE

#include <boost/numeric/mtl/mtl_fwd.hpp>
#include <boost/numeric/mtl/concept/collection.hpp>

#ifdef __GXX_CONCEPTS__
#  include <concepts>
21
#else
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
#  include <boost/numeric/linear_algebra/pseudo_concept.hpp>
#endif

namespace mtl {

/** @addtogroup Concepts
 *  @{
 */

#ifdef __GXX_CONCEPTS__
    concept Vector<typename T>
      : AlgebraicCollection<T>
    {
	const_reference T::operator() (size_type index) const;

	const_reference T::operator[] (size_type index) const;

	size_type nnz(T); // maybe into AlgebraicCollection?
    };
#else
    /// Concept Vector
    /**
        \par Refinement of:
	- AlgebraicCollection < T >
	\par Notation:
	- X is a type that models Vector
	- v is an object of type X
	- r are objects of size_type
	\par Valid expressions:
51
	- Element access: \n v(r) \n Return Type: const_reference
52
53
54
55
56
	  \n Semantics: Element in row \p r and column \p c
	- Element access: \n v[r] \n Equivalent to v(r)
	\invariant
	- Either num_cols(v), in case of a column vector, or num_rows(v),
	  in case of a row vector, must be 1! Otherwise it would be
57
	  a matrix.
58
59
60
	\par Models:
       	- dense_vector
	\note
61
	-# If it would become (extremely) important to support 1D C arrays as Vector,
62
63
	  it might be necessary to drop the requirement
	  of element access by v(r).
64
     */
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
    template <typename T>
    struct Vector
	: public AlgebraicCollection<T>
    {
	/// Element access
	const_reference T::operator() (size_type index) const;

	/// Element access
	const_reference T::operator[] (size_type index) const;
    };
#endif


#ifdef __GXX_CONCEPTS__
    concept MutableVector<typename T>
80
      : Vector<T>,
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
        MutableCollection<T>
    {
	reference T::operator() (size_type index);

	reference T::operator[] (size_type index);
    };
#else
    /// Concept MutableVector
    /**
        \par Refinement of:
	- Vector < T >
	- MutableCollection < T >
	\par Notation:
	- X is a type that models Vector
	- v is an object of type X
	- r are objects of size_type
	\par Valid expressions:
98
	- Element access: \n v(r) \n Return Type: reference
99
100
101
102
103
	  \n Semantics: Element in row \p r for a column vector or in column \p c for a row vector
	- Element access: \n v[r] \n Equivalent to v(r)
	\par Models:
       	- dense_vector
	\note
104
	-# If it would become (extremely) important to support 1D C arrays as Vector,
105
106
	  it might be necessary to drop the requirement
	  of element access by v(r).
107
     */
108
109
    template <typename T>
    struct MutableVector
110
      : public Vector<T>,
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
        public MutableCollection<T>
    {};
#endif


#ifdef __GXX_CONCEPTS__
    concept ConstantSizeVector<typename T>
      : Vector<T>,
	ConstantSizeAlgebraicCollection<T>
    {};
#else
    /// Concept ConstantSizeVector
    /**
        \par Refinement of:
	- Vector < T >
	- ConstantSizeAlgebraicCollection < T >
127
     */
128
129
130
131
132
133
134
    template <typename T>
    struct ConstantSizeVector
      : public Vector<T>,
	public ConstantSizeAlgebraicCollection<T>
    {};
#endif

135

136
137
138
139
140
141
142

/*@}*/ // end of group Concepts


} // namespace mtl

#endif // MTL_VECTOR_CONCEPTS_INCLUDE