enumeration

When items change while being enumerated does it affects the enumeration?

两盒软妹~` 提交于 2019-12-08 16:33:41
问题 Imagine that during a foreach(var item in enumerable) The enumerable items change. It will affect the current foreach? Example: var enumerable = new List<int>(); enumerable.Add(1); Parallel.ForEach<int>(enumerable, item => { enumerable.Add(item + 1); }); It will loop forever? 回答1: Generally, it should throw an exception. The List<T> implementation of GetEnumerator() Provides an Enumerator<T> object whose MoveNext() method looks like this (from Reflector): public bool MoveNext() { List<T> list

is it correct to cast an integer to enumerated type? [duplicate]

戏子无情 提交于 2019-12-08 16:06:54
问题 This question already has an answer here : What happens if you static_cast invalid value to enum class? (1 answer) Closed 6 years ago . My research has not yielded an answer for this yet (in SOF), but I am sure it must have been asked somewhere before, appologies if so. I have created an enumerated type in c++ and then I read in a value from a message header and want to store it into a variable of my enum type, example: // My defined enum type enum myNumType_t { MY_NUM_UNKNOWN = 0, MY_NUM1 =

how to count number of sprites swift

陌路散爱 提交于 2019-12-08 06:39:44
问题 I'm building an app that add sprites to the screen. In several parts of my code I want to know how many sprites I have with a certain key. At the moment I implemented it in this way var counter = 0 enumerateChildNodesWithName("box") { node, _ in counter = counter + 1 } println(counter) Is there another easier and shorter way? Thanks 回答1: From iOS8 , SKNode has subscript member that queries nodes and returns Array<SKNode> . extension SKNode { subscript (name: String) -> [SKNode] { get } } So

How to get all folders paths that contains music (mp3) in Cocoa?

大兔子大兔子 提交于 2019-12-08 05:42:25
问题 I'm new in Cocoa.I'm trying to scan computer for music folders,within my application. But I have some logic for it. What I need to start scaning from /Users , for example if I have /Users/music/anotherMusic and /Users/music/music2/music3 , I need to be able to get only the top for that folders that contains music (/Users/music ). And also need to continue iterate in subfolders to have a count of music files in the root folder (/Users/music). And so on with the same logic continue scanning

Does anyone know how to implement the DynamicEnumProperty type for C++ Project Property rules

China☆狼群 提交于 2019-12-08 04:24:00
问题 I am trying to add a property to our custom build configuration for a C++ project. I want the property combo box to display a dynamic list of values that I can set in code. I think that this should be done using the DynamicEnumProperty type but I am unsure of its implementation. Has anyone worked with this property before that can point me in the right direction? Thanks 回答1: In your VSPackage (or any MEF-exposed DLL referenced by it) create a class implementing IDynamicEnumValuesProvider and

Different behaviour when collection modified between Dictionary and ConcurrentDictionary

风格不统一 提交于 2019-12-08 00:44:18
问题 With a normal Dictionary code as list below, I get exception that Collection was modified; enumeration operation may not execute. Dictionary<int, int> dict2 = new Dictionary<int, int>(); dict2.Add(1, 10); dict2.Add(2, 20); dict2.Add(3, 30); dict2.Add(4, 40); foreach (var d in dict2) { if (dict2.ContainsKey(2)) dict2.Remove(2); if (dict2.ContainsKey(3)) dict2.Remove(3); } However with ConcurrentDictionary, this works fine. ConcurrentDictionary<int, int> dict1 = new ConcurrentDictionary<int,

Zend Mysql get ENUM values

你说的曾经没有我的故事 提交于 2019-12-07 22:01:26
问题 I use Zend Framework in my application. And I want to know how to get values from ENUM field in MySQL table. For example: i have permissions field ( ENUM ('delete_admin', 'edit_admin')). How to get array('delete_admin', 'edit_admin') in he best way? Thank you in advance. 回答1: This is how i did it: in your model put this function getInfoTabella() { $data = $this->info(self::METADATA); return $data; } then use this: $model = new $model_name(); $description = $model->getInfoTabella(); $enum =

How to get all folders paths that contains music (mp3) in Cocoa?

こ雲淡風輕ζ 提交于 2019-12-07 14:04:34
I'm new in Cocoa.I'm trying to scan computer for music folders,within my application. But I have some logic for it. What I need to start scaning from /Users , for example if I have /Users/music/anotherMusic and /Users/music/music2/music3 , I need to be able to get only the top for that folders that contains music (/Users/music ). And also need to continue iterate in subfolders to have a count of music files in the root folder (/Users/music). And so on with the same logic continue scanning whole computer.And results should be displayed in table, for example RESULTS should be like this - -/Users

Rich enumeration in Scala

不打扰是莪最后的温柔 提交于 2019-12-07 12:43:21
问题 I am looking for a mechanism to implement rich enumerations in Scala, the same way you can in Java add abstract methods to enums and implement them in the instances of of the enum. Please note that using a sealed trait and case objects is not a solution, because I would not be able to iterate over the existing case objects, unless I mantain a list of them, which is very fragile to changes (especially by other people who don't understand what's going on there) 回答1: Just extend Val . object

Iterating over each element of an array, except the first one

自古美人都是妖i 提交于 2019-12-07 10:52:05
问题 What is the idiomatic Ruby way to write this code? Given an array, I would like to iterate through each element of that array, but skip the first one. I want to do this without allocating a new array. Here are two ways I've come up with, but neither feels particularly elegant. This works but seems way too verbose: arr.each_with_index do |elem, i| next if i.zero? # skip the first ... end This works but allocates a new array: arr[1..-1].each { ... } Edit/clarification: I'd like to avoid