« first day (536 days earlier)      last day (2320 days later) » 

1:53 AM
@Justin When does that happen. You can just right an avatar and start a room
@FerencRozsa nudzje
 
 
3 hours later…
5:13 AM
wtf is this:

FastLED.addLeds<LED_TYPE,PUPIL_DATA_PIN,COLOR_ORDER>(PUPIL_LEDS_OUT, NUM_PUPIL_LEDS)
the actual function definition has nothing like <LED_TYPE,PUPIL_DATA_PIN,COLOR_ORDER>

https://github.com/FastLED/FastLED/blob/master/FastLED.cpp#L33
but instead has CLEDController *pLed,
as an argument
CLEDController &CFastLED::addLeds(CLEDController *pLed, struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset) {
Can someone explain this syntax to me?

FastLED.addLeds<LED_TYPE,PUPIL_DATA_PIN,COLOR_ORDER>(PUPIL_LEDS_OUT, NUM_PUPIL_LEDS)
the actual function definition has nothing like <LED_TYPE,PUPIL_DATA_PIN,COLOR_ORDER>

github.com/FastLED/FastLED/…
but instead has CLEDController *pLed,
as an argument
CLEDController &CFastLED::addLeds(CLEDController *pLed, struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset) {
where does the <LED_TYPE,PUPIL_DATA_PIN,COLOR_ORDER> go?
 
@SephReed Looks like that function is a member of a class named CFastLED. Look at the class for the template arguments.
 
this is the line of the function. I don't see anything template looking.
 
then you must be calling a different addLeds() function
you are passing 2 args and the one you just linked requires 4
this addLeds() is a template function
looks like addLeds() is overloaded several times
 
5:29 AM
thank you so much. I could not for the life of me understand what was going on there.
 
 
2 hours later…
7:43 AM
@SephReed Look in FastLED.h. There are overloads which accept template parameters
 
8:01 AM
In case someone other than me finds this useful (I was about to ask it here before I came up with an answer): I had an assertion macro MY_ASSERT(cond) that could be removed by the preprocessor, and I wanted to test that it threw an error with the right settings, and did nothing with the other setting. So I needed to turn empty text into an expression. The way I found was to wrap it in a lambda and invoke it: [] { MY_ASSERT(cond); }()
 
 
3 hours later…
10:45 AM
@sehe What you mean exactly ?
 
 
1 hour later…
11:46 AM
@Justin FTR the actual assert macro is not removed, but replaced with a no-op expresion, usually it's (void)0
still, this is a nice trick, macros usually need some "creativity" to them
10 messages moved from Lounge<C++>
 
12:02 PM
I have used an std::unordered_map to maintain a character count. I want to sort the contents and loop through in the sorted order. What are my options?
I can use a std::vector<std::pair<char, int>> but that's going to make the [] operator ugly because now I cannot directly use the character as the index.
The other option I thought of was to make a copy of count in a std::vector<std::pair<int, char>> but this makes me feel silly because I could have used a vector intially.
 
std::array<int, 256>
 
I would have excess elements
I need to loop through non-zero elements after sorting.
I wouldn't need an extra check if I use unordered_map but vector and array will require extra check. It'll also slow down the sorting but I think that's negligible.
 
benchmark that shit first
 
I am not concerned about the speed. I want to make it look tidier.
 
12:28 PM
@milleniumbug After sorting, I would need to know which character had the measured count.
 
How can I always check pressed keys with something like the following codes?
HHOOK hHook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)Process_Shift_Esc, 0, 0);
LRESULT __stdcall Process_Shift_Esc(int nCode, WPARAM wParam, LPARAM lParam)
{
	if (nCode >= 0 && wParam == WM_KEYDOWN)
	{
		KBDLLHOOKSTRUCT kbdStruct = *((KBDLLHOOKSTRUCT *)lParam);
		if (kbdStruct.vkCode == 0x1b && GetAsyncKeyState(VK_SHIFT) & 0x8000)
		{
			MessageBox(NULL, TEXT("Control-A combination has been pressed!"), TEXT("key pressed"), MB_ICONINFORMATION);
		}
	}
	hHook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)Process_Shift_Esc, 0, 0);
 
12:51 PM
@MRS1367 I do not understand this code and your question because I happily forgotten most of what I learned while writing a WinAPI program a year ago. MSDN dat joint.
I also cannot understand why would you want to check for pressed keys instead of keeping track of key messages in your program.
 
@EuriPinhollow I want to check for Shift+Esc keys always
and if the above-mentioned keys are pressed, I want to terminate my current process
 
You cannot do it "always" because of CPU scheduler and other code of your and OS programs being executed obviously.
 
I want to set a global boolean variable to true every time that above-mentioned keys are pressed
 
You get a message every time a key is pressed, what do you want to monitor then?
 
@EuriPinhollow It's a sample
The code in the if condition is just a sample
 
1:01 PM
Well, this is a sample for doing exactly what you want to do.
I do not understand your question.
 
1:31 PM
Why is std::map slightly (~2%) faster than std::unordered_map?
There can be at most 10 elements in either container.
Changing values to std::array<int, 256> almost doubled the speed.
 
1:59 PM
@Yashas because it is
locality of reference, prefetch, branchiness (i.e. instruction pipelining), allocations.
Depending on operations: vectorization
@Yashas nudzje
@FerencRozsa Sorry, I nudged the wrong person by accident :)
 
no problem
but anyway what would you suggest for my problem ?
 
@sehe I paused working on it for a while :)
 
2:19 PM
@sehe I still can't figure out why std::map would be more cache friendly than std::unordered_map.
The nodes in a std::map exist at different locations while the items in an unordered_map exist close to each other?
With std::map, the lookup would involve checks but with std::unordered_map, there isn't any conditional check except for bucket count?
Computing the hash for a character isn't costly, right? There would be a function call overhead though.
 
2:35 PM
> :)
o.O
@Yashas I didn't say it is. Profile it. Your profiler can tell what exactly is taking more time.
 
2:54 PM
@FerencRozsa The hand tracking? I think I gave all the hints I have (not even body is tracking hands)
imgur is acting up (stuck)
 
@Yashas the difference is so small that it can be attributed to architectural difference between CPUs and compiler optimizations. Try -O0 probably. Also STL is implemented by meat coders so there is no guarantee of code being optimal.
 
@EuriPinhollow I was compiling with g++ without any optimization flag (defaults to O0 I think). With O3, the entire program speeds up by 500% and the difference is not measurable.
 
@sehe no sehe....the tracking is not the problem, its the realization of an switch to react of problem cases which i described before -->> chat.stackoverflow.com/transcript/message/40604442#40604442
 
@Yashas then open the header and study implementation.
 
Holidays are not good for me. I rethink about several things in my application. When i create virtual objects, i have to pass through three steps. i have to create the necessary nodes, i have to setup the nodes, which means combine them together, and last, the drawing over the adding to the root node. Is it a good approach to encapsulate these steps in individual methods or better in one method maybe...draw3DPrimitive() ?
 
3:18 PM
@FerencRozsa that's what tracking means
It was also the only message I replied to. And I think I was the only one to reply.
@Yashas 10 elements is almost the territory for arrays/vectors
 
Hi all
"Friday, rebooting the server, hope no one uses it"
 
3:43 PM
This stupid server doesn't rebooted !
and I cannot move to start it manually
and the sys admin is on vacancy
 
4:13 PM
Hi
I tried to use RegisterHotKey for detect my keys
It works like a charm.
but if I want to register two Hot Keys, it only catches the second registered hot key, why?
 
Monogamy
 
4:43 PM
That's what I wonder about too, make sure to post an answer here when you find it.
 
I find this accepetd response: stackoverflow.com/questions/4704134/…
to register multiple hotkeys
 
Question about reinterpret_cast
I've read cppref on it and seem to understand everything except a few details, the first one:

struct S { int x; };
struct S1 : S {}; // standard-layout
S1 s1 = {};
auto p1 = reinterpret_cast<S*>(&s1); // value of p1 is "pointer to the S subobject of s1"
auto i = p1->x; // OK
p1->x = 1; // OK
So the behavior is defined for this code, ok
 
so just incrementing hthe id...
 
I want to know why is it defined in terms of words above (on cppref)
There are rules it's aliasing through pointer
Behavior for aliasing is defined in 3 cases by the words of cppref
Whenever an attempt is made to read or modify the stored value of an object of type DynamicType through a glvalue of type AliasedType, the behavior is undefined unless one of the following is true:

AliasedType and DynamicType are similar.
AliasedType is the (possibly cv-qualified) signed or unsigned variant of DynamicType.
AliasedType is std::byte, (since C++17)char, or unsigned char: this permits examination of the object representation of any object as an array of bytes.
Where similar is basically 'cv-different-excluding-function-types-cv'
So the example above doesn't seems to fit into any of these rules
But cppref also states 2 more rules where aliasing behavior is defined by the standard
AliasedType is an aggregate type or a union type which holds one of the aforementioned types as an element or non-static member (including, recursively, elements of subaggregates and non-static data members of the contained unions).
AliasedType is a (possibly cv-qualified) base class of DynamicType.
There 2 cases
But cppref writes on these 2 cases that they cannot appear in C++, only in C
That's kinda awkward to me :/
 
yeah it's interesting
there are no "base classes" in C
 
4:54 PM
Base class in C -_-
These bullets describe situations that cannot arise in C++ and therefore are omitted from the discussion above. In C, aggregate copy and assignment access the aggregate object as a whole. But in C++ such actions are always performed through a member function call, which accesses the individual subobjects rather than the entire object (or, in the case of unions, copies the object representation, i.e., via unsigned char). See core issue 2051.
So basically I don't understand this paragraph
Haven't looked at CWG thing, sorry, a bit scared to :D
 
@ledonter looks fine
 
Well.... ok, let's take something a bit simpler
I thing a have a clue about it now having thought abotu it more, but still...
struct S1 { int a; } s1;
int* p1 = reinterpret_cast<int*>(&s1);

Am I correct that accessing *p1 here is well-defined?
 
yes
 
So type aliasing is defined for this case
What are DynamicType and AliasedType here then?
S1* and int*?
Or is it more of S1 and int are these types here?
 
I don't know :) I stay away from those. I haven't read the lengthy texts you pasted/referred to - I just replied to the simple questions I know how to answer
 
5:04 PM
Without pointers
 
@ledonter while it may be defined that copy assignment is a member function call there is no obligations for a compiler to not inline it.
 
Yeah, I guess I understood the paragraph with CWG 2051, thanks
 
:)
 
And as for the 2 types, I'm pretty sure they are just int and int in my example
And I think the last question on aliasing
AliasedType is the (possibly cv-qualified) signed or unsigned variant of DynamicType.
I'm confused about how such types can be used
int i = 7;
// type aliasing through reference
reinterpret_cast<unsigned int&>(i) = 42;
std::cout << i << '\n';
There is even an example of this
But like, what should happen if I reinterpret_cast<int &>(i) where i is INT_MAX + 1?
What should be the value of resulting variable?
like
unsigned i = INT_MAX + 1;
int &x = reinterpret_cast<int &>(i);
std::cout << x << std::endl;

I understand I can test it :) But I'm curious about how it's defined
Or will the value after reinterpret casting to another-signedness-type be unspecified?
So it would work almost like single element union :)
Such stuff is undefined for unions though
IIRC
So basically
#include <iostream>
#include <utility>
#include <climits>

int main()
{
unsigned i = unsigned(INT_MAX) + 1;
int &x = reinterpret_cast<int &>(i);
std::cout << x << std::endl;
}
stacked-crooked gives -2147483648
Is it guaranteed to be that value?
 
keep in mind in the memory, this bits values for signed, unsigned, double,, float are the same
the bits*
 
5:16 PM
@Phiber hell what
 
example: 32 bits integer
 
@ledonter binary representation of numbers is defined by C++.
 
int i = 30
double x = (double)i
here, the conversion (double) don'y change the bits values
 
Well, thanks, unfortunately this doesn't answer the question for me :)

Ok, as I remember unsigned stuff is guaranteed to be 2-s complement and signed has pretty much no restrictions on representation whatsoever

So I guess reinterpret_cast signed to unsigned and back will give unspecified values....
But....
#include <iostream>
#include <utility>
#include <climits>

int main()
{
int i = 7;
// type aliasing through reference
reinterpret_cast<unsigned int&>(i) = 42;
std::cout << i << '\n';
}
Anyone understands how this gives 42?
I mean, I thought it would assign bitwise as if it was assigning to an unsigned...
 
5:24 PM
You could at least have a look at that whole page to see what it is about. Do you actually know what 2's complement representation is?
 
I just run your code and it give me : 7
not 42
tested with qtcreator, windows, mingw, 32 bits
 
I... think I know :D
Ok, I think I got what you meant
representations are the same in this particular case
Hm, maybe your ints are not 2-s complement :)
The resulting value is generally unspecified though as I understand now, hope I'm correct, thanks
I guess it's all for reinterpret_cast, it's not as hard as I thought it would be :) thanks again for this :)
However 7 looks more of a UB to be, like the assignment was just ignored
GCC gives 42 on all the '11/'14/'17
 
@Phiber it is an error in the compiler then.
 
So I would think your compiler is doing strange things here
However unchanged value fits into 'unspecified'
So I think the compiler is still complying :)
@EuriPinhollow do you agree with me? I mean, the resulting value is unspecified unless you assign it with the corresponding type
(I'm not sure it's actually true, haven't found anywhere but I hope it's true :)
with the corresponding type*
 
Thanks for those edits, magnitude better now.
Yes, standard says so.
 
5:36 PM
Could you point where? :) I was unable to find this specific thing
 
reinterpret_cast<unsigned int&>(i) = 0xFFFFFFFF ; // can you test with this?
 
Test it yourself on coliru.stacked-crooked.com
 
i = -1 :)
 
I don't see anything surprising :) unsigned and 2's complement differ here
Anyway, next up, declarations, and again not clear immediately :(
cppref:
Function definition
Template declaration
Explicit template instantiation
Explicit template specialization
Namespace definition
Linkage specification
Attribute declaration (attr ;) (since C++11)
Empty declaration (;) (since C++11)
A function declaration without a decl-specifier-seq:
Block declaration
> A function declaration without a decl-specifier-seq:
So, a simple question immediately arises for me
int func(int);
Where does this fall?
Is this NOT a declaration? really?
A declaration is one of the following:
 
http://eel.is/c++draft/expr#basic.lval-11
Actually it is not sufficient to point just at that paragraph to say that it is well-defined to do something because it can be declared as UB in different place but yes, aliasing `int` as `unsigned` and vice versa is fine.
 
5:53 PM
@EuriPinhollow yeah, got this, thanks
Could you also help with where does 'int func(int);' fall into?
To which of categories above
(I just copypasted the categories from cppref)
http://en.cppreference.com/w/cpp/language/declarations
 
It's >A function declaration without a decl-specifier-seq:
 
Quote from cppref page
A function declaration without a decl-specifier-seq:
attr(optional) declarator ;
attr (since C++11) - sequence of any number of attributes
declarator - A function declarator.
This declaration must declare a constructor, destructor, or user-defined type conversion function. It can only be used as part of a template declaration, explicit specialization, or explicit instantiation.
As I understand, 'without decl-specifier-seq' mean we can't have (at least non-trailing) return type
and
int func(int)
has it
@EuriPinhollow am I incorrect?
 
decl-specifier-seq is described below on that page
oh wait
 
yeah :)
 
int func(int); can appear in the block scope
 
6:00 PM
So it's not a declaration or?..
 
> A declaration is one of the following: [...] Block declaration (a declaration that can appear inside a block), which, in turn, can be one of the following:
> simple declaration
 
@ledonter yes, you are correct and I am not.
 
@milleniumbug OK, yes, got this, thank you
By the way
A function declaration without a decl-specifier-seq:
attr(optional) declarator ;
attr (since C++11) - sequence of any number of attributes
declarator - A function declarator.
This declaration must declare a constructor, destructor, or user-defined type conversion function. It can only be used as part of a template declaration, explicit specialization, or explicit instantiation.
As I understands such declaration is smth like
S();
Is this a valid example?
I'm just confused about
> only be used as part of a template declaration, explicit specialization, or explicit instantiation
Like it seems like just a declaration of a constructor
 
Combine your messages please.
 
@EuriPinhollow how to do it? and what is the purpose? :D sorry if I'm doing smth wrong
 
6:07 PM
hi
 
The purpose is to make it easier to read. Also use backticks for code and "> quote" for quotes.
> quote
@ledonter this specific type of declarations is for member functions, it is written right there.
 
Well, anyway
S(); is just a declaration of a constructor
Why can't it be used as a part of just class declaration?"
And I don't see how it can be a part of instantiation... that one always uses decl-specifier-types as I see (at least for functions)
 
Not that it became clearer :D
Anyway

Could anyone at least provide a couple of examples of this "function declaration without a decl-specifier-seq" in action?
 
6:32 PM
Find this: "This declaration must declare a" in the page you linked and you will see what exactly it should be.
 
"It can only be used as part of a template declaration, explicit specialization, or explicit instantiation."
But why this? Isn't constructor in just a class the same thing?
 
7:03 PM
@EuriPinhollow you just cited the same thing I did, didn't you? :)
I mean why is this so?
E.g.
struct S { S(); };
S::S() {}
isn't S() inside the struct the same thing?
 
See member-specification on the gram page.
You won't see nodeclspec-function-declaration there.
I am now searching for good explanation of what this grammar production is.
Wait more.
Disregard that, I was clearly wrong.
 
What do you mean?
I don't see anything wrong in your words
 
It is not mentioned right there but there is a sequence of productions that leads from member specification to nodeclspec function declaration.
 
Oh, ok
So then is
"It can only be used as part of a template declaration, explicit specialization, or explicit instantiation."
incorrect?
 
If it is written in the standard it can't be incorrect.
 
7:12 PM
Yeah
"It is not mentioned right there but there is a sequence of productions that leads from member specification to nodeclspec function declaration."
I don't think it's true
There is member-declaration for inside-classes, but nodeclspec only appear in just "declaration"
But then what is that S(); inside the struct? :)
 
@ledonter you can actually make Clang dump parsed grammar of a program IIRC, do it while I am reading standard.
 
Oh, I don't think that would be easy for me if I had computer at hand, but now I only have an iPad :D
 
You have Coliru which has Clang++ available.
 
Well I tried -ast-dump and -ast-print but I don't see anything similar to the answer...
Sorry, I don't think I would be able to get anything meaningful from that
 
7:36 PM
I was right when I said that nodeclspec-function-declaration cannot be produced from member specification. It totally can be a leftover from some old standard, eel.is is current draft.
I went through the grammar production and could not find a way from member specification to that.
declaration
can produce nodeclspec-function-declaration

declaration-seq
can produce declaration

namespace-body
can produce declaration-seq


linkage-specification:
extern string-literal { declaration-seqopt }
extern string-literal declaration

template-declaration:
template-head declaration
template-head concept-definition


explicit-instantiation:
externopt template declaration

explicit-specialization:
template < > declaration
 
Well, does this relate in some way to my question of what grammatically is S(); inside struct S?..
 
Yes. It is function definition inside member specification.
 
So does func definition allow no-declspec by itself?
Why then invent special func declaration for that?
 
Yes it does: http://eel.is/c++draft/dcl.fct.def.general#nt:function-definition
Also, I am not a fuckng oracul.
 
Don't be so aggressive :D
 
7:43 PM
It is probably for off-class definitions of constructors.
 
What 'it'?
 
The grammar production which you want to know purpose of.
Also:
> In particular, the grammar described here accepts a superset of valid C++ constructs.
 
By the way this is a definition
I don't see that it allows no body
 
Let me check.
Yes, that was dumb.
It is member declaration and it does not have a specific name: eel.is/c++draft/class.mem#nt:member-declaration
Look at the first production in the member-declaration.
 
That seems reasonable, yes..
I'm just woondering what for they invented that not-declspec special thing...
Probably for things like instantiations
 
7:52 PM
Probably not because I could not think out a single example which compiled.
 
So do you understand why templates use not-declspec instead of a simple member-spec for constructors destructors and UD-convertions?
I don't
I think it's probably worth a question on SO :D
What that thing is for
I'll ask it in a few hours I guess
 
Actually, try Google to get a slight clue (as I did now): google.ru/search?q=%22nodeclspec-function-declaration%22
 
8:21 PM
I tried, you're a better googler :)
 
> google.ru
 
>there are no russians on SO
>all russians are on russian.SO
 
I'm russian as well, russian SO is BS, sorry
https://stackoverflow.com/questions/36768804/how-can-f-be-a-declaration-below
As for this, I didn't understand why there is a restriction on templates :(
@Ayrosa That note is correct as written. Different productions are used for the non-template cases. – T.C.

But there is
Oh, maybe because there can't be local (block scope) templates?
It seems like a good guess...
@EuriPinhollow do you agree?
I guess finally it's clear, but it's really a pain to look up stuff like that in the docs...
So that you have to know the internal language grammar for it to make sense
Oh C++ C++ :(
 
8:36 PM
@ledonter What do you need to know it for. It's all context dependent. I mean, I don't blame you for being curious and wanting to know the ins/outs, but the fact of the matter is that you never need reinterpret cast.
It's something people want because ~~purformance~~. Nevermind that performance is usually quite ok without hazardous tricks.
Of course, if you aspire to be a library writer, go for it. The more you know, the better.
 
Ehhh... it's not at all connected with reinterpret_cast, that one is much cleaner :D
I just opened a 'declarations' page on cppref, which I think is designed for most C++ users :)
And there was this:
A declaration is one of the following:
...
A function declaration without a decl-specifier-seq:
This declaration without ....
 
@ledonter What are you looking at this time then? I'm p. sure I can put out the exact same argument mutatis mutandis
@ledonter No. cppref is designed to bridge the gap between end-user doc and the standard(s)
 
That declaration case is only explained by this answer
https://stackoverflow.com/questions/36768804/how-can-f-be-a-declaration-below
:)
 
So it contains a lot of pointers to legalese. Making it an awesome resource BTW. By far the best there is
 
But what is end-user doc then? :(
 
8:41 PM
They don't exist. Also, it's self-defined as documentation for end-users.
That would be: programmers (not library writers, proposal writers, language lawyers, etc.)
 
So, if I understood correctly, cppref is in the end still the end-user doc in absence of other one, correct?
 
cplusplus.com used to be an attempt at "end-user docs". I guess.
@ledonter Yes.
Which makes it easy to mistake it for "designed for most C++ users". It's just the best there is, you need to pick and choose.
 
Well then it's a pity C++ doesn't a good user doc, and I guess will never have...
 
E.g. the fact that std::uninitialized_fill_n and std::launder are there, doesn't mean you should know about them or use them
@ledonter I guess you can answer this rhetorical question: "Why doesn't it" / "Why will it probably never have"?
:)
 
:(
 
8:44 PM
It comes with the territory. But see:
43 secs ago, by sehe
E.g. the fact that std::uninitialized_fill_n and std::launder are there, doesn't mean you should know about them or use them
 
Yeah of course I understand it
Still have my unhappiness-points :)
2
 
It's just that C++ required people to have the discriminatory capabilities to navigate essence and contrivance
2
@ledonter Awarded :) This kind of discussion is probably more on-topic in the Lounge.
The Lounge is where the grumpy C++-ers go to moan about defects, std::async and life in general.
And to celebrate the ugliness of it all.
 
Great, so let's end it here
Just what I wanted to say
> It's just that C++ required people to have the discriminatory capabilities to navigate essence and contrivance
That's a good one btw
 
I'm pretty sure I made "contrivance" up. Sry :)
 
It does exist in GT
 
8:48 PM
Oh golly. Google says it exists
Made my day
(that wasn't sarcastic. just programmer-puppy happiness)
 

« first day (536 days earlier)      last day (2320 days later) »