ΒΆtemplate <class FromType>
inline constexpr auto into(
    FromType&& from) noexcept

Description

Converts from the given value to whatever a receiver requires. The result will be receivable if [`Into <FromType , ToType>`]($sus::construct::Into) is satisfied where `ToType` is deduced by the type constructed from the return value of `into`. The value returned by `into` should be immediately converted into the desired type, and never held as an lvalue itself. The returned type holds a reference to the input that is used to construct the deduced `ToType` from it. If the argument to `into` is [`Copy`]($sus::mem::Copy) then it will be copied if it is an lvalue or const. If the argument to `into` is an rvalue, it will be moved when constructing the `ToType`. # Examples The `into` function deduces the target type while performing an *explicit* conversion via the [`From`]($sus::construct::From) concept (and thus a static `from` method on the target type). ``` auto f = [](Option <i32 > i) { return i.unwrap_or(-1); }; auto num = 3_i32; // Option <T > can be converted into from its inner type T. sus_check(f(sus::into(num)) == 3); ``` The [`Into`]($sus::construct::Into) concept allows generic code to accept any input type that can be explicitly converted into the target type. The body of the function can use the [`into`]($sus::construct::into) function to perform the conversion. ``` // f() accepts anything that can be converted to Option <i32 > via into(). auto f = [](Into <Option <i32 >> auto in) { return Option <i32 >(sus::into(in)); }; auto num = 3_i32; // num will be passed to Option <i32 >::from() inside f(). sus_check(f(num).unwrap_or(-1) == 3); ```

Declared at: sus/construct/into.h:135

Templates

FromType

Parameters

FromType&& from