How do I change or replace, in notepad2 or anywhere, _a for _b and viceversa without changing _a for _b first and now having everything as _b??
Easy:
Replace _a for _XXXX
Replace _b for _a
Replace _XXXX for _a
It's the same as within a script, if you want to change values, you have to make a temp to hold the old value of the first param. Here we do the same, we make a _XXXX which will be replaced after to the other var.
Related
The branch instruction contains labels which are the names of the basicblocks that it might jump to. Given that, is there a way to extract a MachineBasicBlock object from a branching instruction? for example:
for(MachineBasicBlock &BB : MF){
for(MachineInstr &MI : BB){
if(MI.isConditionalBranch()){
MachineBasicBlock &InstBB = something(MI.getOperand(0));
}
}
}
First you cast MI's operand to BasicBlockSDNode and then use getBasicBlock(). Remember to perform the casting using LLVM cast<>() function.
I create a vector of tuples:
std::vector<std::tuple<int*, bool, int*>> *DataStucture;
Next I want to iterate over a data set to get only the first element of each tuple.
Is this legal:
DataStructure -> push_back(std::make_tuple(some_pointer_to_some_int_value, std::ignore, std::ignore));
In next round of data set scanning, I compare the value of some_int_value and upon matching I set following two elements of DataStructure:
DataStructure -> push_back(std::make_tuple(std::ignore, some_bool_value, some_pointer_to_some_int_value2);
I am not sure what exactly std::ignore is for. I tried checking cpp reference website but I did not get it.
I was reading http://en.cppreference.com/w/cpp/utility/tuple/ignore.
And I think you cannot do that because std::ignore is only used as lvalue placeholders.
For example, if you have a return value that you don't want to use, you can do the following.
std::ignore = AFunctionWithAReturnValue();
It cannot be used as a part of rvalue. For your purpose, I'd just fill in placeholder values during the first scanning like this:
std::make_tuple(some_pointer_to_some_int_value, false, nullptr);
Just to elaborate on my previous comment, you cannot use std::ignore here, because it can be used only as lvalue, but really you don't need to either. Just use nullptr or any "default" value instead:
DataStructure->push_back(std::make_tuple(some_pointer_to_some_int_value, false, nullptr));
std::ignore should be used if you want to unpack your tuple into different values like this:
int* p;
bool b;
for (auto& tuple : *DataStructure) {
std::tie(p,b,std::ignore) = tuple;
// p now have value of first element of tuple
// b now have value of second element of tuple
}
On an unrelated note, your second operation does not set values of existing tuple, it adds new one. Also, why use pointer to a vector instead of vector itself or at least std::unique_ptr? It is generaly considered better to omit unnecessary "naked" pointers.
I have two datasets
A(af1, af2, af3)
B(bf1, bf2, bf3)
When I join them in Pig as
C = Join A by af1, B by bf1
And subsequently store as a JSON (after removing the join-predicate column)
store C into 'output.son' using JsonStorage();
I see a JSON schema as
{"A::af1":val, "A::af2":val, ...., "B::bf2":val, ...}
Is there a way I can strip off the unnecessary (as I am taking care of the ambiguity already) nesting-like naming resulting from the join?
Thanks in advance
We have to iterate over relation/alias C and generate the required fields and then store the new alias, lets say new alias is D.
D = FOREACH C GENERATE A::af1 AS af1, A::af2 AS af2, A::af3 AS af3, B::bf2 AS bf2, B::bf3 AS bf3;
STORE D INTO 'output.son' USING JsonStorage();
Update :
If there are 100 of unique field names in alias A, likewise in B, then after join we can use .. operator and select the required columns. We can even access the required fields using position notation also ($0..$99,$101..$200)
C = JOIN A BY af1, B BY bf1;
D = FOREACH C GENERATE af1..af100,bf2..bf100;
STORE D INTO 'output.son' USING JsonStorage();
I would like to create a matrix B from a block of matrix A. The size of A changes, so I'm trying to achieve the following
Eigen::MatrixXd B(A.block<3,N>(0,0));
where N is columns number of A. I get this error the expression must have constant value. How can I solve this problem? I've tried to use const_cast<> but I still get the same problem.
I think this would work:
Eigen::MatrixXd B = A.block(0, 0, 3, N);
The API documentation of eigen is here.
If N is a variable, it can't be used as a template function argument (<3,N>) because those must be compile-time constants (the compiler generates/instanciates a version of the function block for each combination or template arguments.)
I just ran into this piece of code that does this :
delete a, a = 0;
It compiles and runs just fine. But isn't this supposed to be :
delete a;
a = 0;
Why is separating statements using , allowed in this case ?
Thanks :)
In C and C++, most "statements" are actually expressions. The semicolon added to an expression makes it into a statement. Alternatively, it is allowed (but almost always bad style) to separate side-effectful expressions with the comma operator: the left-hand-side expression is evaluated for its side-effects (and its value is discarded), and the right-hand-side expression is evaluated for its value.
This is the comma-operator. It evaluates both it's arguments and returns the second one.
This is the comma operator. It can be used to separate expressions, but not declarations.
That is comma operator. MSDN article is here. And have a look at this question to understand how it works.
While it is possible to write code like that, it may be somewhat weird. A slightly more realistic usecase would be if you have a struct T as follows:
struct T {
bool check() const;
void fix();
};
Now you want to iterate through everything in the struct and run check on it, and then call fix if check returns false. The simple way to do this would be
for (list<T>::iterator it = mylist.begin(); it < mylist.end(); ++it)
if (!it->check())
it->fix();
Let's pretend you want to write it in as short a way as possible. fix() returning void means you can't just put it in the condition. However, using the comma operator you can get around this:
for (auto it = mylist.begin(); it != mylist.end() && (it->check() || (it->fix(), true)); ++it);
I wouldn't use it without a particularly good reason, but it does allow you to call any function from a condition, which can be convenient.