Questions tagged [heterogeneous-array]
24 questions
29
votes
3 answers
Sorting an array based on an attribute that may be nil in some elements
I have an array of objects
[<#a star=1 val=1>, <#a star=nil val=3> , <#a star=2 val=2>]
i need the array to be sorted by time, then by val
[ <#a star=2 val=2>, <#a star=1 val=1>, <#a star=nil val=3> ]
but using the sort_by throws an error…

meow
- 27,476
- 33
- 116
- 177
16
votes
3 answers
What is an heterogeneous object in java?
When I am using any collection of generic type with Object class and I'm storing different objects in that collection in that situation.
Can I say that the collection contains heterogeneous objects or not?

vishal s.
- 370
- 1
- 2
- 21
8
votes
2 answers
What is '[] and ': in Haskell?
I've seen this '[] and ': syntax in a few places, most notably in heterogeneous lists packages like HList or HVect.
For example, the heterogeneous vector HVect is defined as
data HVect (ts :: [*]) where
HNil :: HVect '[]
(:&:) :: !t ->…

mcmayer
- 1,931
- 12
- 22
4
votes
2 answers
How to implement a general pointer type in C++
In C, one can assign a data pointer to a void pointer and then cast it back to the original type, that data pointer will be recovered. The language standard guarantees that such transformation does not lose information. This often means (not…

John Z. Li
- 1,893
- 2
- 12
- 19
3
votes
2 answers
c++ heterogeneous container, get entry as type
I have the following simple implementation of a Heterogeneous container:
struct Container {
struct HolderBase {
};
template
struct Holder : HolderBase {
Holder(S* s) : s_(s) {}
S* s_;
};
…

XPlatformer
- 1,148
- 8
- 18
2
votes
1 answer
Compilation issue with existential types in Haskell
I've written a simple typeclass Shape:
class Shape a where
draw :: a -> IO ()
move :: (Double,Double) -> a -> a
area :: a -> Double
circum :: a -> Double
I also have concrete types Circle, Rect and Triangle that instantiate this…

Thomas Mahler
- 180
- 10
2
votes
3 answers
How do I represent and access elements of this multivalued data structure?
I am trying to implement the Brooks-Iyengar algorithm for sensor fusion, and am trying to represent the following data structure in MATLAB.
A = {([1.5,3.2],4), ([0,2.7],5), ([0.8,2.8],4)}
I tried doing the following
B =…

GothamCityRises
- 2,072
- 2
- 27
- 43
1
vote
2 answers
Kotlin Deserialization - JSON Array to multiple different objects
I'm using the 1.0.0 version of kotlin serialization but I'm stuck when I try to deserialize a "flexible" array.
From the Backend API that I don't control I get back an JSON Array that holds different types of objects. How would you deserialize them…

Dennis Anderson
- 1,348
- 2
- 14
- 33
1
vote
1 answer
How can I write a dynamic heterogenous collection inside C++ without using STL?
Basically I have to store different movies in a heterogenous collection dynamically, I already have the different movie types (documentary and family) and the class which "masks" the difference (movie) so it can be stored in one place (record).
I'm…

Athmos
- 35
- 5
1
vote
2 answers
Storing Generic Objects in a Heterogeneous Array and retrieving object parameter as the correct type
Ahoy everyone,
I have recently been trying to implement a Node based graph system that passes data between nodes using plugs. Similar to many of the 3D applications like houdini and maya.
I have written a similar system before using Python, and…

Simon Anderson
- 53
- 6
1
vote
1 answer
Pass a heterogeneous initializer list to a stream operator
Is it possible to pass to a debug streaming operator a list of heterogeneous types that are streamable?
string str("blabla");
std::cout << {"A", 3, str} << std::endl;
I guess it could be possible with something like a variadic template? I want the…

Llopeth
- 406
- 5
- 11
0
votes
0 answers
Storing heterogeneous data continuously in memory as a sequence of chars
I have a large number of strings and some data associated with each string. For simplicity, lets assume that the data is an int for each string. Lets assume I have an std::vector>. I want to try to store this data…

user542101
- 93
- 5
0
votes
1 answer
Printing from a custom heterogeneous container in C++
I am reading a blog about building a custom heterogeneous container in C++. In the blog, the author used visitor pattern to print out each element of the container ordered by their types. I'm wondering if it is possible for me to write a visitor…

Songg Tùng
- 139
- 8
0
votes
2 answers
How To constraint parameter of generic type in function, to sibling parameter
To understand the origin of the question, let's start with some code:
protocol MyProtocol {
var val1: Int { get set }
}
struct StructA: MyProtocol {
var val1: Int
var structAVal: Int
}
struct StructB: MyProtocol {
var val1: Int
…

Hudi Ilfeld
- 1,905
- 2
- 16
- 25
0
votes
1 answer
In flow how to accept a heterogeneous array, and return that array
When I have a function which accepts an array of a generic type and return a transformed array, I could write:
function myfun(input: Array): Array {}
However this fails if the array is of heterogeneous type, since T is then different over…

paul23
- 8,799
- 12
- 66
- 149