« first day (731 days earlier)      last day (2346 days later) » 

Dan
Dan
02:19
hello
I was wondering if anyone could briefly look at stackoverflow.com/q/51296401/868044 as I can see I am doing something dumb (the question is attracting DVs but no comments/answers), but have no clue what
@JerryCoffin haha
have you heard the Disturbed version?
@JerryCoffin ^^
@Dan No, I don't think so. Come to that, I don't think I've heard any version in quite a while (probably at least a couple of decades).
Dan
Dan
-2
Q: Can't compile vector<bool> using std_lib_facilities.h header from Bjarne Stroustrup's Programming book

DanI'm working through Bjarne Stroustrup's Programming: Principles and Practice Using C++ (2nd ed.) book and ran into a problem using his custom header file, std_lib_facilities.h when I try to use a vector<bool>. I'm working on exercise 13 on p. 130, which is to allow the user to specify an upper b...

Anyone able to just point me in the right direction on this? ^^
self-teaching and stuck
very frustrating because it seems like it should work
The online reference says such a thing exists: en.cppreference.com/w/cpp/container/vector_bool
I just don't understand the error message at all
02:43
12 messages moved from Lounge<C++>
1 message moved from Lounge<C++>
Use at() instead of [ ] in your vector accesses to identify if you're going out-of-bounds.
Dan
Dan
@PaulMcKenzie ok
how do I do that? is_composite.at(0) ?
Dan
Dan
@PaulMcKenzie @sehe looks like that was the issue:
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector<bool>::_M_range_check: __n (which is 0) >= this->size() (which is 0)
Aborted (core dumped)
So, now you use the debugger to see what statement triggered that exception. That's your error.
This exception is what you wanted to have. Better safe than sorry
Dan
Dan
@sehe indeed now i know the issue is my implementation of sieve
arg...
in real world i'd be copy/pasting this
trying to learn tho haha
aha, i was trying to set values at locations i never created/allocated
easy fix
now it works great
Thank you @sehe and @PaulMcKenzie !
I appreciate your help
03:26
@Dan Cheers. Good work, Dan
@Dan Hmm....I guess I can see how people would like it, but I can't say I'm terribly enthused.
Hey, guys. I wanna ask:

Do weak_ptr has its own control block? Or Does it simply refer to share_ptr's control block?

I came out this question while reading a post discussing "new with shared_ptr and make_share()"

https://stackoverflow.com/questions/20895648/difference-in-make-shared-and-normal-shared-ptr-in-c
@Rick There's (at least normally) a single control block for both.
OK thanks
Dan
Dan
03:43
@JerryCoffin perhaps I enjoyed it so much because I was a Disturbed fan already, and the song is quite out of character for the lead singer
@Dan That's certainly easy to believe.
Dan
Dan
@JerryCoffin their most well-known song is this one, if you didn't already know (gives you an idea of their normal sound)
@Dan I think I'll leave their normal sound to my imagination (at least for now). Right now I'm listening to something slightly different...
Dan
Dan
@JerryCoffin very nice. The 3rd comment (from Jordan Wartell) from that video made me lol
@Dan I hadn't even looked at the comments, but now that you mention it, it is pretty funny.
Dan
Dan
03:49
I tend to listen to instrumental rock/metal when coding
Although I may need something like that if I start coding more in C++ to prevent me from killing my computer haha
I can get stuff working in C++, but finally decided to slow down and learn C++ like a beginner and not from material that treats C as a pre-req (I know C)
@Dan I mostly don't do background music. If music isn't good enough to make me concentrate on it, I usually won't listen to it at all.
Dan
Dan
@JerryCoffin makes sense.
It upsets my wife, but I also avoid multitasking at almost any cost.
Dan
Dan
@JerryCoffin I mostly do, too, except of course music (but the type of music does matter)
The thing I see with C++ is that it isn't enough to know how to use it. You have to understand the why behind everything to really get use out of it
otherwise it's like wizardry
i rarely see such detailed semantic discussions of python (although they do happen!)
@Dan Nah--I just have a couple handy rules of thumb, and get by just fine.
Dan
Dan
03:59
I've written some fairly functional things in C++, but could not answer more than half of the interview questions i see floating around
like why a virtual member function cannot be used with a template in C++, or can you call "delete this;" inside a member function, etc.
My thought is, I dunno - why would I?
so trying to learn
@Dan Ummm...you can't use a virtual function in a template? It's probably not very common, but at least offhand I can't see any reason you couldn't to it.
Dan
Dan
@JerryCoffin I have no clue, just questions I've heard. I'm probably regurgitating incorrectly haha - I don't know the answers
@Dan These don't strike me as things to particularly try to learn. I'd start by concentrating on problems to solve, not techniques to use. I've written about using delete this; a few times, but I'm pretty sure I've never used it in any "real" code (though I do know at least on person who has).
@Dan A quick check indicates that compilers accept it anyway.
Now it is true that a template member function can't also be virtual. For example, this shouldn't compile:
class base {
	template <class T>
	virtual void f() { }
};
Dan
Dan
04:18
@JerryCoffin that's good advice. That's basically how I've learned thus far: I need to solve problem X. Python solves it but it's either too slow or not ideal on a specific platform for whatever reason
most of the team I work on are not programmers, only a few have CS backgrounds
just folks who need to get stuff done
and the automation we get from scripting/programming is essential
If you're just doing automation from scripting, I really can't recommend C++. Scripting languages like Python or Ruby are much better at that IMO.
Scripts don't need to be put together that solidly. The price of designing the C++ project is much higher than just hacking something together.
Also, C++'s string support severely lacks features that are very useful for scripting
Dan
Dan
@Justin agreed, and we've been using Python, Ruby, PowerShell, VBScript, bash, etc.
recently also Go and some C#
but we primarily are parsing artifacts and data structures from operating systems
a lot of log data also
and performance becomes an issue, among other reasons
but we use a lot of C libs where ABI stability has increasingly been an issue with python
when libs decide they no longer want to abide by the limitations of VS2008 for instance
If performance is an issue, I would argue it's not really a script anymore. It's becoming a full-on application. Either that, or the algorithm choice wasn't good
Dan
Dan
@Justin the problem is I might write something that works great on 50 endpoints and that was the goal for writing it
I guess you know your situation much better than I do :-).
Dan
Dan
04:27
but tomorrow, i get a new client who wants to run it globally on 50,000 endpoints
@JerryCoffin Sir, back to the "If you use a smart pointer to manage a resource other than memory allocated by new, remember to pass a deleter." question I asked you yesterday. So basically, shared_ptr can handle any stuff as long as it's related to dynamic memory. And you said typically, file handle, network connection are some kind of dynamic memory resource. So, for instance, given a Class API or something, how do I know I can use smart pointer to handle it?
Dan
Dan
and in a situation where they are having AD replication issues, and lots of latency problems, etc.
Do I need to dig into the source code to see if it use "new" or "malloc" to allocate some dynamic memory?
@Rick No. The smart pointer doesn't care at all about something being dynamic memory as such. It's just a way to keep track of something while you need it, and destroy that something when it goes out of scope. The point of mentioning file handles, network connections, etc., was to point out that they're not dynamic memory, but a smart pointer can manage them just fine anyway.
@Dan For string manipulation, I still really prefer SNOBOL4.
Dan
Dan
@JerryCoffin never heard of it -- looks amazing
I'm not sure Google's really got anything on Bell Labs :P
04:34
@Dan It really is quite cool. But it's not surprising you haven't heard of it--it was never widely known, and now it's truly ancient as well.
Dan
Dan
@JerryCoffin dealing with C/C++ strings is indeed awful
we get a lot of data that has binary intermingled with text
and we're a global company so encodings/locale is always fun
@Dan I can't say I've ever really had a big problem with it, but...
Dan
Dan
@JerryCoffin I have many of the same issues with Python
Go makes this much easier
for strings
and I have some colleagues who are insistent that I stop wasting time on C/C++ and learn Rust
Go actually deals with code-points (they call them runes), not bytes
so you can properly get the length of a string in multi-byte encoding
@JerryCoffin Wow, that enlightens me. I had been thinking that smart pointers is only invented for/related to dynamic memory management.
Thank you
@Dan C++ can do that as well, if you want. Not sure it makes a huge difference though.
@Rick Surely.
Dan
Dan
04:39
@JerryCoffin yeah i think boost::locale does ok
@JerryCoffin few devs even know difference between characters, bytes, code points, grapheme clusters, etc.
@Dan I was thinking more along the lines of char32_t, which all deals in utf32 code points.
Dan
Dan
@JerryCoffin gotcha, and probably the only time all that stuff matters is converting to utf32
I just hate that a certain OS forces UTF-16 on me, along with some other languages
@Dan Honestly, I love Rust. But it bugs the heck out of me when people say, "You should use Rust instead of C++." I'll be happy switching to Rust when it can do the things that C++ can. Yes, both are turing-complete programming languages, but C++ has some of my must-have things which Rust does not. Other than that, Rust is new, so it has less legacy baggage and nice tooling. Rust is new, so it has fewer time-hardened libraries / a smaller ecosystem.
@Dan Well...depends on what you're doing. A fully Unicode aware text editor (for example) has to deal in all sorts of ugliness (e.g., what do you do if the user tries to paste something in that claims to be UTF-8, but starts with a byte that can only be in the middle of a sequence?)
@Dan Yes, I'm aware of it. Just not what I was thinking of at the moment.
Dan
Dan
05:02
@Justin I've been wanting to wait a little so it matures more
Pretty much what I'm doing
05:32
It's also poorly differentiated from C++. Its borrow checker solves a problem nobody that does C++ actually has.
It's going to be like Java where people write verbose and shit code to match the borrowing paradigms.
 
2 hours later…
07:17
FD_SET fd;
TIMEVAL tm;

FD_ZER(&fd);
FD_SET(socket_server, &fd);
tm.tv_sec = 600;
tm.tv_usec = 0;

INT nFD = select(socket_server + 1, &fd, NULL, NULL, &tm);
This code doesn't work. In DEBUG mode, I can't pass at select(socket_server + 1, &fd, NULL, NULL, &tm); Why this happens? I can't understand...
nwp
nwp
07:54
Is socket_server a valid file descriptor?
I don't see anything wrong in the shown code.
@nwp Yes of course. Forexampe value of socket_server is 280, not 0 or -1.
I think so, but in Debug mode, I can't pass at line "select(...)".
nwp
nwp
Also what do you mean by "Can't pass"? Did you wait 10 minutes?
No, I will tell you the result after change tm.tv_sec as 5.
nFD returns 0.
did you mean that the last line stops working (returned fd is 0 instead of some sane value), if you change the value of tm.tv_sec?
nwp
nwp
That seems reasonable. Apparently nobody wrote to socket_server.
08:09
It is too long to write my full source code. I ask you understand my poor codes.
Anyway "select(...)" doesn't work well. My lord, help me...
go for epoll then?
Epoll? Sorry pardon me?
it's an alternative to select
Please teach me one.
@login_not_failed No, I changed tm.tv_sec = 600 into = 5. Then I waited for 5 seconds and "select" return 0. If I don't change value of tm, I have to wait for 10 minutes, and I am sure.
nwp
nwp
Did you make sure someone writes to your server?
08:18
Have not you ever seen this problem?
nwp
nwp
It's not a problem, it works exactly as it's supposed to work.
You said "Wait 5 seconds for data to become available to read from socket_server" and there is no data after 5 seconds.
@nwp Yes of course. Some data want to send data to socket_server, but cause of block at "select", socket_server can't receive data from client.
nwp
nwp
If you replace select with read, can you read data?
Just I will check it. Please wait for a moment...
@nwp Oh, no... I can't recv any data, even 1 byte.
nwp
nwp
That explains selects behavior. Time to figure out why nobody sent any data.
08:44
Thank you all guys! I found my mistake. There is no problem in "select(...)". I was confused socket.
Ron
Ron
09:14
Can architecture be learned from books or does it come with experience and gut feeling?
If one aspires to eventually (in a few years) move to architecture.
Ron
Ron
09:41
That aside, how relevant is the Virtual constructor idiom in todays standards?
it's more often called an abstract factory
Ron
Ron
I see. Thanks.
10:13
But what about the architecture? I'm interested in this topic as well.
 
2 hours later…
jww
jww
12:38
Thanks again @nwp. I finally found it. It was a pointer subtraction that was written the way humans write subtraction. Cleared at https://github.com/weidai11/cryptopp/commit/bbf9a109f268 .

I can't help but feel the C++ committee was high on crack when they
came up with a rule that allows basic pointer subtraction to fail when using the minus sign. I mean, nearly every programmer writes readable code like that for Christ's sake.
nwp
nwp
How does basic pointer subtraction fail?
jww
jww
ptr - unsigned int resulted in undefined behavior. I understand not using a ptrdiff_t is undefined behavior in C++. It resulted in a bizarre failure where when GCC transformed the program from a functioning one to a non-functioning one. Also see Pointer addition and integer overflow with Clang 5.0 and UBsan?
subtracting pointers that are from different allocations is UB
nwp
nwp
The points must be elements from the same array, otherwise pointer subtraction makes no sense.
jww
jww
@ratchetfreak - There is one pointer and one integral offset. It is the same array; not two pointers or two different arrays.
nwp
nwp
12:45
Using some other way to make it give you some random number doesn't make the code correct.
pointer - offset works just fine.
Assuming you don't go out of the array.
13:20
Hey, guys. I've kept seeing people on SO referring this site eel.is/c++draft. What is used for? It seems to be C++ standard reference. Normally I use cppreference and cplusplus.com. (I was told the latter is not so good but more friendly for newbie. ) And cpprefence is complex/difficult enough for me to read through already. Just want to know, when do you use eel.is/c++draft? I mean, it seems even much difficult than cppreference to read.
jww
jww
@nwp - I just loaded the code up with asserts that verifies `size_in_bytes <= buffer_end() - buffer_begin()`. If the assert did not hold then it meant we went outside of the array. None of them fired.

This is the second time pointer subtraction bit me. The first time was PowerPC. This time it was ARM A-32. Be very careful of of using `ptr - unsigned`. It can jump up and bite you because the committee wants you to use ptrdiff_t.
nwp
nwp
I still don't understand the issues. ptr - unsigned doesn't simply jump up and bites you.
It's a well-defined operation mandated by the standard.
There is something else going wrong.
jww
jww
@nwp - Maybe a compile bug... But as I understand things you can only subtract a ptrdiff_t. You cannot subtract an unsigned.
nwp
nwp
@Rick When you need to quote the standard use eel.is, when you need to understand stuff go with cppreference. Sometimes the use-cases overlap, but not that much.
@nwp *requires it to work, not merely allows it
14:04
@Rick cplusplus.com isn't newbie friendly IME. It leaves out critical information which will leave your head scratching.
eel.is/c++draft is pretty much the current state of C++ standard, a.k.a. The Holy C++ Bible. You use it when you need to quote an authoritative source, that is, to prove your argument.
You typically don't use as a reference, unless cppreference or cplusplus isn't specific enough about the thing you're looking for
OK. I see. :D
Cplusplus is sometimes much simple and not so overwhelming as reference. I find it useful from time to time. :D
Not aware of any pages there which are outright wrong. Only aware of misleading or missing information.
eel.is (god) > cppreference (Jesus) > cplusplus (Priest)
OK. I would keep that in mind and be careful. Thank you
@milleniumbug some of the examples are, don't recall any specifics at the moment though
Ron
Ron
Do I need to use the somevector.reserve(n) prior to using std::generate_n?
14:18
Assuming output iterator being std::back_inserter(somevector)
Ron
Ron
Yes. Using back inserter with lambda.
reserve doesn't change the vector, it only makes sure it doesn't need to reallocate
in that case you don't need it, it's a potential optimization, but otherwise meh
Ron
Ron
I see. Appreciate.
15:01
quick question, assuming my program is taking arguments, how do i make sure that all the mandatory arguments were used? i was previously building a string while i was reading the arguments and then see if the size of the string was the correct size, is there a better way to do this?
@jeyejow I'd probably just create something like a set, and each time a mandatory argument is processed, you add an item to the set. When you're done, check that the set is the correct size.
what do you mean, set?
i never used set before
is it like a vector?
15:23
set is a collection of values without index
It's similar to set in Python I think
it's not like vector. You use numbers 0,1,2 as index to access vector elements.
and the reason for a set over a vector is to deduplicate
why is doing this if(std::string(argv[i]) == "-m") the same speed as doing this if(argv[1][0] == 'o' && argv[1][1] == 'l')
shouldnt the first one be slower?
i tested and they run at the same speed
i thought comparing chars was always faster then comparing a string
nwp
nwp
Either you tested poorly or you are using a recent compiler that learned to optimize out memory allocations.
this is how i tested:
#include <time.h>
int main(int argc, char **argv)
{
	clock_t tStart = clock();
	if (/*argv[1][0] == '-' && argv[1][1] == 'm')*/ std::string(argv[1]) == "-m")
	{
		std::cout << "huhu\n";
	}

	printf("Time taken: %.10fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC);
	return 0;
}
the cout will dominate your timings
15:37
really?
ok ill remove it
nwp
nwp
But even if it is perfectly optimized: The first version must compare 3 chars while the seconds one compares 2. That probably matters.
3?
because of the argv[1] ?
the null terminator
What is the point here? Are you micro-optimizing command line parsing?!
15:38
don't
but its fun and i have nothing else to do
it only runs once and will not be a significant part of your program unless you have been an idiot with it
well about that
or the program itself is not worth optimizing
i think the way im checking my arguments is unnefficient
but im not sure if it is or im just over looking things
could you mind taking a look at it?
15:40
@jeyejow It is comparable effort. Benchmarking is hard, and utterly irrelevant here. Also, the second is completely unsafe (besides is would match "oldfart" as well)
@jeyejow It's ridiculous and others have better things to do :)
hmm ok..
@jeyejow It can't be inefficient. Unless you write them to 100 remote databases and parse them repeatedly
but the thing is
i do the exact same thing like 5 times in a row
the only thing that chances is the variables that i store the values
the rest i use the same checks for every one
@jeyejow what's the problem?
ill post my code, i just needto remove some comments
15:42
okk
@jeyejow wandbox.org/permlink/V5awy3cBi05SGN2u See what assembly is generated: godbolt.org/g/y5bLps
here is how im checking arguments
@sehe ill have to lose some time decripting that for cicle :p
should i make some alterations in the way im checking things?
it seems like its a very big for cicle
and what if i needed to have more arguments?
it would be even bigger
is there a better way of doing what im doing?
15:59
you can at the end just check mode != nullptr && device_path != nullptr && /*...*/ instead of the set
but if i dod that, if the user calls the program like: test.exe -m hi -m hello, -m will have hello
you keep the if(mode != nullptr) check inside the loop
I meant adding an if checking them all after the loop
hmm so ill safe a if if i do that
ok
but
that doesnt make sence
what would i put inside the if?
break; ?
but that woudlnt protect me from what i sed above
because they can do -m hi -m hello -f somtheing -f other
so it would enter the if (std::string(argv[i]) == "-m") before completing the others
the error message (missing parameter) and return 1
i dont think thhat would work
16:06
or for each parameter you expect:
if (mode == nullptr){
    cout << "no -m parameter";
    return 1;
}
if mode == null then mode == argv[i+1]
no after you have parsed all the args
then if mode is still nullptr then no -m param was passed and you can error out
thats what the std::set is for
just giving another option for that
ohh ok, is you opinion better?
i never used std::set before i idk if is a viable choice
16:08
my option avoids the dependency on std::set...
it also lets you customize the error message for each parameter that wasn't supplied
is it bad to have a dependency on, for example, std::set?
if you don't know how to work with it it could be
hmm ok
is strtoul the only function to convert char* to unsigned long?
sscanf might have it implemented, for example MSVC has it, Arduino didn't
 
2 hours later…

« first day (731 days earlier)      last day (2346 days later) »