Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 36060

C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. This tag should be used for any question which requires knowledge or expertise with the C++ programming language. This is a general tag which is used for any of the C++ language standards (C++98, C++11, C++17, etc.). The question should identify the compiler being used, the operating system, and which of the C++ standards is being targeted.

6 votes
Accepted

A word translator into multiple languages

Your usage of std::map is wrong here, you don't look-up by index. std::map could be used to select correct words container by language though. Keeping one container by language, you might have: #inclu …
Jarod42's user avatar
  • 566
6 votes

findLowest() and findHighest() functions in this simple program

With C++11, some code may be simplified: double findLowest (double aaa, double bbb, double ccc, double ddd, double eee) { return std::min({aaa, bbb, ccc, ddd, eee}); } double findHighest (double …
Jarod42's user avatar
  • 566
4 votes

advfind() template

You don't need std::function, and may do: template<class C, class F> bool advfind(C& collection, F fnCompare) { for (auto& item : collection) { if (fnCompare(item)) { ret …
Jarod42's user avatar
  • 566
2 votes

c++20 compile time string utility

We are in unevaluated context here. // TODO: avoid constructing object here template<template <typename...> typename container, typename... Ts> string(const container<Ts...>& input) -> string<((sizeo …
Jarod42's user avatar
  • 566
4 votes

Calculating Discount C++

Sorry as expected function interface is bad (having bool parameter instead of 2 functions, mixing in/out parameter and return value, function doing several stuff with naming not reflecting that, ...). …
Jarod42's user avatar
  • 566
2 votes
Accepted

Class accepting data input by variable, function pointer or lambda

Your initial traits can be simplified using std::conditional: template <typename T> using GetDataType = std::conditional_t<std::is_invocable_v<T>, std::invoke_re …
Jarod42's user avatar
  • 566
1 vote

Printing a C++ struct

Boost example has already an example for printing aggregate. Format and naming are different, but to adjust to your style, it would be: template <class T> void print_struct(const T& x) { std::co …
Jarod42's user avatar
  • 566
1 vote
Accepted

A partition algorithm for positive integers

Edit:Previous algorithm failed, redo the algorithm completely. Start with a full mid part, and distribute its values to its best neighbor until it is not the greatest part: unsigned int get_min_part …
Jarod42's user avatar
  • 566
3 votes
Accepted

Optimization of sieve of Erathosthenes

if (z[i] == 0) for (j = 2 * i; j < 100000; j = j + i) z[j] = 1; can be changed to if (z[i] == 0) for (j = i * i; j < 100000; j = j + 2 * i) z[j] = 1; as k * i (with k < …
Jarod42's user avatar
  • 566
7 votes
Accepted

Matrix implementation

for Matrix() : mCols(0), mRows(0), mData(0) { }; semicolon should be removed as useless. for Matrix(std::size_t cols, std::size_t rows) : mCols(cols), mRows(rows) { mData.resize(cols * ro …
Jarod42's user avatar
  • 566
3 votes

3Sum implementation

Sort the array -> \$O(N log N)\$ Iterate the array: Use 2 iterators: one from next element, and one from last while Sum < 0, increase first iterator while Sum > 0 decrease last iterator when s …
Jarod42's user avatar
  • 566