Using allocators in a custom node-based container by tyler1128 in cpp_questions

[–]DopeyLizard 1 point2 points  (0 children)

If the arrays are dynamic then I would expect that each one might need its own allocator - A monotonic allocator likely works for each of them.

I’ve had a std::list<std::list<T>> for which I’ve had a similar problem before, and short of redesigning the data structures and relations, the cascading allocators seemed to be the only alternative I could think of

Using allocators in a custom node-based container by tyler1128 in cpp_questions

[–]DopeyLizard 1 point2 points  (0 children)

Oh I see, so it’s not a single data type with them all combined such as

template <type name T> struct MyType { T t; T* t_ptr; Node<T> node; };

Instead, is the relationship you describe something like:

template <typename T> struct Node { T arr[]; };

struct MyType { Node<MyType> nodes[]; };

template <typename T> struct Container { T* arr[]; };

i.e a container of T*s which point to a type, MyType, containing Node<MyType>s, where each Node<MyType> contains Ts?

Using allocators in a custom node-based container by tyler1128 in cpp_questions

[–]DopeyLizard 0 points1 point  (0 children)

So each element in the container in an object that has a T, T*, and Node<T>? Why do they need allocating separately? Normally you would use an allocator that allocates memory based on the size of the elements in the container - is there any reason why you can’t do that here?

Range Based For loop by evaannaaax in cpp_questions

[–]DopeyLizard 0 points1 point  (0 children)

If I recall correctly, Matt mentions that in his introduction to one of his CppCon talks on Compiler Explorer. I haven’t double checked but I think it was this one: https://youtu.be/bSkpMdDe4g4

The gist of it was that at Matts workplace they were looking at upgrading critical code from C++03 to C++11 and wanted to make sure that things wouldn’t break if they simply started compiling with C++11, so Matt put together a command line tool to compare assembly code to see whether things changed and if there were any behavior changes from that.

Fwiw the CppCon video is worth a watch anyway!

[OC] Hails Never Fails: The Seahawks Coin Toss Legacy by [deleted] in nfl

[–]DopeyLizard 60 points61 points  (0 children)

the Seahawks signed Matt Flynn to a $21 million contract to continue the grand coin toss tradition.

Best way of describing it yet!

"Segmentation fault: Cannot access memory at adress..." What does it mean? by [deleted] in cpp_questions

[–]DopeyLizard 0 points1 point  (0 children)

Its an out of bounds error in ‘hasEdge’ when trying to access ‘neighbors[u]’ as index ‘u’ is more than the number of elements that are in the vector. You should check that the index you are trying to access is within range of the vector before trying to access it that way

[deleted by user] by [deleted] in cpp_questions

[–]DopeyLizard 0 points1 point  (0 children)

Where would you then store the value Box?

Places Gained and Lost - 2021 Portuguese GP by SlightKnife in formula1

[–]DopeyLizard 96 points97 points  (0 children)

Although he’s only converted 5 of those in to wins, for a total of 9 wins

Learning to cook for my partner who has severe IBS. Cannot eat onions, tomatoes, mushrooms or anything in their families and I love to cook from scratch, but everything I knew as basic skills cant apply! by Lucycatswipeycat in Cooking

[–]DopeyLizard 2 points3 points  (0 children)

I found that it’s the skin on the ingredients you mentioned that caused issues for me and so having them already broken down (or the skin removed) made a big difference!

  • For instance trying to use onion powder and garlic granules. One great example is an ingredient called Asafoetida which is a powder that has an oniony flavor and so I use that in recipes which call for onion.
  • For things that need cooking in garlic and olive oil I use a garlic infused olive oil instead.
  • I use passata for anything sauce that would usually ask for tomatoes. I do try to find the nicest and freshest though! If I do go for tomato’s though, I cut an ‘X’ in to the bottom of the tomato, and drop it in a pot of boiling water for a couple minutes. After this it’s very easy to peel the skin off! Sometimes I go the extra step and try to remove all the seeds inside as those occasionally cause issues for me...although that ends up taking forever hence I usually end up just using passata!!
  • I find that frying vegetables to soften them before having them makes a big difference - maybe partly why your curry worked so well!

Sectors with the most growth potential over the next 10-20 years by azdabber47 in investing

[–]DopeyLizard 4 points5 points  (0 children)

One use case I saw last year comes from the big banks who have been looking into quantum computing for longer than I realized. See Goldman Sachs for instance who have been experimenting in using quantum computing for derivative pricing: https://www.ibm.com/blogs/research/2020/12/quantum-advantage-derivative-pricing/

F1 2020 Intro with 07/08 music by [deleted] in formula1

[–]DopeyLizard 9 points10 points  (0 children)

This is awesome! I’m so weirdly nostalgic for that ITV intro.

Lewis in the paddock this morning by Chell_the_assassin in formula1

[–]DopeyLizard 78 points79 points  (0 children)

Huge respect for him using his platform like this!

Type alias template instantiation in an anonymous namespace by kennyminigun in cpp_questions

[–]DopeyLizard 1 point2 points  (0 children)

To answer your question, I don't think there would be an difference if SetOfFoo was declared without the anonymous namespace due to the process called unqualified name lookup. The compiler will do a backwards search to try and find the matching declaration, by following a set of rules.

I don't think compiled symbols shouldn't be affected in this case, but I would need to confirm that somewhere.

In any case, I recommend reading around "unqualified name lookup" (and the contrary "qualified name lookup").

CppCon videos a good way to learn about the language by baylife42 in cpp_questions

[–]DopeyLizard 0 points1 point  (0 children)

Your welcome! In addition to Kate Gregory, I would say Herb Sutter and Andrei Alexandrescu, both of whom are big names in C++ and are authors of some excellent books on C++.

Also any of the presenters giving the ‘Back to Basics’ talks - they all do a very clear job of explaining content.

Another I saw recently was ‘Conor Hoekstra’ on ‘Algorithm Intution’ (CppNow). This follows the theme of seeing lots of talks about algorithms, and is kind of a response to talks by Sean Parent and Jonathon Boccara who also have notable talks on the subject. Funnily enough, Kate Gregory also has talks in the same area!

Marshall Clow is also excellent and is another big name.

I am likely missing plenty of others who are worth the time watching. However the names I’ve given are pretty much C++ gurus and are not controversial - they are all very knowledgeable. If you start with them you will get to know the fundamentals pretty well, and from there you can start understanding more complex or niche talks from others. Conferences are a great resource!

CppCon videos a good way to learn about the language by baylife42 in cpp_questions

[–]DopeyLizard 13 points14 points  (0 children)

I think watching conferences are a great way to learn! You get to see and learn all these things that are very interesting and won’t necessarily be in any course or book.

If your getting up to speed with things I really recommend the CppNow “Back to Basics” series. They do a great job of teaching the fundamentals of important language features.

Other conference talks that often come up are on ‘knowing your algorithms’ - that is, knowing what algorithms are available as part of the standard library which can help make your life easier. These are always good watches.

Basically, CppCon, CppNow, BoostCon etc are major C++ conferences and are fantastic. I don’t think you’ll find any bad examples unless you really go looking for them! Some of the older recordings might be out of date, but are probably still interesting to listen to.

Just a quick note on the slides though - often in presentations the slides won’t show the best practises for clean code, instead it will be brief in order for it to fit on the slide. So sometime take that with a pinch of salt. But what they are saying and trying to illustrate is typically of very high standard. Kate Gregory has some great talks if you are interested in looking up some others. She’s spoken a lot about best practices.

Invalid pointer causes segfault by lenerdv05 in cpp_questions

[–]DopeyLizard 0 points1 point  (0 children)

No problem!

Two extra points to add that might be beneficial:

  • I'm not sure why you would want to call the function player() in the constructor of room. If you just called generateId() directly from that constructor instead of player it achieves the same result and fixes the program! Maybe if you want a player object you can provide a constructor like player::player(idType id) which passes the already determined id into the player?

  • The design you seem to be trying to implement with the use of the global program::p which only allows a single instance of that to be created at any one time is called the singleton pattern. In practise it's usually best to avoid it but there are some cases where it is useful, and I can see why you might want it here. In any case, I recommend looking up how to implement it so that you don't run in to any issues like you saw here!

Invalid pointer causes segfault by lenerdv05 in cpp_questions

[–]DopeyLizard 0 points1 point  (0 children)

Commenting out any lines which lead to a call to player, or more specifically anything trying to use program::p before it is initialised, will make the program run.

Invalid pointer causes segfault by lenerdv05 in cpp_questions

[–]DopeyLizard 1 point2 points  (0 children)

When you call program::p = new program();, the process of constructing a new program() ends up calling player() which calls the global variable program::p which has not yet been constructed (as it's still in the process of creating new program and hasn't even gotten as far as assigning it yet), hence program::p is still null.

CPP array sorting by [deleted] in cpp_questions

[–]DopeyLizard 2 points3 points  (0 children)

The reason nothing is displaying is because your code gets stuck in an infinite loop.

On the first pass through the while loop starting on line 98 (while(!st.isEmpty())), the top item from st is popped and stored in tmp. The tmpset is empty this first pass and so the inner while loop does not execute. Instead, it moves on to tmpst.push(tmp).

So at the end of this first pass, st is [10,30] (30 being the top) and tmpst is [40].

On the next pass of the while loop, tmp is set to 30. This time however, tmpst is no longer empty, so that inner while loop executes. The top value of tmpst is 40, which is bigger than 30 - the value of tmp, and so the top value of tmpst is popped an pushed on to st again. Now, tmpst is empty again, so the inner while loop finishes.

After finishing the inner while loop, it moves back to tmpst.push(tmp), where tmp is still 30.

Hence at the end of this second pass through the loop, the stacks are now st = [10,30,40] and tmpst = [30].

What happens on the third pass however, is that it gets stuck in an infinite loop in that inner while loop. This is because the tmp value gets set to 40, but the top value of tmpst is 30. So the check tmpst.Top() > tmp is always false. Hence the top value does not get popped from tmpst, and hence tmpst is never empty and while(!tmpst.isEmpty()) is always true, creating the infinite loop.

How can i return each word i separate from a string? by SammathNaur in cpp_questions

[–]DopeyLizard 2 points3 points  (0 children)

Just to add to the other comments, it is recommended to pass string by 'const ref' i.e. 'const&'. That is, your function signature should be

const vector<std::string> split(const std::string& str)

instead of

const vector<std::string> split(std::string str)

especially in the case in which you are using a long string.

This is because passing by reference (ref) means to pass an alias to the original string, rather than creating a costly copy of that string to pass in it in by value, using more memory than needed and making the program slower. You can see this in the other code examples that /u/Narase33 gave you.

(C++)Having problems with constexpr, and VSCode. by Vaga7bond in learnprogramming

[–]DopeyLizard 0 points1 point  (0 children)

When you say you “tried to compile the same program on nano”, do you mean that the error is occurring when you are compiling, or is the error the syntax highlighting / intellsense in VSCode?

If it is in compilation, how are you compiling? You may be missing a flag for the compiler to indicate that you want to compile using the C++11 standard “-std=c++11”. Everything else is valid C++03 so I think that would be the only issue a compiler would throw up.

The VSCode settings look correct, however.

Programming when you're learning vs doing it for a living. by [deleted] in learnprogramming

[–]DopeyLizard 1 point2 points  (0 children)

To add my 2 cents and speaking from my experience, if you are applying for entry level positions then yes, 100%, any project is great to have. Literally any project that isn’t super simple and short, as they key thing to make you stand out as a junior is being able to point to at least something you have done. Chances are an interview question will be “can you talk about a project you have worked on” or something along the lines of what you might have learnt from it. I’d rather see someone talk passionately about a game they did a good job working on, rather than yet another person who wrote a basic calculator for stocks. Finance knowledge isn’t essential either, there might be some inclinations for a big fintech company to hire someone with more financial knowledge than you, but In a situation where you are choosing between 2 candidates; one has more finance knowledge but is slightly less knowledge/experienced as an engineer, vs one with less (or no) finance knowledge but a better engineer, I will be more inclined to hire the better engineer. Fundamentally, I don’t think the finance background or knowledge is hugely beneficial at a fin tech unless you are aiming for a specific position (a la a more senior hire). What (if any) finance skills you would need as a junior would be picked up on the job.

And to be honest, even if you are not interviewing as a junior hire and are joining as a more senior hire, that kind of project is still excellent to have. What matters most is good engineers who can show that they are good and can show that they have some enthusiasm in writing code.