www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Auto-conversion in array literals?

reply "bearophile" <bearophileHUGS lycos.com> writes:
This is valid Scala code:

object Main {
     def main(args: Array[String]): Unit = {
         val a: List[BigInt] = List(1, BigInt(2))
     }
}


Is it possible/meaningful to support/allow D code like this?

import std.bigint;
void main() {
     BigInt[] a = [1, BigInt(2)];
}

Bye,
bearophile
Jun 11 2012
parent Timon Gehr <timon.gehr gmx.ch> writes:
On 06/12/2012 12:55 AM, bearophile wrote:
 This is valid Scala code:

 object Main {
      def main(args: Array[String]): Unit = {
          val a: List[BigInt] = List(1, BigInt(2))
      }
 }


 Is it possible/meaningful to support/allow D code like this?

 import std.bigint;
 void main() {
      BigInt[] a = [1, BigInt(2)];
 }

 Bye,
 bearophile

Making it work would require a way to specify an implicit conversion from int to BigInt.
Jun 11 2012