tie

can we do deep tie with a c++1y std::tie() -like function?

旧时模样 提交于 2019-12-21 05:36:16
问题 Is there a way to write a variant of std::tie in c++11/1y that ties deeply into a tuple. That is, one in which tie((x,y),z) = make_tuple(make_tuple(1,2),3) binds x, y, z to 1, 2 and 3 , respectively as in the following example. It would be nice. Thanks. #include <tuple> #include <iostream> using namespace std; int main() { int x, y ,z; auto t = make_tuple(1,2); std::tie(y,x)= t; //std::tie((x,y),z) = make_tuple(t,3); //not working cout << x << y << z << endl; return 0; } 回答1: Maybe you're

How can I hook into Perl's print?

佐手、 提交于 2019-12-17 06:35:35
问题 Here's a scenario. You have a large amount of legacy scripts, all using a common library. Said scripts use the 'print' statement for diagnostic output. No changes are allowed to the scripts - they range far and wide, have their approvals, and have long since left the fruitful valleys of oversight and control. Now a new need has arrived: logging must now be added to the library. This must be done automatically and transparently, without users of the standard library needing to change their

Strange behavior of a tied hash in perl, when asking for an arrayref

末鹿安然 提交于 2019-12-12 10:51:49
问题 I was trying to tie an hash (or hashref) in order of tracking variable usages. Everything is working for simple cases, but when I tried to use my module on some real code I had this error: hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this) I've replicated the error using the following code: use Tie::Hash::Usages; use JSON; my @arr = ( { key1 => "ac", key2 => 12, key3 => 12 }, ); my %tied_hash; tie %tied_hash, 'Tie::Hash::Usages'; $tied_hash{key1} = \@arr; my @val

Perl Cannot Binmode STDOUT After Untie Filehandle

点点圈 提交于 2019-12-10 15:53:51
问题 I need to disable progressive buffering of an HTTP response. I've got this working in Perl using a file handle class: $|=1; $TIE = tie(*STDOUT,__PACKAGE__); Print statements are stored in an array and are retrieved via the following: $buffer = tied *STDOUT; $buffer = join('', @$buffer); undef $TIE; untie(*STDOUT); If the HTTP response is text/html , it correctly displays in the browser. However, for binary streams, I can't set binmode on STDOUT after it is untied, and the contents are

How to make a tuple of const references?

半城伤御伤魂 提交于 2019-12-09 08:28:37
问题 Say there are two functions: void ff( const std::tuple<const int&> ) { } template < typename TT > void gg( const std::tuple<const TT&> ) { } and calls to these functions: int xx = 0; ff( std::tie( xx ) ); // passes gg( std::tie( xx ) ); // FAILS !! GCC 4.7.2 fails to compile the last line and reports an error note like: note: template argument deduction/substitution failed: note: types ‘const TT’ and ‘int’ have incompatible cv-qualifiers note: ‘std::tuple<int&>’ is not derived from ‘std:

How can I use tie() to redirect STDOUT, STDERR only for certain packages?

自作多情 提交于 2019-12-08 03:02:07
问题 I need to work with some libraries that unfortunately log diagnostic messages to STDOUT and STDERR. By using tie , I can redirect those writes to a function that captures those. Since I don't want all STDOUT and STDERR output of my programs to be captured thtough the tied handle, I'd like to do this only for certain packages. I have come up with a solution where the actual behavior is determined by looking at caller() as can be seen below, but I have the feeling that there has to be a better

How can I use tie() to redirect STDOUT, STDERR only for certain packages?

*爱你&永不变心* 提交于 2019-12-06 07:59:31
I need to work with some libraries that unfortunately log diagnostic messages to STDOUT and STDERR. By using tie , I can redirect those writes to a function that captures those. Since I don't want all STDOUT and STDERR output of my programs to be captured thtough the tied handle, I'd like to do this only for certain packages. I have come up with a solution where the actual behavior is determined by looking at caller() as can be seen below, but I have the feeling that there has to be a better way... Is there a more elegant solution? package My::Log::Capture; use strict; use warnings; use 5.010;

can we do deep tie with a c++1y std::tie() -like function?

三世轮回 提交于 2019-12-03 17:19:37
Is there a way to write a variant of std::tie in c++11/1y that ties deeply into a tuple. That is, one in which tie((x,y),z) = make_tuple(make_tuple(1,2),3) binds x, y, z to 1, 2 and 3 , respectively as in the following example. It would be nice. Thanks. #include <tuple> #include <iostream> using namespace std; int main() { int x, y ,z; auto t = make_tuple(1,2); std::tie(y,x)= t; //std::tie((x,y),z) = make_tuple(t,3); //not working cout << x << y << z << endl; return 0; } Maybe you're looking for std::tuple_cat : std::tie(x,y,z) = std::tuple_cat(t, make_tuple(3)); You can string together tuples

How to tie every variable in perl script?

青春壹個敷衍的年華 提交于 2019-12-01 18:04:15
问题 I want to see every place when variable in perl script is created/accessed/destroyed It is easily reachable using tie or Variable::Magic But how to apply this magic automatically when variable is created? 回答1: You can take a look at B::Xref which generates a cross reference listing of all variables in your application. Basically, you need to walk the byte code to find all variable declarations/initializations. You can also alter the byte code, i.e. add code to tie the variables. However, I

How to tie every variable in perl script?

跟風遠走 提交于 2019-12-01 17:55:12
I want to see every place when variable in perl script is created/accessed/destroyed It is easily reachable using tie or Variable::Magic But how to apply this magic automatically when variable is created? You can take a look at B::Xref which generates a cross reference listing of all variables in your application. Basically, you need to walk the byte code to find all variable declarations/initializations. You can also alter the byte code, i.e. add code to tie the variables. However, I cannot point you to an example, because this is rarely done. As an alternative, you could use a code filter to