简体   繁体   English

如果我没有返回未知类型的东西,我应该返回什么

[英]what should I return if I don't have something to return for an unknown type

For the following code, what should I return if I don't have something to return ? 对于以下代码,如果我没有要返回的内容,应该返回什么? Currently, I do something like T() but I'm not sure it's correct and proper. 目前,我做的事情就像T(),但我不确定它是否正确。

template<typename T1, typename T2>
tuple<T1, T2, bool> CBR<T1, T2>::getSomething(T1 t)
{
    // here I I don't have something of time T2 or T2 to return
    if( ... )
        return make_tuple(T1(), T2(), false); // @FIXME

    if( ... )
        return make_tuple(something.tp, something.ts, false);
    else
        return make_tuple(something.tp, something.ts, true);
}
boost::optional<tuple<T1, T2, bool> >

The "good" return paths will be unchanged; “良好”的回归路径将保持不变; the "FIXME" one will become: “FIXME”将成为:

return boost::none;

This can allow your class to be used with types that do not support default construction. 这可以允许您的类与不支持默认构造的类型一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果我想找到一些东西但不希望它最后返回,我应该使用哪种STL算法? - Which STL Algorithm should i use if I want to find something but Don't want it to return last if not found? 我不明白什么是回报 - I don't understand what's return for 如果我不知道变量的类型而必须声明一个变量,我该怎么办? - What should I do if I have to declare a variable when I don't know the type for it? 如果我不想在QAbstractItemView中实现选择,应该返回什么值? - What values should I return if I don't want to implement selections in a QAbstractItemView? 当函数没有返回值时,返回类型应该是什么? - What should the return type be when the function might not have a value to return? 如果我不将其存储在任何地方,返回值会怎样? - What happens to the return value if I don't store it anywhere? 我应该为指针分配使用哪种返回类型? - What return type should I use for a pointer assignment? 我应该从静态成员方法返回什么类型的指针 - What type of pointer should I return from static member method Netbeans没有捕获应该返回一些东西但没有返回语句的函数错误 - Netbeans didn't catch error for function that should have return something, not having a return statment 我的退货陈述书有错误,我不知道要解决 - I have an error with my return statements that I don't know to fix
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM