-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sp_ostream_test, ip_ostream_test, lsp_ostream_test
- Loading branch information
Showing
4 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2011, 2025 Peter Dimov | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#include <boost/intrusive_ptr.hpp> | ||
#include <boost/core/lightweight_test.hpp> | ||
#include <sstream> | ||
|
||
class base | ||
{ | ||
private: | ||
|
||
int use_count_; | ||
|
||
base(base const &); | ||
base & operator=(base const &); | ||
|
||
protected: | ||
|
||
base(): use_count_(0) | ||
{ | ||
} | ||
|
||
virtual ~base() | ||
{ | ||
} | ||
|
||
public: | ||
|
||
long use_count() const | ||
{ | ||
return use_count_; | ||
} | ||
|
||
inline friend void intrusive_ptr_add_ref(base * p) | ||
{ | ||
++p->use_count_; | ||
} | ||
|
||
inline friend void intrusive_ptr_release(base * p) | ||
{ | ||
if(--p->use_count_ == 0) delete p; | ||
} | ||
}; | ||
|
||
struct X: public base | ||
{ | ||
}; | ||
|
||
template<class T> std::string to_string( T const& t ) | ||
{ | ||
std::ostringstream os; | ||
os << t; | ||
return os.str(); | ||
} | ||
|
||
int main() | ||
{ | ||
boost::intrusive_ptr<X> p1, p2( new X ); | ||
|
||
BOOST_TEST_EQ( to_string( p1 ), to_string( p1.get() ) ); | ||
BOOST_TEST_EQ( to_string( p2 ), to_string( p2.get() ) ); | ||
|
||
return boost::report_errors(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2025 Peter Dimov | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#include <boost/smart_ptr/local_shared_ptr.hpp> | ||
#include <boost/core/lightweight_test.hpp> | ||
#include <sstream> | ||
|
||
template<class T> std::string to_string( T const& t ) | ||
{ | ||
std::ostringstream os; | ||
os << t; | ||
return os.str(); | ||
} | ||
|
||
int main() | ||
{ | ||
boost::local_shared_ptr<int> p1, p2( new int ); | ||
|
||
BOOST_TEST_EQ( to_string( p1 ), to_string( p1.get() ) ); | ||
BOOST_TEST_EQ( to_string( p2 ), to_string( p2.get() ) ); | ||
|
||
return boost::report_errors(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2025 Peter Dimov | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#include <boost/shared_ptr.hpp> | ||
#include <boost/core/lightweight_test.hpp> | ||
#include <sstream> | ||
|
||
template<class T> std::string to_string( T const& t ) | ||
{ | ||
std::ostringstream os; | ||
os << t; | ||
return os.str(); | ||
} | ||
|
||
int main() | ||
{ | ||
boost::shared_ptr<int> p1, p2( new int ); | ||
|
||
BOOST_TEST_EQ( to_string( p1 ), to_string( p1.get() ) ); | ||
BOOST_TEST_EQ( to_string( p2 ), to_string( p2.get() ) ); | ||
|
||
return boost::report_errors(); | ||
} |