-
Notifications
You must be signed in to change notification settings - Fork 3
/
exp1.cpp
47 lines (38 loc) · 1.13 KB
/
exp1.cpp
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
#include <iostream>
#include <type_traits>
struct A{};
struct B{};
struct M{
int _x;
M(int x): _x(x){}
operator int(){return _x;}
};
template <typename T>
struct is_operand{};
template <>
struct is_operand<A>{typedef M result_type;};
template <>
struct is_operand<B>{typedef M result_type;};
template <typename U, typename V> struct operation_result: is_operand<U>, is_operand<V>{};
template <typename U> struct operation_result<U, U>: is_operand<U>{};
template <> struct operation_result<A, B>{typedef M result_type;};
template <> struct operation_result<B, A>{typedef M result_type;};
template <typename U, typename V>
typename operation_result<U, V>::result_type operator+(U u, V v){
std::cout << "Hallo" << std::endl;
return M(42);
}
int main(){
A a;
B b;
std::cout << 1 + 1 << std::endl;
std::cout << a + 1 << std::endl;
std::cout << 1 + a << std::endl;
std::cout << b + 1 << std::endl;
std::cout << 1 + b << std::endl;
std::cout << a + a << std::endl;
std::cout << b + b << std::endl;
std::cout << a + b << std::endl;
std::cout << b + a << std::endl;
return 0;
};