Skip to content

Instantly share code, notes, and snippets.

@yifu
Created September 21, 2012 15:02
Show Gist options
  • Select an option

  • Save yifu/3762010 to your computer and use it in GitHub Desktop.

Select an option

Save yifu/3762010 to your computer and use it in GitHub Desktop.
#include <vector>
#include <iostream>
template <int VAL>
struct another_template_type
{
int dummy;
another_template_type(const int i = 0) : m_i(i) {}
int m_i;
};
template <int VAL>
class my_template_type
{
public:
int size;
char * ptr;
int method1(const int a);
std::vector<another_template_type<VAL> /*int*/> my_own_vect;
};
template <int VAL>
int my_template_type<VAL>::method1(const int a)
{
int result = a * a;
result += VAL;
my_own_vect.push_back(result);
}
template <int VAL>
class template_instantier
{
my_template_type<VAL> test;
template_instantier<VAL-1> test2;
public:
int method();
};
template <int VAL>
int template_instantier<VAL>::method()
{
const int result = test.method1(VAL + 1);
std::cout << "result is [" << result << "]" << std::endl;
test2.method();
}
template <>
class template_instantier<0>
{
my_template_type<0> test;
public:
int method()
{
return 42;
}
};
int main()
{
template_instantier<10000> aa;
aa.method();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment