[Development] The future of QtAlgorithms

João Abecasis joao.abecasis at nokia.com
Fri Jan 27 16:56:07 CET 2012


Robin Burchell wrote:
> 2012/1/27 João Abecasis <joao.abecasis at nokia.com>:
> > - Provide standard-compliant implementations of the algorithms in
> > QtAlgorithms (no 'q' prefixes, no camel casing -- sorry!) and
> > selectively import those into a known namespace when QT_NO_STL is
> > defined:
> > 
> >    namespace QtPrivateStd {
> >    #ifdef QT_NO_STL
> >        using namespace std;
> >    #else
> >        using namespace QtPrivateStlImpl::std;
> >    #endif
> >    }
> 
> I think you mean #ifndef there, but anyway.

Heh. That's what you get for posting untested code ;-)

> So code using this would be using QtPrivateStd::sort(a.begin(),
> a.end()); sort of stuff? Sounds good to me. Why is this being kept
> private, though? It means that application developers can't make the
> same QT_NO_STL choice, doesn't it?

I think some finer details of the proposal still need to be hammered
down and explored. Ideally, code should be written to use std::sort
directly and we somehow bring namespace QtPrivateStd into scope when
QT_NO_STL is defined.

So let me try again, but with tested code, this time :-)

    #include <stdio.h>

    #ifndef QT_NO_STL
    #include <algorithm>
    #endif

    namespace QtPrivateStd { namespace std {
        template <class T>
        void swap(T &a, T &b)
        {
            puts("Using QtPrivateStd");

            T tmp = a;
            a = b;
            b = tmp;
        }

        template <class Iter>
        void sort(Iter begin, Iter end)
        {
            puts("Using QtPrivateStd; not actually implemented");
        }
    }} // namespace QtPrivateStd::std

    #ifdef QT_NO_STL
    using namespace QtPrivateStd;
    #endif

    void test1()
    {
        int a = 5, b = 3;

        using std::swap;
        swap(a, b);


        printf("a = %i, b = %i\n", a, b);
    }

    void test2()
    {
        int array[5] = { 5, 4, 3, 2, 1 };
        std::sort(array, array + 5);

        printf("array = { %i, %i, %i, %i, %i }\n",
                array[0], array[1], array[2], array[3], array[4]);
    }

    int main()
    {
        test1();
        test2();
    }

> > Thoughts? Comments?
> 
> Having already started trying to butcher QtAlgorithms, I may be
> biased, but well.. can I propose another new gerrit review level: +3
> "give this guy a payrise"? :-)

;-)


João





More information about the Development mailing list