Re: [Development] QOptional

2014-08-21 Thread Иван Комиссаров
I was thinking. If oprerator==(T) can be unsafe, do we really need it? std::optional has it, however we're not forced to copy std; dereferencing opt is just one more symbol to type and it will behave like real pointer. Иван Комиссаров ___ Development

Re: [Development] QOptional

2014-08-21 Thread abbapoh
Well, it doesn't compile. Neither compile int *a=0; if (a==true) {} At least, for clang. Иван Комиссаров > 21 авг. 2014 г., в 20:47, Thiago Macieira > написал(а): > >> On Thursday 21 August 2014 20:29:36 Иван Комиссаров wrote: >> Thiago, i've written a test for a bool optional. Does it work

Re: [Development] QOptional

2014-08-21 Thread Thiago Macieira
On Thursday 21 August 2014 20:29:36 Иван Комиссаров wrote: > Thiago, i've written a test for a bool optional. Does it work as expected? > > void tst_QOptional::boolOptional() > { > QOptional nullOpt; > QOptional trueOpt(true); > QOptional falseOpt(false); > > QVERIFY(!(nullOpt ==

Re: [Development] QOptional

2014-08-21 Thread Иван Комиссаров
do you suggest me to wait about 5 years before i can start working on a new imageformats api? i won't be able to break api in qt6, so i have to wait till qt7?) Иван Комиссаров 21 авг. 2014 г., в 20:29, Milian Wolff написал(а): > On Thursday 21 August 2014 09:18:22 Thiago Macieira wrote: >> On

Re: [Development] QOptional

2014-08-21 Thread Иван Комиссаров
Thiago, i've written a test for a bool optional. Does it work as expected? void tst_QOptional::boolOptional() { QOptional nullOpt; QOptional trueOpt(true); QOptional falseOpt(false); QVERIFY(!(nullOpt == false)); QVERIFY(!(nullOpt == true)); QVERIFY((nullOpt != false));

Re: [Development] QOptional

2014-08-21 Thread Milian Wolff
On Thursday 21 August 2014 09:18:22 Thiago Macieira wrote: > On Thursday 21 August 2014 13:24:23 Иван Комиссаров wrote: > > We can't wait that long when committee will accept std::optional. Are you > > sure it would get into c++14? I'm not. Next, when will MSVC support c++14? > > It still has no su

Re: [Development] QOptional

2014-08-21 Thread Ziller Eike
On Aug 21, 2014, at 5:16 PM, Marc Mutz wrote: > On Thursday 21 August 2014 16:52:05 Thiago Macieira wrote: >> But I'd like QOptional o = QString() result in a null >> (disengaged) QOptional too. Why would that be? The optional got a QString value assigned. It shouldn’t care about more. > Too

Re: [Development] QOptional

2014-08-21 Thread Allan Sandfeld Jensen
On Thursday 21 August 2014, Marc Mutz wrote: > On Thursday 21 August 2014 16:52:05 Thiago Macieira wrote: > > But I'd like QOptional o = QString() result in a null > > (disengaged) QOptional too. > > Too clever for a general optional class, IMO: > > QOptional qs = QString(); > QOptional ss =

Re: [Development] QOptional

2014-08-21 Thread Marc Mutz
On Thursday 21 August 2014 16:52:05 Thiago Macieira wrote: > But I'd like QOptional o = QString() result in a null > (disengaged) QOptional too. Too clever for a general optional class, IMO: QOptional qs = QString(); QOptional ss = std::string(); qs will be disengaged and ss will be engaged

Re: [Development] QOptional

2014-08-21 Thread Marc Mutz
On Thursday 21 August 2014 13:18:35 Иван Комиссаров wrote: > Conclusion - we have 6 identical checks which can be avoided using > QOptional > > So, i still think that simply returning QNothing() from these functions is > a great improvement. I'd say throwing an exception is what should happen, bu

Re: [Development] QOptional

2014-08-21 Thread Thiago Macieira
On Thursday 21 August 2014 16:33:12 André Somers wrote: > Thiago Macieira schreef op 21-8-2014 16:14: > > On Thursday 21 August 2014 11:15:01 Julien Blanc wrote: > >> Do you mean that you would change QSqlRecord::value to return, instead > >> of a QVariant that can be null, a QVariant holding eithe

Re: [Development] QOptional

2014-08-21 Thread André Somers
André Somers schreef op 21-8-2014 16:33: > Thiago Macieira schreef op 21-8-2014 16:14: >> I'd like to deprecate QVariant's internal >> nullability concept and make it rely on carrying a QOptional for a type to be >> null. >> >> If we don't do that, then QVariant: of a QOptional could be: >> >>1

Re: [Development] QOptional

2014-08-21 Thread André Somers
Thiago Macieira schreef op 21-8-2014 16:14: > On Thursday 21 August 2014 11:15:01 Julien Blanc wrote: >> Do you mean that you would change QSqlRecord::value to return, instead >> of a QVariant that can be null, a QVariant holding either an optional or >> a non-optional object ? I don’t see any adva

Re: [Development] QOptional

2014-08-21 Thread Иван Комиссаров
Yes, it has both operator(T) and operator RestrictedBool Still, i don't see a problem - if (opt1 == false) is equal to if (opt1.operator==(false)) than expression is false. If it is equal to if (bool(opt1) == false) than we have a problem. However, why the hell should compiler try to convert t

Re: [Development] QOptional

2014-08-21 Thread Thiago Macieira
On Thursday 21 August 2014 15:18:35 Иван Комиссаров wrote: > QString::toInt() calls: > QString::toIntegral_helper() (which has "if (ok)" check) which calls: > QLocaleData::stringToLongLong (which again has "if (ok)" check); calls: > QLocaleData::numberToCLocale (return bool, fuuuh) OR > QLocaleData

Re: [Development] New module QtCanvas3D now available

2014-08-21 Thread Thiago Macieira
On Thursday 21 August 2014 06:52:06 Keränen Pasi wrote: > Hi Thiego, > > Sorry didn¹t mean to jump the gun. Still a bit new to the Qt process. Just > to clarify, the module is not yet part of ³Qt proper². I guess a more > correct term for it would have been ³a playground type of preview of a > pot

Re: [Development] QOptional

2014-08-21 Thread Thiago Macieira
On Thursday 21 August 2014 11:34:17 Иван Комиссаров wrote: > Иван Комиссаров > > 21 авг. 2014 г., в 2:10, Thiago Macieira написал(а): > > The optional-cast-to-boolean is a source of problems for the current > > std::optional. That hasn't been solved. > > > > QOptional opt1 = false; > > QOptiona

Re: [Development] QOptional

2014-08-21 Thread Thiago Macieira
On Thursday 21 August 2014 11:29:12 Иван Комиссаров wrote: > In gerrit Jørgen Lind suggested to rename class to QMaybe. What do you > think? That's the original name I had for the class when Is started writing it in 2010, due to the D-Bus proposal for maybe type. However, in C++ we should call i

Re: [Development] QOptional

2014-08-21 Thread Thiago Macieira
On Thursday 21 August 2014 11:15:01 Julien Blanc wrote: > Do you mean that you would change QSqlRecord::value to return, instead > of a QVariant that can be null, a QVariant holding either an optional or > a non-optional object ? I don’t see any advantages in doing so. That > would make sense if

Re: [Development] QOptional

2014-08-21 Thread Thiago Macieira
On Thursday 21 August 2014 11:17:36 Milian Wolff wrote: > On Thursday 21 August 2014 13:13:15 Иван Комиссаров wrote: > > Of course, i can:) > > > > bool ok; > > const int value = string.toInt(&ok); > > if (ok) > > > > qDebug() << "value is" << value; > > > > // > > const auto value = st

Re: [Development] QOptional

2014-08-21 Thread Thiago Macieira
On Thursday 21 August 2014 13:24:23 Иван Комиссаров wrote: > We can't wait that long when committee will accept std::optional. Are you > sure it would get into c++14? I'm not. Next, when will MSVC support c++14? > It still has no support for constexprs and unicode literals, AFAIK. More, > Qt has to

Re: [Development] QOptional

2014-08-21 Thread Robert Knight
> Bot classes do NOT allow any default conversions (neither bool nor > value nor string) which made their usage a bit more verbose but > improved readability and safety a lot. My experience has been similar. I took the std::optional proposal as a starting point and stripped it back to just the bas

Re: [Development] QOptional

2014-08-21 Thread Julien Blanc
On 21/08/2014 13:01, Poenitz Andre wrote: > Julien Blanc wrote: >> There are two strong arguments in favor of optional : >> - real life tends to show that the optional &ok parameter is often >> missed in context it should not, leading to hard to find bugs. >> - optional is much more friendly to st

Re: [Development] QOptional

2014-08-21 Thread Иван Комиссаров
People who are using this class are telling you - it is useful:) Discussions started by people who never used this class. And it is ok - i am skeptical to many new features too. Иван Комиссаров 21 авг. 2014 г., в 16:16, Bubke Marco написал(а): > Actually I like the idea but not so much the bo

Re: [Development] QOptional

2014-08-21 Thread Bubke Marco
Actually I like the idea but not so much the bool conversion operator. A explicit method would be better. What about adding it in Qt Creator and testing how useful it is? Is it not better to do something and speak about experiences as to theorize in long discussions about the value of something

Re: [Development] QOptional

2014-08-21 Thread Иван Комиссаров
Actually, i plan to add Error class after (and if) QOptional will be merged. It requires big discussion too (i like idea if having an error code, but it would be better if we use a typed enum instead of int which should add 2nd template parameter - T and ErrorEnum). I don't want to discuss all o

Re: [Development] QOptional

2014-08-21 Thread private
In our projects we are using a Result class that also exists as a derived Outcome class. That Result class consists of a boolean (telling if an error occurred or not) and optional eror code and an optional error message. The derived Outcome class adds a value for functions that do not only

Re: [Development] QOptional

2014-08-21 Thread Иван Комиссаров
You're forgetting that we're talking about private API for now, which means we also need to look at the toInt implementation: QString::toInt() calls: QString::toIntegral_helper() (which has "if (ok)" check) which calls: QLocaleData::stringToLongLong (which again has "if (ok)" check); calls: QLoca

Re: [Development] QOptional

2014-08-21 Thread Poenitz Andre
Julien Blanc wrote: > There are two strong arguments in favor of optional : > - real life tends to show that the optional &ok parameter is often > missed in context it should not, leading to hard to find bugs. > - optional is much more friendly to static verification than &ok (dependancy between v

Re: [Development] QOptional

2014-08-21 Thread Иван Комиссаров
Иван Комиссаров 21 авг. 2014 г., в 14:37, Robert Knight написал(а): > I've written a basic Option class with a minimal interface to > address the problems with bool* OK args Julien mentioned and found it > useful - both > in terms of communicating that something may not have a value and also >

Re: [Development] QOptional

2014-08-21 Thread Robert Knight
I've written a basic Option class with a minimal interface to address the problems with bool* OK args Julien mentioned and found it useful - both in terms of communicating that something may not have a value and also it avoids the need for an invalid/null/empty version of T to be defined. *However

Re: [Development] QOptional

2014-08-21 Thread Harri Porten
On Thu, 21 Aug 2014, Julien Blanc wrote: There are two strong arguments in favor of optional : - real life tends to show that the optional &ok parameter is often missed in context it should not, leading to hard to find bugs. People just write const int value= string.toInt(); optional makes it

Re: [Development] QOptional

2014-08-21 Thread Pocheptsov Timur
AFAIK the better examples/ideas can be found in the design rationale of std::optional. For example (may be, also the bad one:) ), it can be good if you can distinguish initialized/non-initialized state, instead of having int m_val; //every possible integer value is reasonable bool m_valInitializ

Re: [Development] QOptional

2014-08-21 Thread Julien Blanc
On 21/08/2014 11:50, Poenitz Andre wrote: > Hausmann Simon wrote: >> On Thursday 21. August 2014 13.13.15 Иван Комиссаров wrote: >>> Of course, i can:) >>> >>> bool ok; >>> const int value = string.toInt(&ok); >>> if (ok) >>> qDebug() << "value is" << value; >>> >>> // >>> const auto valu

Re: [Development] QOptional

2014-08-21 Thread Bo Thorsen
Den 21-08-2014 11:43, Иван Комиссаров skrev: > > Иван Комиссаров > > 21 авг. 2014 г., в 13:25, Simon Hausmann > написал(а): > >> On Thursday 21. August 2014 13.13.15 Иван Комиссаров wrote: >> >> To be honest: I find the "bool ok" variant much easier to read. >> >> "if (value)" on an auto variable

Re: [Development] QOptional

2014-08-21 Thread Albert Astals Cid
On Thursday 21 August 2014 09:50:04 Poenitz Andre wrote: > Hausmann Simon wrote: > > On Thursday 21. August 2014 13.13.15 Иван Комиссаров wrote: > > > Of course, i can:) > > > > > > bool ok; > > > const int value = string.toInt(&ok); > > > if (ok) > > > > > > qDebug() << "value is" << value;

Re: [Development] QOptional

2014-08-21 Thread Poenitz Andre
Hausmann Simon wrote: > On Thursday 21. August 2014 13.13.15 Иван Комиссаров wrote: > > Of course, i can:) > > > > bool ok; > > const int value = string.toInt(&ok); > > if (ok) > > qDebug() << "value is" << value; > > > > // > > const auto value = string.toInt(); > > if (value) > > qD

Re: [Development] QOptional

2014-08-21 Thread Иван Комиссаров
Иван Комиссаров 21 авг. 2014 г., в 13:25, Simon Hausmann написал(а): > On Thursday 21. August 2014 13.13.15 Иван Комиссаров wrote: > > To be honest: I find the "bool ok" variant much easier to read. > > "if (value)" on an auto variable can mean so many things. In the > above example you could

Re: [Development] QOptional

2014-08-21 Thread Simon Hausmann
On Thursday 21. August 2014 13.13.15 Иван Комиссаров wrote: > Of course, i can:) > > bool ok; > const int value = string.toInt(&ok); > if (ok) > qDebug() << "value is" << value; > > // > const auto value = string.toInt(); > if (value) > qDebug() << "value is" << *value; To be honest

Re: [Development] QOptional

2014-08-21 Thread Иван Комиссаров
21 авг. 2014 г., в 13:17, Milian Wolff написал(а): On Thursday 21 August 2014 13:13:15 Иван Комиссаров wrote: >> Of course, i can:) >> >> bool ok; >> const int value = string.toInt(&ok); >> if (ok) >>qDebug() << "value is" << value; >> >> // >> const auto value = string.toInt(); >> if

Re: [Development] QOptional

2014-08-21 Thread Julien Blanc
On 21/08/2014 11:17, Milian Wolff wrote: > On Thursday 21 August 2014 13:13:15 Иван Комиссаров wrote: >> Of course, i can:) >> >> bool ok; >> const int value = string.toInt(&ok); >> if (ok) >> qDebug() << "value is" << value; >> >> // >> const auto value = string.toInt(); >> if (value) >>

Re: [Development] QOptional

2014-08-21 Thread Poenitz Andre
Milian Wolff [m...@milianw.de] > On Thursday 21 August 2014 13:13:15 Иван Комиссаров wrote: > > Of course, i can:) > > > > bool ok; > > const int value = string.toInt(&ok); > > if (ok) > > qDebug() << "value is" << value; > > > > // > > const auto value = string.toInt(); > > if (value) > >

Re: [Development] QOptional

2014-08-21 Thread Milian Wolff
On Thursday 21 August 2014 13:13:15 Иван Комиссаров wrote: > Of course, i can:) > > bool ok; > const int value = string.toInt(&ok); > if (ok) > qDebug() << "value is" << value; > > // > const auto value = string.toInt(); > if (value) > qDebug() << "value is" << *value; This is a sou

Re: [Development] QOptional

2014-08-21 Thread Julien Blanc
On 21/08/2014 00:07, Thiago Macieira wrote: > On Wednesday 20 August 2014 20:49:03 Marc Mutz wrote: >> I don't find the QVariant::isNull behaviour any useful or intuitive. It's >> too smart. You can always use v.value().isNull() because value() will >> return a default-constructed T if invalid. >

Re: [Development] QOptional

2014-08-21 Thread Иван Комиссаров
Of course, i can:) bool ok; const int value = string.toInt(&ok); if (ok) qDebug() << "value is" << value; // const auto value = string.toInt(); if (value) qDebug() << "value is" << *value; Иван Комиссаров 21 авг. 2014 г., в 13:09, Poenitz Andre написал(а): Иван Комиссаров [abba..

Re: [Development] QOptional

2014-08-21 Thread Poenitz Andre
Иван Комиссаров [abba...@gmail.com] wrote: > The goal is to get rid of ugly "int QString::toInt(bool *ok = 0)" functions. Can you maybe spell out some code to demonstrate why this is ugly, and how the use of QOptional would improve that? Andre' ___ Deve

Re: [Development] QOptional

2014-08-21 Thread Иван Комиссаров
Please look at "Improving toInt..." discussion http://lists.qt-project.org/pipermail/development/2014-February/015422.html The goal is to get rid of ugly "int QString::toInt(bool *ok = 0)" functions. Besides, this class can be used in other places; take a look at http://qt-project.org/doc/qt-4.8

Re: [Development] QOptional

2014-08-21 Thread Poenitz Andre
Иван Комиссаров wrote: > I've started working on a QOptional class > (https://codereview.qt-project.org/#/c/92006/). > As Thiago mentioned in gerrit, there are some things to discuss. 3) Why do we need that class at all? Andre' ___ Development mailing

Re: [Development] QOptional

2014-08-21 Thread Иван Комиссаров
Иван Комиссаров 21 авг. 2014 г., в 2:10, Thiago Macieira написал(а): > The optional-cast-to-boolean is a source of problems for the current > std::optional. That hasn't been solved. > > QOptional opt1 = false; > QOptional opt2 = 0; > if (opt1) > // this is true! > if (opt2) > // t

Re: [Development] QOptional

2014-08-21 Thread Иван Комиссаров
In gerrit Jørgen Lind suggested to rename class to QMaybe. What do you think? Иван Комиссаров ___ Development mailing list Development@qt-project.org http://lists.qt-project.org/mailman/listinfo/development

Re: [Development] New module QtCanvas3D now available

2014-08-21 Thread Keränen Pasi
Forgot to mention, that the “stable” branch of my three.js port should run out of the box on top of QtCanvas3D, the dev branch is always work in progress more or less so might work, but probably doesn't. You can find the stable branch at: https://github.com/tronlec/three.js/tree/stable Pasi On 2