summaryrefslogtreecommitdiff
path: root/test/cedet/tests/templates.cpp
blob: c65365f793282304a965b0b954c23c0222ef70c0 (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// C++ examples and requests from Klaus Berndl

// template in a unnamed namespace
namespace
{
  template<typename Target, typename Source>
  Target lexical_cast(Source arg)
  {
    std::stringstream interpreter;
    Target result;

    if(!(interpreter << arg) || !(interpreter >> result) ||
       !(interpreter >> std::ws).eof())
      throw bad_lexical_cast();
    
    return result;
  }
}


template <class T, FOO> class Vector
{
private:
  static T* v;
  int sz;

public:
  T& elem(int i) {return v[i];}
  virtual ~Vector ();

protected:
  Vector ();
};

template <> class Vector <void*>
{
private:
  void** v;
  int sz;

public:
  Vector ();
  virtual int func1(int i);
  virtual int func2(int i) = 0;
  static virtual int func3(int i) = 0;
  void*& elem(int i) {return v[i];}
  //...
};

// template contains namespace
typedef vector<CzkUtilities::Action*> ActionList;

// declaration of some template-types
map<XXX, Test::YYY>** map_var;

map_with_size<XXX, Test::YYY, size> map_size_var;
typedef map_with_size<XXX, Test::YYY, size> SizedMap;

map_with_10_size<XXX, Test::YYY, 10>* pMap_size10_var;
typedef map_with_10_size<XXX, Test::YYY, 10> Size10Map;

// a function which such a template-argument
void* test_function(map<ClassX, Test::ClassY, 10>* pMap);


template <class T> class Vector <T*> : private Vector <void*>
{
public:
	typedef Vector <void*> Base;

	Vector () : Base() {}

	T*& elem(int i) {return static_cast<T*&>(Base::elem(i));}
	//...
};

// outside method implementation of a template-class
template<class T> T& Vector<T*>::elem(int i)
{
  return C;
}

// same but qualified with a namespace Testnamespace
template<class T> T& Testnamespace::Vector<T*>::elem(int i)
{
  return C;
}

// function templates with keyword typename
template<typename Target, typename Source>
Target lexical_cast(Source arg)
{
  std::stringstream interpreter;
  Target result;

  if(!(interpreter << arg) || !(interpreter >> result) ||
     !(interpreter >> std::ws).eof())
    throw bad_lexical_cast();
    
  return result;
}

template<class T>
static
typename T::_ptr_type
getService(const std::string& pServiceName, const int pRetries=20)
{
  return T::_narrow(getServiceObject(pServiceName, pRetries));
}

// function template declaration
template<class T> void sort(vector<T>&);
// complex function template definition
template<class T, class S, const NamespaceY::ClassX<TestClass, &s> volatile ***&i>
map<ClassY, ClassX, 10>
sort(const vector<T>& v)
{
  return;
}

// variable declarations of template-types
foo<TClass, Testnamespace::XClass, i> *bar1;
foo<TClass, Testnamespace::XClass, **&i> *bar2;
foo<TClass, Testnamespace::XClass, *Namespace::ClassX::i> bar3;
foo<0> bar0;

class SomeName;
class OtherName;

// arch-tag: 55ff74de-74dc-44ad-8252-50dc5f3492c3