There always seem to be a lot of questions regarding the context of creation.
The example given by MSalters is problematic:
template <typename T> void foo() { T() + T(); }
consider the following code:
This compiles and runs on all compilers, but if you put the definition of class A in the namespace:
Clang will not be able to compile, but compiling VC ++ and gcc. What for? Which compiler complies with the specification?
Honestly, I do not know. Some compilers, such as gcc, even contradict themselves in this area. Consider the following code:
Just change from "operator +" to a function named "g", gcc will not compile ??? Why???
If Spec is correct, then why can't GCC find 'g'?
6. The context for creating an expression, which depends on the arguments of the template, is a set of declarations with an external link declared before the creation of the template
specialization in the same translation unit.
When I read Bjarne Stroustrup "C ++ Programming Language, 4th Edition", 26.3.5 Template and Namespaces, it has this example:
namespace N{ class A{}; char f(A); } char f(int); template<typename T> char g(T t) { return f(t);
Here f (t) clearly depends, therefore, we cannot bind f at the definition point. To generate a specialization for g (N :: A), the compiler looks up the N namespace for functions called f () and fins N :: f (N :: A).
F (int) is found because it is in scope at the template definition point. F (double) was not found because it is not in the scope of the point in the template, and the argument-dependent search does not find that the global function accepts only arguments of built-in types.
So this is a mess!