Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <class T>
- class Something
- {
- public:
- Something(const T &something);
- }
- template<template <class T> class U> // must be "class"
- std::string to_string(const U<char>& u)
- {
- return std::string(u.begin(),u.end());
- }
- template<std::size_t max>
- class Foo{...};
- ...
- Foo<10> f;
- template<int I>
- int getTwice()
- {
- return I * 2 ;
- }
- template<class T>
- std::string getType(const T & t)
- {
- return typeid(t).name() ;
- }
- void doSomething()
- {
- std::cout << "25 : " << getTwice<25>() << std::endl ;
- std::cout << "5 : " << getTwice<5>() << std::endl ;
- std::cout << "type(25) : " << getType(25) << std::endl ;
- std::cout << "type(25.5) : " << getType(25.5) << std::endl ;
- std::cout << "type(abc) : " << getType("abc") << std::endl ;
- }
- 25 : 50
- 5 : 10
- type(25) : i
- type(25.5) : d
- type(abc) : A4_c
- // "I" is the value, and "int" is the type of the value
- template <int I>
- // "T" is a type... And "class" is the "this-is-a-type" keyword
- template <class T>
- template<class T> // T could be any STL container, for example a vector<char>
- void printContainerData(const T & t)
- {
- std::cout << "aVector:" ;
- for(T::const_iterator it = t.begin(), itEnd = t.end(); it != itEnd; ++it)
- {
- std::cout << " " << (*it) ;
- }
- std::cout << std::endl ;
- }
- for(class T::const_iterator it = t.begin(), // etc.
- for(typename T::const_iterator it = t.begin(), // etc.
- template <typename T>
- template <class T>
- template<template <class T> class U> // must be "class"
- std::string to_string(const U<char>& u)
- {
- return std::string(u.begin(),u.end());
- }
- template <class T> class U
- template <typename T> class U
- std::string to_string(const U<char>& u)
- template<typename T>
- class U
- {
- // Etc.
- } ;
- U<char> u ;
- // etc.
- to_string(u)
- template<template <class T> class U>
- std::string to_string(const U<char>& u)
- template<template <typename T> class U>
- std::string to_string(const U<char>& u)
- template<typename U>
- std::string to_string(const U & u)
- {
- return std::string(u.begin(),u.end());
- }
- std::list<char> myList ;
- // etc.
- std::cout << to_string(myList) << std:endl ;
- template<typename T, int N=4, bool Flag>
- class myClass { /*...*/ };
- template<typename T, const int& Reference, myClass * Pointer>
- class someClass { /*...*/ };
- template<typename T, int (T::*MemberFunctionPtr)(int, int)>
- class anotherClass { /*...*/ };
Add Comment
Please, Sign In to add comment