Add operator==, operator!= to source_location

This commit is contained in:
Peter Dimov
2022-05-05 03:25:16 +03:00
parent f1a6f9ffd1
commit a7af7efe51
3 changed files with 33 additions and 0 deletions

View File

@ -115,6 +115,15 @@ public:
# pragma warning( pop )
#endif
inline friend bool operator==( source_location const& s1, source_location const& s2 ) BOOST_NOEXCEPT
{
return std::strcmp( s1.file_, s2.file_ ) == 0 && std::strcmp( s1.function_, s2.function_ ) == 0 && s1.line_ == s2.line_ && s1.column_ == s2.column_;
}
inline friend bool operator!=( source_location const& s1, source_location const& s2 ) BOOST_NOEXCEPT
{
return !( s1 == s2 );
}
};
template<class E, class T> std::basic_ostream<E, T> & operator<<( std::basic_ostream<E, T> & os, source_location const & loc )

View File

@ -42,3 +42,4 @@ run source_location_test2.cpp ;
run source_location_test3.cpp ;
run source_location_test4.cpp ;
run source_location_test5.cpp ;
run source_location_test6.cpp ;

View File

@ -0,0 +1,23 @@
// Copyright 2019 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/assert/source_location.hpp>
#include <boost/core/lightweight_test.hpp>
int main()
{
{
boost::source_location loc, loc2;
BOOST_TEST_EQ( loc, loc2 );
boost::source_location loc3 = BOOST_CURRENT_LOCATION;
boost::source_location loc4( loc3 );
BOOST_TEST_EQ( loc3, loc4 );
BOOST_TEST_NE( loc3, loc );
}
return boost::report_errors();
}