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
|
#include <iostream>
#include <array>
#include <vector>
using namespace std;
template<typename C1, typename C2> void add(C1 &v1, const C2 &v2) { cout << "add(v1,v2)" << endl; }
template<typename C1, typename C2, typename C3> void add(C1 &v1, const C2 &v2, const C3 &v3) { cout << "add(v1,v2,v3)" << endl; }
template<typename C1, typename C2>
C1//typename std::enable_if<is_densevector<C1>::value && is_densevector<C2>::value, C1>::type
&operator+=(C1 &v1, const C2 &v2) { cout << "v1 += v2 : "; add(v1, v2); return v1; }
template<typename C1, typename C2>
C1//typename std::enable_if<is_densevector<C1>::value && is_densevector<C2>::value, C1>::type
operator+(const C1 &v1, const C2 &v2) { cout << "C1 = const C1& + const C2& : "; C1 r; add(r, v1, v2); return r; }
template<typename C1, typename C2>
C2//typename std::enable_if<is_densevector<C1>::value && is_densevector<C2>::value, C2>::type
&&operator+(const C1 &v1, C2 &&v2) { cout << "C2&& = const C1& + C2&& : "; return v2 += v1; }
template<typename C1, typename C2>
C1//typename std::enable_if<is_densevector<C1>::value && is_densevector<C2>::value, C1>::type
&&operator+(C1 &&v1, const C2 &v2) { cout << "C1&& = C2&& + const C2& : "; return v1 += v2; }
template<typename C1, typename C2>
C1//typename std::enable_if<is_densevector<C1>::value && is_densevector<C2>::value, C1>::type
&&operator+(C1 &&v1, C2 &&v2) { cout << "C1&& = C1&& + C2&& : "; return v1 += v2; }
int main()
{
std::array<double,3> ar1{1,2,3};
std::vector<int> ar2{3,2,1};
ar1 + ar2;
return 0;
}
|