std::min
を関数に渡すことはコンパイルされません。 std::min
のlibcpp宣言を私のソースファイルにコピーしています。関数std :: minをstd :: minのコピーに渡すことができません。
stdバージョンで何が問題になっていますか? clangとgccでも同じことが起こります。 godboltでテスト:https://godbolt.org/g/zwRqUA
#include <thread>
#include <algorithm>
namespace mystd {
// declaration copied verbatim from std::min (libcpp 4.0)
template <class _Tp> inline constexpr const _Tp&
mymin(const _Tp& __a, const _Tp& __b)
{
return std::min(__a, __b);
}
}
int main()
{
std::thread thr1(std::min<int>, 2, 3); // compile error
std::thread thr2(mystd::mymin<int>, 2, 3); // works
return 0;
}
打ち鳴らすとgccのためのエラー:
[x86-64 clang 5.0.0 #1] error: no matching constructor for initialization of 'std::thread'
[x86-64 gcc 7.2 #1] error: no matching function for call to 'std::thread::thread(<unresolved overloaded function type>, int, int)'
[x86-64 gcc 7.2 #1] note: couldn't deduce template parameter '_Callable'
この関数は、1つのテンプレートパラメータに対してオーバーロードされます。 –
エラーメッセージが表示されるのは、すでに何が間違っているかがわかります。 – hvd
そして、どうしたの? – Quentin