Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F78977357
specialization_vector.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Aug 24, 02:23
Size
815 B
Mime Type
text/x-c++
Expires
Mon, Aug 26, 02:23 (1 d, 22 h)
Engine
blob
Format
Raw Data
Handle
20130552
Attached To
R9360 PCSC_git
specialization_vector.cpp
View Options
#include "myvector_template_dim.hh"
template <typename T> T getMaximum(const T &a, const T &b) {
if (a > b)
return a;
return b;
}
// specialization for vectors
template <>
MyVector<double, 3>
getMaximum<MyVector<double, 3>>(const MyVector<double, 3> &v1,
const MyVector<double, 3> &v2) {
MyVector<double, 3> max;
for (int i = 0; i < 3; ++i) {
max[i] = getMaximum(v1[i], v2[i]);
}
return max;
}
// overloading
template <typename T, int dim>
MyVector<T, dim> getMaximum(const MyVector<T, dim> &v1,
const MyVector<T, dim> &v2) {
MyVector<T, dim> max;
for (int i = 0; i < dim; ++i) {
max[i] = getMaximum(v1[i], v2[i]);
}
return max;
}
int main() {
MyVector<double> v1, v2;
MyVector<double> res = getMaximum(v1, v2);
}
Event Timeline
Log In to Comment