Questions tagged as 'template'

1
answer

Using std :: less with std :: function

I'm trying to meter std::function< > into a std::set< > . For this, we need a function that compares the values entered. As std::function does not provide any comparison operator, I thought about this: #inc...
asked by 08.01.2018 / 15:34
2
answers

Templates for different data in C ++

I'm using templates in C ++ and I'm new to this, so I do not quite understand how to "reuse" functions regardless of the type of data. I have the code shown below: template<typename T> const T &min(const T &a, const T &b)...
asked by 25.05.2018 / 12:43
1
answer

Doubt about SFINAE

How the compiler resolves the case in which it can substitute more than one template and does not give ambiguity using the SFINAE principle. #include <stdio.h> #include <iostream> template<typename T, typename U> U cast(T x)...
asked by 09.10.2018 / 15:52
3
answers

Does not recognize double-float templates

I have this code in which I try to approximate the natural logarithm of a number, but I can not use if , while or for , only the if ternario, but at the time it compiles I'm shot errors that T is ambiguous and th...
asked by 27.09.2018 / 04:21
1
answer

Failures using 'std :: initializer_list' with 'const char *', 'const char * &' and 'std :: string'

I have a simple program that uses a variable template of type std::initializer_list that stores pairs that contain a type and a text: using name_t = const char *; template <typename key_t> using key_name_t = std::pair<key_t, n...
asked by 17.04.2018 / 11:29
1
answer

Extract data without using extra variables

I want to extract a data from a class; Currently, I use an auxiliary variable for it. To work, it works ... but I was wondering if it could be done in another way, saving me the variable inside the function Envoltura::result( ) : #inc...
asked by 15.03.2018 / 21:13
1
answer

Not Suitable User Defined Conversion error with use of templates

I'm doing a program in C ++ that overload the operators. For example, for the operator * you would like it to be multiplied: Cuadrado a(2.1); Circulo b(1.3); Circulo b(4.3); Triangulo x= a * b * c I have created the operation Cuad...
asked by 28.05.2018 / 12:45
2
answers

can members of an object defined as a parameter be accessed in a generic function?

Good morning I am creating a method member of a class, that allows me to receive an object and save the information of the object in a file. MyClase::guardarDatos(Objeto a); Specifically, I need to save three objects that are derived fro...
asked by 28.09.2016 / 21:34
1
answer

Jinja2 check if a value exists in a list of dictionaries

I'm trying to check if a value exists within a dictionary list. Use flask 1.0.2. See the example below: person_list_dict = [ { "name": "John Doe", "email": "[email protected]", "rol": "admin" }, {...
asked by 07.09.2018 / 18:18
1
answer

Builders of a template

A design pattern not very well known is the PassKey pattern that is used mainly to restrict access to certain public functions (the option would be to use friend in the main classes and that produces too much coupling). A basic implementation...
asked by 23.06.2017 / 11:36