Richard Smith | 5de91b5 | 2013-06-25 01:25:15 +0000 | [diff] [blame] | 1 | @import cxx_templates_common; |
| 2 | |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 3 | template<typename T> T f() { return T(); } |
| 4 | template<typename T> T f(T); |
| 5 | namespace N { |
| 6 | template<typename T> T f() { return T(); } |
| 7 | template<typename T> T f(T); |
| 8 | } |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 9 | |
| 10 | template<int N> int template_param_kinds_1(); |
| 11 | template<template<typename T, int, int> class> int template_param_kinds_2(); |
| 12 | template<template<typename T, typename U, T> class> int template_param_kinds_3(); |
Richard Smith | 5de91b5 | 2013-06-25 01:25:15 +0000 | [diff] [blame] | 13 | |
| 14 | template<typename T> struct SomeTemplate<T*>; |
| 15 | template<typename T> struct SomeTemplate<T*> {}; |
| 16 | typedef SomeTemplate<int*> SomeTemplateIntPtr; |
Richard Smith | 0e5d7b8 | 2013-07-25 23:08:39 +0000 | [diff] [blame] | 17 | |
| 18 | template<typename T> void PerformDelayedLookup(T &t) { |
| 19 | t.f(); |
| 20 | typename T::Inner inner; |
| 21 | FoundByADL(t); |
| 22 | } |
Richard Smith | b71782b | 2013-08-01 04:12:04 +0000 | [diff] [blame] | 23 | |
| 24 | template<typename T> void PerformDelayedLookupInDefaultArgument(T &t, int a = (FoundByADL(T()), 0)) {} |
Richard Smith | 7ecc31b | 2013-08-02 01:09:12 +0000 | [diff] [blame] | 25 | |
| 26 | template<typename T> struct RedeclaredAsFriend {}; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 27 | |
| 28 | void use_some_template_a() { |
| 29 | SomeTemplate<char[2]> a; |
| 30 | SomeTemplate<char[1]> b, c; |
| 31 | b = c; |
| 32 | } |
Richard Smith | d46d6de | 2013-10-13 23:50:45 +0000 | [diff] [blame] | 33 | |
| 34 | template<int> struct MergeTemplates; |
| 35 | MergeTemplates<0> *merge_templates_a; |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 36 | |
| 37 | auto enum_a_from_a = CommonTemplate<int>::a; |
| 38 | const auto enum_c_from_a = CommonTemplate<int>::c; |
| 39 | |
| 40 | template<int> struct UseInt; |
| 41 | template<typename T> void UseRedeclaredEnum(UseInt<T() + CommonTemplate<char>::a>); |
| 42 | constexpr void (*UseRedeclaredEnumA)(UseInt<1>) = UseRedeclaredEnum<int>; |
Richard Smith | 0c1065f | 2013-10-15 23:19:58 +0000 | [diff] [blame] | 43 | |
| 44 | template<typename> struct MergeSpecializations; |
| 45 | template<typename T> struct MergeSpecializations<T*> { |
| 46 | typedef int partially_specialized_in_a; |
| 47 | }; |
| 48 | template<> struct MergeSpecializations<char> { |
| 49 | typedef int explicitly_specialized_in_a; |
| 50 | }; |
Richard Smith | c264d35 | 2014-03-23 02:30:01 +0000 | [diff] [blame] | 51 | |
| 52 | void InstantiateWithFriend(Std::WithFriend<int> wfi) {} |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 53 | |
| 54 | template<typename T> struct WithPartialSpecialization<T*> { |
| 55 | typedef int type; |
| 56 | T &f() { static T t; return t; } |
| 57 | }; |
| 58 | typedef WithPartialSpecializationUse::type WithPartialSpecializationInstantiate; |
Richard Smith | 871cd4c | 2014-05-23 21:00:28 +0000 | [diff] [blame] | 59 | |
| 60 | template<> struct WithExplicitSpecialization<int> { |
| 61 | int n; |
| 62 | template<typename T> T &inner_template() { |
| 63 | return n; |
| 64 | } |
| 65 | }; |
Richard Smith | dc5523d | 2014-07-11 00:20:06 +0000 | [diff] [blame] | 66 | |
| 67 | template<typename T> template<typename U> |
| 68 | constexpr int Outer<T>::Inner<U>::f() { return 1; } |
| 69 | static_assert(Outer<int>::Inner<int>::f() == 1, ""); |