Survey for C++ Teachers (results to go in CppCon talk)
Help gather data.
Survey for C++ Teachers (results to go in CppCon talk)
October 25, Pavia, Italy
November 6-8, Berlin, Germany
November 3-8, Kona, HI, USA
By Adrien Hamelin | Sep 17, 2018 11:58 AM | Tags: community
Help gather data.
Survey for C++ Teachers (results to go in CppCon talk)
By Adrien Hamelin | Sep 17, 2018 11:56 AM | Tags: community
Will you try it?
Lightning Talks and a Challenge
by Michael Caisse
From the article:
Lightning Talks have become an attendee favorite at CppCon. Often humorous and high energy, they provide an informal venue to teach, learn, and laugh.
If you have something to share that the C++ community might enjoy, produce a focussed 5-minute talk and register to dazzle the crowd.
By Ansel Sermersheim | Sep 15, 2018 06:05 AM | Tags: None
New video on the CopperSpice YouTube Channel:
Constexpr Static Const
by Barbara Geller and Ansel Sermersheim
About the video:
This presentation covers constexpr and how it differs from const. We also discuss what constexpr means in practice versus what is actually required by the standard, a subject which is often misunderstood. The topic of constexpr vs preprocessor macros is also covered with suggestions for best practices.
Please take a look and remember to subscribe!
By Marco Arena | Sep 15, 2018 03:40 AM | Tags: community
Are you wondering how to use the Microsoft Cognitive Services with C++?
Microsoft Cognitive Services C++ SDK
by Sebastiano Galazzo
Introduction:
The project is a wrapper to use Microsoft Cognitive Services in standard C++ as is currently not supported.
The project provides full support to Computer Vision API. A wrapper to gphoto2 will provide the full control digital cameras (DSLR), getting the raw shot and making manipulations with Computer Vision API.
Available camera-ai, a working commandline example to take a picture from the camera conneced by USB and analyze by Cognitive Services.
A lot of people have a better C++ than mine, who wants to contribute is welcomed!
By Anastasia Kazakova | Sep 13, 2018 11:13 PM | Tags: None
While ReSharper C++ 2018.1 introduced two major new features, debug step filters and includes analyzer, ReSharper C++ 2018.2 is focused on improving its understanding of the C++ language. C++17 and C++20 got some special attention. However, the biggest highlight is the long-awaited support for C++/CLI.
What’s New in ReSharper C++ 2018.2
by Igor Akhmetov
From the article:
This release introduced:
- Initial C++/CLI support
- C++17 features: class template argument deduction, fold expressions, auto non-type template parameters, pack expansions in using declarations, Using declarations with multiple declarators, guaranteed copy elision, and more
- C++20 features: coroutines, designated initialization, and some others
- Integrated spell checking with ReSpeller
- Formatting inspections
By Adrien Hamelin | Sep 13, 2018 12:47 PM | Tags: intermediate c++11
Quick A: auto
never deduces a reference.
Recently on SO:
C++11 auto: what if it gets a constant reference?
Read this article: Appearing and Disappearing consts in C++
Type deduction for auto variables in C++0x is essentially the same as for template parameters. (As far as I know, the only difference between the two is that the type of auto variables may be deduced from initializer lists, while the types of template parameters may not be.) Each of the following declarations therefore declare variables of type int (never const int):
auto a1 = i; auto a2 = ci; auto a3 = *pci; auto a4 = pcs->i;During type deduction for template parameters and auto variables, only top-level consts are removed. Given a function template taking a pointer or reference parameter, the constness of whatever is pointed or referred to is retained:
template<typename T> void f(T& p); int i; const int ci = 0; const int *pci = &i; f(i); // as before, calls f<int>, i.e., T is int f(ci); // now calls f<const int>, i.e., T is const int f(*pci); // also calls f<const int>, i.e., T is const intThis behavior is old news, applying as it does to both C++98 and C++03. The corresponding behavior for auto variables is, of course, new to C++0x:
auto& a1 = i; // a1 is of type int& auto& a2 = ci; // a2 is of type const int& auto& a3 = *pci; // a3 is also of type const int& auto& a4 = pcs->i; // a4 is of type const int&, tooSince you can retain the cv-qualifier if the type is a reference or pointer, you can do:
auto& my_foo2 = GetFoo();Instead of having to specify it as const (same goes for volatile).
Edit: As for why auto deduces the return type of GetFoo() as a value instead of a reference (which was your main question, sorry), consider this:
const Foo my_foo = GetFoo();The above will create a copy, since my_foo is a value. If auto were to return an lvalue reference, the above wouldn't be possible.
By Adrien Hamelin | Sep 13, 2018 12:36 PM | Tags: performance c++17
Are you using the parallel capacities of the std?
Using C++17 Parallel Algorithms for Better Performance
by Billy O’Neal
From the article:
C++17 added support for parallel algorithms to the standard library, to help programs take advantage of parallel execution for improved performance. MSVC first added experimental support for some algorithms in 15.5, and the experimental tag was removed in 15.7.
The interface described in the standard for the parallel algorithms doesn’t say exactly how a given workload is to be parallelized. In particular, the interface is intended to express parallelism in a general form that works for heterogeneous machines, allowing SIMD parallelism like that exposed by SSE, AVX, or NEON, vector “lanes” like that exposed in GPU programming models, and traditional threaded parallelism.
Our parallel algorithms implementation currently relies entirely on library support, not on special support from the compiler. This means our implementation will work with any tool currently consuming our standard library, not just MSVC’s compiler. In particular, we test that it works with Clang/LLVM and the version of EDG that powers Intellisense...
By Adrien Hamelin | Sep 13, 2018 12:33 PM | Tags: intermediate c++17
Variant utility.
How To Use std::visit With Multiple Variants
by Bartlomiej Filipek
From the article:
std::visit is a powerful utility that allows you to call a function over a currently active type in std::variant. It does some magic to select the proper overload, and what’s more, it can support many variants at once.
Let’s have a look at a few examples of how to use this functionality...
By Adrien Hamelin | Sep 12, 2018 12:23 PM | Tags: community
Have you registered for CppCon 2018 in September? Registration is open now.
While we wait for this year’s event, we’re featuring videos of some of the 100+ talks from CppCon 2017 for you to enjoy. Here is today’s feature:
Fantastic Algorithms and Where To Find Them
by Nicholas Ormrod
Summary of the talk:
Come dive into some exciting algorithms — tools rare enough to be novel, but useful enough to be found in practice. Want to learn about "heavy hitters" to prevent DOS attacks? Come to this talk. Want to avoid smashing your stack during tree destruction? Come to this talk. Want to hear war stories about how a new algorithm saved the day? Come to this talk! We'll dive into the finest of algorithms and see them in use — Fantastic Algorithms, and Where To Find Them.
By Adrien Hamelin | Sep 12, 2018 12:20 PM | Tags: intermediate c++11
Quick A: if parameter are not known at compile time, it is like a normal function
Recently on SO:
C++ constexpr - Value can be evaluated at compile time?
The quoted wording is a little misleading in a sense. If you just take PlusOne in isolation, and observe its logic, and assume that the inputs are known at compile-time, then the calculations therein can also be performed at compile-time. Slapping the constexpr keyword on it ensures that we maintain this lovely state and everything's fine.
But if the input isn't known at compile-time then it's still just a normal function and will be called at runtime.
So the constexpr is a property of the function ("possible to evaluate at compile time" for some input, not for all input) not of your function/input combination in this specific case (so not for this particular input either).
It's a bit like how a function could take a const int& but that doesn't mean the original object had to be const. Here, similarly, constexpr adds constraints onto the function, without adding constraints onto the function's input.
Admittedly it's all a giant, confusing, nebulous mess (C++! Yay!). Just remember, your code describes the meaning of a program! It's not a direct recipe for machine instructions at different phases of compilation.
(To really enforce this you'd have the integer be a template argument.)