Prev: Throwing error is potentially buggy
Next: how to non-default construct with multiple virtual inheritance??
From: ShaunJ on 1 Jun 2010 23:06 Hi, I'd like to be able to use a sorted vector as a set (or map) with a parametrized (template) function that expects a set (or map) interface. The function only calls find, not insert or erase. I thought that this could be accomplished using a container adapter. Does this seem like a good approach? Cheers, Shaun -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Goran on 2 Jun 2010 05:06 On Jun 2, 4:06 pm, ShaunJ <sjack...(a)gmail.com> wrote: > Hi, > > I'd like to be able to use a sorted vector as a set (or map) with a > parametrized (template) function that expects a set (or map) > interface. The function only calls find, not insert or erase. I > thought that this could be accomplished using a container adapter. > Does this seem like a good approach? I dunno, but is there something wrong with lower_bound algorithm? That's what you can use if random access sequence is sorted anyhow. Goran. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Maxim Yegorushkin on 2 Jun 2010 05:06 On 02/06/10 15:06, ShaunJ wrote: > I'd like to be able to use a sorted vector as a set (or map) with a > parametrized (template) function that expects a set (or map) > interface. The function only calls find, not insert or erase. I > thought that this could be accomplished using a container adapter. > Does this seem like a good approach? It does indeed. In fact, people sometimes create their own versions of map<> and set<> that use vector<> underneath. Performance of such versions is worse for inserts but better for lookups/finds. -- Max [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Bertrand Motuelle on 7 Jun 2010 18:54
{ Please avoid top-posting. -mod } Just to second that, Matt Austern wrote a nice article about this some time (woa, already 10 years!) ago: http://lafstern.org/matt/col1.pdf Bertrand. On Jun 2, 10:06 pm, Maxim Yegorushkin <maxim.yegorush...(a)gmail.com> wrote: > On 02/06/10 15:06, ShaunJ wrote: > > > I'd like to be able to use a sorted vector as a set (or map) with a > > parametrized (template) function that expects a set (or map) > > interface. The function only calls find, not insert or erase. I > > thought that this could be accomplished using a container adapter. > > Does this seem like a good approach? > > It does indeed. > > In fact, people sometimes create their own versions of map<> and set<> > that use vector<> underneath. Performance of such versions is worse for > inserts but better for lookups/finds. > > -- > Max -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |