We can overload on constness of memberfunction
template <typename T, ... >
class vector
{
public:
T& operator[](size_t i);
const T& operator[](size_t i) const;
};
STL is const-safe:
template <typename It, typename T>
It find( It begin, It end, const T& t)
{
while (begin != end)
{
if ( *begin == t )
{
return begin;
}
++begin;
}
return end;
}
const char t[] = { 1, 2, 3, 4, 5 };
const char *p = std::find( t, t+sizeof(t), 3)
if ( p )
{
}
const std::vector<int> v(t, t+sizeof(t));
std::vector<int>::const_iterator i = std::find( v.begin(), v.end(), 3);
if ( v.end() != i )
{
}
std::vector<int> v(4,5);
auto i = std::find( v.begin(), v.end(), 3);
const std::vector<int> v(4,5);
auto j = std::find( v.begin(), v.end(), 3);
std::vector<int> v(4,5);
auto k = std::find( v.cbegin(), v.cend(), 3);
std::vector<int> v(3,5);
std::vector<int>::const_iterator ci = std::find( v.begin(), v.end(), 3);
v.insert(ci, 2);
std::vector<int> v(3,5);
auto ci = std::find( v.cbegin(), v.cend(), 3);
v.insert(ci, 2);
std::vector<int> v(4,5);
auto i = std::find( begin(v), end(v), 3);
std::vector<int> v(4,5);
auto i = std::find( cbegin(v), cend(v), 3);
std::vector<int> v(4,5);
auto i = std::find( cbegin(v), cend(v), 3);