array

How to pass an array size as a template with template type?

匿名 (未验证) 提交于 2019-12-03 02:24:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: My compiler behaves oddly when I try to pass a fixed-size array to a template function. The code looks as follows: #include <algorithm> #include <iostream> #include <iterator> template < typename TSize , TSize N > void f ( TSize (& array )[ N ]) { std :: copy ( array , array + N , std :: ostream_iterator < TSize >( std :: cout , " " )); std :: cout << std :: endl ; } int main () { int x [] = { 1 , 2 , 3 , 4 , 5 }; unsigned int y [] = { 1 , 2 , 3 , 4 , 5 }; f ( x ); f ( y ); //line 15 (see the error message) } It produces the

Why does gcc allow char array initialization with string literal larger than array?

匿名 (未验证) 提交于 2019-12-03 02:24:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: int main() { char a[7] = "Network"; return 0; } A string literal in C is terminated internally with a nul character . So, the above code should give a compilation error since the actual length of the string literal Network is 8 and it cannot fit in a char[7] array. However, gcc (even with -Wall ) on Ubuntu compiles this code without any error or warning. Why does gcc allow this and not flag it as compilation error? gcc only gives a warning (still no error!) when the char array size is smaller than the string literal. For example, it warns on

Possible Lossy conversion from long to int

匿名 (未验证) 提交于 2019-12-03 02:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I wish to enter one int and another long ex: 1 and 1000000000, and now I wish to create an array of size 1000000000. And then at each index of array, store int val, ex: arr[100000000] = 4 . When I'm trying to do this Netbeans shows me an error in this line: arr = new long[y+1]` and `arr[j] = 0` "Possible Lossy conversion from long to int". Here's my code:- public static void main(String[] args) throws IOException { BufferedReader s = new BufferedReader(new InputStreamReader(System.in)); String[] xe = s.readLine().split(" "); int x = Integer

More efficient way to search an array of javascript objects?

匿名 (未验证) 提交于 2019-12-03 02:22:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Not sure about posting rules, but I will tell you out of the gate that this is a repeat question of this one , but I am asking if this is the "best practice" way to do this? 回答1: That is the straight forward to do this. If you need fast access multiple times, you should create a map keyed by the property name that you're searching by. Here's a function that takes arrays and builds keyed maps. It's not all-purpose, but you should be able to modify it for your own use. /** * Given an array and a property name to key by, returns a map that is

turn URL route into funciton arguments php mvc

匿名 (未验证) 提交于 2019-12-03 02:22:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm writing a custom MVC framework for a PHP project and everything is great until it comes to getting arguments from the URL route. I'm stuck on passing parts of the URL route into a function argument dynamically. I already have a method which is just to implode the route and use the array for the function arguments but I would really like to know how to do it like in CodeIgnitor or CakePHP. Here's what i want to have done. The site url would be... url: http://yoursite.com/profile/view/35/foo and in my controller I would have... <?php Class

how does searchsort in python work?

匿名 (未验证) 提交于 2019-12-03 02:22:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: To make my question clear say if I have an array a as Out[123]: [1, 3, 4, 6, 9, 10, 54] When I try to search the numbers in the list, searchsort returns correct value but when I try something not in the list, it returns an absurd value here is some of the results In [131]: a Out[131]: [1, 3, 4, 6, 9, 10, 54] In [132]: searchsorted(a,1) Out[132]: 0 In [133]: searchsorted(a,6) Out[133]: 3 In [134]: searchsorted(a,[9,54,1]) Out[134]: array([4, 6, 0]) In [135]: searchsorted(a,[9,54,1,0]) Out[135]: array([4, 6, 0, 0]) ***> # here 0 is not in the

validation on a input file in cakephp

匿名 (未验证) 提交于 2019-12-03 02:21:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In cakephp I am trying to check if an file input field has a file attached, and if not output an error. I have done this with other fields but just can't seem to get this to work on that field. Here is the model array('notempty'), 'uploadeduploaded_file' => array('notempty') ); ?> and here is my ctp file <?php echo $form->input('Uploaded.uploaded_file', array('type' => 'file', 'label' => 'Upload file', "label" => false)); ?> I am guessing that it must be something to do with what I should call the field in the model, but I have tried all

Extending Array in TypeScript

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: How to add a method to a base type, say Array? In the global module this will be recognized interface Array { remove ( o ): Array ; } but where to put the actual implementation? 回答1: You can use the prototype to extend Array: interface Array { remove ( o : T ): Array ; } Array . prototype . remove = function ( o ) { // code to remove "o" return this ; } 回答2: declare global seems to be the ticket as of TypeScript 2.1. Note that Array.prototype is of type any[] , so if you want to have your function implementation checked for

NodeJS JSON.stringify of very long array of objects errors “invalid string length”

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've got a very long array of objects that is about 100,000 items in size, and just before I got to write it to file, I pass the data into JSON.stringify I get this error: JSON.stringify( ^ RangeError: Invalid string length How can I stringify a very large json object successfully? Update: since I initially had written this question, I've become more familiar with processing large amounts of data, and I prefer to use Apache Spark for this process. In Spark, it is customary to not use large JSON arrays, but rather a stream or file containing

How to convert uint8 Array to base64 Encoded String?

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I got a webSocket comunication, I recieve base64 encoded string, convert it to uint8 and work on it, but now I need to send back, I got the uint8 array, and need to convert it to base64 string, so I can send it. How can I make this convertion? 回答1: If your browser has TextDecoder then use that: var u8 = new Uint8Array([65, 66, 67, 68]); var decoder = new TextDecoder('utf8'); var b64encoded = btoa(decoder.decode(u8)); If you need to support browsers that do not have TextDecoder (currently just IE and Edge), then the best option is to use a