tuples

How to create named reference-type tuples?

…衆ロ難τιáo~ 提交于 2019-12-07 06:14:16
问题 The following line creates a named ValueTuple : var tuple = (a:1, b:2, c:3, d:4, e:5, f:6); Value types can not be passed around efficiently. Does C#7 offer a way to create named tuples of the Tuple type? 回答1: If you mean if there's a way to attach other names to the properties of System.Tuple<...> instances, no there isn't. Depending on why you want it, you might get around it by converting System.Tuple<...> instances to System.ValueTuple<...> instances using the ToValueTuple overloads in

C++ How to generate the set of cartesian product of n-dimensional tuples

≯℡__Kan透↙ 提交于 2019-12-07 05:33:59
问题 I wish to generate some data that represents the co-ordinates of a cloud of points representing an n-cube of n dimensions. These points should be evenly distributed throughout the n-space and should be able to be generated with a user-defined spacing between them. This data will be stored in an array. 回答1: I have found an implementation of a cartesian product using Boost.MPL. There is an actual Cartesian product in Boost as well but that is a preprocessor directive, I assume it is of no use

the weird result_of<F(Ts…)> in Andrei Alexandrescu's talk about exploding tuple

元气小坏坏 提交于 2019-12-07 04:33:32
问题 Has anyone watched Andrei Alexandrescu's talk about exploding tuple in GoingNative2013 yet? Here is the piece of code I don't quite follow: template <class F, class... Ts> auto explode(F&& f, const tuple<Ts...>& t) -> typename result_of<F(Ts...)>::type { return Expander<sizeof...(Ts), typename result_of<F(Ts...)>::type, F, const tuple<Ts...>&>::expand(f, t); } the F(Ts...) in result_of trouble me much. I mean: doesn't F stands for a function type ? I know R(Ts...) well, but the R here is a

Time complexity of tuple in Python

て烟熏妆下的殇ゞ 提交于 2019-12-07 03:33:38
问题 There is similar question about hash (dictionaries) and lists, also there is a good piece of info here: http://wiki.python.org/moin/TimeComplexity But I didn't find anything about tuples. The access time for data_structure[i] for a linked list is in general O(n) for dictionary is ~ O(1) What about tuple? Is it O(n) like for a linked list or O(1) like for an array? 回答1: It's O(1) for both list and tuple. They are both morally equivalent to an integer indexed array. 回答2: Lists and tuples are

F# parameter passing

陌路散爱 提交于 2019-12-07 02:39:55
问题 I've always thought that F# had two different ways to pass arguments, curry style and tuple style. Is this actually correct? Isn't it simply one style , curry style, and arguments can either be simple values or tuples. e.g. someFunc (a,b) = isn't this a function with one curry style argument which happens to be a tuple ? Thus allowing me to pass tuples to this function using the pipleline operator? (where the elements of the tuple is named) (1,2) |> someFunc Is this correct? 回答1: This will

Use 4 (or N) collections to yield only one value at a time (1xN) (i.e. zipped for tuple4+)

半城伤御伤魂 提交于 2019-12-07 02:32:28
问题 scala> val a = List(1,2) a: List[Int] = List(1, 2) scala> val b = List(3,4) b: List[Int] = List(3, 4) scala> val c = List(5,6) c: List[Int] = List(5, 6) scala> val d = List(7,8) d: List[Int] = List(7, 8) scala> (a,b,c).zipped.toList res6: List[(Int, Int, Int)] = List((1,3,5), (2,4,6)) Now: scala> (a,b,c,d).zipped.toList <console>:12: error: value zipped is not a member of (List[Int], List[Int], List[Int], List[Int]) (a,b,c,d).zipped.toList ^ I've searched for this elsewhere, including this

placing objects deriving from tuple into a vector in C++

空扰寡人 提交于 2019-12-07 01:54:12
问题 I want to create a struct with 3 values: a string and two ints. The string is mandatory, but either (or both) of the ints are optional and can default to -1 if not specified. However, rather than use a struct, I thought I would try an std::tuple. In order to incorporate the optional-ness of the two ints, I setup a "Trio" class which inherits from std::tuple as below: #include <string> #include <tuple> class Trio : public std::tuple<std::string, int, int> { public: explicit Trio(std::string

zip function help with tuples

拥有回忆 提交于 2019-12-07 01:34:10
问题 I am hoping someone can help me with a problem I'm stuck with. I have a large number of tuples (>500) that look like this: (2,1,3,6) (1,2,5,5) (3,0,1,6) (10,1,1,4) (0,3,3,0) A snippet of my code reads: sum1 = (A,B,C,D) # creates a tuple of sums of (A,B,C,D) mysum = map(sum, zip(A, B, C, D)) print(mysum) I realize the above code is not correct. I am trying to find a way to add all the values A together, all the values of B together, all the values of C together, and all the values of D

Haskell Convert List to List of Tuples

左心房为你撑大大i 提交于 2019-12-07 01:24:59
问题 i have a list like this ["peter","1000","michell","2000","kelly","3000"] and i would like to convert to [("peter",1000),("michell", 2000),("kelly",3000)] Please help. Thanks. 回答1: cnv :: [String] -> [(String, Integer)] cnv [] = [] cnv (k:v:t) = (k, read v) : cnv t If you want to handle odd-length just add cnv [x] = variant before last one 回答2: ony's solution is a bit shorter, but here's a non-recursive version using splitEvery from the very handy split library: cnv = map (\[name, amount] ->

What's the most concise way to create an immutable class in C#?

拟墨画扇 提交于 2019-12-06 23:39:55
问题 I find myself having to create a lot of immutable classes and I'd like to find a way to do it with no redundant information. I can't use an anonymous type because I need to return these classes from methods. I want intellisense support, so I'd prefer not to use Dictionaries, dynamic or anything like that. I also want well-named properties, which rules out Tuple<>. So far, some patterns I've tried: // inherit Tuple<>. This has the added benefit of giving you Equals() and GetHashCode() public