tuples

c++ value_type not work for std::tr1:tuple in a std::map

丶灬走出姿态 提交于 2019-12-23 12:16:31
问题 The following code snippet work with Visual Studio 2008 but not with Visual Studio 2010. template <typename TKey> struct MyStruct { typedef std::map<TKey, int> Keys; MyStruct() { } void set(TKey& key) { #if 1 // This works with VS 2008 but not with 2010 keys_.insert(typename Keys::value_type(key, 1)); #else // This works with VS 2008 and VS 2010 keys_.insert(std::pair<TKey, int>(key, 1)); #endif }; private: Keys keys_; }; Usage typedef std::tr1::tuple<int, int> MyValueType; MyStruct

Is there a tuple data structure in Python

Deadly 提交于 2019-12-23 10:37:45
问题 I want to have an 3 item combination like tag, name, and list of values (array) what is the best possible data structure to store such things. Current I am using dictionary, but it only allows 2 items, but easy traversal using for k, v in dict.iteritems(): can we have something similar like: for k, v, x in tuple.iteritems(): 回答1: You can consider the collections.namedtuple type to create tuple-like objects that have fields accessible by attribute lookup. collections.namedtuple(typename, field

C++: Return type of std::tie with std::ignore

我们两清 提交于 2019-12-23 09:55:51
问题 I am wondering if the C++11 standard gives any requirement about the type of the std::tuple returned by std::tie when some arguments are std::ignore . More specifically, can I assume that: decltype(std::tie(42, std::ignore)) is not the same as decltype(std::tie(std::ignore, 42)) decltype(std::tie(42, std::ignore)) is not the same as decltype(std::tie(42)) decltype(std::tie(std::ignore, 42)) is not the same as decltype(std::tie(42)) decltype(std::tie(std::ignore, std::ignore)) is not the same

Python: variable-length tuples

▼魔方 西西 提交于 2019-12-23 09:33:11
问题 [Python 3.1] I'm following up on the design concept that tuples should be of known length (see this comment), and unknown length tuples should be replaced with lists in most circumstances. My question is under what circumstances should I deviate from that rule? For example, I understand that tuples are faster to create from string and numeric literals than lists (see another comment). So, if I have performance-critical code where there are numerous calculations such as sumproduct(tuple1,

C++ Error Handling - downside of using std::pair or std::tuple for returning error codes and function returns [closed]

和自甴很熟 提交于 2019-12-23 09:17:42
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . Without getting into the general exceptions vs error codes discussion, what do you think are the downsides of using std::pair or std

How To Merge an Arbitrary Number of Tuples in Python?

余生颓废 提交于 2019-12-23 08:57:40
问题 I have a list of tuples: l=[(1,2,3),(4,5,6)] The list can be of arbitrary length, as can the tuples. I'd like to convert this into a list or tuple of the elements, in the order they appear: f=[1,2,3,4,5,6] # or (1,2,3,4,5,6) If I know the at development time how many tuples I'll get back, I could just add them: m = l[0] + l[1] # (1,2,3,4,5,6) But since I don't know until runtime how many tuples I'll have, I can't do that. I feel like there's a way to use map to do this, but I can't figure it

XCTest'ing a tuple

血红的双手。 提交于 2019-12-23 08:55:14
问题 I am trying to build a unit test like so: // region is a (Double, Double) tuple XCTAssertEqual(region, (0.0, 200.0)) But Xcode is giving me an error: Cannot invoke 'XCTAssertEqual' with an argument list of type ((Double, Double), (Double, Double)) Is there a different way to test tuples without extracting their members and testing individually? 回答1: XCTAssertEqual requires that the two parameters passed to it are Equatable , which you can see from the method signature. Note that expression1

Accessing SML tuples by Index Variable

六眼飞鱼酱① 提交于 2019-12-23 08:54:05
问题 Question is simple. How to access a tuple by using Index variable in SML? val index = 5; val tuple1 = (1,2,3,4,5,6,7,8,9,10); val correctValue = #index tuple1 ?? I hope, somebody would be able to help out. Thanks in advance! 回答1: There doesn't exist a function which takes an integer value and a tuple, and extracts that element from the tuple. There are of course the #1 , #2 , ... functions, but these do not take an integer argument. That is, the name of the "function" is #5 , it is not the

Accessing SML tuples by Index Variable

独自空忆成欢 提交于 2019-12-23 08:52:57
问题 Question is simple. How to access a tuple by using Index variable in SML? val index = 5; val tuple1 = (1,2,3,4,5,6,7,8,9,10); val correctValue = #index tuple1 ?? I hope, somebody would be able to help out. Thanks in advance! 回答1: There doesn't exist a function which takes an integer value and a tuple, and extracts that element from the tuple. There are of course the #1 , #2 , ... functions, but these do not take an integer argument. That is, the name of the "function" is #5 , it is not the

binding to a list of tuples

不羁岁月 提交于 2019-12-23 08:16:08
问题 I have a list of tuples pairing two pieces of data... I'd like to bind the list to a data grid. For display, it works fine... but if I try and modify an entry, it says "A TwoWay or OneWayToSource binding cannot work on the read-only property 'Item1'"... presumably Tuples are immutable in .NET 4.0. Is there an easy way to bind to pairs of data without creating a mutable tuple class of my own? 回答1: Yes, tuples are immutable. Anonymous types are also immutable. You should use your own generic