Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <int I> struct A {};
- char xxx(int);
- char xxx(float);
- template <class T> A<sizeof(xxx((T)0))> f(T){}
- int main()
- {
- f(1);
- }
- struct X {};
- struct Y
- {
- Y(X){}
- };
- template <class T> auto f(T t1, T t2) -> decltype(t1 + t2); // #1
- X f(Y, Y); // #2
- X x1, x2;
- X x3 = f(x1, x2); // deduction fails on #1 (cannot add X+X), calls #2
- #include <iostream>
- struct not_a_type{};
- // catch-all case
- void test(...)
- {
- std::cout << "Couldn't calln";
- }
- // catch when C is a reference-to-class type and F is a member function pointer
- template<class C, class F>
- auto test(C c, F f) -> decltype((c.*f)(), void()) // 'C' is reference type
- {
- std::cout << "Could call on referencen";
- }
- // catch when C is a pointer-to-class type and F is a member function pointer
- template<class C, class F>
- auto test(C c, F f) -> decltype((c->*f)(), void()) // 'C' is pointer type
- {
- std::cout << "Could call on pointern";
- }
- struct X{
- void f(){}
- };
- int main(){
- X x;
- test(x, &X::f);
- test(&x, &X::f);
- test(42, 1337);
- }
- struct has_member_begin_test{
- template<class U>
- static auto test(U* p) -> decltype(p->begin(), std::true_type());
- template<class>
- static auto test(...) -> std::false_type;
- };
- template<class T>
- struct has_member_begin
- : decltype(has_member_begin_test::test<T>(0)) {};
- struct has_member_begin_test{
- template<class U>
- static auto test(U* p) -> decltype(p->begin(), std::true_type());
- template<class>
- static auto test(...) -> std::false_type;
- };
- template<class T>
- struct has_member_begin
- : decltype(has_member_begin_test::test<T>(0)) {};
- struct has_member_begin_test{
- template<class U>
- static auto test(U* p) -> decltype(p->begin(), std::true_type());
- template<class>
- static auto test(...) -> std::false_type;
- };
- template<class T>
- struct has_member_begin
- : decltype(has_member_begin_test::test<T>(0)) {};
Add Comment
Please, Sign In to add comment