Saut voila, je suis entrain de définir quelques opération sur des array. Certaines sont déjà défini dans array.hpp de boost. Je les complète donc comme ceci :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
	//Vectorial opérations
    template<class T, std::size_t N>
    bool operator== (const array<T,N>& x, const array<T,N>& y) {
        return std::equal(x.begin(), x.end(), y.begin());
    }
    template<class T, std::size_t N>
    bool operator< (const array<T,N>& x, const array<T,N>& y) {
        return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end());
    }
    template<class T, std::size_t N>
    bool operator!= (const array<T,N>& x, const array<T,N>& y) {
        return !(x==y);
    }
    template<class T, std::size_t N>
    bool operator> (const array<T,N>& x, const array<T,N>& y) {
        return y<x;
    }
    template<class T, std::size_t N>
    bool operator<= (const array<T,N>& x, const array<T,N>& y) {
        return !(y<x);
    }
    template<class T, std::size_t N>
    bool operator>= (const array<T,N>& x, const array<T,N>& y) {
        return !(x<y);
    }
 
	template<class T>
    T& operator+=(T& x, const T& y)
    {
      for(unsigned long i = 0; i < x.size(); ++i)
      {
		  x[i] += y[i];
      }
      return x;
    }
 
	template<class T>
    T& operator-=(T& x, const T& y)
    {
      for(unsigned long i = 0; i < x.size(); ++i)
      {
		  x[i] -= y[i];
      }
      return x;
    }
 
	template<class T> /// c'est ici que ca marche plus
    T operator*=(T& x, const T& y)
    {
      for(unsigned long i = 0; i < x.size(); ++i)
      {
		  x[i] =(x[i] *= y[i]);
      }
      return x;
    }

Dans le dernier template, j'essaie de définir un produit scalaire. ma fonction doit donc me renvoyer un scalaire (et non un array), et la vraiment je ne sais plus quoi faire. En fait ici, je sais ca me renvoie un "vecteur", mais je ne sais pas comment lui demander de me renvoyer un scalaire de n'importe quel type. CAr si je met autre chose à la place de T&, il ne reconnait plus les T déclarés plus loin.

ici le code de mon fichier Vector au complet basé sur boos::array.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
/* Vecor.h
 
	Sven
	10/09/2209
*/
 
#include <iostream>
#include <iterator>
#include <algorithm>
 
#include <boost/type_traits.hpp>
 
#ifndef VECTOR_H
#define VECTOR_H
 
namespace CRB {
 
    template<class T, std::size_t N>
    class array {
      public:
        T elems[N];    // fixed-size array of elements of type T
 
      public:
        // type definitions
        typedef T              value_type;
        typedef T*             iterator;
        typedef const T*       const_iterator;
        typedef T&             reference;
        typedef const T&       const_reference;
        typedef std::size_t    size_type;
        typedef std::ptrdiff_t difference_type;
 
        // iterator support
        iterator begin() { return elems; }
        const_iterator begin() const { return elems; }
        iterator end() { return elems+N; }
        const_iterator end() const { return elems+N; }
 
		reference operator[](size_type i) 
        { 
            BOOST_ASSERT( i < N && "out of range" ); 
            return elems[i];
        }
 
        const_reference operator[](size_type i) const 
        {     
            BOOST_ASSERT( i < N && "out of range" ); 
            return elems[i]; 
        }
 
		        // front() and back()
        reference front() 
        { 
            return elems[0]; 
        }
 
        const_reference front() const 
        {
            return elems[0];
        }
 
        reference back() 
        { 
            return elems[N-1]; 
        }
 
        const_reference back() const 
        { 
            return elems[N-1]; 
        }
 
		        // size is constant
        static size_type size() { return N; }
        static bool empty() { return false; }
        static size_type max_size() { return N; }
        enum { static_size = N };
 
		// direct access to data (read-only)
		const T* data() const { return elems; }
        T* data() { return elems; }
 
		// assign one value to all elements
        void assign (const T& value)
        {
            std::fill_n(begin(),size(),value);
        }
	};
 
	//Vectorial opérations
    template<class T, std::size_t N>
    bool operator== (const array<T,N>& x, const array<T,N>& y) {
        return std::equal(x.begin(), x.end(), y.begin());
    }
    template<class T, std::size_t N>
    bool operator< (const array<T,N>& x, const array<T,N>& y) {
        return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end());
    }
    template<class T, std::size_t N>
    bool operator!= (const array<T,N>& x, const array<T,N>& y) {
        return !(x==y);
    }
    template<class T, std::size_t N>
    bool operator> (const array<T,N>& x, const array<T,N>& y) {
        return y<x;
    }
    template<class T, std::size_t N>
    bool operator<= (const array<T,N>& x, const array<T,N>& y) {
        return !(y<x);
    }
    template<class T, std::size_t N>
    bool operator>= (const array<T,N>& x, const array<T,N>& y) {
        return !(x<y);
    }
 
	template<class T>
    T& operator+=(T& x, const T& y)
    {
      for(unsigned long i = 0; i < x.size(); ++i)
      {
		  x[i] += y[i];
      }
      return x;
    }
 
	template<class T>
    T& operator-=(T& x, const T& y)
    {
      for(unsigned long i = 0; i < x.size(); ++i)
      {
		  x[i] -= y[i];
      }
      return x;
    }
 
	template<class T> /// c'est ici que ca marche plus
    T operator*=(T& x, const T& y)
    {
      for(unsigned long i = 0; i < x.size(); ++i)
      {
		  x[i] =(x[i] *= y[i]);
      }
      return x;
    }
 
 
}
#endif
Merci d'avance pour votre aide!!