The main() Course -- Adi Shavit
A fanciful little post about li’l old main().
The main() Course
by Adi Shavit
From the article:
The function main() is a normal program’s entry point.
The shortest conforming C++ executable program is: int main(){}
March 23-28, London, UK
By Adi | Sep 4, 2017 01:05 PM | Tags: basics
A fanciful little post about li’l old main().
The main() Course
by Adi Shavit
From the article:
The function main() is a normal program’s entry point.
The shortest conforming C++ executable program is: int main(){}
By Adrien Hamelin | Aug 30, 2017 12:45 PM | Tags: intermediate c++11
Quick A: Use integer_sequence with a helper function.
Recently on SO:
Array Initialisation Compile Time - Constexpr Sequence
1) How to implement that kind of integer_sequence?
template <std::size_t... Is> constexpr auto make_sequence_impl(std::index_sequence<Is...>) { return std::index_sequence<generate_ith_number(Is)...>{}; } template <std::size_t N> constexpr auto make_sequence() { return make_sequence_impl(std::make_index_sequence<N>{}); }2) Is it possible to build an std::array from that integer_sequence at compile time?
template <std::size_t... Is> constexpr auto make_array_from_sequence_impl(std::index_sequence<Is...>) { return std::array<std::size_t, sizeof...(Is)>{Is...}; } template <typename Seq> constexpr auto make_array_from_sequence(Seq) { return make_array_from_sequence_impl(Seq{}); }Usage:
int main() { constexpr auto arr = make_array_from_sequence(make_sequence<6>()); static_assert(arr[0] == 0); static_assert(arr[1] == 1); static_assert(arr[2] == 2); static_assert(arr[3] == 4); static_assert(arr[4] == 5); static_assert(arr[5] == 7); }
By Adrien Hamelin | Aug 30, 2017 12:34 PM | Tags: None
Quick A: The constructor needs an extra {} pair.
Recently on SO:
vector does not convert brace encloser list
You have two options:
- add a constructor taking
std::initializer_list<std::initializer_list<T>>- eclose the init expression with another set of
{}i.e.Matrix<double> a{{ { 17, 24, 1}, { 23, 5, 7 }, { 4, 6, 13 } }};Ok, I'll try a little explanation of what is going on here:
If there is no constructor taking a
std::initializer_listthen the outermost{}are always opening and closing the constructor call if you will, and not part of what you actually pass to the constructor.Matrix<double> a{ {1, 2}, {3, 4} }; ^ ^~~~~~~~~~~~~~ ^ | 2 parameters | | | | | opening closingAs you can see this is taken as a constructor with 2 parameters, in this case 2
initializer_lists.This is why you need another set of
{}:Matrix<double> a{ {{1, 2}, {3, 4}} }; ^ ^~~~~~~~~~~~~~~~ ^ | 1 parameter | | | | | opening closingIn order for the outermost
{}to be considered aninitializer_listthen the constructor needs to have an overload taking ainitializer_list. That is what is happening in thestd::vectorcase.
By Adrien Hamelin | Aug 29, 2017 12:57 PM | Tags: experimental community
Did you miss something?
C++ Annotated: Apr – Aug 2017
by Anastasia Kazakova
From the article:
Today we are happy to share our next compilation of C++ news with you.
By Adrien Hamelin | Aug 29, 2017 12:43 PM | Tags: intermediate c++17
A handy new feature:
C++17: Inline Variables
by Marc Gregoire
From the article:
Before C++17, if your class had any non-const static data members, you had to allocate memory for them.
By Adrien Hamelin | Aug 28, 2017 01:09 PM | Tags: efficiency c++11
You use threads? You should know this.
Top 20 C++ multithreading mistakes and how to avoid them
by Deb Haldar
From the article:
Threading is one of the most complicated things to get right in programming, especially in C++. I've made a number of mistakes myself over the years. Most of these mistakes were luckily caught in code review and testing ; however, some arcane ones did slip through and make it into production code and we had to patch live systems, which is always expensive.
In this article, I've tried to catalog all the mistakes I know of, with potential solutions. If you know any more pitfalls, or have alternative suggestions for some of the mistakes – please leave a comment below and I'll factor them into the article.
By bfilipek | Aug 23, 2017 10:23 AM | Tags: performance c++17
Let’s see how C++17 can make writing parallel code a bit easier.
C++17 in details: Parallel Algorithms
by Bartlomiej Filipek
From the article:
With C++17 we get a lot of algorithms that can be executed in a parallel/vectorized way. That’s amazing, as it’s a solid abstraction layer. With this making, apps is much easier. A similar thing could be achieved possibly with C++11/14 or third-party APIs, but now it’s all in the standard.
By Adrien Hamelin | Aug 23, 2017 09:19 AM | Tags: intermediate c++17
THe series continue.
C++17 in details: Parallel Algorithms
by Bartlomiej Filipek
From the article:
Writing multithreaded code is hard. You’d like to utilize all of the machine’s processing power, keeping code simple and avoid data races at the same time.
Let’s see how C++17 can make writing parallel code a bit easier.
By Adrien Hamelin | Aug 21, 2017 12:10 PM | Tags: community
ACCU’s Overload journal of June 2017 is out. It contains the following C++ related articles.
From the journal:
Editorial: Gnomes and Misnomers.
What's in a name? Frances Buontempo decides some names are better than others.The Path of the Programmer.
Charles Tolman provides a framework for personal development.A Usable C++ Dialect that is Safe Against Memory Corruption.
Sergey Ignatchenko continues his investigation of allocators for (Re)Actors.Metaclasses: Thoughts on Generative C++.
Herb Sutter shows how metaclasses could simplify C++ with minimal library extension.A C++ Developer Sees Rustlang for the First Time.
Katarzyna Macias provides an introduction to Rust for a C++ developer.Portable Console I/O via iostreams.
Alf Steinbach describes how his library fixes problems streaming non-ASCII characters in Windows.A Functional Alternative to Dependency Injection in C++.
Satprem Pamudurthy showcases a functional alternative to dependency injection in C++.About the C++ Core Guidelines.
Andreas Fertig shows us the C++ core guidelines.Afterwood.
Chris Oldwood reminds us to fix the problem, not to blame.
By Adrien Hamelin | Aug 18, 2017 12:11 PM | Tags: intermediate c++11
Quick Q: Delete its constructor
Recently on SO:
Make C++ fail compilation on specific instantiation of template function
Since foo is a complete specialization, it will always get compiled, and the static assert will always get called.
However, there’s an easier way:
template <> Bar foo<Bar>(Bar val) = delete;This will say that this specific version is deleted, and cannot be called.