P
P
Pavel2016-02-05 16:53:07
C++ / C#
Pavel, 2016-02-05 16:53:07

How can you get the "subtype" of a variable in c++?

I pass a variable of type to the template function vector<double>, is there any way to get information that it is a double? the type of the vector itself, not the type of the variable.

//////////////////////////////////////////////////////////////////////////////////
  //Задание 5. Реализовать функцию сортировки по модулю элементов последовательностей, заданных ниже
  //Собственно для сортировки можно использовать обобщенный алгоритм sort(), 
  //а для задания условия - лямбда-функцию
  {
    std::vector<double> vd = { -3.3,  2.2, -1.1 };
    absSort(vd);


    int ar[] = { -3, 2, -1 };
    absSort(ar);

    __asm nop                                                                                                                                                                              
  }

template<typename Type>
void absSort(Type& input)
{
  sort(begin(input), end(input), [](Type a, Type b)
  {
    return (abs(a) < abs(b));
  });
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Mischuk, 2014-09-28
@Mischuk

Everything is pretty simple here. The color buttons are just plain dotted navigation.
Ready-made 3d-carousels are also full. This guide
helped me a lot . I suggest writing it yourself, rather than looking for a ready-made solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question