Prev: Can const& functors be passed to functions efficiently (i.e. inlined, etc)?
Next: Is there a preferred way of wrapping an object?
From: Roy Smith on 15 Jun 2010 22:55 In article <btudnbk1N85t74rRnZ2dnUVZ7vudnZ2d(a)giganews.com>, "Leigh Johnston" <leigh(a)i42.co.uk> wrote: > The only valid operations on an invalid iterator are initialization and > assignment Well, to pick a nit, there's a third. You can destruct it :-) It's actually not that much of a nit. Letting an object get into a state where it cannot be safely destructed is rather rude, and something to be avoided in polite company. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Stuart Golodetz on 17 Jun 2010 03:52 Daniel Kr�gler wrote: > On 15 Jun., 11:16, Peng Yu <pengyu...(a)gmail.com> wrote: >> Suppose I have an std::vector<int>::iterator that I get from somewhere >> else. I'm not sure if it is properly initialized. Is there a way to >> test in runtime? > > There does not exist a general test function for this. This > is so, because pointers are iterators and there also exists > no general/portable mechanism to verify whether a pointer > value is valid: > > int main() { > int* p, q; // not initialized Not that it in any way obscures the point, but ITYM: int *p, *q; Regards, Stu > if (p == q) ; // Undefined behaviour > } > > HTH & Greetings from Bremen, > > Daniel Kr�gler -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Helge Kruse on 18 Jun 2010 00:30
"Daniel Kr�gler" <daniel.kruegler(a)googlemail.com> wrote in message news:386bf185-b973-405f-bc33-bbc8d0696a25(a)x27g2000yqb.googlegroups.com... > int main() { > int* p, q; // not initialized > if (p == q) ; // Undefined behaviour > } No. It's "defined behaviour". The compiler will not allow to compare an integer and a pointer to integer. ;-) Helge -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |