diff --git a/doc/container.qbk b/doc/container.qbk index d978b73..5fa5298 100644 --- a/doc/container.qbk +++ b/doc/container.qbk @@ -862,6 +862,31 @@ If you need a memory optimized version of `boost::container::vector`, plea [endsect] +[section:non_standard_memset_initialization Non-standard value initialization using `std::memset`] + +[*Boost.Container] uses `std::memset` with a zero value to initialize some types as in most platforms this +initialization yields to the desired value initialization with improved performance. + +Following the C11 standard, [*Boost.Container] assumes that ['for any integer type, +the object representation where all the bits are zero shall be a representation of the value +zero in that type]. Since `_Bool`/`wchar_t`/`char16_t`/`char32_t` are also integer types in C, it considers +all C++ integral types as initializable via `std::memset`. + +By default, [*Boost.Container] also considers floating point types to be initializable using `std::memset`. +Most platforms are compatible with this initialization, but in case this initialization is not desirable the +user can `#define BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_NOT_ZERO` before including library headers. + +By default, it also considers pointer types (pointer and pointer to function types, excluding +member object and member function pointers) to be initializable using `std::memset`. +Most platforms are compatible with this initialization, but in case this initialization is not desired the +user can `#define BOOST_CONTAINER_MEMZEROED_POINTER_IS_NOT_ZERO` before including library headers. + +If neither `BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_NOT_ZERO` nor +`BOOST_CONTAINER_MEMZEROED_POINTER_IS_NOT_ZERO` is defined [*Boost.Container] also considers POD +types to be value initializable via `std::memset` with value zero. + +[endsect] + [endsect] [section:known_issues Known Issues] diff --git a/include/boost/container/detail/utilities.hpp b/include/boost/container/detail/utilities.hpp index d9ebacd..5aca542 100644 --- a/include/boost/container/detail/utilities.hpp +++ b/include/boost/container/detail/utilities.hpp @@ -396,14 +396,14 @@ struct is_memzero_initializable { typedef typename ::std::iterator_traits::value_type value_type; static const bool value = are_elements_contiguous::value && - ( ::boost::is_integral::value - #if BOOST_CONTAINER_MEMZEROED_POINTER_IS_NULL + ( ::boost::is_integral::value || ::boost::is_enum::value + #if defined(BOOST_CONTAINER_MEMZEROED_POINTER_IS_NULL) || ::boost::is_pointer::value #endif - #if BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_ZERO + #if defined(BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_ZERO) || ::boost::is_floating_point::value #endif - #if BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_ZERO && BOOST_CONTAINER_MEMZEROED_POINTER_IS_NULL + #if defined(BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_ZERO) && defined(BOOST_CONTAINER_MEMZEROED_POINTER_IS_NULL) || ::boost::is_pod::value #endif ); diff --git a/include/boost/container/detail/workaround.hpp b/include/boost/container/detail/workaround.hpp index a12e820..c290861 100644 --- a/include/boost/container/detail/workaround.hpp +++ b/include/boost/container/detail/workaround.hpp @@ -50,12 +50,12 @@ // //If your platform does not offer these guarantees //define these to value zero. -#ifndef BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_ZERO +#ifndef BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_NOT_ZERO #define BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_ZERO 1 #endif -#ifndef BOOST_CONTAINER_MEMZEROED_POINTER_IS_NULL -#define BOOST_CONTAINER_MEMZEROED_POINTER_IS_NULL 1 +#ifndef BOOST_CONTAINER_MEMZEROED_POINTER_IS_NOT_NULL +#define BOOST_CONTAINER_MEMZEROED_POINTER_IS_NULL #endif #include