C ++. Generic class that receives lambda and structure function

Expensive,

I try to do some things in C ++, but still start both linguistically and functionally. What I need is to insert a function lambda in one Pair, The first member of Pair will be an object structand the second the lambda function. My lambda function supplies a as parameter struct and one vector and returns linesomething like:

Auto lambda = [](struct & s, vector & v) {
return (s.attribut + "" + v[0]);
};

In this case, the Pair would be something like:

Pair Pair;

I've encountered many typos (as I try to insert the lambda function into one map) and in finding a solution, I've found something that I can solve: a generic class that wraps lambda functions and performs the lambda function. I've found a generic class example for this, but due to my ignorance of the language, I do not know how to change it to accept lambda functions with parameters (without detection):

Class T {
Private:
double (* expression) ();
public
T (double (* exp) ()): expression (exp) {}
do it twice () {
return this-> expression ();
}
};

int main () {
T t[]() -> double {return 1 + 1;});
double val = t.execute (); // val = 2
Return 0;
}

In addition to changing the double to lineWhat else do I have to change in the class so that it receives lambda functions with parameters (without acquisition, only parameters)? The idea is that T-types are created this way:

T t[](struct & s, vector & v) -> string {
return (s.attribut + "" + v[0]);
});

And run like this:

string text = t.execute (struct, vector);

Is that possible Even more important is to insert this type T in the system Pair?

Thanks for any help.

rust reference in a nested structure

I would like to find a way to express that append_message () Method so that I can hide the serialization.

Use std :: sync :: {Arc, Mutex};
const NUM_BUFFERS: usize = 10;
const BUF_SIZE: usize = 10;

#[derive(Copy, Clone)]
struct Msg<'a> {
channel_id: usize,
msg_id: usize,
seq_id: usize,
end_seq_id: usize,
buf: & # 39; a [u8],
}

struct MsgMultiplexer<'a> {
count: use,
Buffer:[Msg[Msg[Msg[Msg<'a>; NUM_BUFFERS],
}

structural joint<'a> {
mplex: Arc <Mutex <MsgMultiplexer<'a>>>
}

impl<'a> connection<'a> {
fn new_with_buffer () -> connection<'a> {
leave msg = Msg {
channel_id: 0,
msg_id: 0,
seq_id: 0,
end_seq_id: 0,
buf: &[],
};
Connection {
mplex: Arc :: new (Mutex :: new (MsgMultiplexer {
Number: 0,
Buffer: [msg; NUM_BUFFERS],
})
)
}
}

// Multiply the message
fn append_message<'b: 'a>(& self, channel: usize, msg: & # 39; b [u8])
{
cnt = msg.len () / BUF_SIZE + if msg.len ()% BUF_SIZE> 0 {1} else {0};
for (seq, data) in msg.chunks (BUF_SIZE) .enumerate () {
leave msg = Msg {
channel_id: channel,
msg_id: 1234,
seq_id: seq,
end_seq_id: cnt,
buf: data,
};
if we use Ok (mut mplex) = self.mplex.lock () {
Let mcnt = mplex.count;
mplex.puffer[mcnt] = msg;
mplex.count + = 1;
if mcnt == NUM_BUFFERS || seq == (cnt - 1) {
mplex.count = 0;
self.send ();
}
}
}
}


fn send (& self) {
// if the message is complete OR all buffers used, send (whichever comes first)

}

}

#[cfg(test)]
Mod tests {
use super :: *;

#[test]
    FN protocol () {
let msg = order {
id: 123,
Price: 456.5,
Size 42,
Asset: Asset :: ALUMINUM,
state: state :: CANCEL,
};
let ser = serialize (& msg) .unwrap ();
let conn = connection :: new_with_buffer ();
conn.append_message (123, & ser);
}
}

When I change append_message () into

fn append_message<'b: 'a, T>(& self, channel: usize, msg: & # 39; b [u8])
from where
T: size + serialization,
{
let ser = serialize (& msg) .unwrap ();
cnt = ser.len () / BUF_SIZE + if ser.len ()% BUF_SIZE> 0 {1} else {0};
for (seq, data) in ser.chunks (BUF_SIZE). enumerate () {
leave msg = Msg {
channel_id: channel,
msg_id: 1234,
seq_id: seq,
end_seq_id: cnt,
buf: data,
};
if we use Ok (mut mplex) = self.mplex.lock () {
Let mcnt = mplex.count;
mplex.puffer[mcnt] = msg;
mplex.count + = 1;
if mcnt == NUM_BUFFERS || seq == (cnt - 1) {
mplex.count = 0;
self.send ();
}
}
}
}

I get an expected error He does not live long enough because it binds the message to the connection; but it is not necessary for a message to live that long. I can not see how I can express that.

I understand that I could redefine msg one included buf: Vec Instead, this solves the problem, but I do not see the need to move the buffer in this case.

Reference Request – Track structure of teleparallel gravity

I am interested in references that deal with teleparallel gravity in a mathematically rigorous way, especially in view of the fact that it is a "gauge of the translation group".

The standard reference is the book by Aldrovandi and Pereira, however, this book sometimes uses extremely sloppy math and is extremely confusing.

The paper "Einstein Lagrangian as translational Yang-Mills Lagrangian
Cho's getting closer to what I'm looking for, but it still seems to suffer from problems (it looks at a basic translation package that seems problematic), some of which are described here (without reference to the Cho paper) ..

What I've been looking for the most is probably the paper "Geometric Importance of Poincaré Group Theory" by Pilch. However, this is rather short, not very detailed and somewhat unclear to me.


Basically, I'm looking for a mathematically accurate, bundle-based treatment of the teleparallel gravity as gauge gauge. Based on the "naive measurement" of the Phyiker, I expect that the compound will be an affine compound whose translational part is dynamic and linear $ O ($ 3.1) Part is flat (Weitzenböck connection) and is somehow determined by the translational part (we have that.) $ W ^ kappa _ { mu nu} = B ^ kappa_a partial_ mu B ^ a_ nu $ in the local wording, where $ W $ is the Weitzenböck connection in a holonomic framework, and $ B_ mu ^ a $ is the parallel covielbein).

However, I miss the peculiarities of it, in particular that in ordinary GR a soldering form is present $ theta $ For the Lorentz main bundle, essentially "global" is the same as for an orthonormal coviel leg, a brazing form can not simply correspond to the parallel Weitzenböck nibble, since this is not invariant under arbitrary point-dependent Lorentz transformations.

The coupling with matter fields is also unclear to me, especially if we want to make the concept "Lagrangian not invariant under dimensional changes" invariant by introducing a connection ", which, as shown, makes sense even for non-trivial main bundles by the formulation (for "ordinary") dimensional theories of David Bleecker in "Doctrine Theory and Principles of Variations".

I wish that the references (if any) should be quite detailed and didactic, as I believe that teleparallel gravity is relatively well defined, albeit somewhat artificially and ad hoc, if the interpretation of dimensional theory does not fit into the However, in the usual physicists' formulations, it is quite confused when the interpretation of the measurement theory is forced. It's clarity I'm looking for.

Although it is primarily about teleparallel gravity, I am interested in any formulation of gravity that corresponds to GR and that can be called the measure theory of a main fiber bundle. References to mathematically accurate formulations of "Poincaré gauge theory" or "Lorentz" "Group Theory of Gravity" are also very welcome, although I am much less informed about these approaches than about telepallallelism.

Project structure – technology stack for physics software

I have a project idea for a formula simulation software for physics with the ability to extend it with custom plugins. I'm just thinking about the tech stack to use.

When I think about the users and their background, I would say that this would be very useful for people in science, and in my experience, most of them know Python pretty well, which gives them the ability to write plug-ins in Python.

For the simulation part, I am currently thinking of 2D and 3D simulatins of different physics models. C ++ could be used, as there are several libraries in this area.

Therefore, my current outline is to use Python for the core interface, the UI, and the plugin interface. And to use C ++ for the simulation part and an interface library like pybind11 or similar for the connection.

Does anyone have experience with this type of software and has to make some input regarding the options of the tech stack?

Redirect plugin: Modify the permalink structure to remove the date, preserve query strings, and pass (? Utm_).

I changed the permalink structure of /%year%/%monthnum%/%postname%.html to /% postname% /.

I added the following regex rule to the redirect plugin:

Source URL: ^ / ([0-9]{4}) / ([0-9]{2}) / ([^/]+). html (. *) $
Destination URL: https://example.com/$3/

This works and redirects links from social media attached to it ? utm_medium = social & utm_source = pinterest etc., but removes this parameter from the target.

How can I edit my regex to pass the query string and append it to the new URL format?

Many Thanks.

Why is there an ASUS folder in C: ProgramData where my full Windows folder structure is mirrored?

I used WindirStat to clean up my SSD. I stumbled across a folder called C: ProgramData ASUS This has mirrored much of my Windows folder structure and is therefore ~ ​​15 GB in size.
If you try to delete files or folders from them, you will see a strange error message that you do not have the appropriate rights, even though you are the administrator.

Is this folder important? It seems like some sort of caching of phenomena, I'd rather have the space on the SSD free.

Correct Python Script Structure – Code Review Stack Exchange

I have been programming in Python for some time and have always used the following structure to organize my code. Lately, I've been wondering if this structure is ideal and usually used in Python, both in terms of pythonic and performance.

The structure that I follow in my scripts is as follows:

def main (argv):

"" "
Main entry for running the program
"" "
To attempt:
call_func1 ()
call_func2 ()
call_func3 ()
except some_specific_exception_type1 as e:
do something
raising
except some_specific_exception_type2 as e:
do something
raising
Exception exception as e: # catches all other possible exceptions
do something
raising

def call_func1 ():
To attempt:
do_something_in_here
except some_specific_exception_type1 as e:
do something
raising
except some_specific_exception_type2 as e:
do something
raising
Exception exception as e: # catches all other possible exceptions
do something
raising

def call_func2 ():
To attempt:
do_something_else_in_here
except some_specific_exception_type1 as e:
do something
raising
except some_specific_exception_type2 as e:
do something
raising
Exception exception as e: # catches all other possible exceptions
do something
raising



if __name__ == & # 39; __ main __ & # 39 ;:
main (sys.argv[1:])

As you can see, in the script I have a central point where the execution of the program begins (in this case it is Main() method) and from there I call other methods that perform certain actions.

Then, each of the methods (whether it's the central starting point or the other methods doing a particular work) handles exceptions that may be triggered by the actions they take and triggers them.

In this way, I have a central point at which the execution of the program begins, but also a central point at which execution ends, as all methods return Main() whether they succeed or throw an exception (since it will trigger them).

I've been wondering if implementing this kind of structure is a good thing, both in terms of Pythonic, and whether it's affecting the program's performance or whether it's the right way to handle bugs.

Thank you in advance!

python – What do I have to do to prevent sleep in the last loop of this control structure?

I check if something is ready at most five times. Each failed readiness test waits 5 seconds.

def sure_ready ():
& # 39; & # 39; & # 39;
Make sure the object is ready
& # 39; & # 39; & # 39;
for i in the range (5):
ready = is_ready ()
logger.warning (& # 39; ready% b on check number% s & # 39 ;, finished, i)
when done:
hand back
otherwise:
Sleep for 5 seconds
sleep (5)
return incorrectly

I could have put that sleep At the beginning I wanted to do the check but the same.

The problem is the last run (where I is 4) and ready Wrong stays, I run unnecessarily sleep