Reputation: 10483
Here I've implemented a templated function and a templated Lambda. I've started exploring C++14 features and not sure what's wrong with the following lambda. Any suggestions?
#include <iostream>
#include <random>
#include <algorithm>
#include <functional>
template<class T = std::mt19937, std::size_t N = T::state_size>
auto MersenneEngine() {
return T(N);
}
template<class T = std::mt19937, std::size_t N = T::state_size>
auto MersenneEngineLambda = []() {
return T(N);
};
int main() {
// your code goes here
std::cout << MersenneEngine<std::mt19937>() << std::endl;
std::cout << MersenneEngineLambda<std::mt19937>() << std::endl; // Compilation error : error: use of 'MersenneEngineLambda<std::mersenne_twister_engine...before deduction of 'auto'
return 0;
}
Here's the complete code http://ideone.com/lveJRN
Upvotes: 0
Views: 231
Reputation: 385144
The code is fine.
You are witnessing a bug in your version of GCC (5.1). This is not highly surprising given that variable templates were brand new in GCC 5.
Empirically, it was fixed either in or before GCC 6.1.1.
Bug 67041 (and, more directly, its dupe bug 67350) looks potentially relevant.
Upvotes: 4