Why are default template arguments only allowed on class templates?

It makes sense to give default template arguments. For example you could create a sort function: template<typename Iterator, typename Comp = std::less< typename std::iterator_traits<Iterator>::value_type> > void sort(Iterator beg, Iterator end, Comp c = Comp()) { … } C++0x introduces them to C++. See this defect report by Bjarne Stroustrup: Default Template Arguments for Function Templates … Read more

Why can’t an interface implementation return a more specific type?

Usually, I’d say that it would be a case of balancing the benefit against the added complexity of supporting such a feature. (All features take effort to design, document, implement, test, and then developers need to be educated about them too.) Note that there could be some significant complexities if you wanted to support returning … Read more

PEG for Python style indentation

Pure PEG cannot parse indentation. But peg.js can. I did a quick-and-dirty experiment (being inspired by Ira Baxter’s comment about cheating) and wrote a simple tokenizer. For a more complete solution (a complete parser) please see this question: Parse indentation level with PEG.js /* Initializations */ { function start(first, tail) { var done = [first[1]]; … Read more

Datatype promotion for dependently challenged

There are at least two examples in the paper itself: “1. Introduction” says: “for example, we might be able to ensure [at compile time] that an alleged red-black tree really has the red-black property”. “2.1 Promoting datatypes” discusses length-indexed vectors (that is, vectors with compile-time “index out of bounds” errors). You can also take a … Read more

What exactly is or was the purpose of C++ function-style casts?

Function style casts bring consistency to primitive and user defined types. This is very useful when defining templates. For example, take this very silly example: template<typename T, typename U> T silly_cast(U const &u) { return T(u); } My silly_cast function will work for primitive types, because it’s a function-style cast. It will also work for … Read more

Why does the implicit copy constructor calls the base class copy constructor and the defined copy constructor doesn’t?

That’s just the way the implicit copy constructor is defined (it wouldn’t make sense calling the default). As soon as you define any constructor (copy or otherwise) its normal automatic behavior is to call the default parent constructor, so it would be inconsistent to change that for one specific user-defined constructor.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)