Skip to content

Commit 7541076

Browse files
committed
fixed defaulted moves on older compilers
1 parent 40f7c97 commit 7541076

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

doc/1A_on_performance.qbk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Lifetime of the `T` inside `_storage` is manually controlled with placement-`new
1919
T _storage;
2020
};
2121

22-
We call it a ['direct] storage. This makes `optional<T>` a trivially-copyable type for scalar `T`s. This only works for compilers that support defaulted functions. On compilers without defaulted functions we still use the direct storage, but `optional<T>` is no longer recognized as trivially-copyable. Apart from scalar types, we leave the programmer a way of customizing her type, so that it is reconized by `optional` as candidate for optimized storage, by specializing type trait `boost::opitonal_config::optional_uses_direct_storage_for`:
22+
We call it a ['direct] storage. This makes `optional<T>` a trivially-copyable type for scalar `T`s. This only works for compilers that support defaulted functions (including defaulted move assignment and constructor). On compilers without defaulted functions we still use the direct storage, but `optional<T>` is no longer recognized as trivially-copyable. Apart from scalar types, we leave the programmer a way of customizing her type, so that it is reconized by `optional` as candidate for optimized storage, by specializing type trait `boost::opitonal_config::optional_uses_direct_storage_for`:
2323

2424
struct X // not trivial
2525
{

include/boost/optional/detail/optional_config.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,16 @@
114114
#endif
115115

116116

117-
// Detection of correctly implemented defaulted functions
117+
// Detect suport for defaulting move operations
118+
// (some older compilers implement rvalue references,
119+
// defaulted funcitons but move operations are not special members and cannot be defaulted)
118120

119121
#ifdef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
120-
# define BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_FUNCTIONS
122+
# define BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_MOVE_FUNCTIONS
121123
#elif BOOST_WORKAROUND(BOOST_MSVC, < 1900)
122-
// on MSVC 12.0 move constructor and move assignment are not reconized as special functions
123-
// and they cannot be defaulted
124-
# define BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_FUNCTIONS
124+
# define BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_MOVE_FUNCTIONS
125+
#elif BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40600)
126+
# define BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_MOVE_FUNCTIONS
125127
#endif
126128

127129

test/optional_test_experimental_traits.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "boost/type_traits/is_base_of.hpp"
2121
#include "boost/optional/detail/experimental_traits.hpp"
2222

23-
#ifndef BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_FUNCTIONS
23+
#ifndef BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_MOVE_FUNCTIONS
2424

2525
struct PrivDefault
2626
{
@@ -144,7 +144,7 @@ void test_trivial_copyability()
144144

145145
int main()
146146
{
147-
#ifndef BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_FUNCTIONS
147+
#ifndef BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_MOVE_FUNCTIONS
148148
test_type_traits();
149149
test_trivial_copyability();
150150
#endif

test/optional_test_static_properties.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "boost/type_traits/is_base_of.hpp"
2121
#include "boost/optional/detail/experimental_traits.hpp"
2222

23-
#ifndef BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_FUNCTIONS
23+
#ifndef BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_MOVE_FUNCTIONS
2424

2525
struct PrivDefault
2626
{
@@ -138,7 +138,7 @@ void test_trivial_copyability()
138138

139139
int main()
140140
{
141-
#ifndef BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_FUNCTIONS
141+
#ifndef BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_MOVE_FUNCTIONS
142142
test_type_traits();
143143
test_trivial_copyability();
144144
#endif

0 commit comments

Comments
 (0)