升压numeric

编程入门 行业动态 更新时间:2024-10-25 04:19:56
本文介绍了升压numeric_cast<>具有默认值,而不是一个异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

每当提升的 numeric_cast<> 转换失败,它抛出一个异常。是否有提振了类似的模板,让我指定一​​个默认值,而不是,或捕捉异常,我可以在这种情况下,唯一能做的?

Whenever boost's numeric_cast<> conversion fails, it throws an exception. Is there a similar template in boost that lets me specify a default value instead, or is catching the exception the only thing I can do in this case?

我不是太担心所有额外的异常处理的表现,但我宁愿使用一个标准的模板比写无用的包装功能。此外,从过去的经验,我认为这很可能是提振居然有我在想什么,我只是还没有发现它。

I'm not too worried about the performance of all the extra exception handling, but I'd rather use a standard template than write useless wrapper functions. Besides, from past experience, I thought it's likely that boost actually has what I'm thinking of, and I simply haven't found it.

推荐答案

的 numeric_cast 函数仅调用boost::numeric::converter模板类的默认参数。其中一个参数是OverflowHandler,和用于该默认值为def_overflow_handler,但是您可以指定silent_overflow_handler共进晚餐preSS例外吧。

The numeric_cast function simply calls the boost::numeric::converter template class with the default arguments. One of the arguments is OverflowHandler, and the default value for that is def_overflow_handler, but you can specify silent_overflow_handler to suppress the exception instead.

然后指定FloatToIntRounder论点,将提供您所需的默认值,如果输入参数超出理想范围。该参数是的正常的用于从浮点型四舍五入提供一个整数,但你真的可以用它来做任何你想要的。更多信息,再加上code描述事件的顺序,在converter文档。

Then specify the FloatToIntRounder argument that will provide your desired default value if the input argument is outside your desired range. The argument is normally used for providing an integer for rounding from a floating-point type, but you can really use it for whatever you want. More information, plus code describing the sequence of events, at the converter documentation.

据我所知,升压没有你在想什么,但它提供了便利,为您建立它自己。

As far as I know, Boost doesn't have what you're thinking of, but it provides the facility for you to build it yourself.

更多推荐

升压numeric

本文发布于:2023-11-17 03:18:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608626.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:numeric

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!