Можете ли вы использовать концепции C++ так же, как и полиморфные интерфейсы? ⇐ C++
-
Anonymous
Можете ли вы использовать концепции C++ так же, как и полиморфные интерфейсы?
I have just stumbled over C++20's "concepts", something that I've wanted in the language for years... well kind of.
Consider the code below:
#include #include template concept IFoo = requires(T t) { { t.foo() } -> std::convertible_to; }; class FooImpl { public: int foo() const { return 3; } }; template void doSomething(const Foo& foo) { std::cout
Источник: https://stackoverflow.com/questions/780 ... interfaces
I have just stumbled over C++20's "concepts", something that I've wanted in the language for years... well kind of.
Consider the code below:
#include #include template concept IFoo = requires(T t) { { t.foo() } -> std::convertible_to; }; class FooImpl { public: int foo() const { return 3; } }; template void doSomething(const Foo& foo) { std::cout
Источник: https://stackoverflow.com/questions/780 ... interfaces
Мобильная версия