language: C++11 (gcc-4.7.2)
date: 176 days 3 hours ago
link:
visibility: public
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
#include <iostream>
#include <type_traits>
 
template<class Typ>
class base {
public:
    const base<Typ> operator+() const{
        base<Typ> result;
        result.fElement = +fElement;
        return result;
    }
 
    template<typename T>
    typename std::enable_if<std::is_same<T, base<double>>::value,
    const base<double>>::type
    operator^(const T& rgh) const
    {
        std::cout << fElement << " ^ " << rgh.fElement << '\n';
        return *this;
    }
private:
    Typ fElement;
};
 
typedef base<double> derived;
 
int main(){
    derived a, b;
    +a;     // It compiles
    a^b;        // It compiles
    +a^b;       // It compiles
    +(a^b);     // It compiles
 
    base<int> c;
    +c; // It compiles
//     c^c; // no ^ for base<int>
}