#include
//is_integral
template
enum {value=false};
};
template<> struct is_integral
enum {value=true};
};
//Enable if
template
template
typedef T type;
};
//Arbitary ovlerload: only allow integer Foo : Substitute failure is not an error
template
typename enable_if
//Concept check
template
template
{
bool x=t;
ignore_unused_variable_warning(x);
}
template
void constraints(){
require_boolean(a==b);
require_boolean(a!=b);
}
T a,b;
};
template
void (Concept::*x)()=&Concept::constraints; //Force compiler to compile the constraints code
}
template
function_requires(Comparable
};
struct Data{
public:
Data operator*(const Data& data){return Data();}
private:
Data& operator=(const Data &);
};
int main()
{
is_integral
is_integral
Data data;
std::cout<<"A:"<
int x=Foo(12);
//Foo(12.3); //Error no matching function for call to Foo(double)
//NeedCompare(data) ; //no match for ‘operator==’ in
NeedCompare(12);
}
No comments:
Post a Comment