« first day (653 days earlier)      last day (2203 days later) » 

2:36 AM
So, I'm trying to utilize a line which reads "this_thread::sleep_for(2);" to get my program to pause for 2 seconds at a particular point. However, I'm getting this error upon compilation:
menu.cpp: In function 'void cinematic(int, int)':
menu.cpp:26:26: error: no matching function for call to 'sleep_for(int)'
  this_thread::sleep_for(2);
Could someone enlighten me as to what's happening. I think the issue is that I'm passing in an int when sleep_for doesn't accept ints. I'm not sure what to put in instead, however.
 
@user8663905 std::this_thread::sleep_for. What is the argument type that it takes?
 
std::this_thread::sleep_for(std::chrono::seconds(3));
 
It's honestly so much better this way. I hate how some languages have sleep(int) taking seconds and some have sleep(int) taking milliseconds, etc.
 
Alright, I can work with that. Also, can I specify a decimal, such as "std::chrono::seconds(.5)" ?
 
2:45 AM
or std::chrono::milliseconds
 
Alright, thanks for the help :]
 
If you write using namespace std::chrono_literals;, you could also write std::this_thread::sleep_for(3s) or std::this_thread::sleep_for(500ms)
 
We're generally encouraged to stick to "using namespace std"
 
If you had a using namespace std; already, you can also just use 500ms and it will work.
 
Also, I'm getting an error that I don't know how to parse:
/tmp/ccMKDfcp.o: In function `main':
driver.cpp:(.text+0x36): undefined reference to `Menu::cinematic(int, int)'
collect2: error: ld returned 1 exit status
 
Really? Because I was using "2s" before and it was throwing an error.
 
It is C++14 though; maybe you are using C++11
 
Yes, C++11
 
@user8663905 Linker errors are harder to read, yeah. It's saying that you never implemented Menu::cinematic(int, int) (the cinematic method on the Menu class)
 
Hmmm, that's odd, because I definitely implemented it.
 
2:56 AM
Then you aren't compiling with the source file that you implemented it in. If it's implemented in menu.cpp, you need to make sure that you are compiling with menu.cpp (e.g. manual command like g++ -std=c++11 main.cpp menu.cpp
 
user6820627
Can you review this SDL code I just wrote?
 
@user8663905 I've often mess up and think I implemented the function but didn't. Sometimes, it's stuff like writing void cinematic(int x, int y) { ... } instead of void Menu::cinematic(int x, int y) { ... }
 
Ooooooo, right.
the Menu:: bit
 
@LearnHowToBeTransparent I don't know SDL, but from that code, it's clearly a C library. I would want to use a C++ wrapper of SDL. There are wrappers already out there. If you don't want to use an existing wrapper, it's at least a good idea to wrap the types like SDL_window so that SDL_DestroyWindow would be automatically called.
 
(Okay, so, I'm getting something where I want the program to sleep after something has been drawn, but, from what I can tell, it's pausing before it finishes drawing.)
 
3:04 AM
You can do a very simple version of that with std::unique_ptr: std::unique_ptr<SDL_window, WindowDestroyer> window = SDL_CreateWindow(...);, where struct WindowDestroyer { void operator()(SDL_window* window) { SDL_DestroyWindow(window); } };
 
user6820627
@Justin OK. I know an SDL wrapper library (libSDL2pp), but I was hesitant to use it because I thought raw SDL was somehow better than a wrapper. Thanks.
 
Is there a way to ensure that a call to sleep_for is not begun until after a call to another function has concluded?
 
put the call after that function?
function();sleep();
 
3:20 AM
Yeah, that's what I've currently done, but it appears that the previous function doesn't fully finish before sleep is called.
 
Formally, that is impossible
 
The previous function essentially just prints out a field of colored boxes. However, with sleep there, it doesn't finish the field, stopping partway through.
Could it be that the boxes are printed, but sleep stops it in the middle of rendering it to the monitor?
 
Not directly
what are you using to print?
 
cout <<
The code prints "/033[42m" followed by a series of " ", and then, finally, "/033[49m"
 
Well you could try flushing, but I don't understand why the console is stopping...
 
3:29 AM
So, just "flush();" ?
 
Well, I like to use std::cout << "box" << std::endl; maybe this flushes
 
flush fixed it. :]
 
3:49 AM
@user8663905 If you are calling std::flush(std::cout), just FYI that's exactly the same as std::cout << std::flush
 
 
2 hours later…
5:48 AM
Question about pure virtual functions: If you have a function set to be pure virtual in the declaration, what do you need to do in the definitions?
 
nwp
Depends on if the pure virtual function needs to be called.
Usually it doesn't, then you don't provide a definition.
For pure virtual destructors or pure virtual functions that get called manually you need to provide a definition (or = default for the destructor).
If there is no obvious definition that makes sense you probably shouldn't have one.
 
6:05 AM
Alright, and when do you provide a pure virtual destructor?
 
You'd mark a destructor as pure virtual when you want an abstract class and there are no other virtual functions that make sense as pure
 
 
2 hours later…
7:50 AM
@Rithaniel on your concrete types or better, the types you want to instantiate.
....with the implementation you break the abstractness.
quite ordinary
 
nwp
@FerencRozsa What? No you don't.
 
@nwp ...you have to implement otherwise your subclass gets abstract too in that case polymorphie.
 
nwp
8:07 AM
We are probably talking about different things. What I meant is that providing implementations for pure virtual functions doesn't prevent the class from being abstract.
 
8:22 AM
But thats the purpose of pure virtual functions...forcing type depending implementations to given function prototype in your concrete types otherwise they stay/become abstract. So the implementation breaks the abstractness.
 
Ron
8:45 AM
@nwp Have you personally went through the core guidelines?
 
nwp
I briefly looked through them.
 
Ron
I see.
I find some code snippets quite confusing.
 
nwp
@FerencRozsa When you inherit yes, otherwise no.
I'm expressing this really poorly. I apologize for that.
 
9:47 AM
 
nwp
One issue is that scene gets defined once every time the header is included, so you get a multiple definitions error if you include it at least twice.
 
o.k. but it is extern so it should be only defined ones regardless how many times i include the header.
 
nwp
10:03 AM
Oh, wait, I misread that as a single header.
Ignore what I said before.
But there is the issue of the type of scene.
Is it Scene or LMScene?
 
nwp
That looks correct.
How does it "not work"?
 
i get compiler error
missing ";" before scene in GlobalScene.h
 
it's more likely that GlobalScene is missing that semicolon
 
nwp
That indicates that the compiler doesn't understand what Scene is which indicates that Scene.h doesn't define it properly.
 
10:37 AM
I think its a cyclic dependency somewhere.
 
nwp
Does Scene.h include GlobalScene.h?
 
I want to be able to accept 1 to 6 inputs which are all entered at once and then ended with a "-1." Numbers from 1 to 7 are okay, and so is -1 (so long as it's not at the end), but anything else is not acceptable. What would be the best way to do this?
 
@nwp no
 
nwp
@Rithaniel Do you care about error reporting and recovery?
 
int input;
do{
    input = readAnIntSomehow();
}while(input < -1 || input >7);
 
10:42 AM
Yes, if the user enters something incorrect, it needs to say "wait, hold up" and give them a second chance
 
nwp
Would 54631-1. be an example of correct input?
 
Nope, would be in the format 5 4 6 3 1 -1
afk for a moment
 
nwp
std::cin >> some_int; a couple of times can do the int parsing. You can do the error checking directly on std::cin. Recovery can be done with std::cin.clear(); and std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');.
This basically solves the assignment.
 
When i want to use this root pointer i have to do a cast to a complete type static_cast<RootNode*>(additionalSGInfo.root) ?
 
nwp
No, that doesn't do anything.
You need to define what RootNode is in order to use it. Usually with #include "RootNode.h".
 
10:58 AM
yes but it is forward declared in this case
 
nwp
Well, you can't use a forward declared type until you properly define it.
You can use a pointer to a forward declared type, but only if you define it before you dereference it.
 
o.k. so when i want to use it then i have to include RootNode.h
?
 
nwp
If by "it" you mean the RootNode then yes.
Can't use something that is not defined.
 
Okay, I have a small issue: I have set up a colored box in the terminal. When the user enters a '\n,' it erases part of the box. Is it possible to catch a newline character and prevent it from being printed to the terminal when accepting inputs?
 
yes i mean the root node pointer
 
nwp
11:04 AM
If by "it" you mean the pointer then you don't need to define the type it points to. You can copy the pointer, increment it, assign it and so on.
@Rithaniel Not with the standard library. Other libraries like ncurses can do that.
 
Alright, don't want to fool around with ncurses right now. I guess I'll redraw the parts that are disrupted.
 
nwp
Technically you could also do it manually by detecting or assuming the terminal type and then using its commands, but that tends to be quite a bit of work.
Arguably since you are already drawing colored boxes you are already assuming a terminal, so might as well use all the features.
 
@nwp o.k. better, when i want to dereference the pointer i have to include RootNode.h
 
nwp
Basically yes.
 
Ron
@nwp What about GOTW blog? Seems interesting. Would you recommend it?
 
nwp
11:14 AM
It seem like it can make for fun challenges and learning about some dark corners of C++. If that is what you are looking for then it's great.
> [… GotW issues in this range are being revised for C++14 and will appear here as they are ready…]
That's almost all of them and it's been like that for years.
It's one of those situations where it doesn't make sense to update to C++14 because by the time it is done it will be outdated anyways. But if you keep switching targets you never update anything.
 
Ron
I see.
Appreciate it.
 
12:20 PM
Here is an example code from the book I am reading:
string ident(string arg) // string passed by value (copied into arg)
{
return arg; // return str ing (move the value of arg out of ident() to a caller)
}
int main ()
{
string s1 {"Adams"}; // initialize str ing (constr uct in s1).
s1 = indet(s1); // copy s1 into ident()
// move the result of ident(s1) into s1;
// s1’s value is "Adams".
string s2 {"Pratchett"}; // initialize str ing (constr uct in s2)
s1 = s2; // copy the value of s2 into s1
// both s1 and s2 have the value "Pratchett".
}
Then, the writer (Bjarne) says that these operations are executed:
• A constructor initializing a string with a string literal (used for s1 and s2)
• A copy constructor copying a string (into the function argument arg)
• A move constructor moving the value of a string (from arg out of ident() into a temporary
variable holding the result of ident(s1))
• A move assignment moving the value of a string (from the temporary variable holding the
result of ident(s1) into s1)
• A copy assignment copying a string (from s2 into s1)
• A destructor releasing the resources owned by s1, s2, and the temporary variable holding the
 
nwp
> return arg; // return str ing (move the value of arg out of ident() to a caller)
Huh, I remember that not doing a move.
 
The only part I do not get is why is the temporary variable holding the result of ident(s1) not destroyed at the 4th operation, rather than on the last?
Sorry for the spaces between characters, its just how its been copied
@nwp I do not know, its what says in the book. I assumed everything is correct, as the book is from the author of C++.
Although I did think that when function returns, it returns rvalue, so I thought there is a move.
 
nwp
I'm probably just confusing it with (N)RVO.
 
@nwp And, can you help me with my question? Im not sure if you quite catched it, thats why I am seperatly writing this.
@nwp But now that you have said it, how does it happen? Does ident create a temporary of type string and calls move ctor and passes arg and returns that? I mean, is that what he means by the temporary?
 
nwp
12:37 PM
I somewhat understand the question, but I don't really follow what Bjarne is writing here. There should not be any temporary here at all.
 
I'm going to assume Bjarne describes a situation pre-C++17 and with no copy elision done whatsoever (which is impractical because you need to explicitly tell the compiler to not do copy elision)
 
Ok so, what does happen here now (in the example code) ? I thought that when you call a function int foo() { return 1; } that it returns a temporary object of type int which contains the value 1. Am I going very wrong on this?
 
Oh I get it
Bjarne doesn't present the order of the operations
He groups them in the respective categories
 
12:52 PM
Oh okay. That explains it then. So the temporary, in fact, is destroyed before s1 and s2 are, right?
 
And what about this thought of mine. Is it incorrect?
 
nwp
When you write int i = foo(); there is no temporary. Instead foo directly instantiates i with 1 without temporaries or copy constructing.
 
@nwp Because of copy elision?
 
well, these are trivial types anyway
 
nwp
12:56 PM
You can't really tell with int, but if you write a class that prints something when being copied you will see a lack of output there.
@MuhamedCicak Yes.
 
So, as milleniumbug said, Bjarne describes a situation without copy elision?
If so, what does happen then? I mean, when there is no copy elision.
 
nwp
Without copy elision you get what bjarne wrote. I guess.
Arguably since copy elision has basically always existed and is required for C++17 the question of what happens without copy elision is mostly pointless.
 
@nwp Hmm. I see.
Thanks you both guys for explanation and the help.
 
Good day!
So I'm currently working through SDL in C++ and I'd say I've got quite good progress - however, I've seem to hit a rather interesting obstacle.

I've got this textures folder with, currently 18 PNG's in it, and for some reason, it fails to load one specific PNG.
Any ideas on why this is happening? If it would be multiple, or all PNG's it would be one thing, but I'm very conflicted as to why it is one - specific - PNG
If it helps, this is what the function looks like that loads the images.
And the function call looks like:

    SDL_RenderCopy(renderer, tmgr.LoadTexture("skull_overlay.png"), NULL, &bg_overlay);
 
nwp
Maybe it is slightly corrupted or in a different format than the others. Try opening it with mspaint and saving it again and then opening the copy that paint made.
 
1:06 PM
or the file name isn't exactly what you put in there
 
@ratchetfreak Trust me, i've copy and pasted the name back and forth too many times already, lol
@nwp Not a bad idea tbh, one sec
 
in you're on linux, identify the file with file command
 
Ah fuck me. What @nwp said was completely correct. I had downloaded a image, hard-changed it to PNG from JPG, and I guess that broke it enough for the program to not see it
 
most likely it saw the file, opened it, saw the magic number didn't match the extension and aborted
 
Hm
Logical, I guess. But TIL!
 
1:10 PM
see if you can get some debug output from sdl
that may shed some light on errors like that
 
Well I know for a fact that the image couldn't at all be loaded in the first place, so it never "processed" it apart from IMG_Load()
Anyways, cheers for the help!
 
cyclic dependency is a mess....i look for approaches to deal with this...forward declaration or better put the problematic includes in cpp file.
 
Ron
What would be the optimal duration of a C++ training course for a group of 10+ people who are complete beginners, in your view?
I am talking language basics only. Would 2 weeks be a bit of a squeeze?
It probably would...
 
nwp
1:28 PM
Depends on the goals and what they are supposed to be capable of afterwards.
You can steal borrow with attribution some slides.
Although they seems to be too much for 2 weeks.
 
Ron
I know I say this a lot but you people are good. Quite good. Someone should pay you top bucks for your expertise.
 
however we became good over a long period of time
and it gets hard to judge how beginners deal with learning all the information we already know
 
Ron
I see.
The goal would be to get them interested in the language first, as where I am there are almost no C++ developers.
 
nwp
What do people there care about?
 
Ron
So that the company could profit ultimately.
Java, C#, Kotlin. I can't imagine why.
 
nwp
1:36 PM
C++ is relatively decent at expressiveness and performance which should be good arguments against Java.
Arguing against C# is much more difficult.
 
Ron
My goal would be to get them interested in the language and show them just how deep the rabbit hole goes. It was certainly a revelation for me.
Plenty of C++ gigs and no one to fill the positions. It's either that or slave away in some braindead legacy maintenance. And legacy maintenance is no fun for me.
 
Language preference really is up to the thinking mechanism. Some people do like to finish things fast and not care about understanding much, whereas others are willing to spend plenty of time, just to understand.
 
nwp
Be prepared for people objecting that they are already spending all their brain power on the problem and don't have enough left to deal with C++'s complexity.
2
 
Ron
Will do.
I am pitching in a C++ mentoring programme where there is none.
If 3 out of 10 get the C++ joke I would consider it a success.
 
Well technically they're not wrong. There is so little brain power a given person has.
 
1:49 PM
@nwp C++ is as complex as you make it, if you follow value semantics you can do pretty well even without pointers.
@Ron just remember not to teach C first, teach modern C++ idiom and you'll have fewer issues
if they want to learn C on their own time, fine, but don't let it confuse them
 
If you are fighting C++ complexity while also needing to deal with the problem domain, one of them will suffer. Fortunately not a lot of that C++ complexity shows up on daily basis, except for taking forever to build.
Also see's Kate Gregory's talk - full of tips on teaching C++
 
nwp
You can also obsess over The Correct Way™ to make a variable named i of type int with value 0.
 
@nwp whichever way is clearest at the time of declaration
which is probably int i = 0;
 
Ron
2:18 PM
@Mgetz Will do, many thanks.
 
What's an elegant way to find the hash of a string after adding a character at the end and erase one from the beginning in O(1) without having to manually write all the code?
 
Iam trying to find a way to deal with includes in the case of cyclic dependencies...what about this coliru.stacked-crooked.com/a/b6ed832caac5e7e9
 
@Yashas know the hash algorithm and then write out what it would mean for the first char to change, all chars to move up 1 and adding a new char to the end
 
@Yashas std::hash
 
@Mgetz That would rehash the entire string I think.
 
nwp
2:29 PM
@Yashas What does the complexity refer to?
 
@ratchetfreak Is there something in the standard library that could help? I
 
@Yashas then you'd have to do something like an xor hash
 
@nwp Modifying the hash in terms of the length of the substring hashed.
 
nwp
@Yashas I'm fairly sure there is no way around that for cryprographic hashing functions.
 
for the classic sum(c*p^i) it's pretty simple
 
2:30 PM
If the substring is of length M, I want to remove one character from the begining and add one at the end and compute the new hash from the old one in O(1).
 
nwp
If your hash function is "xor all the chars" then it's really easy.
Although calling that a hash function is a bit of a stretch.
 
@ratchetfreak That's what I am doing right now but I had to write all the code for it.
 
@ratchetfreak does it work when you erase the first character though?
 
Im sorry, Bjarne explained it later, I just didn't read below, he said: "An optimizer can eliminate some of this work. For example, in this simple example the temporary
variable is typically eliminated. However, in principle, these operations are executed."
 
Have a mathworks question but not seeing a room. Attempting to create a function to plot position from spherical coordinates (ρ φi, θi)
 
2:34 PM
@milleniumbug subtract what that first char would contribute and multiply with multiplicative inverse of p
 
@milleniumbug subtract c1 and divide the entire thing by p and add last character * p ^ (M - 1)?
 
in need of maybe a link to a site
 
you have overflows though
 
hash' output is already defined in mod 2^bits
 
@user1740058 math.stackexchange.com I assume
 
nwp
2:36 PM
@user1740058 Maybe here.
 
Looks like a cemetery. Thx.
 
Is it possible to iterate over first k characters of std::string_view using range-for-loop?
 
yes
for(auto& c : stview.substr(0, k)) + safeguards
 
safegaurd? if k > strview.size()?
 
yeah all the bound checks and ensuring the temporaries are live while iterating
 
 
2 hours later…
4:32 PM
Hi!
I'm writing MPI code and I thought I could write some wrappers. I've created https://paste.debian.net/1022004/ so that my templated code would be able to recreate the MPI description of type I want to send. It works well for ordinary POD structs but fails when I want to define the translation for a templated type:

template<typename T>
void mpi_dtype< item<T> >::init() {
int lengths[] = {sizeof(item<T>::idx), sizeof(item<T>::val)};
MPI_Aint offsets[] = {offsetof(item<T>, idx), offsetof(item<T>, val)};
Templated type in question is a very simple
template<typename T>
struct item {
unsigned long idx;
T val;
};
 
4:48 PM
I want to later use mpi_dtype<item<T>> with two different types, both template arguments, so I can't specialize void mpi_dtype< item<T> >::init() where I define template item itself.
 
nwp
@aitap Can you make a [mcve] on coliru?
 
Is there a reason code would work on onlinegdb.com
But not with microsoft's compiler?
It keeps glitching out when I compile on my PC
 
> Is there a reason
lots of them
 
I have this code:
If I put in an input of 53+
I get the expected output of 53
 
in Lounge<C++>, Mar 22 '16 at 20:12, by milleniumbug
@sehe I run process in valgrind with valgrind --vgdb=yes --vgdb-error=0 ./my_program and then I follow the instructions (as in, running gdb ./my_program and paste in target remote | /usr/lib64/valgrind/../../bin/vgdb --pid=PID)
 
4:59 PM
If I do the same using the visual studio dev prompt (compiling via cl)
I get 5883
 
Is there a way to detect and treat newlines differently from spaces with cin?
 
@Annabelle what's the full error
 
std::getline(std::cin, line)
 
@Mgetz I don't get an error on compiling or running either
Just run behaviour is different
 
nwp
> ERROR: AddressSanitizer: stack-buffer-overflow
in main.cpp:115
@Annabelle Use better tools or settings.
 
5:03 PM
I guess I should just install cygwin on my PC and use g++
 
or WSL
 
Oh right
forgot that existed
 
Well, I want 1 to 7 entries, each separated by a space, but, in case a newline character is entered, to run a particular code snippet.
 
Feb 24 '17 at 20:12, by milleniumbug
@sweg_yolo_69 read entire lines with std::getline, split the lines by using std::stringstream
 
nwp
@Annabelle That's the line temp_num += atoi(chi); so you should read what atoi does and why it failed.
 
5:07 PM
atoi is garbage
can't distinguish valid input from invalid input
 
nwp
> This frame has 5 object(s):
[32, 33) '<unknown>'
[96, 97) 'ch' <== Memory access at offset 97 overflows this variable
[160, 168) 'num_el'
[224, 232) 'popped'
[288, 320) 'line'
Sometimes ASan is really neat.
 
very good SSCCE
 
nwp
Yes, minimal enough.
template<typename T>
void mpi_dtype<T>::init() {
	type.dummy = (void*)0x42;
}
That would be a workaround.
If you want to explicitly express that T must be an instantiation of item then there are ways to do that, but it's probably not necessary.
 
There must have been something I left off. In my mpi_dtype< item<T> >::init() I actually need to create an instance of mpi_dtype<T>, so there has to be a way to distinguish them.
 
5:22 PM
Well it more or less works fine now
But for some reason it isn't exiting loop when I divide by zero
Example expression is: (56/0)
Instead it just says result: 0
 
nwp
You didn't even fix the error that I pointed out :(
 
I mean it's not throwing any error when I use onlinegdb to compile
So I'm not sure what there is to fix
for atoi
 
nwp
The stack buffer overflow on the variable ch.
 
Uhm, I don't see how a stack buffer overflow would occur, it's only one character, no?
 
const char* chi = &ch;
temp_num += atoi(chi);
 
nwp
5:26 PM
It is. And that is not enough for atoi.
 
...really?
 
Hmm
 
nwp
20 mins ago, by nwp
@Annabelle That's the line temp_num += atoi(chi); so you should read what atoi does and why it failed.
I recommend you actually do that.
 
Oh it needs to be nul terminated it seems?
 
nwp
Basically yes.
 
5:28 PM
temp_num *= 10;
const char* chi = &ch + '\0'; // Need nul termination
temp_num += atoi(chi);
Does that work?
 
Damn it
How do I fix it then? Cause that's as much as I managed to understand from it.
 
49
Q: How to convert a single char into an int

jonsbI have a string of digits, e.g. "123456789", and I need to extract each one of them to use them in a calculation. I can of course access each char by index, but how do I convert it into an int? I've looked into atoi(), but it takes a string as argument. Hence I must convert each char into a stri...

 
Oh.
Huh.
So it follows then...
temp_num *= 10;
int digit = ch - '0';
temp_num += digit;
 
this of course assumes that ch actually has a digit
 
5:31 PM
Well I'm using the isdigit()
to check for it
and all inputs are well formed according to assignment
So uhm I still don't understand why the divide by 0 is failing
 
@nwp Could you give me a hint on how could I apply stackoverflow.com/questions/165101/… in my case? I have to distinguish mpi_dtype<item<T>> and mpi_dtype<T>.
 
It doesn't quit the loop as it should
I check for the operator and operand to be a division and 0, and I set a flag and then break out of loop.
 
nwp
22
Q: C++11 is_same type trait for templates

user2052436Is it possible to check that type T is an std::array of arbitrary type and size? I can check for a particular array, for instance: is_same<T, std::array<int,5>>::value But I'd like to check that T is any instantiation of std::array. Something like below (which, of course, does not compile...

Note that mpi_dtype<T> includes mpi_dtype<item<T>>, so you need to distinguish mpi_dtype<item<T>> and "mpi_dtype<T> where T is not an instantiation of item".
 
6:02 PM
@nwp Thanks, I'm going to specialize the whole class.
 
or, extract the specialized bits into a base class
and specialize only that one
 
Hmm trying to refactor it and check for the flag before I read in/process another character
Isn't working either
 
6:24 PM
https://stackoverflow.com/questions/29776122/c11-noexcept-specifier-definition-versus-declaration
What does it mean?
struct S { void func() noexcept(true);};
void S::func() { std::cout << "test" << std::endl; }
Compilers don't like this
How can noexcept be omitted?
 
you misread the answer basically
 
haha noexcept(false)
thanks
 
6:54 PM
hey guys, I'm trying to write a scope time profiler and I want to measure the execution time IN THIS WAY:
PROFILE("some desc text")
{
// block to be measured
}
how could this be done?
I can successfully do the following, but thats NOT what I'm looking for:
{
PROFILE("desc");
// rest of the block
}
 
a.k.a. you're looking for a dumb macro that does this
#define PROFILE(whatever) if(auto x_whatever_so_it_wont_collide = underlying_shit(whatever)) {} else
then again, this sounds like something you could do with lambdas, no need for macros
profile("some desc text", [](){/* block to be measured */ });
also, nonius.io
 
I wouldn't recommend it, but you could do similar tricks to SCOPE_EXIT with #define PROFILE(desc) something_t{desc} + [&] where something_t is a type with an overloaded operator+ that calls OLD_PROFILE(desc) and calls the lambda.
Your syntax would then be PROFILE("some desc text") { /* measure this */ }; (an extra semicolon)
 
7:28 PM
@milleniumbug how could one pass a macro block to the `
profile("some desc text", [](){/* macro block */ });` example?
so thatd achieve what im looking for
 
Why do you want it to be a macro @YvesHenri?
What does "macro block" mean?
 
MACRO("foo")
{
// macro block
}
 
I don't understand what you mean. How is this different from a normal block?
 
7:38 PM
that's a dumb use of macro
 
^
And the compile error is because you have Function& as the type of the parameter. You want either Function const& or Function&& (this last one can bind to const&, &&, or regular &; it's special)
 
its slightly less verbose
 
wow 4 characters
 
so why not?
 
2 characters actually. You can leave off the () on the lambda like [] { ... }
 
7:42 PM
its slightly more intuitive for those not familiar with lambdas
 
no, not really
 
its has slightly more advantages :)
 
Why not: 1. Macros are to be avoided. They are not namespaced, so the naming scheme has to be very careful. Also, when you see a macro, it's not completely obvious what it should do. I see PROFILER("desc", { .... }); and it's immediately unclear what it does. I see profiler("desc", []{ ... }); and it's immediately clear that that's a lambda that can be called
 
you polluted all the namespaces with a macro, needs extra explanation what does the syntax mean
 
PROFILER("desc", { ... }); isn't more intuitive with those unfamiliar with lambdas; it has a lambda with a weird syntax.
 
7:45 PM
also lol, you broke it by adding an extra semicolon
you failed "How to write macros 101"
but hey, we saved 2 extra characters
 
ok, I'm convinced lol
thank you
 
8:37 PM
Hmm
Okay I figured out that my division is failing somewhere
So trying to fix this I did:
result.operand = (double)num_1.operand / (double)num_2.operand;
but no matter what I'm doing, it always returns 0 when dividing
 
what's the input
 
@Annabelle suggestion to avoid C style casts... they may not do what you intend
 
two unsigned ints
I was simply trying whatever I could @Mgetz
 
bzzzzzt wrong answer
what is the text you're actually typing into the program
also
2 mins ago, by Annabelle
I was simply trying whatever I could @Mgetz
this approach never works
 
8:58 PM
oh
(55/11)
 
@milleniumbug I'm having trouble moving specialized bits into base class: compiler keeps asking for declaration of the function I would expect it to pick up from said base class: coliru.stacked-crooked.com/a/a1e8d5217cf8365d
 
make it this->mk() instead of mk()
 
So how would I fix it? @milleniumbug
 
@milleniumbug Thanks! It fixed the example; off to implement it in the actual code...
 

« first day (653 days earlier)      last day (2203 days later) »