[Kde-pim] Abiguity in kleopatra/mainwindow.cpp

Marc Mutz marc at kdab.net
Wed Apr 23 07:35:27 BST 2008


On Tuesday April 22 2008 23:40, Adriaan de Groot wrote:
> I'm looking at this bit of code in kleopatra/mainwindow.cpp:
>
>     template <typename T>
>     void createAndStart( QAbstractItemView * view ) {
>         ( new T( view, &this->controller ) )->start();
>     }
>     template <typename T, typename A>
>     void createAndStart( const A & a ) {
>         ( new T( a, this->currentView(), &this->controller ) )->start();
>     }
>
> which my compiler (SS12) says is ambiguous -- you can substitute
> QAbstractItemView * for A -- so kleopatra doesn't compile.

In my book it's not ambiguous, since non-template parameters are better 
matches than template ones, but I'm not sure this is indeed per-parameter, or 
only for whole functions. E.g.
  template <typename T> int foo( T t );
and
 int foo( int i );
are definitely not ambiguous in the following call:
 int j, i = foo( j );

The question is: how about if we add a template parameter to both?
Like here:
  template <typename S, typename T> S foo( T t );
  template <typename S> S foo( int i );
in
  int j, i = foo<int>( j );

And I must say I don't really know. My feeling says (obviously, I've written 
the offending code) that it's not. GCC agrees. The reason I feel that it 
should be allowed is that you can't partially specialize function templates, 
you're supposed to revert to overloading instead, which is what I'm doing 
there. If it wasn't SS_12_ you'd be talking about, I'd dismiss it as a 
compiler bug, but then I have only the greatest of respects for the work Sun 
is putting into the compiler to make it more standards compliant (their 
decision to stick with a crappy STL so as to make most C++ code unusable with 
the default compiler settings nonwithstanding) so I'm wary of that.

If typename A -> QStringList fixes it for you, then I'll just apply that 
change. However, I would still invite you to check that the first example 
(with int foo(int)) works as expected on your compiler. If it doesn't, it's 
_very_ broken, and probably a regression from SS11.

Thanks,
Marc

> I can't figure 
> out what the right way of writing this down is -- partial template function
> specialization is not my forte and mostly I end up with the compiler
> complaining that an explicit parameter list is not allowed in a primary
> template.
>
> The three uses of the second template all take arguments of type
> QStringList, so in my local copy I've just written it out and removed the
> typename A template parameter.
>
> What would be the best solution in this case?
>
> [ade] (please CC: i might be subscribed, but delivery is certainly set
> to 'off')
> _______________________________________________
> KDE PIM mailing list kde-pim at kde.org
> https://mail.kde.org/mailman/listinfo/kde-pim
> KDE PIM home page at http://pim.kde.org/

-- 
Marc Mutz - marc at kdab.com, mutz at kde.org - Klarälvdalens Datakonsult AB
Platform-independent software solutions - www.kdab.com info at kdab.com
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/



More information about the kde-pim mailing list