Skip to content

Instantly share code, notes, and snippets.

@redpist
Created September 17, 2012 22:49
Show Gist options
  • Save redpist/3740265 to your computer and use it in GitHub Desktop.
Save redpist/3740265 to your computer and use it in GitHub Desktop.
C++ML example 2
#ifndef _2_H_
#define _2_H_
#include <iostream>
struct Abidbul { };
template <int i>
struct NumType { };
// Test 0
template <typename T0, typename T1>
struct Americaine
{
void MondeDeMerde()
{
std::cout << "Americaine<int, double>" << std::endl;
}
};
// Test 1
template <typename T0>
struct Americaine<T0, Abidbul>
{
void MondeDeMerde()
{
std::cout << "Americaine<int, Abidbul>" << std::endl;
}
};
// Test 2
template <int i>
struct Americaine<NumType<i>, Abidbul>
{
void MondeDeMerde()
{
std::cout << "Americaine<NumType<" << i << ">, Abidbul>" << std::endl;
}
};
// Test 3
template <template <template <class, class> class> class Lol>
struct Americaine<Lol<Americaine>, Abidbul>
{
void MondeDeMerde()
{
std::cout << "Americaine<OLol<Americaine>, Abidbul>" << std::endl;
}
};
// Test 4
template <int i>
using Californienne = Americaine<NumType<i>, Abidbul>;
#endif /* _2_H_ */
#include "2.hh"
template <template <class, class> class Temp>
struct OLol { };
int main(int argc, char *argv[])
{
// Test 0
{
Americaine<int, double> o;
o.MondeDeMerde();
}
// Test 1
{
Americaine<int, Abidbul> o;
o.MondeDeMerde();
}
// Test 2
{
Americaine<NumType<42>, Abidbul> o;
o.MondeDeMerde();
}
// Test 3
{
Americaine<OLol<Americaine>, Abidbul> o;
o.MondeDeMerde();
}
// Test 4
{
Californienne<34> o;
o.MondeDeMerde();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment