Questions tagged [implicit-conversion]

Converting an object, variable or value from one type to another to satisfy a type restriction, without specifically requesting that conversion through language syntax.

Converting an object, variable or value from one type to another to satisfy a type restriction, without specifically requesting that conversion through language syntax.

Implicit conversion is a subset of .

2401 questions
1
vote
2 answers

Deserializing a string property value to a class instance using JSON.Net

I'm deserializing some JSON from a server which is, for the most part, simple: { "id": "ABC123" "number" 1234, "configured_perspective": "ComplexPerspective[WithOptions,Encoded]" } That "configured_perspective" property, however, is an…
Alain
  • 26,663
  • 20
  • 114
  • 184
1
vote
3 answers

Scala: 'implicit conversions are not applicable' in a simple for expression

I started out with Scala today, and I ran into an intriguing problem. I am running a for expression to iterate over the characters in a string, like such: class Example { def forString(s: String) = { for (c <- s) { // ... } …
Félix Saparelli
  • 8,424
  • 6
  • 52
  • 67
1
vote
1 answer

Are implicit conversions for Scala numeric types special?

I've defined an implicit class providing a method foo on all instances of Double. Strangely, this method can now also be called e.g. on Float instances, which is shown by the following example accepted by scalac 2.12.5 (use -Xscript Foo): implicit…
Feuermurmel
  • 9,490
  • 10
  • 60
  • 90
1
vote
1 answer

C++ implicitly transform trivially constructable struct to member

I feel that its unlikelier than not, but I'd like to see if a function can deduce its parameters from a trivially wrapped struct. For example: struct wrapped_float { float f; wrapped_float(float f) : f(f) {} }; float saxpy(float a, float x,…
Michael Choi
  • 610
  • 5
  • 22
1
vote
1 answer

can scala implicit convert from `Long` to `AnyRef`

def testLong(v: Any): Unit = { println(v.getClass) // print: class java.lang.Long } testLong(103L) // compile passed from last snippet, it shows that the variable v is class java.lang.Long.And it's a subclass of…
Adooo
  • 640
  • 6
  • 22
1
vote
1 answer

How to convert from Hexadecimal to Decimal and from Decimal to Binary

I would like how can I include the decimal result from the dance method to the light one. For example, in this program, if I input 5F, the decimal result would be 95. Well, I want that 95 to appear as a static int variable in the light method in…
1
vote
1 answer

In Scala how to find THE effective implicit methods, declarations and conversions during an execution

Trying to understand akka marshalling/unmarshalling and found a lot of scala implicit magic that goes on in the background and under the hood. Question: Is there a way to find which implicit constructs are effective during an execution. Things that…
jakstack
  • 2,143
  • 3
  • 20
  • 37
1
vote
0 answers

Why can't we cast as generic type if the supplied type has implicit conversion available?

I've looked around for some time now and can't seem to find a direct answer to my question. I am creating (as an exercise, self induced, not homework) a basic Cast method, where an object is supplied and if the conversion is valid then T is…
1
vote
1 answer

How to prevent PostgreSQL from rounding the output of double precision values?

I have a table of locations with associated data combined from multiple providers. I had the provider id, the latitude and the longitude (both coordinates are double precision) as primary keys. But now, I would like to generate an id of type…
1
vote
2 answers

c++ Force implicit conversion on pass as argument

I have problem with implicit conversions in C++. I'm trying to create some Expression template for vector arithmetics (I know that same libraries already exists. I'm just learning C++ so I wanted to try something with templates). I would like to…
Payne
  • 456
  • 6
  • 21
1
vote
0 answers

Why does dynamic call dispatch prefer double conversion to invoking object overload?

I am working on arbitrary object tree conversion to some specific format, using dynamic dispatch (to simplify handling generics). The object tree is generated by interop code, wraps some values into containers, which have implicit conversions…
LOST
  • 2,956
  • 3
  • 25
  • 40
1
vote
1 answer

inconsistent compiler behavior for user defined conversion to a reference for templated class

Lets say we have a templated class template< typename T> FOO that wraps a T pointer and we want to have a user defined conversion for getting a FOO & that points to an instantiation of FOO. The following reproducer code illustrates the…
doc07b5
  • 600
  • 1
  • 7
  • 18
1
vote
2 answers

How to implicitly convert class template object when passing as argument to function template?

Considering the following small code snippet: template class A{ public: A() { }; ~A() { }; // ... template operator std::vector(){ /* implicit/explicit cast to std::vector */ } }; template…
joaocandre
  • 1,621
  • 4
  • 25
  • 42
1
vote
2 answers

Using map to create a copy of an array (with generic type) results in error [Scala]

I am trying to copy an array of generic type using maps. class MaObj[T](val arr : Array[T])(implicit ordering : Ordering[T]) { val internalCopy : Array[T] = arr.map(e => e) //This line But I run it gives an error saying found :…
Ashwin
  • 12,691
  • 31
  • 118
  • 190
1
vote
1 answer

c# problem with deriving from generic class

Below are working classes: public class CatalogManager where T1 : CatalogDataEntryForm, new() where T2 : CatalogDataGridForm, new() …
Tim
  • 459
  • 1
  • 4
  • 20