List:MySQL++« Previous MessageNext Message »
From:Chris Frey Date:September 18 2005 7:16am
Subject:Re: [patch] row::operator[] - template version
View as plain text  
(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

Thread
[patch] row::operator[] - template versionChris Frey18 Sep
  • Re: [patch] row::operator[] - template versionWarren Young19 Sep
    • Re: [patch] row::operator[] - template versionWarren Young19 Sep
      • Re: [patch] row::operator[] - template versionChris Frey19 Sep
        • Re: [patch] row::operator[] - template versionWarren Young19 Sep
          • Re: [patch] row::operator[] - template versionChris Frey19 Sep
Re: [patch] row::operator[] - template versionChris Frey18 Sep
  • Re: [patch] row::operator[] - template versionUnknown Sender18 Sep
    • Re: [patch] row::operator[] - template versionChris Frey18 Sep
      • Re: [patch] row::operator[] - template versionUnknown Sender18 Sep
        • Re: [patch] row::operator[] - template versionWarren Young19 Sep
          • Re: [patch] row::operator[] - template versionUnknown Sender19 Sep
            • Re: [patch] row::operator[] - template versionWarren Young19 Sep
      • Re: [OBORONA-SPAM] Re: [patch] row::operator[] - template versionUnknown Sender19 Sep
        • Re: [OBORONA-SPAM] Re: [patch] row::operator[] - template versionChris Frey19 Sep
          • Re: [patch] row::operator[] - template versionUnknown Sender19 Sep
            • Re: [patch] row::operator[] - template versionChris Frey19 Sep
            • Re: [patch] row::operator[] - template versionWarren Young19 Sep
        • Re: [patch] row::operator[] - template versionWarren Young19 Sep
    • Re: [patch] row::operator[] - template versionChris Frey18 Sep
  • Re: [patch] row::operator[] - template versionWarren Young19 Sep