#include <iostream>
#include <boost/smart_ptr/intrusive_ptr.hpp>
#include <boost/smart_ptr/intrusive_ref_counter.hpp>
template<class T>
struct wrapper
{
wrapper() = default;
wrapper(boost::intrusive_ptr<T> const& p) : _p(p) {}
boost::intrusive_ptr<T> const& get_ptr() const
{
#if 0
// This is OK.
if (_p)
return _p;
return nullptr;
#else
// Strange behavior.
return _p ? _p : nullptr;
#endif
}
private:
boost::intrusive_ptr<T> _p;
};
struct W : boost::intrusive_ref_counter<W>
{
};
template<class T1, class T2>
inline void test(wrapper<T1> const& s1, wrapper<T2> const& s2)
{
auto tup = std::make_tuple(s1.get_ptr(), s2.get_ptr());
std::cout << 0 << ":" << (void*)std::get<0>(tup).get() << "\n";
std::cout << 1 << ":" << (void*)std::get<1>(tup).get() << "\n";
}
int main()
{
wrapper<W> a(new W), b(new W);
test(a, b);
return 0;
}