Last active
September 7, 2019 16:59
-
-
Save heatblazer/87ff6ce90892224dc3ad803a66532328 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#if 0 | |
#define BINDABLE \ | |
template<typename Type1, typename Type2> \ | |
friend void* bind(const Type1& t1, const Type2& t2); \ | |
\ | |
template<typename Type1, typename Type2> \ | |
friend void* bind(Type1* t1, Type2* t2); \ | |
\ | |
template<typename Type1, typename Type2> \ | |
friend void* bind(Type1 const &t1, Type2 const& t2); \ | |
\ | |
template<typename Type1, typename Type2> \ | |
friend void* bind(Type1 t1, Type2 t2); | |
#endif | |
#define BINDABLE \ | |
template<typename Type1, typename Type2> \ | |
friend void* bind(Type1* t1, Type2* t2); \ | |
\ | |
template<typename Type1, typename Type2> \ | |
friend void* bind(const Type1& t1, const Type2& t2); | |
class A | |
{ | |
BINDABLE | |
int a; | |
public: | |
A(const A& ref) = default ; // test std::is_trivially_copy_constructible<>(.T.) | |
A() : a (20) {} | |
~A() {} | |
}; | |
class B | |
{ | |
BINDABLE | |
int b; | |
public: | |
B(const B& ref) = default ; | |
B() : b(10) {} | |
~B() {} | |
}; | |
template<> | |
void* bind(A a, B b) | |
{ | |
std::cout << "Called by value\r\n"; | |
std::cout << "[" << a.a + b.b << "]\r\n"; | |
} | |
template<> | |
void* bind(const A& a, const B& b) | |
{ | |
std::cout << "Called by ref\r\n"; | |
std::cout << "[" << a.a + b.b << "]\r\n"; | |
} | |
template<> | |
void* bind(A* a, B* b) | |
{ | |
std::cout << "Called by ptr\r\n"; | |
std::cout << "[" << a->a + b->b << "]\r\n"; | |
} | |
template <class T> | |
struct U | |
{ | |
typename std::enable_if<std::is_union<T>{}, T>::type m_ref; | |
U(const T& ref) : m_ref{ref} { } | |
}; | |
union tst | |
{ | |
int val; | |
}; | |
int main() | |
{ | |
A a; | |
B b; | |
tst vvv = {10}; | |
U<tst> rrr {vvv}; | |
bind(a, b); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment