int value (Foo* a) { return (a->*Id)(); }
};
-template class Bar <Derived, &Signal::Name>;
+/* The following line is illegal under the new rules for non-type
+ template arguments in the standard, so it is commented out. */
+/* template class Bar <Derived, &Signal::Name>; */
template class Bar <Signal, &Signal::Name>;
template class Bar <Derived, &Derived::Name>;
Derived a;
-Bar<Derived, &Signal::Name> dispatcher1;
+/* Bar<Derived, &Signal::Name> dispatcher1; */
Bar<Derived, &Derived::Name> dispatcher2;
main() {
- int i1 = dispatcher1.value(&a);
+ /* int i1 = dispatcher1.value(&a); */
int i2 = dispatcher2.value(&a);
- return i1 != 1 || i2 != 2;
+ return /* i1 != 1 || */ i2 != 2;
}
}
typedef char * char_ptr_t;
+
+template <>
syHandle<char_ptr_t>::syHandle()
{
_repr = 0;
}
+template <>
syHandle<char_ptr_t>::~syHandle()
{
_repr = 0;
// Build don't link:
template <char* c> struct B { B() { } };
-B<0> bnull;
+B<0> bnull; // ERROR - could not convert template argument
--- /dev/null
+extern "C" void abort();
+
+struct S
+{
+ static const int i = 3;
+};
+
+const int S::i = 2; // ERROR - duplicate initialization
--- /dev/null
+template<class Type>
+class A
+{
+public:
+ Type m;
+};
+
+template<class Type>
+void f(A<Type>& a, Type d)
+{
+ A.m=d; // ERROR - invalid use of template
+}
+
+int main()
+{
+ A<int> a;
+ f(a,2);
+}
+
void foo();
};
-template <>
+
void S<int>::foo()
{
}
void foo(T t);
template <>
-void foo(int) {}; // ERROR - redefinition.
+void foo(int) {};
template <>
-void foo<int>(int) {} // ERROR - redefinition.
+void foo<int>(int) {} // ERROR - duplicate specialization.
--- /dev/null
+template <int I>
+void f(int j);
+
+void g()
+{
+ f<7, 12>(3); // ERROR - no matching function.
+}
--- /dev/null
+template <class T>
+void f(int i);
+
+void g()
+{
+ f<7>(3); // ERROR - no matching function.
+}
--- /dev/null
+extern "C" void abort();
+
+template <void* P>
+void f(int j);
+
+template <unsigned int I>
+void f(int j);
+
+
+template <void* P>
+void f(int j)
+{
+ abort();
+}
+
+
+template <unsigned int I>
+void f(int j)
+{
+}
+
+
+int main()
+{
+ f<3>(7);
+}
+
--- /dev/null
+template <int I>
+void f(int i);
+
+void g()
+{
+ int i;
+ f<i>(7); // ERROR - template argument 1 is invalid.
+}
--- /dev/null
+extern "C" void abort(void);
+
+template <int I>
+void f(int i)
+{
+}
+
+template <void*>
+void f(int i)
+{
+ abort();
+}
+
+int main()
+{
+ f<0>(3);
+}
--- /dev/null
+extern "C" void abort(void);
+
+void F(int)
+{
+}
+
+
+void F(double)
+{
+ abort();
+}
+
+template <void (*F)(int)>
+void g()
+{
+ (*F)(3);
+}
+
+
+int main()
+{
+ g<&F>();
+}
--- /dev/null
+// Build don't link:
+
+template <class T>
+void f(T t);
+
+template void f<int>(int);
+template void f<>(long);
+
+template <class T>
+struct S
+{
+ void bar(int) {}
+
+ template <class U>
+ void baz(U u) {}
+};
+
+
+template S<char>;
+template void S<int>::bar(int);
+template void S<double>::baz<short>(short);
+template void S<long>::baz<>(char);
--- /dev/null
+template <class STRUCT, class MEMBER> inline STRUCT *
+setback(MEMBER *bp, MEMBER STRUCT::*offset)
+{
+ if(!bp) return 0;
+ union { int i; MEMBER STRUCT::*of; } u;
+ u.of = offset;
+ return (STRUCT *) ((int) bp - u.i);
+}
+
+
+struct S
+{
+ int i;
+};
+
+int main()
+{
+ S s;
+
+ S* sp = setback (&s.i, &S::i);
+}
--- /dev/null
+extern "C" void abort();
+
+template <class T>
+void f(T)
+{
+ struct S {
+ int i;
+ } s;
+
+ s.i = 3;
+
+ if (s.i != 3)
+ abort();
+}
+
+
+int main()
+{
+ f(7);
+}
--- /dev/null
+extern "C" void abort();
+
+template <class T>
+void f(T)
+{
+ struct S {
+ int i;
+ };
+
+ S s;
+
+ s.i = 3;
+
+ if (s.i != 3)
+ abort();
+}
+
+
+int main()
+{
+ f(7);
+}
--- /dev/null
+extern "C" void abort();
+
+template <class T>
+struct S {};
+
+S<int> si;
+
+template <class T>
+int f(T t)
+{
+ struct S {
+ int g(int i) { return i + 2; }
+ };
+
+ S s;
+
+ return s.g(t) + s.g(t);
+}
+
+
+int main()
+{
+ if (f(3) != 10)
+ abort();
+}
--- /dev/null
+template <class INT>
+class b
+{
+private:
+ char a(int x)
+ {
+ union {
+ int i;
+ char c;
+ } val;
+ val.i = x;
+ return val.c;
+ };
+
+public:
+ b() {
+ }
+};
+
+int main() {
+ b<int> n;
+ return 0;
+}
+
-// Build don't run:
-// GROUPS passed templates membertemplates
-extern "C" int printf(const char*, ...);
+extern "C" void abort();
+
+int k;
template <class X>
struct S
{
template <class U>
void f(U u)
- { printf ("In S::f(U)\n"); g(u); }
+ { ++k; g(u); }
template <class U>
void g(U u)
- { printf ("In S::g(U)\n"); }
+ { ++k; }
int c[16];
};
S<char*> s;
s.f(3);
s.f("adf");
+
+ if (k != 4)
+ abort();
}
--- /dev/null
+// Build don't link:
+
+template<unsigned int n> struct PartialDotProduct {
+ template<class T>
+ static T Expand(T* a, T* b) { return T(); }
+};
+
+const int N = 10;
+
+template<class In1, class In2>
+void
+dot(In1 f1, In2 f2)
+{
+ PartialDotProduct<N>::Expand(f1, f2);
+
+}
+
+int main()
+{
+ double a[N], b[N];
+
+ dot(&a[0], &b[0]);
+}
--- /dev/null
+// Build don't link:
+
+template <class T>
+struct S
+{
+ template <class U>
+ void f(U u) { this->template f<>(3); }
+};
+
+
+void g()
+{
+ S<char> s;
+ s.f(1.0);
+}
--- /dev/null
+template <class T>
+struct A
+{
+ template <class T2>
+ operator A<T2>() const { return A<T2>(); }
+};
+
+main()
+{
+ A<int> a1;
+ A<long> a2;
+ A<double> a3;
+ A<char> a4;
+
+ a2 = a1.operator A<long>();
+ a3 = (A<double>) a1;
+ a4 = a1;
+}
+
--- /dev/null
+// Build don't link:
+
+const double M_PI=3.14159265358979323846;
+
+template<int N,int I,int J,int K>
+inline double SineSeries()
+{
+ const double x=I*2*M_PI/N;
+ const bool go=K+1!=J;
+ return 1.0-x*x/(2*K+2)/(2*K+3)*SineSeries<N*go,I*go,J*go,(K+1)*go>();
+}
+
+template<>
+inline double SineSeries<0,0,0,0>()
+{
+ return 1.0;
+}
+
+template<int N,int I>
+inline double Sine()
+{
+ const double x=(I*2*M_PI/N);
+ return x * SineSeries<N,I,10,0>();
+}
+
+int main()
+{
+ double f=Sine<32,5>();
+ return 0;
+}
+
--- /dev/null
+template< int i > struct T :
+public T< i-1 >
+{
+};
+
+template<> struct T< 0 >
+{
+};
+
+template< class F > struct T1 :
+public T< F::dim >
+{
+};
+
+template< int i > struct S
+{
+ enum { dim = i } ;
+};
+
+int main()
+{
+ T1< S< 4 > > t ;
+ return( 0 ) ;
+}
+
--- /dev/null
+extern "C" void abort();
+
+template <class T>
+struct S
+{
+ template <int i>
+ int f(int j) { abort(); return 0; }
+
+ template <>
+ int f<7>(int j) { return j + 7; }
+
+ template <>
+ int f<8>(int j) { return j + 8; }
+};
+
+
+int main()
+{
+ S<double> s;
+
+ if (s.template f<7>(3) != 10)
+ abort();
+
+ if (s.template f<8>(3) != 11)
+ abort();
+}
--- /dev/null
+extern "C" void abort();
+
+template <class T>
+struct S
+{
+ template <class U>
+ int f(U u);
+};
+
+template <class T>
+template <>
+int S<T>::f(int i) { return 1; }
+
+int main()
+{
+ S<char> sc;
+
+ if (sc.f(3) != 1)
+ abort();
+}
--- /dev/null
+// Build don't link:
+
+class X
+{
+ public:
+ virtual void f() const = 0;
+};
+
+template <class T>
+class Y: public X
+{
+ public:
+ virtual void f() const;
+};
+
+template <class T>
+void Y<T>::f() const
+{
+}
+
+template <>
+void Y<bool>::f() const;
+
+template <>
+void Y<bool>::f() const
+{
+}
--- /dev/null
+extern "C" void abort();
+
+class X
+{
+ public:
+ virtual int f() const = 0;
+};
+
+template <class T>
+class Y: public X
+{
+ public:
+ virtual int f() const;
+};
+
+template <class T>
+int Y<T>::f() const
+{
+ abort();
+ return 0;
+}
+
+template <>
+int Y<bool>::f() const;
+
+template <>
+int Y<bool>::f() const
+{
+ return 0;
+}
+
+int main()
+{
+ Y<bool> yb;
+
+ yb.f();
+}
--- /dev/null
+// Build don't link:
+
+template <class T>
+struct S {};
+
+template <>
+struct S<int>
+{
+ void f();
+ void g();
+};
+
+void S<int>::f() {}
+
+template <>
+void S<int>::g() {} // ERROR - does not match any template declaration
--- /dev/null
+// Build don't link:
+
+template <class T>
+void f(T t1, T t2);
+
+template <>
+void f(int i, int j);
+
+template <class T>
+void g(T t1, T t2) {}
+
+template void g(int i, int j);
+
+void h()
+{
+ f(3, 'c'); // ERROR - no matching function
+ g(3, 'c'); // ERROR - no matching function
+}
+
+
--- /dev/null
+// Build don't link:
+
+struct S1
+{
+ template <class T>
+ void f(T t1, T t2);
+
+ template <>
+ void f(int i1, int i2);
+};
+
+template <class U>
+struct S2
+{
+ template <class T>
+ void f(T t1, T t2);
+
+ template <>
+ void f(int i1, int i2);
+};
+
+void h()
+{
+ S1 s1;
+ s1.f(3, 'c'); // ERROR - no matching function
+
+ S2<char> s2;
+ s2.f(3, 'c'); // ERROR - no matching function
+}
--- /dev/null
+extern "C" void abort();
+
+template <class T>
+void f(T t1, T t2);
+
+template <>
+void f(int i, int j)
+{
+ abort();
+}
+
+void f(short s, char c)
+{
+}
+
+int main()
+{
+ f(3, 'c');
+}
--- /dev/null
+extern "C" void abort();
+
+template <void* P>
+void f(int j);
+
+template <int I>
+void f(int j);
+
+
+template <void* P>
+void f(int j)
+{
+ abort();
+}
+
+
+template <int I>
+void f(int j)
+{
+}
+
+
+int main()
+{
+ f<3>(7);
+}
+
--- /dev/null
+extern "C" void abort();
+
+template <class T>
+inline int f(T t)
+{
+ return 0;
+}
+
+int main()
+{
+ if (!f(3))
+ abort();
+}
+
+template <>
+int f(int i)
+{ // ERROR - specialization of f<int>(int) after instantiation
+ return 1;
+}
+
+
--- /dev/null
+// Build don't link:
+
+template <class InputIterator, class BinaryOperation>
+void accumulate(InputIterator first,
+ BinaryOperation binary_op) {
+}
+
+
+template<class R> int p( int val, R& r )
+{
+ return val + r;
+}
+
+template<class R> void f(R)
+{
+ accumulate(0, static_cast<int (*)(int, R&)>(p) );
+}
+
+main()
+{
+ f(0);
+}
// Build don't link:
-// GROUPS passed templates
+
template <class T>
-struct bar {
- typedef typename T::baz baz;
+struct A
+{
+ typedef T A_Type;
};
-template <class T>
-void foo(T)
+
+template <class U>
+struct B : public A<U>
{
- bar<T>::baz(); // ERROR - T is int.
-}
+ A_Type Func();
+};
+
-void foobar()
+template <class U>
+A<U>::A_Type B<U>::Func()
{
- foo(3);
}