tuples

Do std::tuple and std::pair support aggregate initialization?

最后都变了- 提交于 2019-12-10 03:37:04
问题 Aggregate initialization requires among other things no user-provided constructors . But std::tuple and std::pair pair have a large set of overloaded constructors. From the point of the core language, are these constructors user-provided or even user-declared ? With C++17 it will be possible to write (update/clarification: where nocopy is a class that can not be copied or moved, such as std::mutex ) auto get_ensured_rvo_str(){ return std::pair(std::string(),nocopy()); } edit: no, it's not

Python, Convert 9 tuple UTC date to MySQL datetime format

∥☆過路亽.° 提交于 2019-12-10 02:31:02
问题 I am parsing RSS feeds with the format as specified here: http://www.feedparser.org/docs/date-parsing.html date tuple (2009, 3, 23, 13, 6, 34, 0, 82, 0) I am a bit stumped at how to get this into the MySQL datetime format (Y-m-d H:M:S)? 回答1: tup = (2009, 3, 23, 13, 6, 34, 0, 82, 0) import datetime d = datetime.datetime(*(tup[0:6])) #two equivalent ways to format it: dStr = d.isoformat(' ') #or dStr = d.strftime('%Y-%m-%d %H:%M:%S') 来源: https://stackoverflow.com/questions/686717/python-convert

Will tuple unpacking be directly supported in parameter lists in Scala?

为君一笑 提交于 2019-12-10 02:14:03
问题 In Haskell you can write: x :: (Int,Int) -> Int x (p,s) = p In Scala you would write: def x(a: (Int, Int)) = a._1 or: def x(a: (Int, Int)) = a match { case (p, s) => p } Why not have something like def x(_: (p: Int, s: Int)) = p or def x(foo: (p @ Int, s @ Int)) = p ? 回答1: The feature you're looking for is called destructuring and, in it's general form, would go well beyond just tuple unpacking. I've often found myself wishing that Scala had it since it's such a natural extension of the

Is there a version of the class Tuple whose Items properties are not readonly and can be set? [duplicate]

ⅰ亾dé卋堺 提交于 2019-12-10 00:35:22
问题 This question already has an answer here : Class inheritance: recreate base class items (or instance) from a property of the inherited class (1 answer) Closed 4 years ago . I want to know whether there is a built-in version of the class Tuple whose Items properties are not readonly and can be set. Or can someone provide me such a version? I am searching for a solution that implements the base functions of the Tuple class, ( Equals , GetHashCode ) 回答1: No, as mentioned a Tuple<> is intended to

Multidimension histogram in python

浪子不回头ぞ 提交于 2019-12-09 22:34:54
问题 I have a multidimensional histogram H=histogramdd((x,y,z),bins=(nbins,nbins,nbins),range=((0,1),(0,1),(0,1))) I need to print in an array the values of H which are different from zero and I also need to know the coordinate/the bins where this happens. I am not familiar with tuples. Can you help me? 回答1: use where to find the index of nozeros in H, and use the index to get the coordinate: import numpy as np x = np.random.random(1000) y = np.random.random(1000) z = np.random.random(1000) nbins

get dictionary/object keys as tuple in typescript

99封情书 提交于 2019-12-09 20:44:53
问题 I would like to get proper tuple type with proper type literals from an object in TS 3.1: interface Person { name: string, age: number } // $ExpectType ['name','age'] type ObjectKeysTuple = ToTuple<keyof Person> Why?: To get proper string literals tuple when using Object.keys(dictionary) I wasn't able to find a solution for this as keyof widens to union which returns ('name' | 'age')[] which is definitely not what we want. type ObjectKeysTuple<T extends object> = [...Array<keyof T>] type Test

Error with Tuple in C# 2008

我的梦境 提交于 2019-12-09 14:10:55
问题 I have made a program in C# 2010 and my code contains a Tuple, but when I put my program into C# 2008 it does not recognise it, and comes up with the error of: "The type of namespace name 'Tuple' could not be found" So I don't know how to make this work, this is the line of code in which the error occurs: private List<Tuple<Point, Point>> lines = new List<Tuple<Point, Point>>(); Please help. EDIT Basically this is my code at the moment which doesn't compile due to the error: public partial

What is the best way to check if a tuple has any empty/None values in Python?

南楼画角 提交于 2019-12-09 14:06:09
问题 What is the best/most efficient way to check if all tuple values? Do I need to iterate over all tuple items and check or is there some even better way? For example: t1 = (1, 2, 'abc') t2 = ('', 2, 3) t3 = (0.0, 3, 5) t4 = (4, 3, None) Checking these tuples, every tuple except t1 , should return True, meaning there is so called empty value. P.S. there is this question: Test if tuple contains only None values with Python, but is it only about None values 回答1: It's very easy: not all(t1) returns

List Tuple more than 8 items

邮差的信 提交于 2019-12-09 13:01:48
问题 Can anyone help the following List Tuple more than 8 elements is not working: List<Tuple<int, string, double, string, int, string, double, Tuple<int, string>>> tpl = new List<Tuple<int, string, double, string, int, string, double, Tuple<int, string>>>(); tpl.Add(Tuple.Create(1, "ABC", 100.123, "XYZ", 1, "ABC", 100.123, new Tuple<int, string>(100, "My Rest Item"))); foreach(var k in tpl) listBox1.Items.Add(k.Item1.ToString() + " ---> " + k.Item2.ToString() + " ---> " + k.Item3.ToString() + " -

Sorting a list of tuples with multiple conditions

徘徊边缘 提交于 2019-12-09 12:40:57
问题 I am currently trying to sort the following list: list_ = [(1, '0101'), (1, '1010'), (1, '101'), (2, '01'), (2, '010'), (2, '10')] These are the steps I want to take in order to sort it: Sort the list by the value of the first element of the tuples Next, sort the list by the length of the second element of the tuples (not the value, the length!) AFTER step 1 finishes. Next, sort the list by the value of the second element of the tuples AFTER step 1 and step 2 finishes. My attempt: sorted_by