Originally Posted by
anonytmouse
Is concept checking a worthwhile feature? I would have thought that programmers implementing an STL concept (how often is this done anyway?) would be fairly experienced and not require hand holding by the compiler.
concept checking isn't really for the programmers writing the STL, it's for the users.
for example, ever done this?
Code:
#include <vector>
class MyClass
{
public:
MyClass(int x)
:m_x(x)
{}
private:
const int& m_x;
};
int main()
{
std::vector<MyClass> x;
x.push_back(MyClass(2));
}
the problem with this code is that MyClass has no available operator=, but the error output (VC7.1) produced is
Code:
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xutility(1136) : error C2582: 'operator =' function is unavailable in 'MyClass'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\vector(862) : see reference to function template instantiation 'void std::fill<std::vector<_Ty>::_Tptr,_Ty>(_FwdIt,_FwdIt,const _Ty &)' being compiled
with
[
_Ty=MyClass,
_FwdIt=std::vector<MyClass>::_Tptr
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\vector(809) : while compiling class-template member function 'void std::vector<_Ty>::_Insert_n(std::vector<_Ty>::iterator,std::vector<_Ty>::size_type,const _Ty &)'
with
[
_Ty=MyClass
]
f:\tests\dlltest\testDll\testDll.cpp(19) : see reference to class template instantiation 'std::vector<_Ty>' being compiled
with
[
_Ty=MyClass
]
and clicking on it brings you to this function:
Code:
// TEMPLATE FUNCTION fill
template<class _FwdIt,
class _Ty> inline
void fill(_FwdIt _First, _FwdIt _Last, const _Ty& _Val)
{ // copy _Val through [_First, _Last)
for (; _First != _Last; ++_First)
*_First = _Val;
}
the average C++ beginner sees this, screams and thinks "OMG my STL has been hax0red!!"
A concept checked stl would produce something more along the lines of
MyClass does not implement the Assignable concept
and point you at the MyClass definition