Hi all,
Please consider this example:
template
struct vec{};
namespace std
{
template
T* begin(vec& a)
{
return 0;
}
template
T* begin(const vec& a)
{
return 0;
}
template
T* end(vec& a)
{
return 0;
}
template
T* end(const vec& a)
{
return 0;
}
}
using namespace std;
int main()
{
vec vecDef;
for(auto it:vecDef);
return 0;
}
clang compile: clang++ -std=c++11 rangedfor.cpp (the code above)
result:rangedfor.cpp:37:14: error invalide range expression of type ‘vec’; no viable ‘begin’ function available
i already read http://comments.gmane.org/gmane.comp.compilers.clang.devel/31712 but in that, he creates a new begin and her,e i create an overload and this is enabled:
http://en.cppreference.com/w/cpp/iterator/begin see User-defined overloads part
The question is: am i intepret this wrong or this is a bug or what? the g++ , and visual c++ compile this code without a question.
clang version: 26 May 2015 3.6.1
release windows, but in linux the same problem stands
Thanks János
Hi all,
Please consider this example:
template<typename T>
struct vec{};
namespace std
{
template<typename T>
T* begin(vec<T>& a)
{
return 0;
}
template<typename T>
T* begin(const vec<T>& a)
{
return 0;
}
template<typename T>
T* end(vec<T>& a)
{
return 0;
}
template<typename T>
T* end(const vec<T>& a)
{
return 0;
}
}
using namespace std;
int main()
{
vec<char> vecDef;
for(auto it:vecDef);
return 0;
}
clang compile: clang++ -std=c++11 rangedfor.cpp (the code above)
result:rangedfor.cpp:37:14: error invalide range expression of type
'vec<char>'; no viable 'begin' function available
i already read
http://comments.gmane.org/gmane.comp.compilers.clang.devel/31712
<https://urldefense.proofpoint.com/v2/url?u=http-3A__comments.gmane.org_gmane.comp.compilers.clang.devel_31712&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=ImzhkWDMFEMiWBqnwuyC-isY3Kc5XNTD5dRy8mg7X7M&s=un4RlsLD0nXrDD6ZtmK66JmSdLCsq7gnYrPB2kk46WM&e=>
but in that, he creates a new begin and her,e i create an overload and this
is enabled:
http://en.cppreference.com/w/cpp/iterator/begin
<https://urldefense.proofpoint.com/v2/url?u=http-3A__en.cppreference.com_w_cpp_iterator_begin&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=ImzhkWDMFEMiWBqnwuyC-isY3Kc5XNTD5dRy8mg7X7M&s=v3nzN8N0CSO2-EMbtjLy1FyKt25ZrRkBTqK08lWZHY4&e=>
see User-defined overloads part
The question is: am i intepret this wrong or this is a bug or what? the
g++ , and visual c++ compile this code without a question.
That's a bug in those other compilers. You're supposed to put the
non-member begin/end functions in the same namespace as your container.