Why is the HTML SCRIPT tag not subject to the same origin policy

I suppose this draft titled “Principles of the Same-Origin Policy” explains (albeit briefly) what’s pretty much in everyone’s head: In principle, user agents could treat every URL as a separate principal and isolate each document from every other URL unless the document explicitly indicated that it trusted that URL. Unfortunately, this design is cumbersome for … Read more

Why doesn’t C++ support dynamic arrays on the stack? [closed]

I think, it’s because C++ provides superior solutions: std::vector<T> and std::array<T,N> (C++11); though the latter is not dynamic as such but it’s superior to raw arrays. You can always know the size, no matter which function you pass the vector or array. Since C cannot provide these solutions, C99 came up with Variable Length Array … Read more

Format for writing a JSON log file?

You’re not going to write a single JSON object per FILE, you’re going to write a JSON object per LINE. Each line can then be parsed individually. You don’t need to worry about trailing commas and have the whole set of objects enclosed by brackets, etc. See http://blog.nodejs.org/2012/03/28/service-logging-in-json-with-bunyan/ for a more detailed explanation of what … Read more

Is there a way to access the underlying container of STL container adaptors?

I spotted the following solution somewhere on the web and I’m using it in my projects: template <class T, class S, class C> S& Container(priority_queue<T, S, C>& q) { struct HackedQueue : private priority_queue<T, S, C> { static S& Container(priority_queue<T, S, C>& q) { return q.*&HackedQueue::c; } }; return HackedQueue::Container(q); } int main() { priority_queue<SomeClass> … Read more

Understanding the C11 type hierarchy

The cluttered structure of C11 types resulting from the second step of the question can be simplified by removal/reduction of less important nodes and delegating some redundant/subsidiary information to be presented by other means. I propose the following five-step algorithm for that: Removal of all extended integer types (strictly conforming implementation assumed); Reduction of the … Read more

Can a lambda capturing nothing access global variables?

Yes, sure. Normal name lookup rules apply. [expr.prim.lambda]/7 … for purposes of name lookup … the compound-statement is considered in the context of the lambda-expression. Re: why local variables are treated differently from global ones. [expr.prim.lambda]/13 … If a lambda-expression or an instantiation of the function call operator template of a generic lambda odr-uses (3.2) … Read more

Why 1103515245 is used in rand?

If you use a LCG to draw points on the d dimensional space, they will lie on at most (d!m)1/d hyperplanes. This is a known defect of LCGs. If you don’t carefully choose a and m (beyond the condition for full periodicity), they may lie on much fewer planes than that. Those numbers have been … Read more

Is for(auto i : unordered_map) guaranteed to have the same order every time?

The iteration order of unordered associative containers can only change when rehashing as a result of a mutating operation (as described in C++11 23.2.5/8). You are not modifying the container between iterations, so the order will not change. Although the specification doesn’t explicitly state that rehashing can’t occur at any other time, doing so would … Read more

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