|
|
Choosing A Webhost: |
Re: [patch] row::operator[] - template version: msg#00070db.mysql.c++
(btw, please feel free to reply to the list... I know the list config doesn't make that easy, but we need to have valuable input like yours archived) :-) On Sat, Sep 17, 2005 at 11:35:37PM -0400, pps wrote: > Chris Frey wrote: > >Here's the template version of the patch, for evaluation. > > > >Applies to CVS. > > /// See operator[](const char*) for more caveats. > >- const ColData operator [](size_type i) const > >+ template <class IndexT> > >+ const ColData operator [](IndexT i) const > > { > > I had a similar problem where properties could be accessed by their > indeces or by their names. My first solution was also like this: one of > the functions is plain method and the other is templated. But I later > found out that there were some problems with it - it just worked on some > compilers (or something like this, not sure what the problem was > exactly, but I had to redo it) I'd be interested in what kind of errors the above patch could cause. I suppose the template/non-template could confuse some compilers. If so, we could get rid of non-template members completely, and make a specialization for the const char * version. That should work. I haven't tried my patch on windows, so I don't know if there are funky errors there. mysql++ can only be compiled on fairly recent compilers (VC7.0 doesn't even do it, so I hear), so maybe this is a non-issue, since all supported compilers may handle it. Could you run a test compile and let us know, on WinXP? > my final solution was two templated methods that use boost::enable_if & > boost::mpl::not_ & boost::is_integral > basicly, it enables int version for integral types and non-int for > non-integral types. (obviously it's better to use enable_if and > disable_if, but this combination has some problems on vc i think) > > > in short it looks something like this: > template<class T> > typename enable_if< is_integral<T>, return_type>::type > operator[](const T& a){ ... } > > template<class T> > typename enable_if< not_<is_integral<T> >, return_type>::type > operator[](const T& a){ ... } > > all the things used here (enable_if etc.) are really simple to implement. That's good, because I don't think we can, or want to, add boost to the build dependencies. I'll have to read up on enable_if. Some of the things that boost manages to do with C++ really surprise me. I just looked at the new parameter library, and wow. :-) > One another solution is to take only c-arays of chars, and not pointers > (row[] is almost always used in this way: either row["c-array"] or const > char a[] = "c-array"; row[a]) > for this case something like this will work: > > template<unsigned int N> > return_type operator[](const char(&a)[N]){ ... } > return_type operator[](unsigned int){ ... } This looks interesting, and similar to libpqxx, except for the templates. I think const char* behaviour is worth keeping though. Thanks for the feedback, - Chris -- MySQL++ Mailing List For list archives: http://lists.mysql.com/plusplus To unsubscribe: http://lists.mysql.com/plusplus?unsub=gcdmc-plusplus@xxxxxxxxxxx
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: [patch] row::operator[](int), Chris Frey |
|---|---|
| Next by Date: | Re: [patch] row::operator[] - template version, pps |
| Previous by Thread: | [patch] row::operator[] - template version, Chris Frey |
| Next by Thread: | Re: [patch] row::operator[] - template version, pps |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
Free MagazinesCisco NewsReceive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business. subscribe Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field. subscribe The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business. subscribe Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company. subscribe Total Telecom Total Telecom is "The Economist of the communications industry". subscribe |