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
4 views

how to use input variables in custom template file in visual studio code

I'm trying to create a template where I supply namespace name on the creation of a new file. but no matter what I do it won't work. Tab stops in snippets work great, but nothing I've tried works for ...
0
votes
0answers
11 views

Template in Visual Studio 2019 for Autocad

I want to have a template in visual studio 2019 for Autocad 2017. My goal is to create a C# ProjectTemplate for AutoCAD in Visual Studio 2019, template allowing to automatically launch AutoCAD by ...
1
vote
1answer
55 views

How to check for operator != existence for template arguments with C++ 17?

I have the following use case: template<typename T> struct Foo { bool setValue(T const &iValue) { if(fValue != iValue) { fValue = iValue; return true; } ...
1
vote
1answer
34 views

From a tuple of types to an array of values returned by calling a template function

I have a tuple type definition : using types = std::tuple<A,B,C>; I have a template function : template <typename T> uint32 f() { return 0; } I define the following type and variable (...
4
votes
2answers
93 views

Correct C++ approach to store multi-type data

Let me consider that I have 4 bytes that describe some real system parameters. Suppose that could be interpreted as float, uint32_t and boolean. The main idea to store and process this variables ...
0
votes
0answers
20 views

Deduce return type on base class virtual method [duplicate]

Assuming the following couple of classes Base and Derived, is there a way to either a) declare a virtual method value() on the base class without a specific return type (which I doubt it's possible) ...
-1
votes
0answers
23 views

Move stars before rating text on single product page

Currently on the single product page, the rating text is displayed first and then the stars. I would like to swap them. I have tried to look for the code that displays the stars but without success. ...
0
votes
0answers
11 views

Shopify Theme Development - Edits to one collection affect all collections using same template

I have built a couple collection templates - in this instance I am editing one called 'collection.brand.liquid', placing sections through out this collection template so the content can be edited in ...
4
votes
1answer
63 views

SFINAE detect if type is defined

I want to pick a specialization of a template when a certain type is defined. I still cannot wrap my head around SFINAE :(. I might be close or I might be completely off. I tried different things ...
5
votes
2answers
84 views

Get function arguments type as tuple

Problem Given any function (or callable) type Function, how can I get its all arguments types as a tuple type ? For example, I need a trait function_traits<Function>::arguments, where: int ...
0
votes
0answers
10 views

How to properly link multiple source files(that implements templates) during compilation? [duplicate]

I am trying to create template class for arrays in C++ and I am new to templates. I am having problem when trying to compile the source code from different files. I have tried to merge all the codes ...
4
votes
2answers
87 views

How do I make for_each work with templates?

I am new to c++ and am trying to understand how for_each works. So I wanted to see how it works with templates and tried this code but it gives out an error When I tried to use the for each in the ...
0
votes
0answers
7 views

How to create an SSIS Package as an ItemTemplate in SSDT 2017 and save it in User Item Templates Location?

I've created a number of SSIS .DTSX packages and I want to use them as SHARED templates. Since our company will not allow us/Developers Admin Privileges on our systems, I'm trying to save the .DTSX ...
1
vote
4answers
81 views

C++ Function Template Questions

I've been using C# so long, I have a couple of questions about function templates in C++. template <typename T> T max(T x, T y) { return (x > y) ? x : y; } Why do some examples use ...
1
vote
3answers
40 views

Template function where template argument type depends on function arguments

I'm porting some C code to C++, and I came across a macro that has the following the signature. bound_check(v, l, h) In practice, l and h are (integer) constants, which lends itself to template ...
2
votes
1answer
30 views

Template function to override std::vector::assign

I am writing a C++ class which contains a member vector. I would like to override the vector methods so that MyVector can be used like a std::vector. However, the assign method keeps throwing a ...
0
votes
0answers
7 views

How to modify url for pagination with aditional get parameters

I'm realising a search list using a simple form using GET. After that, I'm trying to introduce pagination to the list of objects that has been found using that form. The problem is that, inside of ...
0
votes
1answer
37 views

Calling a template function problems “No matching function for call” arguments: iterators, object function

I am learning for an exam in Object oriented course, and I have an ex about STL, including library algorithm, iterators, etc etc. I am trying to send to a function iterators, and object function, and ...
2
votes
2answers
58 views

Explicit specialization must precede its first use

I need to be able to insert stub code into a template function, where the stub code is specialized. This is allowed by most compilers if I use a trampoline like template <class T> T foo(T t) { ...
12
votes
2answers
138 views

Why is the Visual Studio C++ Compiler rejecting an enum as a template parameter?

I'm using the Microsoft Visual Studio 2019 compiler (cl.exe), and it is rejecting some code accepted by both Clang and GCC, related to using enums as template parameters, where the templates are ...
0
votes
1answer
44 views

What is checked in this template exactly?

I was working a little on this code: #include <type_traits> template<typename T, typename T2> constexpr bool Assignable = std::is_assignable<T&,T2>::value; template<...
0
votes
2answers
60 views

Avoid “recursive” function calls while unpacking variadic templates until runtime condition

Basically, I want to find a template in a parameter pack that satisfies some runtime conditions. Intuitively, I just want to iterate over my instantiations of the parameter pack and find the first ...
0
votes
0answers
31 views

Overload operator [] with a template [duplicate]

I'm trying to overload operator[] using a template so it is possible to choose what type is returned. Simplified example: class A { uint8_t buff[10]; public: template<typename T> ...
8
votes
0answers
103 views

Should a definition inside template class be instantiated if it is not used?

template <typename T> struct A { static constexpr T obj {}; static constexpr bool noexcept_copy = noexcept( T{obj} ); static void UsesCopy() { T{obj}; } static constexpr int C ...
4
votes
3answers
96 views

Idiomatic way to get size_type from std::array or the like

Triggered by this question, I came up with code along the line of (it was boost::array in my answer, but the same applies for std::array): template <std::array<char,1>::size_type size> ...
-2
votes
0answers
26 views

Practice recommendation for translation with template engines (Smarty, Twig, …) [on hold]

My "problem" is translations (i18n) with template engines like Smarty or Twig for medium/large scale websites. There are multiple approaches of resolution how to handle translating small websites/...
3
votes
2answers
113 views

How to encode a list of types to be used for template parameters?

Considering the following code, where I define a strong-typed enum Fruit, as well as several PeelerX classes: #include <vector> enum class Fruit { Avocado, Banana, Coconut, ...
0
votes
0answers
25 views

How to do Spring rest template call with service request as a input parameter

This is the input parameter, > <ServiceRequest> > <filters> > <Criteria field="launchedDate" operator="GREATER">2019-08-18</Criteria> > </...
-1
votes
1answer
24 views

Azure ARM template vnet peering - subnets deleting

This is a known 'issue' from what I've gathered (https://github.com/Azure/azure-quickstart-templates/issues/2786) I've build a python script that takes in a .csv and builds out an environment. All ...
2
votes
1answer
58 views

Capture size of array template parameter

When using an array non-template type parameter, it seems that size information is basically impossible to recover without passing it separately. For example, in a template template<const char ...
2
votes
2answers
93 views

Type traits style to test if T is a basic_string<> or printable string-like type?

Im writing a template that can print ranges using ostream's : template<class T> struct range_out { range_out(T& range) : r_(range) { } T& r_; //static_assert(std::is_same<...
6
votes
3answers
163 views

How to provide the function signature for a function taking iterators of stl containers?

I want to write a function my_func that can be called as so, but does not care that v is a std::vector, it could be any STL container. A bit like std::for_each: std::vector<std::string> v = {......
-1
votes
3answers
43 views

Booststrap table insert break after modulus

What should I change in my code in order to have only 3 columns? <table class="table"> <thead class="thead-light"> <tr> <th scope="col">Start</th> &...
2
votes
0answers
71 views

boost::future::then how is it implemented?

I am using futures and especially the continuations (then) a lot in other languages (javascript, python) and recently learned that something like it is also available in c++. For example like this: #...
-1
votes
1answer
41 views

How to fix no matching overloading function found? [duplicate]

Trying to write in C++ the function similar to range in python, taking various types of numerical arguments and returning vector of user-specified type. Do not understand the origin of error. If ...
1
vote
3answers
54 views

how to list initialise a templated class without std::initializer_list so it has a fixed size

Without using stdlib(due to arduino platform) I'm trying to create a map like class that I can use to run functions given a string. Its size needs to be fixed on creation. So i've been trying to ...
1
vote
2answers
64 views

Variadic argument subset

I am trying to obtain a subset of the variadic arguments of current class wrapper to instantiate a new one Currently I have this: // Reference: /questions/27941661/...
0
votes
1answer
37 views

How do I sort based on a vector of type template [duplicate]

How do I pass in / use a vector <T> vect in sort() function ? Thanks for the help. I have a few classes: class A { int x; int getX() {return x;} } class B : public A { int x; } and a ...
-1
votes
0answers
40 views

Calculating Log 2 at Compile Time [duplicate]

I'm in the process of designing a class that will take an unsigned value as its template argument. This number will determine how many states are available for this class. Now within the class I'm ...
3
votes
0answers
44 views

C++: Perfectly forwarded integral_constant can't be evaluated at compile-time with template function [duplicate]

I wrote the following function that returns me the value of an integral_constant during compile-time such that I can use it in lambas with auto parameters: template<typename T, T v> constexpr ...
0
votes
0answers
33 views

Non-Type Template Parameters or Template Parameters [duplicate]

Good day. I am continuing to read the book " C++17 in detail " of Bartlomiej Filipek. Page 63 ( 85 of pdf ebook), he wrote the following code at the bottom of my message. I kindly ask your help to ...
1
vote
1answer
34 views

Deducing template parameter types for each type in parameter pack

Let's say I have a type template <class T, class U> class Pass { }; I want to make a class that will accept a list of Pass objects, each with arbitrary T and U and make 3 std::tuples. ...
-1
votes
0answers
36 views

using sizeof function to find array's size(example code) [duplicate]

I wrote a code to practice c++. but it doesn't return the size of the array. where is my problem? #include <iostream> #include <conio.h> using namespace std; namespace vari { int ...
0
votes
2answers
19 views

Invisble checkbox in Arcana Template

I use Arcana HTML5 Template from https://html5up.net/arcana and adopted the template to GetSimple CMS. Both templates (the original one and the one I have in CMS) don#t display elements. Text is ...
0
votes
0answers
44 views

Create method template C# in Visual Studio

I can't seem to find anything about this online, it may not be possible, but I wanted to double check here: I want to make a standardisation for methods the way I use them. For example, if I create ...
-1
votes
2answers
58 views

when trying to construct an Array of ints with a template for a Array class, Error: Why is the array type 'int [5]' is not assignable,

When trying to build an array with a template, I get an error when implementing a default constructor for the Array class template. int main() { Array<int,5> arrayOfFiveInts; return 0; }...
0
votes
2answers
44 views

Bind member function to instance with variadic arguments

My goal is to create a generic Event type that can be used in subscribe/notify architecture, but I am having trouble getting class member functions to work. Event.hpp: #ifndef EVENT_HPP #define ...
3
votes
1answer
102 views

Why does the compiler require the type to be specified?

I've implemented a class template that is responsible for constructing a single type (follows the builder pattern). The builder's constructor is used to deduce two types. Below is an example that ...
0
votes
0answers
16 views

How am i calling the template function incorrectly? [duplicate]

//When I attempt to call the template function using the class 'Zombie', I //get an error. //I have tried changing the word typename to class and vice versa. I have //searched up solutions on ...
3
votes
1answer
76 views

Why does std::is_convertible_v return true even though this conversion isn't legal?

I'm working on a C++ project that requires the use of type introspection to determine what sort of object type a template is. In doing so, I ran into an unusual issue. I've isolated the root issue to ...