////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2014-2014. 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) // // See http://www.boost.org/libs/container for documentation. // ////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace boost::container; typedef boost::container::dtl::aligned_storage::type buffer_t; static buffer_t buffer_0x00; static buffer_t buffer_0xFF; template const Iterator &on_0x00_buffer() { BOOST_STATIC_ASSERT(sizeof(buffer_t) >= sizeof(Iterator)); return * ::new(std::memset(&buffer_0x00, 0x00, sizeof(buffer_0x00))) Iterator(); } template const Iterator &on_0xFF_buffer() { BOOST_STATIC_ASSERT(sizeof(buffer_t) >= sizeof(Iterator)); return * ::new(std::memset(&buffer_0xFF, 0xFF, sizeof(buffer_0xFF))) Iterator(); } namespace boost { namespace container { namespace test { BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(reverse_iterator) BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(const_reverse_iterator) }}} //namespace boost::container::test { template void check_plus_zero_impl(RandomAccessIterator it) { RandomAccessIterator cpy(it + 0); BOOST_TEST(cpy == it); } template void check_plus_zero(const Category&) {} template void check_plus_zero(const std::random_access_iterator_tag&) { check_plus_zero_impl(typename Container::iterator()); check_plus_zero_impl(typename Container::const_iterator()); check_plus_zero_impl(typename Container::reverse_iterator()); check_plus_zero_impl(typename Container::const_reverse_iterator()); Container c; check_plus_zero_impl(c.begin()); check_plus_zero_impl(c.cbegin()); check_plus_zero_impl(c.rbegin()); check_plus_zero_impl(c.crbegin()); } template void check_plus_zero() { typedef typename Container::iterator iterator; typedef typename std::iterator_traits::iterator_category category; category tag; check_plus_zero(tag); } template void check_null_iterators() { typedef typename Container::iterator iterator; typedef typename Container::const_iterator const_iterator; typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT (boost::container::test::, Container ,reverse_iterator, iterator) reverse_iterator; typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT (boost::container::test::, Container ,const_reverse_iterator, const_iterator) const_reverse_iterator; BOOST_TEST(on_0xFF_buffer() == on_0x00_buffer()); BOOST_TEST(on_0xFF_buffer() == on_0x00_buffer()); BOOST_TEST(on_0xFF_buffer() == on_0x00_buffer()); BOOST_TEST(on_0xFF_buffer() == on_0x00_buffer()); } int main() { check_null_iterators< vector >(); check_plus_zero< vector >(); check_null_iterators< deque >(); check_plus_zero< deque >(); check_null_iterators< stable_vector >(); check_plus_zero< stable_vector >(); check_null_iterators< static_vector >(); check_plus_zero< static_vector >(); check_null_iterators< string >(); check_plus_zero< string >(); check_null_iterators< list >(); check_plus_zero< list >(); check_null_iterators< slist >(); check_plus_zero< slist >(); check_null_iterators< map >(); check_plus_zero< map >(); check_null_iterators< multimap >(); check_plus_zero< multimap >(); check_null_iterators< set >(); check_plus_zero< set >(); check_null_iterators< multiset >(); check_plus_zero< multiset >(); check_null_iterators< flat_set >(); check_plus_zero< flat_set >(); check_null_iterators< flat_multiset >(); check_plus_zero< flat_multiset >(); check_null_iterators< flat_map >(); check_plus_zero< flat_map >(); check_null_iterators< flat_multimap >(); check_plus_zero< flat_multimap >(); return boost::report_errors(); }