generic-programming

DLR: Do i really need code generation here?

女生的网名这么多〃 提交于 2020-01-05 08:57:31
问题 spent some time again with the scripting interface of my app. i guess i now have an advanced dlr problem here. I have a python script I have an .NET object [o1] I call a method on the python script from .NET via Iron Python. The python code creates an object [o2] The python code calls an method on object [o1] passing [o2] as an argument (Via subclassing DynamicMetaObject) In the .NET code of the o1-method i want to dynamically call methods on o2 For example i could do that via ((dynamic)o2)

Conditionally implement a Rust trait only if a type constraint is satisfied

北慕城南 提交于 2020-01-05 05:55:17
问题 I have the following struct: pub struct Foo<T> { some_value: T, } impl<T> Foo<T> { pub fn new(value: T) -> Self { Self { some_value: value } } } // Implement `Default()`, assuming that the underlying stored type // `T` also implements `Default`. impl<T> Default for Foo<T> where T: Default, { fn default() -> Self { Self::new(T::default()) } } I would like Foo::default() to be available if T implements Default , but not available otherwise. Is it possible to specify "conditional implementation"

Conditionally implement a Rust trait only if a type constraint is satisfied

岁酱吖の 提交于 2020-01-05 05:55:05
问题 I have the following struct: pub struct Foo<T> { some_value: T, } impl<T> Foo<T> { pub fn new(value: T) -> Self { Self { some_value: value } } } // Implement `Default()`, assuming that the underlying stored type // `T` also implements `Default`. impl<T> Default for Foo<T> where T: Default, { fn default() -> Self { Self::new(T::default()) } } I would like Foo::default() to be available if T implements Default , but not available otherwise. Is it possible to specify "conditional implementation"

Scala: Implementing a subtype of Numeric[T]

浪尽此生 提交于 2019-12-31 10:51:46
问题 How does one go about implementing a subtype of Numeric[T]? I have been looking for at guide on this but haven't found any. Example of subtypes could be Rational or Complex? Thanks in advance Troels 回答1: An absolutely useless String Numeric: trait StringIsNumeric extends Numeric[String] { def plus(x: String, y: String): String = "%s+%s" format (x, y) def minus(x: String, y: String): String = "%s-%s" format (x) def times(x: String, y: String): String = "%s*%s" format (x, y) def quot(x: String,

Scala: Implementing a subtype of Numeric[T]

喜夏-厌秋 提交于 2019-12-31 10:51:09
问题 How does one go about implementing a subtype of Numeric[T]? I have been looking for at guide on this but haven't found any. Example of subtypes could be Rational or Complex? Thanks in advance Troels 回答1: An absolutely useless String Numeric: trait StringIsNumeric extends Numeric[String] { def plus(x: String, y: String): String = "%s+%s" format (x, y) def minus(x: String, y: String): String = "%s-%s" format (x) def times(x: String, y: String): String = "%s*%s" format (x, y) def quot(x: String,

Shapeless code to convert Map[String, Any] to case class cannot handle optional substructures

寵の児 提交于 2019-12-31 04:06:08
问题 I'm trying to use this https://stackoverflow.com/a/31641779/1586965 (How to use shapeless to convert generic Map[String, Any] to case class inside generic function?) to process case class Address(street: String, zip: Int) case class PersonOptionalAddress(name: String, address: Option[Address]) I have a test that fails: "Convert Map to PersonOptionalAddress Some" in { CaseClassFromMap[PersonOptionalAddress](Map( "name" -> "Tom", "address" -> Some(Map("street" -> "Jefferson st", "zip" -> 10000)

Generic programming vs. Metaprogramming

别等时光非礼了梦想. 提交于 2019-12-29 14:29:21
问题 What exactly is the difference? It seems like the terms can be used somewhat interchangeably, but reading the wikipedia entry for Objective-c, I came across: In addition to C’s style of procedural programming, C++ directly supports certain forms of object-oriented programming, generic programming, and metaprogramming. in reference to C++. So apparently they're different? 回答1: Programming : Writing a program that creates, transforms, filters, aggregates and otherwise manipulates data.

Generic programming vs. Metaprogramming

痞子三分冷 提交于 2019-12-29 14:29:08
问题 What exactly is the difference? It seems like the terms can be used somewhat interchangeably, but reading the wikipedia entry for Objective-c, I came across: In addition to C’s style of procedural programming, C++ directly supports certain forms of object-oriented programming, generic programming, and metaprogramming. in reference to C++. So apparently they're different? 回答1: Programming : Writing a program that creates, transforms, filters, aggregates and otherwise manipulates data.

Provide AoS access to SoA

风流意气都作罢 提交于 2019-12-25 08:31:24
问题 I have data laid out in memory in a Structure of Arrays (SoA) or Sturcture of Pointers (SoP) form, and have a way to access that data as though it were laid out in Array of Structure (AoS) form -- code given below. However, I am not too happy about use of struct AoS_4_SoP -- although this struct appears to use templates, it is not really generic since, for example, foo and bar are hard-coded inside it. Two questions/requests: 1) For read-write performance, is AoS access provided as good as

Calling a particular implementation inside a generic method

大城市里の小女人 提交于 2019-12-24 11:34:50
问题 I'm currently trying to implement a generic method to adapt a DTO that comes from an external service into a model of my servisse and I ran into an issue. First let me just contextualize the problem. Let's say that an external service returns the following DTO to my application. public class ExampleDTO { public int Field1 { get; set; } public int Field2 { get; set; } } And this is my model. public class ExampleModel { public int Field1 { get; set; } public int Field2 { get; set; } } If I