Directly initialize variable from std::istream
There are corner cases where this will not work or even worse produce silent errors.


The function as it is, depends on the client to check for errors on the stream (either by calling std::cin.exceptions(std::ifstream::failbit); or by checking the stream state, after the call to get).

Ideally, I would want to write:

if(auto a = get&lt;int&gt;(std::cin))
    // use a here


Maybe you could add something like this to your solution:

template&lt;class T&gt;
boost::optional&lt;T&gt; get_optional(std::istream&amp; in){
    T tmp;
    in &gt;&gt; tmp;
    return (in) ?
        boost::optional&lt;T&gt;{ std::move(tmp) } :
        boost::optional&lt;T&gt;{};
}