FAQ Database Discussion Community


template template class specialization

c++,templates,template-specialization
I am just learning about Template Template class specialisation. Not a big problem to explain in detail. From my understanding std::uniform_int_distribution is a template whereas std::uniform_int_distribution<Type> is the full specialisation of uniform_int_distribution giving a type. I pass this in the specialisation class template as follows below Main class template <template...

Append inline scripts inside Twig layout block

php,symfony2,templates,twig,fosuserbundle
I have a layout that looks like this: <html> <body> <!-- Omitted --> <div class="content"> {% block body %}{% endblock %} </div> <script src="js/vendor.js"></script> {% block javascripts %} <!-- I want to be able to inject inline scripts from sub-templates here --> {% endblock %} </body> </html> Then I have...

How literal are passed in template function

c++,templates,pass-by-reference
#include <iostream> using namespace std; template <typename T> void fun(const T& x) { static int i = 10; cout << ++i; return; } int main() { fun<int>(1); // prints 11 cout << endl; fun<int>(2); // prints 12 cout << endl; fun<double>(1.1); // prints 11 cout << endl; getchar(); return 0;...

decltype does not resolve nested vectors. How can I use templates for nested vectors?

c++,templates,vector,nested
I am trying to overload the + operator to deal with nested vectors. I thought the function would call itself until the nested vectors resolve to basic types, but instead I get a huge list of errors when I compile it. My vector operations that I have defined work for...

AngularJS template reload and page disappears

javascript,angularjs,templates
On my website, if I load a template and then refresh that page, I get a "page not found" error. Is there any way to prevent this? I can post the code, but I'm not quite sure which piece of code would be valuable. Here is my home page (where...

Virtual function implemented as template in derived class

c++,templates,inheritance
Having following code: struct Base { virtual void print(int x) = 0; virtual void print(float x) = 0; }; struct Derived : public Base { template<typename T> void print(T x) { std::cout<<x<<std::endl; } }; Is it possible to do some C++ black magic(explicit instantiation for those types, some smart using,...

Type function that returns a tuple of chosen types

c++,templates,c++11,metaprogramming
I've implemented a type function Tuple that turn a list of My_enum values into an std::tuple of corresponding types: #include <tuple> enum My_enum{ t_int, t_double }; // Bind_type is a type function that given a My_enum returns the corresponding type template<My_enum E> struct Bind_type; template<> struct Bind_type<t_int>{ using type =...

How can I access item in parent repeat template while in filter

javascript,html,templates,polymer
<iron-pages> <template is="dom-repeat" items="{{fruit_categories}}" as="category"> <div> <template is="dom-repeat" items="{{all_fruits}}" as="fruit" filter="isThisFruitInTheRightCategory"> <!-- Some more stuff --> <span>{{fruit.weight}}</span> <span>{{fruit.age}}</span> <!-- ... --> </template> </div> </template> </iron-pages> isThisFruitInTheRightCategory: function(fruit){ return fruit.category === /* Q: How do I get the current category? */ } Suppose I...

Why doesn't a left fold expression invert the output of a right fold expression?

c++,templates,c++1z,fold-expression
I'm taking a look at C++17 fold expressions and I'm wondering why does the following program outputs 4 5 6 4 5 6 for both of the for_each calls template<typename F, typename... T> void for_each1(F fun, T&&... args) { (fun (std::forward<T>(args)), ...); } template<typename F, typename... T> void for_each2(F fun,...

constructor and templates

c++,templates,constructor
I was going through this piece of code where I came across a while calling this code from main #include <iostream> #include <vector> using namespace std; class abc { public: enum example { a=1, b=2, c=3, d=4 }; }; template<typename T> class xyz { public: xyz(T &v,abc::example ex=abc::a):b(v),len(sizeof(T)) { }...

Nested template parameters and type deduction

c++,templates,type-deduction
Hi I am practicing with templates and type deduction and wanted to try making a simple function template with nested template parameters to print out the contents of any stl container: template <template<T, ALLOC> CONT> void Print(const CONT<T, ALLOC> &c) { for (const T &elem : c) std::cout << elem...

Can we access Ember.TEMPLATES in controller?

javascript,templates,ember.js
Is it possible to use Ember.TEMPLATES to check the existence of a template within a controller or component? I am using v1.12.1 We are currently transitioning to a route that is rendering a template that may not exist. Prior to the transition, we need an existence check of the template...

Get the type of & for built-in and operator&()?

c++,templates,operator-overloading,template-meta-programming,addressof
Edit: The answer I've marked below isn't 100% correct, that's actually in a comment: using TPtr = decltype(&std::declval<T&>()); I'm trying to use std::conditional<> to get the type of &T, where T may have operator&(), or not. The simple solution is to not even try, instead specify another template argument: struct...

Crash cause of own template

c++,qt,templates,crash,qvector
why is my program crashing when I use my template? What I'm doing wrong? That's a test program, because the actual program is too big for posting here. The first qDebug with test1 are displayed but the second not. #include <QCoreApplication> #include <QDebug> #include <QMutex> class MutexLocker { public: MutexLocker(QMutex&...

Conditional compile based on type

c++,templates
Assuming I have a 4 value vector union, used to hold either a spatial coordinate or colour and I wish to use one of two functions to convert between integer and real format, how would I construct the functions? My (failed) attempt is: template<class T, class S, typename = std::enable_if_t<std::is_floating_point<T>>,...

How to parameterize the number of parameters of a constructor?

c++,templates,c++11,constructor
I want to accept up to a number of parameters (this number being defined in a template parameter) in a template class constructor. I can't use an initializer_list, since I can't assert its size at compile time, as far as I know. What I tried My first attempt was using...

C++ templating syntax - allocate type with pointer

c++,templates
How can I do memory allocation like this: template <class T> class A { T Generate() { return new T(); // Error } }; A<B *> a; B * pI = A.Generate(); Or can you only ever define something as: A<B> a; ...

Syntax help. Template operator() in template function object

c++,templates,c++11,functor
What is the proper syntax I need to run what I'm trying to run in main() below? #include <iostream> #include <vector> template <int... Is> void foo() { std::vector<int> v{Is...}; for (int x : v) std::cout << x << ' '; } template <int... Is> struct Foo { template <typename T,...

Error when using pointer to derivative class as template argument

c++,templates,pointers
I have encountered a problem when giving as a template pointer argument a pointer to the derivative class instead of the base class. E.i. the following code: class First{}; class Second : public First {}; template<First* ptr> class Third {}; Second obj; int main(){ Third<&obj> obj2; } when compiled returns...

Linker error with variable templates

c++,templates,linker,c++14,template-variables
Consider the code below: #include <iostream> template<typename T> T n; int main() { n<int> = 42; std::cout << n<int> << std::endl; } It compiles and links with g++5.1, and it displays 42. However, clang++ fails to link it: undefined reference to n<int> If I initialize the template variable like template<typename...

Call template function for the value of a pointer out of a template function, in C++

c++,templates,pointers,c++11
I am trying to call a template function for the pointer that was given as template parameter in my calling function. My code is: template <> struct serialize_helper<std::string> { // not important code... } }; template <class T> inline void serializer(const T& obj, StreamType::iterator& res) { if(std::is_pointer<T>::value) { //THIS doesn'...

Function with variable parameters as parameter to function C++

c++,templates,c++11
I am trying to create measuring class with one function that take function to be measured as parameter. Its called ChronoTimer.h content is: #include <chrono> template<typename TimeT = std::chrono::milliseconds, class ClockT = std::chrono::system_clock> class ChronoTimer { public: template<typename F, typename ...Args> static typename TimeT::rep duration(F func, Args&&... args) { auto...

multiple similar files on one host from one template in puppet

templates,puppet
all. This seems like something other people would have already answered, but I couldn't find it, so apologies if this is an old question. I want to make multiple files on one host from the same template. These are dnsmasq hosts files for IPs on an internal vs external network....

Getting template error [duplicate]

c++,templates
This question already has an answer here: Where and why do I have to put the “template” and “typename” keywords? 6 answers I am getting compilation error , please help i am not able to resolve it class A { public : A() {} virtual ~A() {} int getID()...

c++ va_list function overload

c++,templates,c++11,overloading,va-list
I currently have 2 function overloads: void log(const char* format, ...); void log(const string& message); and I want that in case of this call: log("hello"); the string version will be called, or in other words the first overload should only be called in case of 2 arguments or more. I...

C++: Store pointer to a member function of an object in another object

c++,templates,function-pointers,member-functions
I have a class which shall invoke a function specified by the user on certain occasions. Therefore the class has a method void setExternalPostPaintFunction(void(*function)(QPainter&)); that can be used to "register" a function. This function then will be called on that occasion: class A { public: void setExternalPostPaintFunction(void(*function)(QPainter&)); private: void (*_externalPostPaint)(QPainter&);...

SilverStripe 3: Loop greatgrandchildren pages WITH OUT grouping by parent

sorting,loops,templates,silverstripe
In my template I'm looping my child pages as 2 separate lists and then their grandchild pages under these. But I want these greatgrandchild pages to be sorted as an entire list and not divided / grouped by their parents. Simply loop after loop does not work as all greatgrandchild...

A structure that stores its fields by size

c++,templates,c++11,struct,variadic-templates
I would like to know how can I do the following in C++: Consider these classes : C1 < C2 < C3 < ... < Cn, Ci < Cj means sizeof(Ci) < sizeof(Cj) I want a structure that uses variadic templates as a sequence of Ci's, OrderBySize<AnySequenceOfCis>, for example :...

Templates with Operation for 2d array addition

c++,arrays,templates,operator-overloading
I have two 2d arrays arr1 this belongs to object s1 and arr2 this belongs to object s2 and I want to store the addition to the object s3. After a lot of searching and experimenting with this , this is my code: #include <iostream> #include <sstream> using namespace std;...

Determining return type of std::function

c++,templates,c++11
I'm writing a template function that receives a std::function object (Generated by calling std::bind with the proper arguments). Within this function, I would like to determine the return type of this function object. Is is possible? As a matter of fact, I want the template function to return the same...

c++ class template can be instantiated but a function template instantiation with the same template parameters fails

c++,templates,variadic-templates
I have a wrapper class for binded function calls (a helper class to fight some legacy code issues): template <class Result, class... Args> class FunctionWrapper { std::function<Result()> func_; public: FunctionWrapper(std::function<Result(Args...)> f, Args&&... args) : func_(std::bind(f, std::forward<Args>(args)...)) { } //...some methods using that func_ }; I can write the following code,...

How to re-write templated function to handle type deduction

c++,templates,c++11
So, I have this search function for the map container: template <typename Key, typename T> void searchInMapByKey(std::map<Key,T> Map, T keyValue) { if(Map.empty()) { std::cout << "Map is empty, nothing to search for..." << "\n"; } else { for(const auto & element : Map) { if(element.first==keyValue) { std::cout << keyValue <<...

Getting “symbols not found” errors implementing a Stack as Linked List using templates

c++,templates,linked-list,stack
I'm trying to create a stack using a linked list. I've already got it working using integers, but now I want to implement Templates to it. There are no errors detected before compile, but after running I get these errors: *Undefined symbols for architecture x86_84: "Stack::printStack()", referenced from: _main in...

Rails: Include Javascript_include_tag outside default folders

javascript,ruby-on-rails,templates,folder
I have a template that I'm trying to include on my Rails Aplication. This template has it's own structure that I don't want to mess with. Lets call this template "material". I've put all the files under my vendor/assets folder, so that I have this structure: railsApp/vendor/assets/material/material Inside this last...

C++ Will using a pointer to the same function as a template parameter always lead to the same instantiation?

c++,templates,function-pointers
I have a template function taking a function pointer as an argument, and a normal function like so: template <void()> int foo() {static int c = 0; return ++c;} void bar() {} If I understand correctly, two different function pointers can have different binary representations, even if using them would...

dom-if doesn't get updated in dom-repeat

javascript,html,templates,polymer,polymer-1.0
<template is="dom-repeat" items="{{fruit_list}}" as="fruit"> <template is="dom-if" if="{{fruit.isOrange}}"> I'm an orange! </template> </template> Here I have a dom-if template inside a dom-repeat template. It works great if the value of fruit.isOrange has already been finalized. However if not, for example, it was true when before but now I change it to...

Compile-time pure virtual functions

c++,templates
I've tried implementing a list container, and decided to move some general functions like sum() to base class, so that I can reuse them later in other containers. All the base support class needs are three methods empty(), head() and tail. I can't make those pure virtual because support class...

Explicit instantiation of class template not instantiating constructor

c++,templates,constructor,explicit-instantiation
I'm working on a project in C++ and am having trouble understanding what members of a template class get explicitly instantiated when I explicitly instantiate the template class. I've written the following file, which I then compile using Visual C++ 2008 Express Edition's Release configuration and then pop into a...

Partial specialization of nested template types produces “internal error” in VC++ 2012 compiler

c++,templates,visual-studio-2012,nested
In the following example, I have an object class which defines a reference class. Both accept mutability as a template argument. In the case that 'obj' is 'Const', I want to disallow a reference of type 'Non_Const'. The example produces the ambiguous message, "An internal error has occurred in the...

I don't understand how the template function gets to be a friend of the class A::X::Y in the example in [namespace.memdef]/3 in C++14

c++,templates,language-lawyer,c++14,friend
Consider the following code from the example in [namespace.memdef]/3 in C++14: // Assume f and g have not yet been declared. void h(int); template <class T> void f2(T); namespace A { class X { friend void f(X); // A::f(X) is a friend class Y { friend void g(); // A::g...

c++ template function with predicate support

c++,templates
I want to implement a priority queue using template.I tried but i am getting some error , i want to pass custom predicate support for less function. #include <iostream> using namespace std; template <typename T, std::size_t N, typename lessFunction> class MyClass { typedef std::size_t size_type; public: void push( const T&...

Definition of private weak_ptr in template class

c++,templates,static
First of all: I am new to C++, so don't judge me. :) I tried defining a static weak_ptr in a template class in order to use it over all instances. This is my code: template <class T> class my_template : public my_class { protected: std::shared_ptr<T> sp; virtual bool...

Variadic template arguments passed to template function

c++,templates
I have class which accepts one int template parameter, and one int parameter pack (neurons). One of the constructor's goals is to take each of the parameters in the pack and add an instance of a class to a vector. The class, however, takes its arguments as template parameters. I...

Django : How to hide a variable in a template

django,variables,templates
I have a template with a tree Ceramic Composite Metals general I want to hide general I wrote {% for category in object_list %} {% if category != "general" %} <li class="closed"><span class="folder"><a >{{ category }}</a></span></li> {% endif %} it does not work What is the error...

What does SFINAE not work correctly with following has_member function?

c++,templates,c++11,template-specialization,sfinae
I'm trying out examples from Walter Brown's TMP talk and I'm trying to get his has_member implementation working. However the implementation seems to falsely return true which leads me to believe there is some detail of SFINAE that I am not understanding. #include <iostream> #include <type_traits> template <class ...> using...

Invalid use of incomplete type for partial template specialization c++

c++,templates,template-specialization
I am trying to specialize a class method foo(). This works well for full template specialization. However, this does not work with partial template specialization. Here the example code which compiles fine on GCC and Clang : #include <iostream> #include <string> template <typename Key, typename Value> struct SimpleKey { Key...

Cannot instantiate abstract class: Why is the template parameter (reference) causing this?

c++,templates,abstract
I am having trouble with some code. 'Bar' : cannot instantiate abstract class I have (finally) been able to recreate the error in a small amount of code. struct SomeStruct { // ****** }; template <typename TIN, typename TOUT, typename TINDEX> struct IFoo { public: virtual void add(const TIN item)...

Display wordpress posts in ascending order

php,wordpress,templates
I am trying to display wordpress posts in ascending instead of descending order. The code I am using in my template is below <?php $temp = $wp_query; $wp_query = null; $wp_query = new WP_Query(); $wp_query->query('showposts=24&post_type=movie&orderby=ASC' . '&paged=' . $paged); while ($wp_query->have_posts()) : $wp_query->the_post(); ?> however this is not working. Does...

How can I write a decltype expression using a function that expects a non-const reference?

c++,templates,c++11,decltype
Consider: int convert_it(std::string& x) { return 5; } void takes_int_ref(int& i) { } I want to write a function which only exists if convert_it can be applied and the result passed into takes_int_ref. That is, the function body is: template <typename A> void doit(A& a) { int i = convert_it(a);...

Wordpress Custom Post type archive display

wordpress,templates,custom-post-type,advanced-custom-fields
I have a custom post type named STORIES. Within that post type, I have categories, so each STORY is also assigned a category like this... Story 1 (assigned category RED) Story 2 (assigned category BLUE) Story 3 (assigned category GREEN) etc. I need to display a page which lists the...

Why does compilation fail when a function template calls a static method template of a class template? [duplicate]

c++,templates
This question already has an answer here: Where and why do I have to put the “template” and “typename” keywords? 6 answers I don't understand why it succeeds when calling the static method template directly, but not when calling it through the function template. #include <iostream> #include <type_traits> template...

Angular - show key match with value

javascript,angularjs,templates,key-value
In my page I can select a type. The type has following structure: vm.types = { prospect: 'Prospekt', article: 'Artikel', photo: 'Photo', literature: 'Literatur' } In the template there is the select field which writes inside the current document the key of the type. <select data-ng-model="file.docType" data-ng-options="key as value for...

How to use template within Django template?

python,html,django,templates,django-1.4
I have the django template like below: <a href="https://example.com/url{{ mylist.0.id }}" target="_blank"><h1 class="title">{{ mylist.0.title }}</h1></a> <p> {{ mylist.0.text|truncatewords:50 }}<br> ... (the actual template is quite big) It should be used 10 times on the same page, but 'external' html elements are different: <div class="row"> <div class="col-md-12 col-lg-12 block block-color-1"> *django...

C++11 Generate template arguments

templates,c++11,pack,variadic
Is it possible to generate somehow template argument pack? I have the following code working: zip<0,1,2>.expand(c); My goal is to generate the list 0,1,2 at compile time as it is going to be used with variadic templates, for example: zip<make_sequence<3>>.expand(c); I need this to be generated at compile time, as...

Which could be the cause of a variable not being printing in an HTML template called from another PHP class?

php,templates,model-view-controller
I'm developing the base of an MVC project in PHP. I'm advancing with the View part, but something is now working as expected in the rendering of the HTML template. Here are some contents of the files I'm coding to make this work: my_project_root/views/templates/humans_list.php <!doctype html> <html> <head> <meta charset="utf-8">...

Mapping const char * to duck-typed T at compile-time or run-time

c++,templates,c++11
I have many classes A, B, C, D, etc that are duck-typed and thus have the same methods and interface but do not inherit from the same class. E.g. class A { public: void foo(); void bar(); } class B { public: void foo(); void bar(); } class C {...

c++: Two ways of declaring multiple templates

c++,templates
I have the following code: template<typename T> struct Pair3{ T first, second; Pair3() : first(T()), second(T()) {} Pair3(T first, T second) : first(first), second(second) {} Pair3(const Pair3<T>& in) : first(in.first), second(in.second) {} template<typename U> void copyFrom(Pair3<U> in); }; template<typename T> template<typename U> void Pair3<T>::copyFrom(Pair3<U> in){ first = in.first; second =...

Derive return type from template arguments

c++,templates
I have a class like to represent a fixed point number using P total number of bits and F number of fractional bits (leaving P-F-1 integer bits, one bit reserved as sign bit) : #include <bitset> // Fixed point class // P : Total number of bits // F :...

Duplicate values with Polymer template repeat

templates,polymer,repeat,web-component
Okay any I have a strange thing happening with my polymer template <polymer-element name="my-playlist" attributes="info"> <template> <core-ajax url="/getlist" method="POST" auto response="{{data}}" handleAs="json"> </core-ajax> <style> </style> <core-selector class="list"> <template repeat="{{k in data}}"> <core-ajax url="http://api.soundcloud.com/tracks/{{k.track}}.json?client_id=9a6dccd301f1d1cbab751e0a1ec82e2e" method="GET" auto response="{{response}}" handleAs="json">...

can't understand variadic templates in c++

c++,templates,c++11,variadic-templates
I was reading about variadic templates and I came across this example. The book mentions that to end the recursion process, the function print() is used. I really can't understand its use. Why does the author use this empty print() function? void print () // can't get why this function...

Confused about returns in stack template

c++,templates,generic-programming
I'm implementing a generic stack (with an array) in C++ and am confused about what to return in this situation: template <class T> T Stack<T>::pop(void) { if (size != 0) { return items[size - 1]; size--; } else { cerr << "Cannot pop from empty stack." << endl; return ???;...

C++ error: deduced conflicting types for parameter 'T' string vs const char *

c++,string,templates,c++11,char
So, I am writing a simple, templated search function for deque container. Here's the code: template <typename T> void searchInDequeFor(std::deque<T> Deque, T searchValue) { for(const auto & element : Deque) { if(Deque.empty()) { std::cout << "Deque is empty, nothing to search for..." << "\n"; } else if(element==searchValue) { std::cout <<...

Is there a generic way to negate a decltype condition with SFINAE?

c++,templates,c++11,generics,sfinae
I have a dozen functions or so that take two parameters: a generic, and a specific type. E.g.: template <class A, class B> void foo(A& a, B& b) { cout << "generic fallback" << endl; } template <class A> void foo(A& a, int &i) { cout << "generic int" <<...

Django, creating variables in a Template and assigning a value

python,django,templates
I am trying to create a template in Django. In that template i have: dato which contains a dictionary like this {"Name":"Someone","Age":"23"} and propiedad which contains a dictionary like this {"parameterName":"Name"}. I can make {{propiedad.parameterName}} and get the value Name. After that i would like to store that value in...

pyramid_mako not finding templates. is there a hook to find the directory / file being called?

python,templates,mako
This one is really really buggging me. Will start by saying that everything is working perfectly on my local machine. On the server however, whatever I do ends up in a "Can not locate template for uri: ..." On my local machine I use a Linux VM on Mac OS...

Template C++: How to access iterator value for both std::map and std::set?

c++,templates,dictionary,stl,set
I have a specific search function. Because it's used on both std::set and std::map, it was duplicated in our code (not using template). I have to maintain those two functions, and I'd like to move them to a single function using a template (and then have only one search preocedure...

c++: Passing objects to functions

c++,templates,object
I was going through a code where I encountered some problem and was able to crack this piece of code: #include <iostream> #include <stdint.h> #include <unistd.h> #include <errno.h> #include <vector> #include <sys/types.h> using namespace std; class abc { public: abc(int x,int y) { cout << "x:" << x << endl;...

How to force operator>>(C) overload to match container?

c++,templates,operator-overloading,containers,extraction-operator
I would like to have operator>>() overloads for any "base" type and for any container type. This is what I have so far: typedef uintmax_t my_t; template <typename T> std::istringstream &operator>>(std::istringstream &iss, T &v) { static my_t um = 6009; v = um++; return iss; } template <template <class> class...

Template specialization with std::enable_if<>

c++,templates,c++11,template-specialization
The following code compiles and runs: #include <cinttypes> #include <cstdlib> #include <iostream> #include <limits> #include <sstream> #include <stdexcept> class UnsignedBox { public: typedef std::uint64_t box_type; template<typename UNSIGNED_TYPE, typename std::enable_if< std::numeric_limits<UNSIGNED_TYPE>::is_signed==false && (sizeof(UNSIGNED_TYPE) >= sizeof(UnsignedBox::box_type)), int>::type = 0 > UNSIGNED_TYPE toUnsigned()const { //We've established we're not returning a...

using class name in a class template without template parameters

c++,templates
the code comes from a C++ book as below: Why does this public member Link* next have no typename argument? template <typename E> class Link { private: static Link<E>* freelist; public: E element; Link* next; // this line confused me.... Link(const E& elemval, Link* nextval = NULL) { element =...

Check a template type is in a list of available types

c++,templates,c++98
I have a template class Foo. I wrote it template to avoid a huge duplication of code, but this class must be used only with some specific other classes. How can I check that without C++11 ? For the moment, the solution I'm going to write is something like that:...

C++ vector error C2036: 'int (*)[]' : unknown size

c++,templates,c++11,vector
I am getting 5 compile errors C2036: 'int (*)[]' : unknown size all from various places in the vector class. #include <gl\glew.h> #include "Vector2.h" #include "Vector3.h" #include "WFObjModel.h" #include <vector> #include <memory> using namespace math; using std::vector; using std::string; using io::WFObjModel; using std::unique_ptr; class Mesh { private: GLuint textureID; unique_ptr<vector<Vector3<float>>>...

Template cast operator when T is QPointF

c++,qt,templates,casting
I have a custom two dimensional point type, which has a template cast operator: struct MyPoint { double x, y; template < typename T > operator T() const { return T{ x, y }; } }; All works fine for std types: auto p1 = MyPoint{ 1, 2 }; auto...

Double templated function overload fails

c++,visual-studio-2010,templates,compiler-errors,c++03
I have a template class, having various template functions. One of them need to be overloaded (a couple of times). Basically - if my class would not be a template, these would be my function(s): class OtherClass { public: template<class T> T foo(T &t, const std::string &trash); }; template<class T>...

Django template not found in main project directory error

python,django,templates
I am getting a 'template not found' error, although I've set up a correct template hierarchy (or so I thought) . ├── manage.py ├── twinja │   ├── admin.py │   ├── admin.pyc │   ├── __init__.py │   ├── __init__.pyc │   ├── migrations │   │   ├── __init__.py │   │   └── __init__.pyc │   ├──...

C++ name resolution for member functions in template class

c++,templates
#include <iostream> template<class T> struct A { typedef T a; }; template<class T> struct B { typedef typename A<T>::a a; static a foo(a b); }; template<class T> a B<T>::foo(a b) {return b} int main() { std::cout << B<int>::foo(1); } Gives the following error: (try it). main.cpp:13:1: error: 'a' does not...

What does STATIC_ASSERTION_FAILURE do?

c++,templates
I am trying to understand an open source implementation of a SAT solver (miniSAT http://minisat.se/downloads/MiniSat_v1.12b_src.zip) . In one of the header files I came across the following code snippet. template <bool> struct STATIC_ASSERTION_FAILURE; template <> struct STATIC_ASSERTION_FAILURE<true>{}; #define TEMPLATE_FAIL STATIC_ASSERTION_FAILURE<false>() I am unable to understand what this does exactly. From...

All the F# templates in VS 2015 RC disappear

templates,f#,visual-studio-2015
I installed in a fresh Win 8.1 machine VS 2015 RC. I load VS and create a F# project. Fine. Eventually, I do some other stuff (that I have not remember) and then I found that no single F# template (for projects) exist anymore in VS. Only C#/VB ones....

Why can't this metametafunction's template parameter be deduced?

c++,templates,template-meta-programming
I have the following wrapper-maker metametafunction: template <class ToWrap> struct wrapper_maker { template <bool> struct wrapper { wrapper(ToWrap& a) : a(a) { } ToWrap& a; }; }; I want to use it in this template function foo: template <class ToWrap> void foo(typename wrapper_maker<ToWrap>::template wrapper<true>& wrapped) { cout << "foo" <<...

How to add angular attribute directive to input in rails slim template?

angularjs,html5,templates,ruby-on-rails-4,slim
Trying to attach custom angular attribute directive to rails slim template. But all attempts are not successful. Here is the code input#title.form-control placeholder="Product titile" type="text" ng-model='product.title' server-error where 'server-error' is a custom directive. But when browser renders this html this directive is cutted off and printed as a plain text....

Error using range-based for loop - Eclipse CDT Luna

templates,c++11,for-loop,mingw,eclipse-luna
I am a beginner at C++ programming. I tried to write a very simple program that combines the use of templates, passing arrays as arguments to a function and a range-based for loop. This is the program that I wrote and compiled using the Eclipse Luna CDT software. #include <iostream>...

How to partially substitute an Underscore.js template, or how to create a template from a template

javascript,templates,underscore.js,underscore.js-templating
I would create a master template for generating other templates. The only method I found is this one: var test_tpl_master = _.template( "StackOverflow <%= type %> question number <%= num %>" ); var test_tpl_1 = _.template(test_tpl_master({ "type": "good", "num": "<%= num %>" })); var test_tpl_2 = _.template(test_tpl_master({ "type": "stupid", "num":...

C++ why does SFINAE fail with only a class template parameter?

c++,templates,c++11,sfinae
I'm using SFINAE in the style of this answer in order to call a generic vector object by using an appropriate member function. For example, the following code calls operator[](int) const first, and if that doesn't exist then operator()(int) const: template<int I> struct rank : rank<I-1> { static_assert(I > 0,...

Mandrill Handlebar Template does not render / merge with Parse.com object correctly

templates,parse.com,mandrill
I'm using Mandrill to send template-based email notifications each time a given Object is created in a Parse.com app. The Mandrill template (made with Handlebars) uses 2 typical Parse.com object properties: objectId --> {{object.objectId}} in the template createdAt --> {{object.createdAt}} in the template The problem is that other object properties,...

Variadic Generation of Tuples

c++,templates,c++11
I want to write a c++ code that based on an integer value and a coordination, generates a set of tuples and function calls like this: // dimension = 1, input = (i) generated tuples: (i-1) (i), (i+1) // dimension = 2, input = (i,j) generated tuples: (i-1, j), (i,...

Django: reference static file from js in static file directory

javascript,python,django,templates,django-staticfiles
I'm trying to call a static file from a js file placed in the static files directory of my Django project. Here it is an example. From my template I call a js from the static files in the following way: {% load staticfiles %} ... <script src="{% static 'js/init.js'...

template specialization function c++

c++,templates,cout
This is my code: #include <iostream> using namespace std; template< typename T > T silnia( T w ) { cout << "not special" << endl; } template<> int silnia<int>( int x ) { cout << "special" << endl; } int main() { cout << silnia<double>(5) << endl; cout << silnia<int>(5)...

Accessing base member data error when derived class is templated

c++,templates,template-meta-programming
I have the following problem with the curiously recurring template, with a problem when I try to access the data member of CRTP base class. template<typename T> struct Base { int protectedData=10; }; struct Derived : public Base<Derived> { public: void method() { std::cout<<protectedData<<std::endl; }; }; int main () {...

Combining multiple template classes to one class using typedef

c++,templates,macros,typedef
I have the following piece of code. Let us have the function declaration and implementation seperate. #include <iostream> class Y1 {}; class Y2 {}; template <class T1, class T2> class A { public: explicit A(); void foo() const; int bar() const; }; template <class T1, class T2> A<T1, T2>::A() {}...

C++ method forwarding

c++,templates,c++11,operator-overloading,perfect-forwarding
I need to implement a class Container which acts exactly as the contained template class: template <typename T> class Container { public: //... private: // T data_; }; T can be either a predefined type (e.g., int) or a user-defined type. The purpose is to intercept any read/write operations done...

VS2015: Variadic template specialization

c++,templates,c++11,c++14,visual-studio-2015
This code #include <iostream> #include <type_traits> template<typename Head, typename... Tail> struct Is_Admitted { constexpr static bool value = Is_Admitted<Head>::value && Is_Admitted<Tail...>::value; }; template<> template<typename T> struct Is_Admitted<T> : public std::false_type{}; template<> struct Is_Admitted<int> : public std::true_type{}; template<> struct Is_Admitted<double> : public std::true_type{}; int main() { std::cout << Is_Admitted<int,...

How do I access request parameters in kademi templates?

html,templates,velocity,kademi
I've been developing a website with Kademi and i'm trying to implement a date range search, I've got the date range adding parameters to the URL ?startDate=02/05/15&endDate=12/12/2015 But I don't know how to retrieve these values in kademi templates. How do I do this?...

Overloading Assignment operator in template based class

c++,templates,type-conversion,operator-overloading,template-meta-programming
I am writing a library to support a type of integers which have two template parameters INT_BITS and FRAC_BITS. I was successful in writing a convert function to convert different class types from one to another [ which vary in values of INT_BITS and FRAC_BITS ]. But when I try...

C++ template template

c++,templates
I'm trying to understand C++ template templates by implementing a generic container class. Here is the code: using namespace std; template <typename T, template <typename STORETYPE> class Container> class Store { public: ~Store() {}; Store() {}; void someFunc( const T & ) {}; //... private: Container<T> storage; }; int main(int...

Meteor template helper not returning value

javascript,templates,methods,meteor
I wrote a method to return a value onto the client: Template.Cart.helpers({ cartPrice: function(result) { Meteor.call('returnCartPrice', function(error, result) { if(error) { alert(error.reason); } else { alert('result is ' + result); //this alerts return result; } alert('result is ' + result); //this does NOT alert return result; }); } }); cart.html:...

Silex - How to process template includes separately

symfony2,templates,include,silex
I've got a Twig base template like so: {% include "./partials/navigation.html" %} <!-- Main Wrapper --> <div id="wrapper"> {% block content %}{% endblock content %} </div> I also have a route controller which is outputting the response content to the page using twig: return template->render('path/to/teplate', args()); where args[] array is...

Syntax errors when right shift operator is used as a template parameter

c++,templates,syntax-error
If I take the address of a right shift operator and pass it as a template parameter, the right shift symbol is being misread as the end of the template parameter list, and the resulting confusion is causing multiple errors. template <class T, void(T::*)(int)> struct TemplateMagic {}; struct TestStruct {...

Passing a struct to a template with extern const. What is the extern for?

c++,templates,struct,const,extern
I am asking myself why the following code works and what the specifier extern does when instantiating baz_instance: struct baz { int value; }; extern const baz baz_instance = {3}; template<baz const& b> int foo(){ return b.value; } int main(){ foo<baz_instance>(); return 1; } Why does the above code compile...

Mail with html content shows break lines or ignores newlines

email,templates,go,mandrill
I am sending mail to users via mandrill and I using both smtp and mandrill api to send. Content of the mail is rendered go template (.tpl) When I put template like Hi {{.name}}, <br/> This is support. <br/> it sends via mandrill api ok, but is visible when I...

Symfony2 service unable to find template

php,email,symfony2,templates,twig
I've just pulled an all-nighter trying to get this to work, and I'm probably missing something foolish, but help me out. I have a symfony2 service which sends emails. I have injected the @templating service into my service's constructor like so: services.yml order_service: class: AppBundle\Services\OrderService arguments: [ "@doctrine.orm.entity_manager", "@mailer", "@templating"...