template-deduction

How to define template parameters for a generic lambda argument? [duplicate]

守給你的承諾、 提交于 2019-12-02 07:54:03
问题 This question already has an answer here : Constructing std::function argument from lambda (1 answer) Closed 7 months ago . Explanation: CLion and it's standard compiler give me an error that the "candidate template [is] ignored", when I write a lambda as parameter for a generic function that takes a lambda as argument. This lambda takes a generic type T and returns another unknown type A . The container class that I am writing is supposed to support functional operations like these in Scala

How to define template parameters for a generic lambda argument? [duplicate]

故事扮演 提交于 2019-12-02 04:12:21
This question already has an answer here: Constructing std::function argument from lambda 1 answer Explanation: CLion and it's standard compiler give me an error that the "candidate template [is] ignored", when I write a lambda as parameter for a generic function that takes a lambda as argument. This lambda takes a generic type T and returns another unknown type A . The container class that I am writing is supposed to support functional operations like these in Scala or the ones from the Java Stream API. To be exact: The map function makes huge problems. It is implemented as a member function

no matching function call for selection sort function with templates(C++)

大憨熊 提交于 2019-12-02 02:14:01
问题 I'm playing around with templates and I was wondering why I'm getting a no matching function error using templates. /*selection sort*/ template <typename InputIterator, typename T> void selection_sort(InputIterator first, InputIterator last){ InputIterator min; for(; first != last - 1; ++first){ min = first; for(T i = (first + 1); i != last ; ++i) { if(*first < *min) min = i; } myswap(*first, *min); } } int main(){ int a[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; vector<int> v(a, a+10); selection

no matching function call for selection sort function with templates(C++)

ぐ巨炮叔叔 提交于 2019-12-01 23:10:57
I'm playing around with templates and I was wondering why I'm getting a no matching function error using templates. /*selection sort*/ template <typename InputIterator, typename T> void selection_sort(InputIterator first, InputIterator last){ InputIterator min; for(; first != last - 1; ++first){ min = first; for(T i = (first + 1); i != last ; ++i) { if(*first < *min) min = i; } myswap(*first, *min); } } int main(){ int a[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; vector<int> v(a, a+10); selection_sort(v.begin(),v.end()); } TemplateRex You have an undeduced template parameter T, so you need 1) move

Is it possible to deduce whether type is incomplete without compilation failure?

…衆ロ難τιáo~ 提交于 2019-12-01 20:12:36
I want to achieve behavior like sizeof(complete_type) will return real sizeof, and sizeof(incomplete_type) - will be just 0 I need this to provide extended run time type information for IPC(inter-process) communication with the description structure per type: struct my_type_info { bool is_pointer; size_t size; //for double* will be 4 on i386. that is sizeof(double*) size_t base_size; //for double* will be 8. that is sizeof(double) }; The problem appears when into my system goes something like class MyOnlyDeclaredClass; I got compilation error, obviously by reason I can't take size of it. boost

C++ template parameter deduction for std::array with non size_t integer

心已入冬 提交于 2019-12-01 17:55:40
I'm trying to adapt the solution presented in Avoiding struct in variadic template function to my need. However, I can't understand the the behavior of G++. Consider the following function: template <typename T, unsigned Size> int nextline(const typename std::array<T, Size> ar) { return 0; } Then the call nextline(std::array<int, 2> { 1,0 }); doesn't match with GCC complaining with eslong.cpp: In function ‘int main()’: eslong.cpp:10:38: error: no matching function for call to ‘nextline(std::array<int, 2ul>)’ nextline(std::array<int, 2> { 1,0 }); ^ eslong.cpp:10:38: note: candidate is: eslong

C++ template parameter deduction for std::array with non size_t integer

允我心安 提交于 2019-12-01 16:46:28
问题 I'm trying to adapt the solution presented in Avoiding struct in variadic template function to my need. However, I can't understand the the behavior of G++. Consider the following function: template <typename T, unsigned Size> int nextline(const typename std::array<T, Size> ar) { return 0; } Then the call nextline(std::array<int, 2> { 1,0 }); doesn't match with GCC complaining with eslong.cpp: In function ‘int main()’: eslong.cpp:10:38: error: no matching function for call to ‘nextline(std:

Return double or complex<double> from template function

。_饼干妹妹 提交于 2019-12-01 06:41:25
I am writing some function templates to overload the * operator for a matrix class. I do a lot of work with matrices of type double and complex<double> . Is it possible to write a single template function that returns the correct type? For example: template<class T, class U, class V> matrix<V> operator*(const T a, const matrix<U> A) { matrix<V> B(A.size(1),A.size(2)); for(int ii = 0; ii < B.size(1); ii++) { for(int jj = 0; jj < B.size(2); jj++) { B(ii,jj) = a*A(ii,jj); } } return B; } I would like the return type V to be determined by the natural result of T*U . Is this possible? EDIT: A

Can't deduce template type

孤街浪徒 提交于 2019-11-30 18:58:59
I'm trying to pass an iterator as a template parameter to a template method, but the compiler complains that: error C2783: 'void Test::Assert(std::vector<T>::const_iterator)': could not deduce template argument for 'T' The code that produces the error is: #include "stdafx.h" #include <iostream> #include <vector> class Test { public: template <typename T> void Assert(typename std::vector<T>::const_iterator it) { std::cout << *it << std::endl; } }; int _tmain(int argc, _TCHAR* argv[]) { Test test; std::vector<double> myVec; test.Assert(myVec.cbegin()); return 0; } I'm guessing there is a simple

C++ pointer-to-method template deduction doesn't compile when targeting x86, but works with x64

眉间皱痕 提交于 2019-11-30 04:44:14
问题 I've got this sample code: struct A { int foo() { return 27; } }; template<typename T> struct Gobstopper { }; template<> struct Gobstopper<int(void)> { Gobstopper(int, int) { } // To differentiate from general Gobstopper template }; template<typename ClassType, typename Signature> void DeduceMethodSignature(Signature ClassType::* method, ClassType& instance) { // If Signature is int(), Gobstopper<> should resolve to the specialized one. // But it only does on x64! Gobstopper<Signature>(1, 2);