TAILIEUCHUNG - HandBooks Professional Java-C-Scrip-SQL part 61

Tham khảo tài liệu 'handbooks professional java-c-scrip-sql part 61', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | A Look at regex_iterator We have seen how to use several calls to regex_search in order to process all of an input sequence but there s another more elegant way of doing that using a regex_iterator. This iterator type enumerates all of the regular expression matches in a sequence. Dereferencing a regex_iterator yields a reference to an instance of match_results. When constructing a regex_iterator you pass to it the iterators denoting the input sequence and the regular expression to apply. Let s look at an example where we have input data that is a comma-separated list of integers. The regular expression is simple. boost regex reg d Adding the repeat match zero or one times to the end of the regular expression ensures that the last digit will be successfully parsed even if the input sequence does not end with a comma. Further we are using another repeat . This repeat ensures that the expression matches one or more times. Now rather than doing multiple calls to regex_search we create a regex_iterator call the algorithm for_each and supply it with a function object to call with the result of dereferencing the iterator. Here s a function object that accepts any form of match_results due to its parameterized function call operator. All work it performs is to add the value of the current match to a total in our regular expression the first subexpression is the one we re interested in . class regex_callback int sum_ public regex_callback sum_ 0 template typename T void operator const T what sum_ atoi what 1 . str . c_str int sum const return sum_ You now pass an instance of this function object to std for_each which results in an invocation of the function call operator for every dereference of the iterator i tthat is it is invoked every time there is a match of a subexpression in the regex. int main boost regex reg d std string s 1 1 2 3 5 8 13 21 boost sregex_iterator it reg boost sregex_iterator end regex_callback c int sum for_each it end c .sum As you .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.