ストリームとコンセプト
ストリームとコンセプトを組み合わせてみた。
#include <iostream> #include <concepts> auto concept HasShowing<typename T> { requires std::HasLeftShift<std::ostream&, T>; } template <HasShowing T> void show(T x) { std::cout << x; } int main() { show('A'); show("abc"); //show(123); // ambiguous //show(3.14); // ambiguous //show(main); // no match }
intとdoubleが曖昧になる理由はよく分からない。showの中身をlate_checkで囲ってやれば、とりあえずコンパイルは通る。
現在のドラフトでは、ストリーム系のクラスにコンセプトがあまり使われていない。後々の対応に期待したい。