Re: set begin() retrieved the minimum element?
"Andre Kostur" <nntpspam@kostu r.net> wrote in message
news:Xns967F45F 077886nntpspamk osturnet@207.35 .177.134...[color=blue]
> "Chris Theis" <christian.thei s@nospam.cern.c h> wrote in
> news:d9gvk3$pjb $1@sunnews.cern .ch:
>[color=green]
> >
> > "Rolf Magnus" <ramagnus@t-online.de> wrote in message
> > news:d9gs9q$vp4 $02$1@news.t-online.com...[color=darkred]
> >> pmatos wrote:
> >>
> >>> Hi,
> >>>
> >>> If I have set<unsigned int> s; will *(s.begin()) give me the minimum
> >>> element of the set?
> >>
> >> Yes, though I'd write s.front() instead.
> >>[/color]
> >
> > AFAIK front is only supplied by vectors, deques and lists. However,
> > assuming that we have such a container, why would you write front()
> > instead of begin()? This is just out of curiosity because I tend to
> > use begin() and I guess that you have a good reason for the
> > suggestion.[/color]
>
> front() returns a reference to the first element in the container, begin
> () returns an iterator to the first element in the container.
>
> So effectively:
>
> T & container::fron t()
> {
> return *begin();
> }
>[/color]
Looks like I'm already so used to iterators that my head is so clouded that
I didn't think of this ;-)
Cheers
Chris
"Andre Kostur" <nntpspam@kostu r.net> wrote in message
news:Xns967F45F 077886nntpspamk osturnet@207.35 .177.134...[color=blue]
> "Chris Theis" <christian.thei s@nospam.cern.c h> wrote in
> news:d9gvk3$pjb $1@sunnews.cern .ch:
>[color=green]
> >
> > "Rolf Magnus" <ramagnus@t-online.de> wrote in message
> > news:d9gs9q$vp4 $02$1@news.t-online.com...[color=darkred]
> >> pmatos wrote:
> >>
> >>> Hi,
> >>>
> >>> If I have set<unsigned int> s; will *(s.begin()) give me the minimum
> >>> element of the set?
> >>
> >> Yes, though I'd write s.front() instead.
> >>[/color]
> >
> > AFAIK front is only supplied by vectors, deques and lists. However,
> > assuming that we have such a container, why would you write front()
> > instead of begin()? This is just out of curiosity because I tend to
> > use begin() and I guess that you have a good reason for the
> > suggestion.[/color]
>
> front() returns a reference to the first element in the container, begin
> () returns an iterator to the first element in the container.
>
> So effectively:
>
> T & container::fron t()
> {
> return *begin();
> }
>[/color]
Looks like I'm already so used to iterators that my head is so clouded that
I didn't think of this ;-)
Cheers
Chris
Comment