Created
August 27, 2015 11:43
-
-
Save yksym/983a526ba34c027dc830 to your computer and use it in GitHub Desktop.
bound qualification?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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