Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added shared_array constructor from nullptr, per #8894.
- Loading branch information
Showing
3 changed files
with
122 additions
and
1 deletion.
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
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,112 @@ | ||
// | ||
// shared_array nullptr test | ||
// | ||
// Copyright 2012, 2013 Peter Dimov | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// See accompanying file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt | ||
// | ||
|
||
#include <boost/shared_array.hpp> | ||
#include <boost/detail/lightweight_test.hpp> | ||
#include <cstddef> | ||
#include <memory> | ||
|
||
#if !defined( BOOST_NO_CXX11_NULLPTR ) | ||
|
||
struct X | ||
{ | ||
static int instances; | ||
|
||
X() | ||
{ | ||
++instances; | ||
} | ||
|
||
~X() | ||
{ | ||
--instances; | ||
} | ||
|
||
private: | ||
|
||
X( X const & ); | ||
X & operator=( X const & ); | ||
}; | ||
|
||
int X::instances = 0; | ||
|
||
int main() | ||
{ | ||
{ | ||
boost::shared_array<int> p( nullptr ); | ||
|
||
BOOST_TEST( p.get() == 0 ); | ||
BOOST_TEST( p.use_count() == 0 ); | ||
|
||
BOOST_TEST( p == nullptr ); | ||
BOOST_TEST( nullptr == p ); | ||
BOOST_TEST( !( p != nullptr ) ); | ||
BOOST_TEST( !( nullptr != p ) ); | ||
} | ||
|
||
{ | ||
boost::shared_array<int> p( new int[ 1 ] ); | ||
|
||
BOOST_TEST( p.get() != 0 ); | ||
BOOST_TEST( p.use_count() == 1 ); | ||
|
||
BOOST_TEST( p != nullptr ); | ||
BOOST_TEST( nullptr != p ); | ||
BOOST_TEST( !( p == nullptr ) ); | ||
BOOST_TEST( !( nullptr == p ) ); | ||
|
||
p = nullptr; | ||
|
||
BOOST_TEST( p.get() == 0 ); | ||
BOOST_TEST( p.use_count() == 0 ); | ||
|
||
BOOST_TEST( p == nullptr ); | ||
BOOST_TEST( nullptr == p ); | ||
BOOST_TEST( !( p != nullptr ) ); | ||
BOOST_TEST( !( nullptr != p ) ); | ||
} | ||
|
||
{ | ||
BOOST_TEST( X::instances == 0 ); | ||
|
||
boost::shared_array<X> p( new X[ 2 ] ); | ||
BOOST_TEST( X::instances == 2 ); | ||
|
||
BOOST_TEST( p.get() != 0 ); | ||
BOOST_TEST( p.use_count() == 1 ); | ||
|
||
BOOST_TEST( p != nullptr ); | ||
BOOST_TEST( nullptr != p ); | ||
BOOST_TEST( !( p == nullptr ) ); | ||
BOOST_TEST( !( nullptr == p ) ); | ||
|
||
p = nullptr; | ||
BOOST_TEST( X::instances == 0 ); | ||
|
||
BOOST_TEST( p.get() == 0 ); | ||
BOOST_TEST( p.use_count() == 0 ); | ||
|
||
BOOST_TEST( p == nullptr ); | ||
BOOST_TEST( nullptr == p ); | ||
BOOST_TEST( !( p != nullptr ) ); | ||
BOOST_TEST( !( nullptr != p ) ); | ||
} | ||
|
||
return boost::report_errors(); | ||
} | ||
|
||
#else | ||
|
||
int main() | ||
{ | ||
return 0; | ||
} | ||
|
||
#endif |