28 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 ...
  • 54.4k
27 votes
Accepted

std::tuple foreach implementation

Loki's solution does not enforce the order in which the function calls are performed, because the order in which function arguments are evaluated is unspecified. Here's a C++14 solution that ensures ...
25 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: ...
  • 10.2k
23 votes
Accepted

Implementing a Stack with Templates and Smart pointers

Readability Please put a space after the include and before the < ...
  • 92.3k
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 ...
  • 92.3k
16 votes
Accepted

Templated doubly-linked-list

File extensions Separating the interface from the implementation is great. However, the .h/.hpp split is not obvious. The most frequent file extensions used for implementation files that cannot go ...
  • 19.9k
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 ...
  • 956
15 votes
Accepted

Calculator using class templates

Don't flush where you don't need to. Flushing is expensive, so don't use std::endl unless you need it. Nearly always, the shorter ...
  • 18.2k
15 votes
Accepted

Create New C++ Class

Use input redirection instead of cat | ... Instead of cat somefile | somecommand, you should use input redirection, for example:...
  • 110k
15 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 ...
  • 16.4k
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 ...
  • 5,697
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-...
  • 16.4k
14 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 ...
13 votes
Accepted

n number of x on the y

Your code is simple and just works. For that reason, you can be happy and there is not much comment to give. However, being very picky just for the sake of learning, one could say various things. <...
  • 29k
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 ...
  • 5,220
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 ...
  • 38.2k
11 votes
Accepted

C++ Stack using template

If you provide a destructor you should handle copying and assigning. In other words follow the Rule of 3 (or 5 if you care about move semantics). You can also disallow them but then there should be ...
11 votes

Simple Python 3 templating module

There's a lot of code here, so I'm just going to look at the documentation, the _split_by_braces function, and the visit_Str ...
  • 49.3k
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 ...
  • 9,431
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 ...
  • 11.1k
10 votes

Very basic tuple implementation

In C++14, it's possible to implement a tuple in a very concise way. However, you lose some functionality of std::tuple (constexpr...
10 votes

Calculator using class templates

In addition to the previous good answer, in order to keep your code efficient not only for the C++ primitive data types but also for the compound user defined types, I suggest: Make the member ...
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. ...
  • 11.1k
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 ...
  • 9,191
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 ...
  • 9,269
10 votes
Accepted

Checking if a value is in a container

Neat idea. ...
  • 9,431
9 votes
Accepted

Fastest possible text template for repeated use?

The compile concept produced incorrect results for me. When I run your code the template does not produce the correct results. For the input parameters: ...
  • 96.9k
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 ...
  • 16.4k
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)? ...
  • 6,428

Only top scored, non community-wiki answers of a minimum length are eligible