reference

using references to point to sliding window array in Perl

痞子三分冷 提交于 2020-01-02 08:02:12
问题 here is my problem: I have 2 arrays. One is character array and represents a sliding window. Characters gets shifted from the beginning and pushed at the end. I would like to use a second array to store references to array slices that 'follow' the characters as they move along. Example: my @char_array = ('h','e','l','l','o','w','o','r','l','d'); my $char_arr_ref=[@char_array[1..$#char_array]]; print @$char_arr_ref, "\n"; # slice contains 'elloworld'; shift(@char_array); push(@char_array), 'x'

using references to point to sliding window array in Perl

半腔热情 提交于 2020-01-02 08:02:11
问题 here is my problem: I have 2 arrays. One is character array and represents a sliding window. Characters gets shifted from the beginning and pushed at the end. I would like to use a second array to store references to array slices that 'follow' the characters as they move along. Example: my @char_array = ('h','e','l','l','o','w','o','r','l','d'); my $char_arr_ref=[@char_array[1..$#char_array]]; print @$char_arr_ref, "\n"; # slice contains 'elloworld'; shift(@char_array); push(@char_array), 'x'

Is it possible to attach an action to a boost::spirit::rule parser which assigns the parsed result to a member of a (yet) unknown instance?

一曲冷凌霜 提交于 2020-01-02 07:12:23
问题 I'm trying to reference a member of a (yet) unknown instance from within a boost::spirit rule definitions' action, so in pseudocode, instead of double_[ref(rN) = _1] I'm looking for something like X** ppx; double_[ref(&X::rN, ppx) = _1] A workaround for it could be a simple "semantic action" with a parameter which knows the instance and would be able to write to it, like qi::rule<Iterator, Skipper> start; my_grammar(DataContext*& dataContext) : my_grammar::base_type(start) , execContext

Is it possible to attach an action to a boost::spirit::rule parser which assigns the parsed result to a member of a (yet) unknown instance?

巧了我就是萌 提交于 2020-01-02 07:12:21
问题 I'm trying to reference a member of a (yet) unknown instance from within a boost::spirit rule definitions' action, so in pseudocode, instead of double_[ref(rN) = _1] I'm looking for something like X** ppx; double_[ref(&X::rN, ppx) = _1] A workaround for it could be a simple "semantic action" with a parameter which knows the instance and would be able to write to it, like qi::rule<Iterator, Skipper> start; my_grammar(DataContext*& dataContext) : my_grammar::base_type(start) , execContext

PHP's current() & key() functions; inconsistent with function signature

坚强是说给别人听的谎言 提交于 2020-01-02 05:02:16
问题 I've noticed that PHP's current() and key() array functions ( like other array-pointer functions ) take the array argument by reference: mixed current ( array &$array ) Every array has an internal pointer to its "current" element, which is initialized to the first element inserted into the array. After a few quick checks, it appears that both current() and key() ( unlike other array-pointer functions ) accept the array argument by value, thereby not throwing an error when passed the return

How to convert Option<&T> to Option<T> in the most idiomatic way in Rust?

本小妞迷上赌 提交于 2020-01-02 02:43:05
问题 When using HashMap's get method, I get an Option<&T> , I've encountered it again this time with Option<&String> . I'd like to get an owned value Option<String> . Is this possible without me writing map(|x| x.to_owned()) ? I'm just wondering if there's a way to write a blanket implementation for any of the utility traits to achieve that? 回答1: Option comes with utility methods for various transformations, which are listed in its documentation. For any T that implements Clone (which String does)

C# how to calculate hashcode from an object reference

半城伤御伤魂 提交于 2020-01-02 00:44:43
问题 Folks, here's a thorny problem for you! A part of the TickZoom system must collect instances of every type of object into a Dictionary<> type. It is imperative that their equality and hash code be based on the instance of the object which means reference equality instead of value equality. The challenge is that some of the objects in the system have overridden Equals() and GetHashCode() for use as value equality and their internal values will change over time. That means that their Equals and

returning reference to private vs public member

走远了吗. 提交于 2020-01-01 18:18:47
问题 I would like to know what could be reasons to provide a public access method returning a reference instead of making the member public. QPoint has methods int& rx and int& ry that let me directly manipulate the coordinates. I guess the implentation looks similar to this: public: int& rx(){return x;} private: int x; The only idea I had so far is the following: By keeping the member private and "only" providing a reference, the class can still change to use a different data type for its

Why does the constness of a reference affect whether it can be initialized with a variable of a different type?

点点圈 提交于 2020-01-01 17:07:13
问题 Why does this code fail to compile? double d ; int & i1 = d // Compilation FAILS While this one does? double d ; const int & i = d // Compilation Succeeds Please, I am interested in knowing what was in mind of C++ designers that they allowed one behavior while disallowed another. I know in either case it's immoral, independent of technically possible or not. Also FYI I am using GCC on mac with "-O0 -g3 -Wall -c -fmessage-length=0" 回答1: Because it creates a temporary int where the double is

C++: Passing reference of constructing object to constructed member objects?

空扰寡人 提交于 2020-01-01 12:11:24
问题 Okay, consider the following classes: class Object { public: // Constructor Object() : [Initialization List] { ... } ... }; class Container { public: Object A; Object B; .... Container() : [Initialization List] { } }; I'd like to provide [access to Container and it's members] to the Objects. My first thought was to somehow pass a reference to the current Container object to the constructors of the Objects. But I can't figure out how to do this. I've messed around with "this", but I'm not