Hello,
I have some questions about QString etc.
 
1. What should I just, QStringLiteral or QLatin1String ? Old discussion (around 2011-2012) said QStringLiteral, but in gerrit a lot of changes from StrinLiteral to Latin1String orccured lately.
 
2. Will there be a char16_t constructor for QString and char16_t overloads for +, += etc? If not why not? 
 
3. Will the be support for fast concat with QStringBuilder and char16_t?
 
I made my own support for this:
 
#ifdef Q_COMPILER_UNICODE_STRINGS
template <int N> struct QConcatenable<char16_t[N]> : private QAbstractConcatenable
{
    typedef char16_t type[N];
    typedef QString ConvertTo;
    enum
    {
        ExactSize = false
    };
    static int size(const char16_t[N]) { return N - 1; }
    static inline void appendTo(const char16_t a[N], QChar*& out)
    {
        static_assert(sizeof(char16_t) == sizeof(QChar), "char16_t size is different from qchar");
        const int n = N - 1;
        memcpy(out, reinterpret_cast<const char*>(a), sizeof(QChar) * n);
        out += n;
    }
};
template <int N> struct QConcatenable<const char16_t[N]> : private QAbstractConcatenable
{
    typedef const char16_t type[N];
    typedef QString ConvertTo;
    enum
    {
        ExactSize = false
    };
    static int size(const char16_t[N]) { return N - 1; }
    static inline void appendTo(const char16_t a[N], QChar*& out)
    {
        static_assert(sizeof(char16_t) == sizeof(QChar), "char16_t size is different from qchar");
        const int n = N - 1;
        memcpy(out, reinterpret_cast<const char*>(a), sizeof(QChar) * n);
        out += n;
    }
};
#else // for old vs2012 , we use wchar_t instead
template <int N> struct QConcatenable<wchar_t[N]> : private QAbstractConcatenable
{
    typedef wchar_t type[N];
    typedef QString ConvertTo;
    enum
    {
        ExactSize = false
    };
    static int size(const wchar_t[N]) { return N - 1; }
    static inline void appendTo(const wchar_t a[N], QChar*& out)
    {
        static_assert(sizeof(wchar_t) == sizeof(QChar), "wchar_t size is different from qchar");
        const int n = N - 1;
        memcpy(out, reinterpret_cast<const char*>(a), sizeof(QChar) * n);
        out += n;
    }
};
template <int N> struct QConcatenable<const wchar_t[N]> : private QAbstractConcatenable
{
    typedef const wchar_t type[N];
    typedef QString ConvertTo;
    enum
    {
        ExactSize = false
    };
    static int size(const wchar_t[N]) { return N - 1; }
    static inline void appendTo(const wchar_t a[N], QChar*& out)
    {
        static_assert(sizeof(wchar_t) == sizeof(QChar), "wchar_t size is different from qchar");
        const int n = N - 1;
        memcpy(out, reinterpret_cast<const char*>(a), sizeof(QChar) * n);
        out += n;
    }
};
#endif
 
The #else case does only work on windows or where wchar_t is 2 bytes on other systems build fails.
 
 
Regards,
Gunnar Roth
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to