« first day (263 days earlier)      last day (2581 days later) » 

9:00 AM
So there an alternative to printf in C++. Which offers essentially string interpolation?
 
nwp
Can you give an example of string interpolation? The interpolation I'm thinking of doesn't make sense for strings.
 
@nwp printf("customer [%s]\n", parsed_options.customer)
 
nwp
I think you mean format strings
 
In Python "customer {}, something else {}".format(customer, something)
 
nwp
you would normally do std::cout << "customer [" << parsed_options.customer << "]\n";
 
9:04 AM
the "standard" formatted string output is IO streams
 
though I'm sure boost has a more typesafe printf safe somewhere in there
 
nwp
which makes more sense because you put the variable where it belongs instead of listing it at the end and then having trouble checking if it is the correct number of arguments in the correct order
although that breaks when you want to do translations
there is nothing that does format strings in the standard library, you will have to use boost or QString::arg or some other library or write your own based on maybe std::string::replace
 
@nwp that syntax isn't very readable, with the alternative I can read the string in its entirety and see where the substitutions are.
If I want to edit the string I only have to edit it in one place.
Whereas if I have a long string with multiple substitutions I have to jump around a lot more.
 
nwp
9:09 AM
looks insane to me as boost always does
I wish they would go easy on operator overloading.
 
license is liberal enough that you can copy and change the code if you hate operator overloading enough
 
9:30 AM
Seems like C++ was not designed to be used without C. However, I'm getting pressure from some developers to only use C++.
 
@JoshuaBarnett yes, use a library for that
 
@JoshuaBarnett depends on what they call C
 
fmtlib and Boost.Format are popular choices
 
int a = c+b; is also C
 
Any #include <*.h> headers. :P
 
9:32 AM
*printf are shit at interpolation anyway since you can't reorder the fields without non-standard extensions
 
writing your own isn't that hard though
 
I implemented getopt.h instead of using the hand rolled argument parser already written (which didn't account for edge cases, or generic things like this option requires an argument).
Then got criticised for it not being strictly C++.
 
getting a good syntax for the format string is tricky but interpreting it is dead easy once you nail it down
 
IYAM if you're writing C++ and not using Boost, you're essentially wasting your time
 
nwp
Reordering arguments based on the format string is actually called interpolation?
 
9:36 AM
In computer programming, string interpolation (or variable interpolation, variable substitution, or variable expansion) is the process of evaluating a string literal containing one or more placeholders, yielding a result in which the placeholders are replaced with their corresponding values. It is a form of simple template processing or, in formal terms, a form of quasi-quotation (or logic substitution interpretation). String interpolation allows easier and more intuitive string formatting and content-specification compared with string concatenation. String interpolation is common in many programming...
 
 
4 hours later…
1:13 PM
anybody here have experience with boost share ptrs
 
aren't they basically the same as std::shared_ptrs?
also take C++ questions to the room specifically made for it: chat.stackoverflow.com/rooms/116940/c-questions-and-answers
 
thx
anybody here have experience with boost shared ptrs?
 
i am trying to use a boost shared pointer with custom deleter. i'm not sure what i'm doing wrong m_mb = boost::shared_ptr<modbus_t>( modbus_new_rtu(m_heatercomport.c_str(),9600,'N',8,1), freemodbus);
void freemodbus(modbus_t *mb)
{
if(mb != NULL)
{
modbus_close(mb);
modbus_free(mb);
}
} my program keeps crashing when i call m_mb.reset()
 
did you try stepping through reset() with a debugger?
 
1:19 PM
it dies at modbus_free(mb).
 
for sure
 
says invalid handle
 
nwp
0
Q: boost shared pointer custom deleter example

rafael gonzalezI'm using the libmodbus library. i need to pass instances of the modbus_t pointer between threads. I am having difficulty with just raw pointers and I think i can solve the problem with using boost_shared_ptr with custom deleter. i don't get any compiler issues but when i run the program it cras...

 
m_heatercomport.c_str() looks suspicious
 
it is a valid port. "\\.\COM24"
 
your OpenModBusConnection code looks quite silly here stackoverflow.com/questions/43141564/…
what do you think this does
    // open modbus connection
    m_mb.reset();
 
do i need to pass parameters to reset()? i thought it would just call m_mb = boost::shared_ptr<modbus_t>( modbus_new_rtu(m_heatercomport.c_str(),9600,'N',8,1), freemodbus); again.
 
this should reset the shared_ptr to the new owner, which should be nullptr
because you didn't provide anything to it
 
reset sets the shared_ptr to nullptr
 
thanks found the problem then.
 
1:27 PM
@rafaelgonzalez no, it's the same as m_mb = nullptr;
 
.reset() should also drop the refcount for shared_ptr
 
1:38 PM
thanks its workign now.
 
 
1 hour later…
2:47 PM
there is still something wrong with my implementation. 2nd time around it doesn't work anymore. only works first time i press the button.
 
check that you didn't reset the shared_ptr
if it was then do the init of it again
 
if(m_mb.get() != NULL)
{
wxString msg("Closing port \"");
msg.append(m_heatercomport);
msg.append("\" modbus port ");
wxLogMessage(msg);

readoutput->AppendText("Modbus Connection Closed\n");

m_mb.reset();
}

// open modbus connection
m_mb= boost::shared_ptr<modbus_t>( modbus_new_rtu(m_heatercomport.c_str(),9600,'N',8,1),modbus_free);
 
3:03 PM
how come m_mb is always 0x0000 even when i use m_mb= boost::shared_ptr<modbus_t>( modbus_new_rtu(m_heatercomport.c_str(),9600,'N',8,1),modbus_free);
 
most likely modbus_new_rtu returns nullptr
 
3:16 PM
it works now when i do this. mb = modbus_new_rtu(m_heatercomport.c_str(),9600,'N',8,1);
m_mb = boost::shared_ptr<modbus_t>( mb, freemodbus );
 
 
1 hour later…
4:41 PM
Hello people
I am trying to bfs and for each node I also save its parent, but seems like parent and child nodes have same address whatever the case, I can't use pointers
Is it because of initialization list on stack?
 
3 messages moved from Lounge<C++>
what
 
@RE60K We'll have to see code to be sure, but it sounds like you're filling various values into a struct, pushing the strut's address to the tree (or graph, or whatever) then filling the same struct with new values (and repeating).
 
like I am doing next_node = {apply_action(parent_node, action), action, &parent_node}
I can give the minimum code
her.. wait
see this ~edited
@JerryCoffin
 
4:58 PM
the address of top is always the same
 

« first day (263 days earlier)      last day (2581 days later) »