Questions tagged [templates]

The templates tag is used in multiple contexts: generic programming (especially C++), and data/document generation using template engines. When using this tag on implementation heavy questions - tag the code language the implementation is written in.

Filter by
Sorted by
Tagged with
0
votes
0answers
25 views

Templates with Nested class: Injected Class Name (C++)

Given that a template class called Queue with a nested class Node (not a template), I can do this: template<typename T> void Queue<T>::enqueue(const T& elem) { Node* temp = new ...
0
votes
0answers
7 views

Using a formset to create links to records

I'm using Django version 3.0.1, python version 3.6.9 I am trying to set urls to individual records in a loop inside a formset but the url tag can't see my variable even though it is printed out in ...
0
votes
1answer
27 views

Type deduction of parameter and parameter pack

I have the following code for generically wrapping Petsc objects in a unique_ptr, but it doesn't quite work the way I'd expect from cppreference's documentation on template type deduction: https://en....
2
votes
1answer
24 views

Adapting a template with a non-type parameter as a template template parameter

I have a template which can be reduced to the following template <typename T, template <typename U> class Base> class Derived: Base<T> { }; As Base I would like to be able to use a ...
0
votes
1answer
20 views

Unexpacted value inside Vector when using filestream to insert data

I got a template class in which I got a function which should read the content of a textfile and create a object which is being pushed into an own implemented vector class. I can compile the code but ...
4
votes
1answer
59 views

Class Template with <T> or without (C++)

According to Why isn't argument deduction allowed in function return type? When specifying a return type in a template class member function we have to be specific, for example: "the type std::...
2
votes
0answers
25 views

Why is plain old function not selected for explicit call? [duplicate]

I have been reading the interesting topic Why Not Specialize Function Templates? and somewhere encountered the following example. struct Base{}; template<class T> void f(T) { cout << "...
0
votes
1answer
42 views

Undefined reference to struct method [duplicate]

I tried to make an Array template class but when I try to build the compiler fails to link the constructor and the method and I get : undefined reference to `Array::Array() undefined reference to `...
1
vote
1answer
83 views

what is difference of two kinds of template examples?

I intended to make a class 'MyVector' has 3D coordinates(X, Y, Z). I tried making a constructor has three types of function parameter which each parameter type satisfies std::is_arithmetic. I made ...
-1
votes
0answers
34 views

Current file path in form action

I'm trying to execute the current script in a php file as form action, with a basic MVC structure : Create.php <?php $file_path = str_replace('\\', '/', __FILE__); $url_path = ...
4
votes
1answer
83 views

std::accumulate with a reference?

Trying to 'misuse' std::accumulate for an algorithm (why is it in "numeric" header anyway ? ;) ) template<class Range, class Seperator> std::string strjoin(Range&& range, Seperator&&...
0
votes
0answers
24 views

Creation of template class objects [duplicate]

I made this template class: //Elenco.h #pragma once #include "Tipi.h" #include <vector> template <typename T> class Elenco { public: //constructor Elenco() : Elenco::Elenco(std::...
2
votes
5answers
98 views

Template typedef?

In an external API, I have structs defined: Foo1, Foo4, Foo8, Foo16 Now I need to define four functions: void bar(Foo1*); void bar(Foo4*); void bar(Foo8*); void bar(Foo16*); These functions do the ...
0
votes
0answers
27 views

Template methods in a DLL class C++

I'm implementing a DLL in C++ and in my library I have a class which contains a template method. For example class A : public IA { public: A() { /* constructor stuff */ } template <typename T&...
1
vote
2answers
44 views

How to obtain inner type of template type?

I've got the following situation: This is a wrapper type template <typename wrapperInnerType> struct wrapperT{ ... }; using wrapper = wrapperT<float>; And it's used in this class ...
1
vote
1answer
47 views

noexcept + declval fail to compile under MSVC

I'm trying to implement the answer I got to my SO question here: My goal is to detect the existence of void cancel() noexcept method in a template class T. here is my minimal example: #include <...
0
votes
1answer
22 views

is there an good way to debug vuejs computed properties and templates?

I have some problems in vuejs debugging, like in debugging the computed properties, or data values in templates, etc... right now i use IIFE method to debug it which is mentioned in https://vuedose....
0
votes
2answers
44 views

Variadic Template Parameter Expansion Inside Class member of Type std::function

I have a class called "Menu" that is used for displaying options the user can choose from. The user then selects an option and that value is processed. However, I have a child class that does not ...
0
votes
1answer
21 views

Excel sports template rank table

I am currently working on a sports template prediction for the upcoming Euro 2020. I haven't gotten that far yet but below is an example of a group. So the "Tecken" column says which team won the game,...
2
votes
1answer
57 views

Creating tuple of types derived from Variadic Template Pack

Given a list of size_t values as a variadic template parameter pack, how does one make a tuple of derived types (e.g. Matrix) depending on the parameter pack in such a way, that n-th element of ...
2
votes
1answer
70 views

Unforgettable Factory: When is constructor instantiated?

I'm implementing the unforgettable factory. Everything works fine but one thing: The classes are not registered, sometimes. I think the crucial part is the Registrar::registered member. If it is used,...
0
votes
0answers
18 views

Creating an instance of a templated class on the stack in C++ [duplicate]

I want to create an instance of a templated class on the stack. For example: In my Point.h file: template <class T> class Point { public: Point(); ~Point(); }; In my Point.cpp file: ...
0
votes
0answers
28 views

InputValidator for json - GCC compilation fail

I am using nlohmann json library which has json::get<>() function to get the value out of json with type checking. It throws an exception when there is a type mismatch. In my project I need a ...
0
votes
4answers
52 views

Is it possible to cast template parameters on runtime?

Given the following templated method template <typename T> T max(T x, T y) { return (x > y)? x : y; } I want the following call to work: int main() { cout << max(3, 7.0) <&...
1
vote
2answers
28 views

SFINAE disable constructor if conversion exists from `double` to `T`

The following is the minimal meaningful program that I could come up with to reproduce my predicament for this question. The program fails to compile due to a conflict between the constructors of ...
0
votes
3answers
48 views

Template member std::function of none templated class

I have a class that it has a templated function class DialogManager { public: template<class T> using TimeoutCallback = std::function<void (T)>; DialogManager(); virtual ~...
0
votes
1answer
25 views

template parameter is ambiguous / deduced conflicting types for parameter

The program below generates a compiler error: MSVC: error C2782: 'double dot(const V &,const V &)': template parameter 'V' is ambiguous GCC: deduced conflicting types for parameter 'const V' ...
0
votes
2answers
65 views

C++ variadic function template in std::functional

basically I want to integrate a multi-dimensional integral with this recursion. But the problem itself is a general one. It's not specific for integration. #include "math.h" #include <iostream>...
2
votes
0answers
23 views

C++ event system with templates - how to store subscriber functions taking arbitrary type? [closed]

I'm trying to write an event system using templates for flexibility and std::strings as event IDs. I want to be able to fire an event with an argument of any type and then a list of functions handles ...
1
vote
1answer
26 views

C++ - using parent class attributes [duplicate]

I am writing a general Vector class and I want a Vector3 class to inherit from Vector. Vector's data can be of any length, Vector3's data is of length 3. So I want to make a different constructor for ...
1
vote
1answer
51 views

c++ template short circuit logic AND (&&)

I've been told that logic AND (&&) in template doesn't work, so I want to use template specialization to achive it. My test code like follows: #include <iostream> template <bool b1,...
0
votes
2answers
32 views

C++ - empty template class constructor does not initialize value

I have 2 constructors in my self-made template class. One is the empty constructor, which initializes the value to 0. In the other constructor, you can pass a value, which initializes the value to ...
-1
votes
1answer
18 views

can one have multiple html files in a single template directory in django?

I have a templates directory with two other directories, home, and diagnosis each directory having its own respective HTML file. So I want to know if that's the best way to do it or am I doing it the ...
0
votes
0answers
36 views

Call variadic template function using std::delcval [duplicate]

I was playing around with templates, and ended up with a code like this: #include <iostream> #include <tuple> #include <functional> template<int... seq> class A { public: ...
2
votes
1answer
45 views

How to detect a noexcept method using SFINAE

I'm asking about a variation of a (popular) question - detecting the existence of a method of a class. I've read many answers here in SO, and most of the (post C++17) solutions look like this: #...
0
votes
1answer
8 views

Orchard Core: How to create a shape from ContentItem in liquid tempale

I'm still learning how Orchard renders content types through shapes and I'm having issues to understand if the following is a supported configuration or not: 1) I've created two content types called ...
1
vote
1answer
23 views

Thread messaging or better: Accessing members from other class in “master-class”

First of all: Sorry for the probably bad title and that many text - this is because I'm trying to describe my problem as exact as possible! :) If my principle idea is unclear please add a comment - I ...
0
votes
1answer
61 views

C++: Why is name dependent in constructor, not in static member function

I have got somewhat of a follow-up question to the scenario I described here, I found this post especially helpful for reasoning about my problem. Background In my original question, I was ...
0
votes
0answers
35 views

C++ function template argument deduction guide

I have a function and a simple class template <class T, class U> int foo(T t, U u) { return t + u; } template <class A, class B> class C : public A { ... }; C<something, ...
2
votes
2answers
70 views

define non-template function outside a templated class

I was learning about non-template friend function & template friend function to a templated class. So I tried the code below : #include <iostream> template<typename T> class cl { ...
1
vote
2answers
41 views

How to access the template argument's own template arguments?

Say you have a class template (e.g. second below). Say that class template's template arguments are instantiations of another class template (e.g. first below). How do you access the template argument'...
0
votes
3answers
65 views

Conditional template

I have a class with template Inside this class there is a variable T * Variable; and variable string str; and there is function with part of the code: if(std::is_same<T, string>::value){ *...
-2
votes
1answer
47 views

Simplify casts to type which depends on a parameter

I have data in a void pointer that need to be cast in a type depending on an Integer received in parameter. First thought would be doing a simple if/switch statement like: if (dataType == 1) data =...
0
votes
1answer
14 views

In Django template, image is not displayed correctly

I have model class with fields current_value and previous_value. And then, in template used by listview, inside loop i have code like this: {% if data.current_value < data.previous_value %} &...
0
votes
1answer
14 views

HandlebarsJS: display sum of number of objects in a JSON Array?

I have the following simple handlebarsjs email HTML template: <script id="emailTemplate" type="text/x-handlebars-template"> <div> Hi {{name }} , you have submitted {{ ...
0
votes
2answers
38 views

Split for line issue

I have a code: public static CuttingTemplate parseCuttingTemplate(String[] lines) { int size = lines.length; int[] arr = new int[size]; int i; for(i = 0; i < size;...
0
votes
0answers
40 views

Attribute error while creating custom template using python in Google Cloud DataFlow

I am facing issue while creating custom template for Cloud Dataflow. its simple code that takes data from input bucket and loads in BigQuery. We want to load many tables so trying to create custom ...
7
votes
2answers
95 views

Distinguish between function references/pointers accepting const and non-const argument with same name as function parameter

Let's consider two functions with same names: int func(int&) { return 7; } int func(const int&) { return 5; } Let int mutableValue = 5 be defined somewhere. Is there any possibility ...
3
votes
1answer
60 views

c++ template implement loop with recursion

I'm trying to write a meta function with recursion. The inputs are variadic integers, and the output should be the sum of the inputs. My code like follows: template <size_t curInput, size_t......
0
votes
2answers
56 views

How to Check if a Template Type can be Constructed from a Given Type

I'm trying to use std::enable_if_t to enable a class if the template parameter is any type of std::string (bonus points for an answer that shows how to do this with a general string from multiple ...