« first day (1249 days earlier)      last day (1607 days later) » 

12:32 AM
@rezi-ReinstateMonica To an extent, it's just how SO works. The volume of questions is high enough that a question only stays on the front page for a very short time. I'm pretty sure they don't publish the algorithm, but I think it gets to stay on the front page longer if it receives up-votes. So basically, if somebody up-votes it quickly, it stands a good chance of getting a lot of up-votes. If it doesn't get up-voted quickly, it drops off the front page, losing most of the chance for up-votes.
 
 
9 hours later…
9:03 AM
Thats... damning.
 
 
3 hours later…
11:54 AM
In case anyone is interested, this is the answer my professor gave me (about the question above):
Both inheritance and standard composition suffer from the instability of WIP's data organization. At each new WIP release all sources defining and using OpusMagnum objects must be recompiled, because their data structures have likely changed.

This can be avoided using bridging: OpusMagnum now defines a pointer to a WIP object, allocating the object during OpusMagnum's construction, and using OpusMagnum's destructor to destroy it again:


class OpusMagnum
{
WIP *d_wip;

OpusMagnum() // in-class for brevity
 
 
1 hour later…
nwp
1:16 PM
@rezi-ReinstateMonica Tell them that now the compiler doesn't see the inner workings of WIP anymore and therefore cannot optimize properly.
I'd say they are putting way too much priority on avoiding recompilation.
Also you have to reimplement the whole interface of WIP inside OpusMagnum. That seems like a huge amount of code and bugs for insignificant gain.
Also d_wip should really be a std::unique_ptr<WIP> which avoids all this boilerplate code.
 
1:35 PM
@nwp thanks, I'll ask about that! (std::unique_ptr<> wasn't covert yet though)
 
I somehow doubt that RAII was covered yet... and yet you're using destructors without understanding the real why
 
 
3 hours later…
4:56 PM
Sooooo we lately learned about variadics... they look usefull, but i hate the syntax... lets say we have a template<class T, class ...List> doSomething(T first, List ...second), how do i call this function ? When i call " doSomething('a',120,500,20); my IDE tells me that this isnt possible
doSomething<char>('a',120,500,20); isnt possible either... whats the right syntax to call this function properly ?
 
nwp
Looks like you need a better IDE.
Looks valid to me.
 
Really ? Wait... im gonna copy CLions error message... weird
This is what i get... prnt.sc/q9ygaw
 
nwp
Run the compiler, see what error message you get there.
 
@nwp ahhh... is it possible that variadics cannot be empty ? I quickly checked it and it told me that my variadic method wont work, because i dont have a specialisation which accepts only one single element
 
nwp
Variadics can be empty.
You probably keep removing an element until you end up with 0 elements and doSomething(); or own_print(); is indeed not valid because it requires at least 1 argument.
So probably somewhere you do own_print(second); which sometimes is invalid.
 
5:09 PM
@nwp That makes sense... thanks ! :D
 
nwp
An easy fix would be to add <spoiler>void own_print() {}</spoiler> and it should work.
 
Reminds me of what we did in Prolog...
 
nwp
If you want to be fancy you can do if constexpr(sizeof...(second)) { own_print(second); } instead.
 
5:25 PM
@nwp Thanks im gonna try this ! :D
 
nwp
Requires C++17.
 
Furthermore... why "can" templates only be defined/declared in headerfiles ? Didnt found a easy understandable reason for this...
 
nwp
Partially it's not true. You can defined a template in a .cpp file just fine and it works. The problem arises when you split the declaration and definition into header and source file. The source file doesn't use some instantiation, so it doesn't generate code for it. Another source file includes the header and instantiates the declaration, but then the definition doesn't exist.
This has more detailed answers.
A more accurate rule would be "The user of a template must see the definition in order to instantiate it or someone else must provide the definition", but that's more complicated, especially the "someone else must provide the definition" part.
I would not recommend the #include <something.tpp> inside header approach by the way. The benefit of people not seeing the implementation is not worth the annoyance of having to jump between files. Putting overly long definition at the end of the header with a comment separating them is good enough in my opinion.
 
5:46 PM
I like the rule of the users seing the definition... thats good to remember :D Thanks !
 
6:06 PM
...but (of course) modules will fix this (and everything else, including world hunger).
@genaray Even that's not technically true though. If one user that instantiates a template over a given type sees the definition, then other users that instantiate it over the same type don't need to see the definition. You can, for example, manually make a list of the types over which a template is instantiated, and explicitly instantiate it over those types in one cpp file that also sees the template definition, and then everybody else can just see the template declaration.
That's not always practical, but for some specific situations it can actually be pretty useful (e.g., it can help keep build times under control, and sometimes you have templates that are really only intended to work for some specific set of types, and this can be an easier way to enforce that than using lots of enable_if and such.
 
nwp
Maybe "Someone must have instantiated the definition" is the correct rule. Unfortunately that doesn't help anyone.
 
@nwp Yeah--it's had to come up with a formulation that's entirely accurate, easy to understand, and helpful. That's why I tried to make it clear that this is mostly a technicality--from a practical viewpoint, I think your formulation is perfectly reasonable (with the proviso that somebody might eventually ask something about "how could this possibly work--this code couldn't see the definition...").
 
6:22 PM
Looks like this is a big topic :o googled a bit and found some forums where c++ developers nearly went crazy about this ^^ atleast it seems like theres a lot of critic
Meanwhile i went into another template problem... prnt.sc/q9zkwz tried to write my own print method... but in case the input ends with a string, it should use the specialised abort function... when i try to run this, the compiler complains that there multiple definitions of own_print();
Isnt this how you specialise templates ?
Im sorry for the comments... commented my test project in german, it helps me to understand whats going on there :)
 
@genaray Can you put the code on, say, coliru instead of using a screen shot? Note that this recursive approach to variadic templates is mostly obsolete--you can usually use a fold expression to do the job more easily (and expect faster compilation as well).
6
A: Using fold expressions to print all variadic arguments with newlines inbetween

Yakk - Adam Nevraumontrepeat takes a function object f, and return a new function object. The return value runs f on each of its args. It "repeats" f on each of its args. template<class F> auto repeat( F&& f ) { return [f=std::forward<F>(f)](auto&&...args)mutable{ ( void(f(args)), ... ); }; } Use: repeat...

 
 
1 hour later…
7:33 PM
Hello all... I'm trying to get a C++ application working in Visual Studio and eventually begin extending its features. Please take a look here: stackoverflow.com/questions/59309464/…
 
8:15 PM
If I had a class Book , what would be the difference between Book b{x} and Book b={x} ? (Suppose that I have Book (int x) {...} defined )
 
i just cannot understand why dp is so hard
 
8:54 PM
@GRRohman I would suggest that in the second example... the object is build by searching the best fitting constructor... so the code is similar
if x is a existing book... than the copy constructor is used
Or it uses a initializer list constructor
c++ is really confusing sometimes
 
@genaray hahah indeed , thanks for the effort
 
@GRRohman Did some research... if x isnt a book... than book b = {x} searches for the best fitting constructor, creates a new object using that constructor and assigns it to the existing b. While book b{x}; simply creates a object in one step by using that constructor without assigning.
 
@genaray so with book b={x} we are creating two objects in the background ?
 
@GRRohman If im not totally wrong... than yes... the created object for x gets destroyed once it was assigned to b...
 
@genaray But why would you suggest using that instead of book b{x} ? Don't we want as less work as possible ?
 
9:08 PM
@GRRohman For any practical purpose, there's no difference. In theory, the one using = will first create a temporary object from x, then copy construct b from that temporary object. In reality, the compiler will optimize that out so there's no extra object created.
 
@JerryCoffin Ok I see now
 
Oh, one other detail (sorry, I'm old) it can be moved rather than copied, assuming the type supports that.
 
@JerryCoffin Not sure I'm following , what exactly can be moved ?
 
@GRRohman The temporary can be moved (rather than copied) into b.
But as noted, in reality that won't happen:
 
IIm still stuck with that damn specialisation problem... its working in online compilers... but not in my project...
dammit
 
9:18 PM
@genaray What compiler are you using for your project?
 
Im trying to specialize this template... a string - specialisation... compiles fine in that online compiler... in CLion with cygwin... it always throws me errors that the specialised method is defined multiple times
I tried to either put the declarations in the .h file... didnt worked... and then i put them into the cpp file... didnt worked either... always getting "multiple definitions"
 
@genaray What version of gcc are you using in cygwin?
 
7.4.0
gcc & g++
 
@genaray Hmm...that is strange. That's new enough I wouldn't expect problems like this from it.
Doing a quick check with g++ 4.8.5 and g++ 7.2 under Linux seems to work fine too.
Not sure it'll help, but maybe try using MingW instead of cygwin?
 
It doesnt make even sense... normally you declare templates in the h file, right ? You also implement the logic in there... first the default template is declared... then specialisied... and a specialised isnt a new method...
Tried mingw... same result :/
 
9:52 PM
@genaray I may be able to take a look when I get home tonight, but that'll be late and it works fine with the tools I have here at work (on Linux).
 
would be great, thanks ! :)
 

« first day (1249 days earlier)      last day (1607 days later) »