I was trying to understand the behavior of Argument Dependent Lookup in case of range-based for loop. I implement the begin and end for my type as free functions within the same namespace as my type. I keep getting runtime assertion failed error.
Expression: vector iterator not dereferncable
Here is the sample code that I'd written:
namespace my {
struct MyType {
std::vector<int> hiddenData;
MyType(int i) : hiddenData(i) {}
};
auto begin(MyType obj) {
return obj.hiddenData.begin();
}
auto end(MyType obj) {
return obj.hiddenData.end();
}
}
void test() {
my::MyType m(5);
for (auto& e : m)
std:: cout << e << std:: endl;
}
Thanks for taking a look at it!
begin()
andend()
functions likely aren't working as you intend. – Ðаn Feb 8 '17 at 17:56