1// Copyright 2021 Peter Dimov
2// Distributed under the Boost Software License, Version 1.0.
3// https://www.boost.org/LICENSE_1_0.txt
4
5#include <boost/lambda2.hpp>
6#include <boost/core/lightweight_test.hpp>
7#include <sstream>
8#include <string>
9
10template<class T> T from_string_1( std::string const& s )
11{
12 using namespace boost::lambda2;
13
14 std::istringstream is( s );
15
16 T t{};
17
18 ( std::ref( t&: is ) >> _1 )( t );
19
20 return t;
21}
22
23template<class T> T from_string_2( std::string const& s )
24{
25 using namespace boost::lambda2;
26
27 std::istringstream is( s );
28
29 T t{};
30
31 ( is >> _1 )( t );
32
33 return t;
34}
35
36int main()
37{
38 BOOST_TEST_EQ( from_string_1<int>( "123" ), 123 );
39 BOOST_TEST_EQ( from_string_2<int>( "456" ), 456 );
40
41 return boost::report_errors();
42}
43

source code of boost/libs/lambda2/test/stream_extract.cpp