Skip to content

Instantly share code, notes, and snippets.

@yksym
Created August 27, 2015 11:43
Show Gist options
  • Save yksym/983a526ba34c027dc830 to your computer and use it in GitHub Desktop.
Save yksym/983a526ba34c027dc830 to your computer and use it in GitHub Desktop.
bound qualification?
#include <typeinfo>
//g++ -std=gnu++0x jikken.cxx
//g++ -std=c++11 jikken.cxx
template <bool B> void sassert()
{
int dummy[B ? 1:-1];
dummy[0] = 0;
}
template <int N> struct NatVal {};
class Nat3 {
int val;
public:
template <int N> Nat3(NatVal<N>) {
sassert<N < 3>();
val = N;
}
template <int N> void set(NatVal<N>) {
sassert<N < 3>();
val = N;
}
};
int main()
{
NatVal<0> v0;
NatVal<3> v3;
Nat3 test1(v0); // gccのバージョンが古いと挙動変かも
//Nat3 test2(v3); //compile error
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment