29
votes
Accepted
Python - Tkinter - periodic table of chemical elements
I hope you enjoy this bit of code.
I did!
Your symbols, keywords and values should have capitalised variable names since they're global constants. However, life would be easier if your symbols were ...
27
votes
Python - Tkinter - periodic table of chemical elements
Don't optimize the wrong thing
You have an excellent review already, so I'll comment on a narrow topic: cramped
code layout. For example:
...
23
votes
Accepted
Implementing a Stack with Templates and Smart pointers
Readability
Please put a space after the include and before the <
...
23
votes
Accepted
A vector implementation
Design
The main thing about a vector is not constructing its members until they are put into the container. The vector you have constructs all the members immediately which can be very expensive if ...
22
votes
Accepted
Modern C++ Singleton Template
Okay so first of the obligatory Singletons are bad practice so you probably shouldn't make it easy to write bad code.
Ignoring the fact that the class probably shouldn't exist at all we can look at ...
22
votes
Accepted
Simple Container Class
Advice for learning
Don’t do this.
The container you are trying to implement is std::vector. You don’t call it that, and you never say explicitly that ...
16
votes
2D counterpart of std::array in C++17
Let me collect a couple of thoughts here.
Aggregate initialization currently works like this:
array2d<int, 2, 2> a{{1, 2, 3, 4}};
but wouldn't it be ...
15
votes
Modern C++ Singleton Template
Singletons make it hard to test your code, and in my job I'd reject this at review for encouraging the development of untestable features. That said, I'll continue reviewing despite that.
No need for ...
15
votes
Accepted
"contains" function for STL containers
If you like new features, and even experimental features, you can make your code a lot cleaner.
Concepts
A lot of those arcane SFINAE techniques will be obsolete once ...
14
votes
Accepted
Vector implementation, which received unhelpful negative feedback from professor
I understand that some of this class is predicated by your professor; However I will review the code as a whole and you can then choose what can be changed and what cannot be changed.
Interface/High-...
13
votes
Accepted
C++ reduce repetitions of code for similar classes
Yes, there is. In fact, a very nice way to solve this code redundancy issue comes to mind if you consider that std::string is a just type alias for ...
13
votes
Generic C++ Class to Associate enum Values with Strings for Translation
Consider using magic enum instead. It basically automates this.
Alternatively, for example if you want other spellings for the string representations, I found X-macros very useful:
...
12
votes
C++11 Custom Vector Implementation
This is not a bad attempt at making a vector-like container, except it is lacking support for const and makes unnecessary copies (see below for a more detailed ...
11
votes
Accepted
Templated CSV file parser
#include <iostream>
You don't seem to need this include.
size_t _width;
size_t _height;
These should both be ...
11
votes
Accepted
C++ math vector template
A few issues:
Functions defined in the class in the header are inline by default, so there's no need to use the keyword everywhere.
Use ...
10
votes
C++ Stack Implementation Using Templates and Linked List
If you have a destructor you should also define the copy constructor and copy assign + the move variants. Otherwise the compiler will generate its own (incorrect) copy and move facilities which will ...
10
votes
"contains" function for STL containers
Rather than writing your detection from scratch, use the detection idiom, either in the compiler's header if you have it, or a copy of the published definitions otherwise.
...
10
votes
"contains" function for STL containers
Wrong usage
One shouldn't be afraid of manual SFINAE, but one should also use it appropriately. I'm in no way professional in this question, but guidelines are roughly the following for SFINAE and ...
10
votes
YAVI (Yet another vector implementation)
As a learner, I think you have done a great job. Here's some suggestions:
General
Don't use multiple public: labels. It seems your intent is to split the ...
10
votes
Accepted
10
votes
Accepted
Generic C++ Class to Associate enum Values with Strings for Translation
It's not going to be perfect
Unfortunately, until we get true enum reflection in C++ (supposedly in C++26), any solution to map enum values to strings is going to have some issues. Your solution ...
9
votes
Accepted
Concurrent FIFO in C++11
I'm in a bit of a hurry so I'll only touch on the big high level stuff that I noticed.
Abuse of SFINAE
I think that the way you are designing two different use cases into one template class and ...
9
votes
A vector implementation
Implementation
There is a lot of code duplication. Maybe introduce helper functions (in an internal namespace if you don't want to pollute the outer one)?
...
9
votes
Template Matrix Class: implemented some basic functionalities
Overview
Potentially not very efficient.
I have seen other Matrix libraries not do the actual computation until the value is needed. So what is passed around is a Matrix wrapper that contains ...
9
votes
Accepted
Generic Doubly Linked-list implementation in C++
Identifiers that start with a double underscore, or a single underscore followed by a capital letter, are reserved for use by the implementation. Your use of __T ...
9
votes
Accepted
C++ Shared_Ptr implementation
Overview
Templated classes "normally" should provide all the code at the point of usage. As a result you should probably not have a separate shared.cpp. Though some people put the ...
9
votes
C++ template class to calculate CRC
Here are some things that may help you improve your code.
Understand the nature of templates
In modern C++, putting headers in a header file and the implementation in a ...
9
votes
Accepted
3D Inverse Discrete Cosine Transformation Implementation in C++
Use std::uint8_t instead of BYTE
I see you are declaring a type alias BYTE. However, I think ...
8
votes
Accepted
(Optionally Concurrent) FIFO
Your popped elements will not be destructed. You move them but that isn't the same as being destructed and it doesn't guarantee that memory will be released.
Furthermore your container requires T to ...
8
votes
Accepted
Generic merge sort in C++ using a user-defined comparison function or the < operator by default
Avoid a copy by passing by const reference.
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
template × 547c++ × 427
c++11 × 100
c++20 × 59
c++17 × 42
recursion × 40
javascript × 32
template-meta-programming × 28
constrained-templates × 28
c++14 × 27
python × 24
php × 24
variadic × 22
object-oriented × 21
reinventing-the-wheel × 21
design-patterns × 18
linked-list × 16
performance × 15
iterator × 15
vectors × 15
beginner × 14
algorithm × 14
memory-management × 13
classes × 13
pointers × 13