parameter-passing

How do I set parameter default values that rely on other parameters?

旧城冷巷雨未停 提交于 2019-12-12 07:24:25
问题 The following code compiles and works as expected. #include <vector> void function(std::vector<int> vec, int size=1); int main(){ std::vector<int> vec = {1,2,3}; function(vec); } void function(std::vector<int> vec, int size){ //code.. return; } However, I would like the size parameter's default value to be deduced based on a previous parameter. So for example: void function(std::vector<int> vec, int size=vec.size()); But this however results in: error: local variable ‘vec’ may not appear in

How can I get kermit script to accept arguments and connect to serial device

我只是一个虾纸丫 提交于 2019-12-12 06:59:55
问题 I wrote the following in a kermit script to connect to my serial device: #!/usr/bin/env kermit set port /dev/ttyUSB8 set speed 115200 set carrier-watch off set flow-control none set prefixing all set input echo on It does the job pretty well. Now, I want to make this a generic script and would like to take the input from the user which port he wants to connect. So, I thought taking input as a commandline argument is the best way to do. And I modified the above in the following way: #!/usr/bin

How to pass hidden parameter to controller in Rails3

六月ゝ 毕业季﹏ 提交于 2019-12-12 05:56:19
问题 I'd like to pass the parameter recipient to controller. I can show it in my view like this: @recipient.username How can I pass this value to params[:message][:recipient] ? Note that I do not have a model called "Message". controllers/messages_controller.rb def deliver recipient = User.find_by_username(params[:recipient]) subject = params[:subject] body = params[:body] current_user.send_message(recipient, body, subject) redirect_to :controller => 'messages', :action => 'received' flash[:notice

What is better practise in high-performance computing: passing a struct of data into a function or a set of variables?

三世轮回 提交于 2019-12-12 05:28:16
问题 Imagine that I have a struct that contains a set of variables that describe an object, which is a grid in my case. I was wondering, if I have a function that only uses a subset of the grid, whether there are any performance differences in the two variants of the computational_kernel functions below. The kernels are the same, except that the one in which the struct is passed has to extract the itot , jtot and ktot from the struct before heavy computations are done. struct Grid { int itot; int

how to pass 2d array object to function in c++? [closed]

℡╲_俬逩灬. 提交于 2019-12-12 05:01:45
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I have a 2D fixed size object array of "spot" class Spot map[row][col];//row & col are dynamic changed integer I want to pass it to a function bool

Reference object passed to Thymeleaf fragment

假如想象 提交于 2019-12-12 04:20:44
问题 I have a Parent class that is instantiated twice in ParentForm backing class as mother and father. The web form expects a first and last name to be validated for each Parent as NotNull. I created a Thymeleaf fragment specifically for the "mother" instance, but I want to make the fragment generic for both Parent instances: <div class="form-group" th:fragment="name"> <div class="form-row clearfix"> <div th:classappend="${#fields.hasErrors('mother.firstName') or #fields.hasErrors('mother

Passing properties as parameters to be Got and Set

半腔热情 提交于 2019-12-12 02:56:36
问题 Well, I need to repeat same code for many properties. I've seen examples taking Action delegates, but they don't fit quite well here. I want something like this: (see explanation below) Dictionary<Property, object> PropertyCorrectValues; public bool CheckValue(Property P) { return P.Value == PropertyCorrectValues[P]; } public void DoCorrection(Property P) { P.Value = PropertyCorrectValues[P]; } . I want to have a dictionary containing many properties and their respective "correct" values. (I

codeigniter pass data from view to model

◇◆丶佛笑我妖孽 提交于 2019-12-12 02:26:15
问题 i need to show category and sub category, my model right now is show static $id as you can see i attempted to write $id = 4 (for testing only), so it's only show subcategory where $id = 4 in every category. public function get_subkriterias($id = 4) { $this->db->select('kriterias.nama as kriterias_nama, kriterias.id, sub_kriterias.id, sub_kriterias.nama, sub_kriterias.nilai'); $this->db->from('kriterias'); $this->db->join('sub_kriterias', 'kriterias.id = sub_kriterias.kriteria_id', 'LEFT');

What does map(&:name) mean in Ruby?

白昼怎懂夜的黑 提交于 2019-12-12 01:56:10
问题 I found this code in a RailsCast: def tag_names @tag_names || tags.map(&:name).join(' ') end What does the (&:name) in map(&:name) mean? 回答1: It's shorthand for tags.map(&:name.to_proc).join(' ') If foo is an object with a to_proc method, then you can pass it to a method as &foo , which will call foo.to_proc and use that as the method's block. The Symbol#to_proc method was originally added by ActiveSupport but has been integrated into Ruby 1.8.7. This is its implementation: class Symbol def

function as templated parameter in cuda

两盒软妹~` 提交于 2019-12-12 01:29:15
问题 I'm attempting to write a reduction function in cuda (this is an exercise, I know that I'm doing things which have been done better by other people) which takes a binary associative operator and an array and reduces the array using the operator. I'm having difficulty with how to pass the function. I've written hostOp() as a host based example which works fine. deviceOp() works for the first statement with an explicit call to fminf(), but when I call the function parameter, there is an illegal