Modulus % in Django template

You need divisibleby, a built-in django filter. {% for p in posts %} <div class=”post width1 height2 column {% if forloop.counter0|divisibleby:4 %}first{% endif %}”> <div class=”preview”> </div> <div class=”overlay”> </div> <h2>p.title</h2> </div> {% endfor %}

using extern template (C++11)

You should only use extern template to force the compiler to not instantiate a template when you know that it will be instantiated somewhere else. It is used to reduce compile time and object file size. For example: // header.h template<typename T> void ReallyBigFunction() { // Body } // source1.cpp #include “header.h” void something1() { … Read more

Why can’t I use float value as a template parameter?

THE SIMPLE ANSWER The standard doesn’t allow floating points as non-type template-arguments, which can be read about in the following section of the C++11 standard; 14.3.2/1      Template non-type arguments      [temp.arg.nontype] A template-argument for a non-type, non-template template-parameter shall be one of: for a non-type template-parameter of integral or enumeration type, a converted constant … Read more

Explicit specialization in non-namespace scope [duplicate]

VC++ is non-compliant in this case – explicit specializations have to be at namespace scope. C++03, §14.7.3/2: An explicit specialization shall be declared in the namespace of which the template is a member, or, for member templates, in the namespace of which the enclosing class or enclosing class template is a member. An explicit specialization … Read more

How to emulate C array initialization “int arr[] = { e1, e2, e3, … }” behaviour with std::array?

Best I can think of is: template<class T, class… Tail> auto make_array(T head, Tail… tail) -> std::array<T, 1 + sizeof…(Tail)> { std::array<T, 1 + sizeof…(Tail)> a = { head, tail … }; return a; } auto a = make_array(1, 2, 3); However, this requires the compiler to do NRVO, and then also skip the copy … Read more

Flask raises TemplateNotFound error even though template file exists

You must create your template files in the correct location; in the templates subdirectory next to the python module (== the module where you create your Flask app). The error indicates that there is no home.html file in the templates/ directory. Make sure you created that directory in the same directory as your python module, … Read more

Does it make any sense to use inline keyword with templates?

It is not irrelevant. And no, not every function template is inline by default. The standard is even explicit about it in Explicit specialization ([temp.expl.spec]) Have the following: a.cc #include “tpl.h” b.cc #include “tpl.h” tpl.h (taken from Explicit Specialization): #ifndef TPL_H #define TPL_H template<class T> void f(T) {} template<class T> inline T g(T) {} template<> … Read more

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