Update tests with std::ref(is), std::ref(os)

This commit is contained in:
Peter Dimov 2021-09-05 03:01:31 +03:00
parent f2ab3ade7c
commit d6389b60f5
2 changed files with 30 additions and 4 deletions

View File

@ -7,7 +7,20 @@
#include <sstream>
#include <string>
template<class T> T from_string( std::string const& s )
template<class T> T from_string_1( std::string const& s )
{
using namespace boost::lambda2;
std::istringstream is( s );
T t{};
( std::ref( is ) >> _1 )( t );
return t;
}
template<class T> T from_string_2( std::string const& s )
{
using namespace boost::lambda2;
@ -22,7 +35,8 @@ template<class T> T from_string( std::string const& s )
int main()
{
BOOST_TEST_EQ( from_string<int>( "123" ), 123 );
BOOST_TEST_EQ( from_string_1<int>( "123" ), 123 );
BOOST_TEST_EQ( from_string_2<int>( "456" ), 456 );
return boost::report_errors();
}

View File

@ -7,7 +7,18 @@
#include <sstream>
#include <string>
template<class T> std::string to_string( T const& t )
template<class T> std::string to_string_1( T const& t )
{
using namespace boost::lambda2;
std::ostringstream os;
( std::ref( os ) << _1 )( t );
return os.str();
}
template<class T> std::string to_string_2( T const& t )
{
using namespace boost::lambda2;
@ -20,7 +31,8 @@ template<class T> std::string to_string( T const& t )
int main()
{
BOOST_TEST_EQ( to_string( 123 ), "123" );
BOOST_TEST_EQ( to_string_1( 123 ), "123" );
BOOST_TEST_EQ( to_string_2( 456 ), "456" );
return boost::report_errors();
}