#include <iostream>Compiled with conceptgcc-boostcon (g++, not conceptg++) on Linux, this produces
template<typename T>
T foo() {
return 0;
}
template<>
int foo<int>() {
return 1;
}
int foo() {
return 2;
}
int main() {
std::cout << "foo<char>(): " << (int)foo<char>() << std::endl; // writes 0
std::cout << "foo<int>(): " << foo<int>() << std::endl; // writes 1
std::cout << "foo(): " << foo() << std::endl; // writes 2
// With out the non-template 'int foo()' above, this last line won't compile
// (error: no matching function for call to `foo()')
return 0;
}
foo<char>(): 0It is conceivable that a concept may require both the template specialization and non-template functions to exist. In this case, the caller needs to make the call explicit - which would require template syntax. Alternatively, a concept_map could potentially handle this, but that doesn't feel right to me - how would it know whether the call should be satisfied by a template or non-template function?
foo<int>(): 1
foo(): 2
On Jun 6, 2007, at 4:36 PM, Walter E Brown wrote:I would like to express a concept, Foo<T>, that requires the existence of a specialization, foo<T>, of a function template. I tried the following with conceptgcc-boostcon under Cygwin, but got an ICE (I submitted a bug report earlier today): #include <concepts> concept Foo< class T > { template<> T foo<T>(); }; Is the above the correct way to express the desired concept? Thanks,A template specialization has to specialize something. In this case, there is no primary template to be specialized. One thing you can do is write this: concept Foo<class T> { T foo(); } You can call it as just "foo()", or (to be more specific), Foo<T>::foo (). - Doug _______________________________________________ ConceptGCC mailing list ConceptGCC@generic-programming.org http://www.osl.iu.edu/mailman/listinfo.cgi/conceptgcc