私はSVNのGCCでコンセプトライトを試してきました。私の理解不足が原因であると思われる問題に遭遇しました。誰かが私を正しい方向に向けることができれば幸いです。私のコードは次のとおりです。
#include <iostream>
#include <string>
// Uncomment this declaration to change behaviour
//void draw(const std::string&);
template <typename T>
concept bool Drawable() {
return requires (const T& t) {
{ draw(t) }
};
}
void draw(const std::string& s)
{
std::cout << s << "\n";
}
int main()
{
static_assert(Drawable<std::string>()); // Fails
}
ここでは単純な概念 を定義しますDrawable
。これは、指定された type のパラメーターをconst T&
関数がdraw(t)
コンパイルすることを要求することを目的としています。
draw(const std::string&)
次に、文字列を に「描画」する関数を定義しますcout
。最後に、コンセプトにstd::string
一致するかどうかをチェックします。Drawable
draw()
static_assert
ただし、概念定義のdraw(const std::string&)
前に宣言を含めない限り、静的アサートは失敗し、その理由はわかりません。
これは概念で予想される動作ですか、それとも何か間違っていますか?