template-function

Why doesn't C++11 implicitly convert lambdas to std::function objects?

被刻印的时光 ゝ 提交于 2019-11-30 14:41:59
问题 I implemented a generic event emitter class which allows code to register callbacks, and emit events with arguments. I used Boost.Any type erasure to store the callbacks so they can have arbitrary parameter signatures. It all works, but for some reason, lambdas being passed in must first be turned into std::function objects. Why doesn't the compiler infer that the lambda is the function type? Is it because of the way I use variadic templates? I use Clang (version string: Apple LLVM version 5

Why doesn't ADL find function templates?

試著忘記壹切 提交于 2019-11-26 04:21:32
What part of the C++ specification restricts argument dependent lookup from finding function templates in the set of associated namespaces? In other words, why does the last call in main below fail to compile? namespace ns { struct foo {}; template<int i> void frob(foo const&) {} void non_template(foo const&) {} } int main() { ns::foo f; non_template(f); // This is fine. frob<0>(f); // This is not. } This part explains it: C++ Standard 03 14.8.1.6 : [Note: For simple function names, argument dependent lookup (3.4.2) applies even when the function name is not visible within the scope of the

Why doesn&#39;t ADL find function templates?

微笑、不失礼 提交于 2019-11-26 01:15:44
问题 What part of the C++ specification restricts argument dependent lookup from finding function templates in the set of associated namespaces? In other words, why does the last call in main below fail to compile? namespace ns { struct foo {}; template<int i> void frob(foo const&) {} void non_template(foo const&) {} } int main() { ns::foo f; non_template(f); // This is fine. frob<0>(f); // This is not. } 回答1: This part explains it: C++ Standard 03 14.8.1.6 : [Note: For simple function names,