implicit

Why is there an implicit type conversion from pointers to bool in C++?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 14:48:33
问题 Consider the class foo with two constructors defined like this: class foo { public: foo(const std::string& filename) {std::cout << "ctor 1" << std::endl;} foo(const bool some_flag = false) {std::cout << "ctor 2" << std::endl;} }; Instantiate the class with a string literal, and guess which constructor is called? foo a ("/path/to/file"); Output: ctor 2 I don't know about you, but I don't find that the most intuitive behavior in programming history. I bet there is some clever reason for it,

Why does the compiler choose bool over string for implicit typecast of L“”?

时光毁灭记忆、已成空白 提交于 2019-11-26 14:29:23
问题 Having recently introduced an overload of a method the application started to fail. Finally tracking it down, the new method is being called where I did not expect it to be. We had setValue( const std::wstring& name, const std::wstring& value ); std::wstring avalue( func() ); setValue( L"string", avalue ); std::wstring bvalue( func2() ? L"true", L"false" ); setValue( L"bool", bvalue ); setValue( L"empty", L"" ); It was changed so that when a bool value is stored we use the same strings

Android, How to read QR code in my application?

我怕爱的太早我们不能终老 提交于 2019-11-26 11:48:31
问题 In my application I need to read Qr code. I searched the net and found Zing codes however lots of developers had problem with using it and it seems it is buggy! If i assume that my customers has qr reader installed on their device, how can i use those applications and call them via implicit intents? if user doesn\'t have any qr reader, what will happen to the application? if it crashes, may i ask user to download for example QrDroid and after that use it? 回答1: try { Intent intent = new Intent

Implicit keyword before a parameter in anonymous function in Scala

喜你入骨 提交于 2019-11-26 10:58:09
问题 I understand implicit parameters and implicit conversions in Scala but I saw this for the first time today: the implicit keyword in front of a parameter in an anonymous function: Action { implicit request => Ok(\"Got request [\" + request + \"]\") } What does the implicit keyword do here? Are there resources on the web that describes more on what the use case is? 回答1: There are two distinct features here. First, request isn't really an argument in a method invocation. It's the argument of an

Is there a way to control which implicit conversion will be the default used?

人盡茶涼 提交于 2019-11-26 09:45:06
问题 Suppose I have this: class String2(val x:String) { def *(times:Int) : String = { val builder = new StringBuilder() for( i <- 0 until times) { builder.append(x) } builder.toString() } } now if I add this implicit: implicit def gimmeString2(y:String) = new String2(y) I will get a compilation error because stringWrapper also adds this implicit. Is there a way of saying to the compiler \"ignore other implicits, use this\", so that I don\'t have to instantiate a String2 object and work on that? I

ReSharper and var [duplicate]

倖福魔咒の 提交于 2019-11-26 09:09:31
问题 Possible Duplicate: Why does ReSharper want to use 'var' for everything? I have ReSharper 4.5 and have found it invaluable so far but I have a concern; It seems to want to make every variable declaration implicit (var). As a relatively new developer, how much should I trust ReSharper when it comes to this? Take the below code snippet from a method that Paints Tab Headers. TabPage currentTab = tabCaseNotes.TabPages[e.Index]; Rectangle itemRect = tabCaseNotes.GetTabRect(e.Index); SolidBrush

Why do members of a static class need to be declared as static? Why isn&#39;t it just implicit?

ぃ、小莉子 提交于 2019-11-26 07:41:24
问题 Obviously there can\'t be an instance member on a static class, since that class could never be instantiated. Why do we need to declare members as static? 回答1: I get asked questions like this all the time. Basically the question boils down to "when a fact about a declared member can be deduced by the compiler should the explicit declaration of that fact be (1) required, (2) optional, or (3) forbidden?" There's no one easy answer. Each one has to be taken on a case-by-case basis. Putting

What are type classes in Scala useful for?

不问归期 提交于 2019-11-26 04:06:57
问题 As I understand from this blog post \"type classes\" in Scala is just a \"pattern\" implemented with traits and implicit adapters. As the blog says if I have trait A and an adapter B -> A then I can invoke a function, which requires argument of type A , with an argument of type B without invoking this adapter explicitly. I found it nice but not particularly useful. Could you give a use case/example, which shows what this feature is useful for ? 回答1: One use case, as requested... Imagine you

Is it possible to plot implicit equations using Matplotlib?

♀尐吖头ヾ 提交于 2019-11-26 02:08:27
I would like to plot implicit equations (of the form f(x, y)=g(x, y) eg. X^y=y^x) in Matplotlib. Is this possible? Steve I don't believe there's very good support for this, but you could try something like import matplotlib.pyplot from numpy import arange from numpy import meshgrid delta = 0.025 xrange = arange(-5.0, 20.0, delta) yrange = arange(-5.0, 20.0, delta) X, Y = meshgrid(xrange,yrange) # F is one side of the equation, G is the other F = Y**X G = X**Y matplotlib.pyplot.contour(X, Y, (F - G), [0]) matplotlib.pyplot.show() See the API docs for contour : if the fourth argument is a

Is it possible to plot implicit equations using Matplotlib?

我们两清 提交于 2019-11-26 01:08:43
问题 I would like to plot implicit equations (of the form f(x, y)=g(x, y) eg. X^y=y^x) in Matplotlib. Is this possible? 回答1: I don't believe there's very good support for this, but you could try something like import matplotlib.pyplot from numpy import arange from numpy import meshgrid delta = 0.025 xrange = arange(-5.0, 20.0, delta) yrange = arange(-5.0, 20.0, delta) X, Y = meshgrid(xrange,yrange) # F is one side of the equation, G is the other F = Y**X G = X**Y matplotlib.pyplot.contour(X, Y, (F