From c86be274be628ca204a24f04cf81e9cc8749330f Mon Sep 17 00:00:00 2001 From: xscript Date: Fri, 29 Apr 2011 02:32:56 +0200 Subject: [PATCH] Move tests in cedet/semantic --- .../cedet/cedet/semantic/tests/templates.cpp | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 test/manual/cedet/cedet/semantic/tests/templates.cpp diff --git a/test/manual/cedet/cedet/semantic/tests/templates.cpp b/test/manual/cedet/cedet/semantic/tests/templates.cpp new file mode 100644 index 00000000000..881c5b2ad02 --- /dev/null +++ b/test/manual/cedet/cedet/semantic/tests/templates.cpp @@ -0,0 +1,128 @@ +// C++ examples and requests from Klaus Berndl + +// template in a unnamed namespace +namespace +{ + template + 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 Vector +{ +private: + static T* v; + int sz; + +public: + T& elem(int i) {return v[i];} + virtual ~Vector (); + +protected: + Vector (); +}; + +template <> class Vector +{ +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 ActionList; + +// declaration of some template-types +map** map_var; + +map_with_size map_size_var; +typedef map_with_size SizedMap; + +map_with_10_size* pMap_size10_var; +typedef map_with_10_size Size10Map; + +// a function which such a template-argument +void* test_function(map* pMap); + + +template class Vector : private Vector +{ +public: + typedef Vector Base; + + Vector () : Base() {} + + T*& elem(int i) {return static_cast(Base::elem(i));} + //... +}; + +// outside method implementation of a template-class +template T& Vector::elem(int i) +{ + return C; +} + +// same but qualified with a namespace Testnamespace +template T& Testnamespace::Vector::elem(int i) +{ + return C; +} + +// function templates with keyword typename +template +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 +static +typename T::_ptr_type +getService(const std::string& pServiceName, const int pRetries=20) +{ + return T::_narrow(getServiceObject(pServiceName, pRetries)); +} + +// function template declaration +template void sort(vector&); +// complex function template definition +template volatile ***&i> +map +sort(const vector& v) +{ + return; +} + +// variable declarations of template-types +foo *bar1; +foo *bar2; +foo bar3; +foo<0> bar0; + +class SomeName; +class OtherName; -- 2.39.2