Important semantic effects of small syntax errors -- Matt Wilson
Every C++ programmer should see a bug like this, from Matthew Wilson's post. As a warning.
Important semantic effects of small syntax errors
by Matt Wilson
October 25, Pavia, Italy
November 6-8, Berlin, Germany
November 3-8, Kona, HI, USA
By Andrzej Krzemienski | May 18, 2017 07:34 AM | Tags: basics
Every C++ programmer should see a bug like this, from Matthew Wilson's post. As a warning.
Important semantic effects of small syntax errors
by Matt Wilson
By Adrien Hamelin | May 16, 2017 12:38 PM | Tags: intermediate c++11
Quick A: In C++11 it's required to be constant time.
Recently on SO:
Is list::size() really O(n)?
In C++11 it is required that for any standard container the
.size()operation must be complete in "constant" complexity (O(1)). (Table 96 — Container requirements). Previously in C++03.size()should have constant complexity, but is not required (see Isstd::string size()a O(1) operation?).The change in standard is introduced by n2923: Specifying the complexity of size() (Revision 1).
By bfilipek | May 12, 2017 11:42 AM | Tags: performance
Can you pack 8 bools into one BYTE efficiently?
Packing Bools, Performance tests
by Bartlomiej Filipek
From the article:
The simple problem of packing seems to show a lot of performance issues. If the packing is really needed? Can we make the code parallel? What are the branching effects here?
By Meeting C++ | May 10, 2017 03:09 AM | Tags: conferences community basics
An update on the ongoing call for talks for Meeting C++ 2017:
Reaching out for new speakers at Meeting C++ 2017
by Jens Weller
From the article:
Maybe you can help in an ongoing effort for the C++ Community...
There is an ongoing effort, to ensure that everyone feels welcome at our C++ events...
By Felix Petriconi | May 6, 2017 07:50 AM | Tags: c++2x
Jakie Kay explores in her recent blog post the borders of nearly unknown C++ features:
Fun with Reflection in C++
by Jakie Kay
From the article:
In my previous post, we learned about the current and future state of reflection in C++. But I left a few questions unanswered. Indeed, you may still be wondering why I care so much about reflection and if it has any useful applications for the average programmer. In this post, I’ll try to answer that question with real code examples using the two reference implementations of C++ reflection. I’ll explore the strengths of the two implementations, as well as the major limitations. These examples make heavy use of metaprogramming and C++17 features, so if you find yourself in unfamiliar territory while reading the code, I suggest supplementing this article with other resources.
When I refer to the reflexpr implementation, I’m talking about Matúš Chochlík’s fork of Clang which implements P1094, by Chochlík, Axel Naumann, and David Sankel.
When I refer to cpp3k, I’m talking about Andrew Sutton’s fork of Clang which implements P0590R0, by Sutton and Herb Sutter.
By Adrien Hamelin | May 4, 2017 01:21 PM | Tags: intermediate
Quick A: They behave differently, it depends on what you need.
Recently on SO:
When should you ever use functions over functors in C++?
Functions support distributed overriding. Functors do not. You must define all of the overloads of a Functor within itself; you can add new overloads of a function anywhere.
Functions support ADL (argument dependent lookup), permitting overloading in the argument-type associated namespace. Functors do not.
Function pointers are a kind of type-erased stateless functor that is a POD, as evidenced by how stateless lambdas convert into it. Such features (POD, stateless, type erasure) are useful.
By Adrien Hamelin | May 4, 2017 01:08 PM | Tags: None
An interesting article as well as a nice demo!
A true heterogeneous container in C++
by Andy G
From the article:
Oftentimes I see questions StackOverflow asking something to the effect of
“Can I have a std::vector that holds more than one type?”
The canonical, final, never-going-to-change answer to this question is a thorough“No”
C++ is a statically-typed language. A vector will hold an object of a single type, and only a single type.“But…”
Of course there are ways to work around this...
By Adrien Hamelin | May 4, 2017 01:05 PM | Tags: c++11 basics
Quick A: No.
Recently on SO:
Is there a way to mark a parent's virtual function final from a child class without reimplementing it
No, you can't do it without reimplementing it. So just reimplement it:
struct Child : public Parent { virtual void fn() override final { Parent::fn(); } };N.B. saying
virtual ... override finalis entirely redundant,finalis an error on a non-virtual function, so you should just say:void fn() final { Parent::fn(); }See http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rh-override
By Meeting C++ | May 4, 2017 07:55 AM | Tags: user groups community
The monthly C++ User Group listing at Meeting C++:
C++ User Group Meetings in May 2017
by Jens Weller
From the article:
The monthly overview on upcoming C++ User Group Meetings. Lots of meeting are already planned for May, even more should be announced in the coming weeks.
There are 2 new C++ User Groups: Minneapolis, Stockholm (LLVM).
By Adrien Hamelin | May 2, 2017 01:47 PM | Tags: c++11 basics
Quick A: Are equivalent, but shrink_to_fit mark the intention.
Recently on SO:
shrink_to_fit() vs swap trick
The swap trick isn't actually constant-time. The cost of performing the actual swap is indeed O(1), but then there's the cost of the
std::vectordestructor firing and cleaning up all the allocated space. That can potentially have cost Ω(n) if the underlying objects have nontrivial destructors, since thestd::vectorneeds to go and invoke those destructors. There's also the cost of invoking the copy constructors for all the elements stored in the initial vector, which is similarly Ω(n).As a result, both approaches should have roughly the same complexity, except that
shrink_to_fitmore clearly telegraphs the intention and is probably more amenable to compiler optimizations.