range

Range-based for statement definition redundancy

為{幸葍}努か 提交于 2019-11-28 00:41:47
Looking at n3092, in §6.5.4 we find the equivalency for a range-based for loop. It then goes on to say what __begin and __end are equal to. It differentiates between arrays and other types, and I find this redundant (aka confusing). It says for arrays types that __begin and __end are what you expect: a pointer to the first and a pointer to one-past the end. Then for other types, __begin and __end are equal to begin(__range) and end(__range) , with ADL. Namespace std is associated, in order to find the std::begin and std::end defined in <iterator> , §24.6.5. However, if we look at the

Continuous integer runs

守給你的承諾、 提交于 2019-11-28 00:41:24
I have some data in a list that I need to look for continuous runs of integers (My brain think rle but don't know how to use it here). It's easier to look at the data set and explain what I'm after. Here's the data view: $greg [1] 7 8 9 10 11 20 21 22 23 24 30 31 32 33 49 $researcher [1] 42 43 44 45 46 47 48 $sally [1] 25 26 27 28 29 37 38 39 40 41 $sam [1] 1 2 3 4 5 6 16 17 18 19 34 35 36 $teacher [1] 12 13 14 15 Desired output: $greg [1] 7:11, 20:24, 30:33, 49 $researcher [1] 42:48 $sally [1] 25:29, 37:41 $sam [1] 1:6, 16:19 34:36 $teacher [1] 12:15 Use base packages how can I replace

Java - limit number between min and max

ⅰ亾dé卋堺 提交于 2019-11-28 00:37:45
I want to return the number as long as it falls within a limit, else return the maximum or minimum value of the limit. I can do this with a combination of Math.min and Math.max . public int limit(int value) { return Math.max(0, Math.min(value, 10)); } I'm wondering if there's an existing limit or range function I'm overlooking. 3rd party libraries welcome if they are pretty common (eg: Commons or Guava) As of version 21, Guava includes Ints.constrainToRange() (and equivalent methods for the other primitives). From the release notes : added constrainToRange([type] value, [type] min, [type] max)

Test if range exists in VBA

♀尐吖头ヾ 提交于 2019-11-27 23:54:59
问题 I have a dynamically defined named range in my excel ss that grabs data out of a table based on a start date and an end date like this =OFFSET(Time!$A$1,IFERROR(MATCH(Date_Range_Start,AllDates,0)-1,MATCH(Date_Range_Start,AllDates)),1,MATCH(Date_Range_End,AllDates)-IFERROR(MATCH(Date_Range_Start,AllDates,0)-1,MATCH(Date_Range_Start,AllDates)),4) But if the date range has no data in the table, the range doesn't exists (or something, idk). How can I write code in VBA to test if this range exists

range and xrange for 13-digit numbers in Python?

淺唱寂寞╮ 提交于 2019-11-27 23:38:54
range() and xrange() work for 10-digit-numbers. But how about 13-digit-numbers? I didn't find anything in the forum. You could try this. Same semantics as range: import operator def lrange(num1, num2 = None, step = 1): op = operator.__lt__ if num2 is None: num1, num2 = 0, num1 if num2 < num1: if step > 0: num1 = num2 op = operator.__gt__ elif step < 0: num1 = num2 while op(num1, num2): yield num1 num1 += step >>> list(lrange(138264128374162347812634134, 138264128374162347812634140)) [138264128374162347812634134L, 138264128374162347812634135L, 138264128374162347812634136L,

Forcing auto to be a reference type in a range for loop

这一生的挚爱 提交于 2019-11-27 23:22:39
问题 Suppose I have foo which is a populated std::vector<double> . I need to operate on the elements of this vector. I'm motivated to write for (auto it : foo){ /*ToDo - Operate on 'it'*/ } But it appears that this will not write back to foo since it is a value type: a deep copy of the vector element has been taken. Can I give some guidance to auto to make it a reference type? Then I could operate directly on it . I suspect I'm missing some trivial syntax. 回答1: A minimal auto reference The loop

Regular expression Range with decimal 0.1 - 7.0

混江龙づ霸主 提交于 2019-11-27 23:19:44
I need a regular expression that should validate decimal point as well as range. Totally 3 number should be present including dot and the value must be greater than 0.0. That means the valid range is from 0.1 to 7.0. I used the following regex: ^\\d{1,1}(\\.\\d{1,2})?$ It works fine except for the range validation. What do I need to change? Regexes are notoriously bad at validating number ranges. But it's possible. You have to break down the number range into the expected textual representations of those numbers: ^ # Start of string (?: # Either match... 7(?:\.0)? # 7.0 (or 7) | # or [1-6](?:\

Need to set cursor position to the end of a contentEditable div, issue with selection and range objects

混江龙づ霸主 提交于 2019-11-27 23:15:59
I'm forgetting about cross-browser compatibility for the moment, I just want this to work. What I'm doing is trying to modify a script (and you probably don't need to know this) located at typegreek.com The basic script is found here . Basically what it does is when you type in characters, it converts the character your are typing into greek characters and prints it onto the screen. What I'm trying to do is to get it to work on contentEditable div's (It only works for Textareas) My issue is with this one function: The user types a key, it get's converted to a greek key, and goes to a function,

How to find if range is contained in an array of ranges?

℡╲_俬逩灬. 提交于 2019-11-27 22:53:06
问题 Example business_hours['monday'] = [800..1200, 1300..1700] business_hours['tuesday'] = [900..1100, 1300..1700] ... I then have a bunch of events which occupy some of these intervals, for example event = { start_at: somedatetime, end_at: somedatetime } Iterating over events from a certain date to a certain date, I create another array busy_hours['monday'] = [800..830, 1400..1415] ... Now my challenges are Creating an available_hours array that contains business_hours minus busy_hours available

What is the difference between `Range#include?` and `Range#cover?`?

旧城冷巷雨未停 提交于 2019-11-27 22:40:35
Edit Fixed following toro2k's comment. Range#include? and Range#cover? seem to be different as seen in the source code 1 , 2 , and they are different in efficiency. t = Time.now 500000.times do ("a".."z").include?("g") end puts Time.now - t # => 0.504382493 t = Time.now 500000.times do ("a".."z").cover?("g") end puts Time.now - t # => 0.454867868 Looking at the source code, Range#include? seems to be more complex than Range#cover? . Why can't Range#include? be simply an alias of Range#cover? What is their difference? The two methods are designed to do two slightly different things on purpose.