Date: Tue, 27 Dec 2022 08:46:30 -0300
On Tuesday, 27 December 2022 08:07:27 -03 Frederick Virchanza Gotham via Std-
Proposals wrote:
> template<typename T> catch(T &obj)
> {
> if constexpr ( requires { obj.what(); } )
> {
> cout << obj.what() << endl;
> }
> else
> {
> cout << "Thrown object is a " << typeid(T).name() << " and its
> value is " << obj << endl;
> }
> }
Exception matching is a dynamic feature, based on RTTI. Templates are a
compile-time feature. Your idea is nice, but impossible.
Instead, just use what polymorphism was invented for.
Proposals wrote:
> template<typename T> catch(T &obj)
> {
> if constexpr ( requires { obj.what(); } )
> {
> cout << obj.what() << endl;
> }
> else
> {
> cout << "Thrown object is a " << typeid(T).name() << " and its
> value is " << obj << endl;
> }
> }
Exception matching is a dynamic feature, based on RTTI. Templates are a
compile-time feature. Your idea is nice, but impossible.
Instead, just use what polymorphism was invented for.
-- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org Software Architect - Intel DCAI Cloud Engineering
Received on 2022-12-27 11:46:33