boostorg / system

Boost.org system module
http://boost.org/libs/system
35 stars 86 forks source link

Is conversion from result<T> to result<U> a valid use-case? #82

Closed ytimenkov closed 2 years ago

ytimenkov commented 2 years ago

Working with generic code it may be beneficial if result<T> can be implicitly converted to result<U> if such conversion is allowed for underlying T and U.

For example:

void f(result<std::size_t> ec)
{
}

template<typename T>
void g(T&& arg)
{
    f(result<std::decay_t<T>>{arg});
}

int main()
{
    g(0);

    return 0;
}

results in error

error: could not convert 'boost::system::result<int, boost::system::error_code>((* & arg))' from 'result<int,[...]>' to 'result<long unsigned int,[...]>'

This mostly needed for generic code, where it is impossible (or at least very hard) which type the final function really accepts and argument (or result) may be passed through multiple forwarding functions.

pdimov commented 2 years ago

The converting constructor is implemented on the develop branch now.

pdimov commented 2 years ago

Has been merged to master, should be in 1.80.