#cpp17
Explore tagged Tumblr posts
simplifyyourday · 8 months ago
Video
youtube
STD::VARIANT IN C++17 #cpp #shorts #cpp17
0 notes
coralkashri · 8 months ago
Text
It's just ',' - The Comma Operator
Is the comma operator in C++ a hidden gem or a lurking danger? In 'It's just ',' - The Comma Operator,' I explore its surprising dangers. Could using it lead to subtle, unnoticed errors? Let’s uncover the truth together! #cpp #cppsenioreas #cpp17 #cpp23
We all know that every ‘,’ matters in this language, so I decided to talk directly about that letter today. So, how much impact can be for such a small little character? The Comma Operator This operator comes from C, where it tells the compiler to evaluate all the expressions (left to right) and to return the result of the latest evaluated expression. For example: int a, b; a = 5, b = 4, b +=…
0 notes
carrieforle · 4 years ago
Text
C++ Tips: std::optional<T>
std::optional<T> is a class defined in <optional>. It is added in C++17 and it presents a variable that may have a value. The value is optional, so the name.
There are 2 ways to make a std::optional
Tumblr media
You will use 6 functions when you work with std::optional 90% of the time.
std::optional() //the constructor
std::make_optional() //make std::optional
has_value() //true if it has a value, otherwise false
value() //get the value of optional
value_or() //get the value of optional but if the optional doesn't contain one, it returns another value from the arguments
reset() //reset / destroy the contained value
Generally, std::make_optional is the way to go for creating objects unless you don't want to have a value contained when initializing.
Tumblr media
3 notes · View notes
airakose · 7 years ago
Photo
Tumblr media
Since we’re locked to C++03 at work, I thought I’d sit down and try to learn the newer features of the language while working on personal projects... Just this simple exercise in calculating the length of a c-style string got me through a fair number of the newer concepts.
Generics are a bit... heavy and verbose still, but otherwise they seem powerful? I’m very much into the constexpr stuff, especially with the gains in the second version of the “Len” function, and the static_assert combined with type_traits is wonderfully expressive.
I even got in a bit of SFINAE (Substitution Failure is Not an Error) because of how string literals resolve in overload lookups: both the array reference and the type pointer resolve as equally valid and the compiler throws an “Ambiguous Function Call” error. It’s a bit disheartening that the resolution is so indirect and awkward, but it works.
1 note · View note
viva64 · 8 years ago
Text
C++17
C++ language is constantly evolving, and for us, as for developers of a static analyzer, it is important to track all its changes, in order to support all new features of the language. In this review article, I would like to share with the reader the most interesting innovations introduced in C++17, and demonstrate them with examples.
Tumblr media
Now, developers of compilers are actively adding support for the new standard. You can see what is supported at the moment via the following links:
GCC
Clang
Visual Studio
Fold expressions
I would like to start with a few words about what a fold is (also known as reduce or accumulate).
Fold is a function that applies the assigned combining function to sequential pairs of elements in a list, and returns a result. The simplest example is the summing up of elements in the list using a fold:
Example from C++:
std::vector<int> lst = { 1, 3, 5, 7 }; int res = std::accumulate(lst.begin(), lst.end(), 0,  [](int a, int b)  { return a + b; }); std::cout << res << '\n'; // 16
If the combining function is applied to the first item in a list and to the result of the recursive processing of the tail of a list, then the fold is called 'right'. In our example, we will get:
1 + (3 + (5 + (7 + 0)))
If the combining function is applied to the result of the recursive processing at the top of the list (the entire list without the last element) and to the last element, then a folding is called 'left'. In our example, we will get:
(((0 + 1) + 3) + 5) + 7
Thus, the fold type determines the order of evaluation.
In C++17 there is also folding support for a template parameters list. It has the following syntax:
Tumblr media
op is one of the following binary operators:
+ - * / % ^ & | ~ = < > << >> += -= *= /= %= ^= &= |= <<= >>= == != <= >= && || , .* ->*
pack is an expression containing an undisclosed parameter pack
init - initial value
For example, here's a template function that takes a variable number of parameters and calculates their sum:
// C++17 #include <iostream> template<typename... Args> auto Sum(Args... args) {  return (args + ...); } int main() {  std::cout << Sum(1, 2, 3, 4, 5) << '\n'; // 15  return 0; }
Note: In this example, the Sum function could be also declared as constexpr.
If we want to specify an initial value, we can use binary fold:
// C++17 #include <iostream> template<typename... Args> auto Func(Args... args) {  return (args + ... + 100); } int main() {  std::cout << Func(1, 2, 3, 4, 5) << '\n'; //115  return 0; }
Before C++17, to implement a similar function, you would have to explicitly specify the rules for recursion:
// C++14 #include <iostream> auto Sum() {  return 0; } template<typename Arg, typename... Args> auto Sum(Arg first, Args... rest) {  return first + Sum(rest...); } int main() {  std::cout << Sum(1, 2, 3, 4); // 10  return 0; }
It is worth highlighting the operator ',' (comma), which will expand the pack into a sequence of actions separated by commas. Example:
// C++17 #include <iostream> template<typename T, typename... Args> void PushToVector(std::vector<T>& v, Args&&... args) {  (v.push_back(std::forward<Args>(args)), ...); //This code is expanded into a sequence of expressions       //separated by commas as follows:  //v.push_back(std::forward<Args_1>(arg1)),  //v.push_back(std::forward<Args_2>(arg2)),  //.... } int main() {  std::vector<int> vct;  PushToVector(vct, 1, 4, 5, 8);  return 0; }
Thus, folding greatly simplifies work with variadic templates.
Tumblr media
Read more - https://www.viva64.com/en/b/0533/
15 notes · View notes
stevenfusco · 8 years ago
Link
C++17 immutable compile-time key value map
0 notes
zoopirgamer · 7 years ago
Photo
Tumblr media
https://t.co/R3Iqg2lV5M خرید کوسن برای مبلمان منزل و ادارات کد: CPP17 https://t.co/ZJWGYZcMXR http://ift.tt/2o5ZWl8
0 notes
script-ease · 8 years ago
Link
0 notes
newseveryhourly · 8 years ago
Link
  http://ift.tt/2kETy1J
0 notes
toytoycy · 8 years ago
Text
非推奨だった bool 型に対するインクリメント演算子を削除
https://cpprefjp.github.io/lang/cpp17/remove_deprecated_increment_of_bool.html bool型に対する前置および後置のoperator ++とはC++98の時点で非推奨になっていた機能である。 具体的にどのような働きをするのかというと、以下のように値をtrueに書き換える機能をもつ。
0 notes
oakcape · 8 years ago
Quote
非推奨だった bool 型に対するインクリメント演算子を削除 - cpprefjp C++日本語リファレンス概要 C++17では bool 型に対する前置および後置の operator ++ を削除する。 bool 型に対する前置および後置の operator ++ とはC++98の時点で非推奨になっていた機能である。 具体的にどのような働きをするのかというと、以下のように値を true に書き換える機能をもつ。
https://cpprefjp.github.io/lang/cpp17/remove_deprecated_increment_of_bool.html
0 notes
rsstotxt · 8 years ago
Link
ymrl yamifuu rin51 FTTH だいぶ変態的な用途だし普通困らんでしょ stealthinu programming 『これに起因するバグで少なくとも6つの過度の放射線被曝事故を引き起こし3人が死亡した例がある』『条件変数を非0にする(=trueにする)ために、インクリメントを使っていた』うげー
0 notes
turimotonaoki · 8 years ago
Quote
これに起因するバグで少なくとも6つの過度の放射線被曝事故を引き起こし、3人が死亡した例がある。 Therac-25はカナダ原子力公社(AECL)とフランスCGR-MeV社によって開発・製造された放射線療法機器である。 この装置のソフトウェアのバグの一つに、条件変数を非0にする(=trueにする)ために、インクリメントを使っていたというものがあった。 条件変数はC++でいえばstd::uint8_t型で、つまり256回に1度オーバーフローを起こして値が0になるために、falseとして扱われた。 この結果ほかの条件変数の状態によっては25MeVという通常の100倍のβ線が射出されることがあった。 こうした事故を防ぐためなのかは不明だが、C++のbool型はインクリメントした際、常にtrueになるように定められていた。 しかし、そもそも上記のバグを防ぐには、インクリメントではなく単に固定値を代入するようにするべきであり、C++98の時点でdeprecatedになっていたと思われる。
非推奨だった bool 型に対するインクリメント演算子を削除 - cpprefjp C++日本語リファレンス https://cpprefjp.github.io/lang/cpp17/remove_deprecated_increment_of_bool.html
0 notes
joannanawn · 8 years ago
Text
Concrete Poetry
The concrete poetry project was created as a collaborative project involving everyone in the class.  Each person was given a word to use.  We decided as a group to create a narrative including all the words.  Below is a link to the page I created.
http://personal.psu.edu/jen5156/cpp17/instrumental.html
  To view the page from the beginning use the link below:
http://personal.psu.edu/wrc11/cpp17/i…
View On WordPress
0 notes
viva64 · 8 years ago
Link
3 notes · View notes
stevenfusco · 8 years ago
Link
Thanks @jfbastien for the mega awesome presentation!  https://jfbastien.github.io/what-is-cpp17/#/
0 notes