Advantage of using trailing return type in C++11 functions

In this example, they mean the exact same thing. However, there are a few advantages to using the trailing return type form consistently (Phil Nash calls these “East End Functions”, since the return type is on the east end). Using parameters. Obviously when using parameters to determine the return type, you must use a trailing … Read more

undefined behaviour somewhere in boost::spirit::qi::phrase_parse

You cannot use auto to store parser expressions¹ Either you need to evaluate from the temporary expression directly, or you need to assign to a rule/grammar: const qi::rule<std::string::const_iterator, qi::space_type> doubles_parser_local = qi::double_ >> *(‘,’ >> qi::double_); You can have your cake and eat it too on most recent BOost versions (possibly the dev branch) there … Read more

Does a declaration using “auto” match an extern declaration that uses a concrete type specifier?

There’s surprisingly little in the standard about this. About all we hear about redeclaration is: [C++11: 3.1/1]: A declaration (Clause 7) may introduce one or more names into a translation unit or redeclare names introduced by previous declarations. [..] and the only relevant part of auto‘s semantics: [C++11: 7.1.6.4/3]: Otherwise, the type of the variable … Read more

C++ auto& vs auto

auto and auto && cover most of the cases: Use auto when you need a local copy. This will never produce a reference. The copy (or move) constructor must exist, but it might not get called, due to the copy elision optimization. Use auto && when you don’t care if the object is local or … Read more

Arrow operator (->) in function heading

In C++11, there are two syntaxes for function declaration:     return-type identifier ( argument-declarations… ) and     auto identifier ( argument-declarations… ) -> return_type They are equivalent. Now when they are equivalent, why do you ever want to use the latter? Well, C++11 introduced this cool decltype thing that lets you describe type of an expression. So … Read more

Range-for-loops and std::vector

Because std::vector<bool> is not a container ! std::vector<T>‘s iterators usually dereference to a T&, which you can bind to your own auto&. std::vector<bool>, however, packs its bools together inside integers, so you need a proxy to do the bit-masking when accessing them. Thus, its iterators return a Proxy. And since the returned Proxy is an … Read more

C++ auto keyword. Why is it magic?

auto was a keyword that C++ “inherited” from C that had been there nearly forever, but virtually never used because there were only two possible conditions: either it wasn’t allowed, or else it was assumed by default. The use of auto to mean a deduced type was new with C++11. At the same time, auto … Read more

tech